changeset 9e556fb25900 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=9e556fb25900
description:
        Change interface between coherence protocols and CacheMemory
        The purpose of this patch is to change the way CacheMemory interfaces 
with
        coherence protocols. Currently, whenever a cache controller (defined in 
the
        protocol under consideration) needs to carry out any operation on a 
cache
        block, it looks up the tag hash map and figures out whether or not the 
block
        exists in the cache. In case it does exist, the operation is carried out
        (which requires another lookup). As observed through profiling of 
different
        protocols, multiple such lookups take place for a given cache block. It 
was
        noted that the tag lookup takes anything from 10% to 20% of the 
simulation
        time. In order to reduce this time, this patch is being posted.

        I have to acknowledge that the many of the thoughts that went in to this
        patch belong to Brad.

        Changes to CacheMemory, TBETable and AbstractCacheEntry classes:
        1. The lookup function belonging to CacheMemory class now returns a 
pointer
        to a cache block entry, instead of a reference. The pointer is NULL in 
case
        the block being looked up is not present in the cache. Similar change 
has
        been carried out in the lookup function of the TBETable class.
        2. Function for setting and getting access permission of a cache block 
have
        been moved from CacheMemory class to AbstractCacheEntry class.
        3. The allocate function in CacheMemory class now returns pointer to the
        allocated cache entry.

        Changes to SLICC:
        1. Each action now has implicit variables - cache_entry and tbe. 
cache_entry,
        if != NULL, must point to the cache entry for the address on which the 
action
        is being carried out. Similarly, tbe should also point to the 
transaction
        buffer entry of the address on which the action is being carried out.
        2. If a cache entry or a transaction buffer entry is passed on as an
        argument to a function, it is presumed that a pointer is being passed 
on.
        3. The cache entry and the tbe pointers received __implicitly__ by the
        actions, are passed __explicitly__ to the trigger function.
        4. While performing an action, set/unset_cache_entry, set/unset_tbe are 
to
        be used for setting / unsetting cache entry and tbe pointers 
respectively.
        5. is_valid() and is_invalid() has been made available for testing 
whether
        a given pointer 'is not NULL' and 'is NULL' respectively.
        6. Local variables are now available, but they are assumed to be 
pointers
        always.
        7. It is now possible for an object of the derieved class to make calls 
to
        a function defined in the interface.
        8. An OOD token has been introduced in SLICC. It is same as the NULL 
token
        used in C/C++. If you are wondering, OOD stands for Out Of Domain.
        9. static_cast can now taken an optional parameter that asks for 
casting the
        given variable to a pointer of the given type.
        10. Functions can be annotated with 'return_by_pointer=yes' to return a
        pointer.
        11. StateMachine has two new variables, EntryType and TBEType. 
EntryType is
        set to the type which inherits from 'AbstractCacheEntry'. There can 
only be
        one such type in the machine. TBEType is set to the type for which 
'TBE' is
        used as the name.

        All the protocols have been modified to conform with the new interface.

diffstat:

 src/mem/protocol/MESI_CMP_directory-L1cache.sm     |  234 ++++---
 src/mem/protocol/MESI_CMP_directory-L2cache.sm     |  308 ++++++----
 src/mem/protocol/MESI_CMP_directory-dir.sm         |   49 +-
 src/mem/protocol/MI_example-cache.sm               |  112 ++-
 src/mem/protocol/MI_example-dir.sm                 |   72 +-
 src/mem/protocol/MOESI_CMP_directory-L1cache.sm    |  313 ++++++-----
 src/mem/protocol/MOESI_CMP_directory-L2cache.sm    |  570 ++++++++++----------
 src/mem/protocol/MOESI_CMP_directory-dir.sm        |   72 +-
 src/mem/protocol/MOESI_CMP_directory-dma.sm        |   40 +-
 src/mem/protocol/MOESI_CMP_token-L1cache.sm        |  573 +++++++++++---------
 src/mem/protocol/MOESI_CMP_token-L2cache.sm        |  325 ++++++-----
 src/mem/protocol/MOESI_CMP_token-dir.sm            |  119 ++-
 src/mem/protocol/MOESI_hammer-cache.sm             |  434 +++++++++------
 src/mem/protocol/MOESI_hammer-dir.sm               |  279 ++++++---
 src/mem/protocol/RubySlicc_Types.sm                |    7 +-
 src/mem/ruby/slicc_interface/AbstractCacheEntry.cc |   17 +
 src/mem/ruby/slicc_interface/AbstractCacheEntry.hh |    7 +-
 src/mem/ruby/system/CacheMemory.cc                 |   64 +-
 src/mem/ruby/system/CacheMemory.hh                 |   11 +-
 src/mem/ruby/system/TBETable.hh                    |   17 +-
 src/mem/slicc/ast/ActionDeclAST.py                 |   19 +-
 src/mem/slicc/ast/FormalParamAST.py                |   16 +-
 src/mem/slicc/ast/FuncCallExprAST.py               |   53 +-
 src/mem/slicc/ast/IfStatementAST.py                |    4 +
 src/mem/slicc/ast/InPortDeclAST.py                 |   14 +-
 src/mem/slicc/ast/IsValidPtrExprAST.py             |   53 +
 src/mem/slicc/ast/LocalVariableAST.py              |   54 +
 src/mem/slicc/ast/MethodCallExprAST.py             |   95 ++-
 src/mem/slicc/ast/OodAST.py                        |   40 +
 src/mem/slicc/ast/ReturnStatementAST.py            |    2 +-
 src/mem/slicc/ast/StaticCastAST.py                 |    8 +-
 src/mem/slicc/ast/TypeDeclAST.py                   |    5 +
 src/mem/slicc/ast/__init__.py                      |    3 +
 src/mem/slicc/parser.py                            |   25 +-
 src/mem/slicc/symbols/Func.py                      |    4 +
 src/mem/slicc/symbols/StateMachine.py              |  241 ++++++++-
 36 files changed, 2600 insertions(+), 1659 deletions(-)

diffs (truncated from 8991 to 300 lines):

diff -r 696063d6ed04 -r 9e556fb25900 
src/mem/protocol/MESI_CMP_directory-L1cache.sm
--- a/src/mem/protocol/MESI_CMP_directory-L1cache.sm    Sat Jan 15 15:30:34 
2011 -0800
+++ b/src/mem/protocol/MESI_CMP_directory-L1cache.sm    Mon Jan 17 18:46:16 
2011 -0600
@@ -36,8 +36,6 @@
    int l1_response_latency = 2,
    int to_l2_latency = 1
 {
-
-
   // NODE L1 CACHE
   // From this node's L1 cache TO the network
   // a local L1 -> this L2 bank, currently ordered with directory forwarded 
requests
@@ -135,65 +133,63 @@
   int cache_state_to_int(State state);
   int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
 
+  void set_cache_entry(AbstractCacheEntry a);
+  void unset_cache_entry();
+  void set_tbe(TBE a);
+  void unset_tbe();
+
   // inclusive cache returns L1 entries only
-  Entry getL1CacheEntry(Address addr), return_by_ref="yes" {
-    if (L1DcacheMemory.isTagPresent(addr)) {
-      return static_cast(Entry, L1DcacheMemory[addr]);
-    } else {
-      return static_cast(Entry, L1IcacheMemory[addr]);
+  Entry getCacheEntry(Address addr), return_by_pointer="yes" {
+    Entry L1Dcache_entry := static_cast(Entry, "pointer", 
L1DcacheMemory[addr]);
+    if(is_valid(L1Dcache_entry)) {
+      return L1Dcache_entry;
     }
+
+    Entry L1Icache_entry := static_cast(Entry, "pointer", 
L1IcacheMemory[addr]);
+    return L1Icache_entry;
   }
 
-  void changeL1Permission(Address addr, AccessPermission permission) {
-    if (L1DcacheMemory.isTagPresent(addr)) {
-      return L1DcacheMemory.changePermission(addr, permission);
-    } else if(L1IcacheMemory.isTagPresent(addr)) {
-      return L1IcacheMemory.changePermission(addr, permission);
-    } else {
-      error("cannot change permission, L1 block not present");
-    }
+  Entry getL1DCacheEntry(Address addr), return_by_pointer="yes" {
+    Entry L1Dcache_entry := static_cast(Entry, "pointer", 
L1DcacheMemory[addr]);
+    return L1Dcache_entry;
   }
 
-  bool isL1CacheTagPresent(Address addr) {
-    return (L1DcacheMemory.isTagPresent(addr) || 
L1IcacheMemory.isTagPresent(addr));
+  Entry getL1ICacheEntry(Address addr), return_by_pointer="yes" {
+    Entry L1Icache_entry := static_cast(Entry, "pointer", 
L1IcacheMemory[addr]);
+    return L1Icache_entry;
   }
 
-  State getState(Address addr) {
-//    if((L1DcacheMemory.isTagPresent(addr) && 
L1IcacheMemory.isTagPresent(addr)) == true){
-//      DEBUG_EXPR(id);
-//      DEBUG_EXPR(addr);
-//    }
+  State getState(TBE tbe, Entry cache_entry, Address addr) {
     assert((L1DcacheMemory.isTagPresent(addr) && 
L1IcacheMemory.isTagPresent(addr)) == false);
 
-    if(L1_TBEs.isPresent(addr)) {
-      return L1_TBEs[addr].TBEState;
-    } else if (isL1CacheTagPresent(addr)) {
-      return getL1CacheEntry(addr).CacheState;
+    if(is_valid(tbe)) {
+      return tbe.TBEState;
+    } else if (is_valid(cache_entry)) {
+      return cache_entry.CacheState;
     }
     return State:NP;
   }
 
-
-  void setState(Address addr, State state) {
+  void setState(TBE tbe, Entry cache_entry, Address addr, State state) {
     assert((L1DcacheMemory.isTagPresent(addr) && 
L1IcacheMemory.isTagPresent(addr)) == false);
 
     // MUST CHANGE
-    if(L1_TBEs.isPresent(addr)) {
-      L1_TBEs[addr].TBEState := state;
+    if(is_valid(tbe)) {
+      tbe.TBEState := state;
     }
 
-    if (isL1CacheTagPresent(addr)) {
-      getL1CacheEntry(addr).CacheState := state;
+    if (is_valid(cache_entry)) {
+      cache_entry.CacheState := state;
 
       // Set permission
       if (state == State:I) {
-        changeL1Permission(addr, AccessPermission:Invalid);
+        cache_entry.changePermission(AccessPermission:Invalid);
       } else if (state == State:S || state == State:E) {
-        changeL1Permission(addr, AccessPermission:Read_Only);
+        cache_entry.changePermission(AccessPermission:Read_Only);
       } else if (state == State:M) {
-        changeL1Permission(addr, AccessPermission:Read_Write);
+        cache_entry.changePermission(AccessPermission:Read_Write);
       } else {
-        changeL1Permission(addr, AccessPermission:Busy);
+        cache_entry.changePermission(AccessPermission:Busy);
       }
     }
   }
@@ -210,6 +206,9 @@
     }
   }
 
+  int getPendingAcks(TBE tbe) {
+    return tbe.pendingAcks;
+  }
 
   out_port(requestIntraChipL1Network_out, RequestMsg, requestFromL1Cache);
   out_port(responseIntraChipL1Network_out, ResponseMsg, responseFromL1Cache);
@@ -220,27 +219,32 @@
     if (responseIntraChipL1Network_in.isReady()) {
       peek(responseIntraChipL1Network_in, ResponseMsg, block_on="Address") {
         assert(in_msg.Destination.isElement(machineID));
+
+        Entry cache_entry := getCacheEntry(in_msg.Address);
+        TBE tbe := L1_TBEs[in_msg.Address];
+
         if(in_msg.Type == CoherenceResponseType:DATA_EXCLUSIVE) {
-          trigger(Event:Data_Exclusive, in_msg.Address);
+          trigger(Event:Data_Exclusive, in_msg.Address, cache_entry, tbe);
         } else if(in_msg.Type == CoherenceResponseType:DATA) {
-          if ( (getState(in_msg.Address) == State:IS || 
getState(in_msg.Address) == State:IS_I) &&
-                machineIDToMachineType(in_msg.Sender) == MachineType:L1Cache ) 
{
+          if ((getState(tbe, cache_entry, in_msg.Address) == State:IS ||
+               getState(tbe, cache_entry, in_msg.Address) == State:IS_I) &&
+              machineIDToMachineType(in_msg.Sender) == MachineType:L1Cache) {
 
-              trigger(Event:DataS_fromL1, in_msg.Address);
+              trigger(Event:DataS_fromL1, in_msg.Address, cache_entry, tbe);
 
-          } else if ( (L1_TBEs[in_msg.Address].pendingAcks - in_msg.AckCount) 
== 0 ) {
-            trigger(Event:Data_all_Acks, in_msg.Address);
+          } else if ( (getPendingAcks(tbe) - in_msg.AckCount) == 0 ) {
+            trigger(Event:Data_all_Acks, in_msg.Address, cache_entry, tbe);
           } else {
-            trigger(Event:Data, in_msg.Address);
+            trigger(Event:Data, in_msg.Address, cache_entry, tbe);
           }
         } else if (in_msg.Type == CoherenceResponseType:ACK) {
-          if ( (L1_TBEs[in_msg.Address].pendingAcks - in_msg.AckCount) == 0 ) {
-            trigger(Event:Ack_all, in_msg.Address);
+          if ( (getPendingAcks(tbe) - in_msg.AckCount) == 0 ) {
+            trigger(Event:Ack_all, in_msg.Address, cache_entry, tbe);
           } else {
-            trigger(Event:Ack, in_msg.Address);
+            trigger(Event:Ack, in_msg.Address, cache_entry, tbe);
           }
         } else if (in_msg.Type == CoherenceResponseType:WB_ACK) {
-          trigger(Event:WB_Ack, in_msg.Address);
+          trigger(Event:WB_Ack, in_msg.Address, cache_entry, tbe);
         } else {
           error("Invalid L1 response type");
         }
@@ -253,15 +257,19 @@
     if(requestIntraChipL1Network_in.isReady()) {
       peek(requestIntraChipL1Network_in, RequestMsg, block_on="Address") {
         assert(in_msg.Destination.isElement(machineID));
+
+        Entry cache_entry := getCacheEntry(in_msg.Address);
+        TBE tbe := L1_TBEs[in_msg.Address];
+
         if (in_msg.Type == CoherenceRequestType:INV) {
-          trigger(Event:Inv, in_msg.Address);
+          trigger(Event:Inv, in_msg.Address, cache_entry, tbe);
         } else if (in_msg.Type == CoherenceRequestType:GETX || in_msg.Type == 
CoherenceRequestType:UPGRADE) {
           // upgrade transforms to GETX due to race
-          trigger(Event:Fwd_GETX, in_msg.Address);
+          trigger(Event:Fwd_GETX, in_msg.Address, cache_entry, tbe);
         } else if (in_msg.Type == CoherenceRequestType:GETS) {
-          trigger(Event:Fwd_GETS, in_msg.Address);
+          trigger(Event:Fwd_GETS, in_msg.Address, cache_entry, tbe);
         } else if (in_msg.Type == CoherenceRequestType:GET_INSTR) {
-          trigger(Event:Fwd_GET_INSTR, in_msg.Address);
+          trigger(Event:Fwd_GET_INSTR, in_msg.Address, cache_entry, tbe);
         } else {
           error("Invalid forwarded request type");
         }
@@ -280,40 +288,55 @@
           // ** INSTRUCTION ACCESS ***
 
           // Check to see if it is in the OTHER L1
-          if (L1DcacheMemory.isTagPresent(in_msg.LineAddress)) {
+          Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
+          if (is_valid(L1Dcache_entry)) {
             // The block is in the wrong L1, put the request on the queue to 
the shared L2
-            trigger(Event:L1_Replacement, in_msg.LineAddress);
+            trigger(Event:L1_Replacement, in_msg.LineAddress,
+                    L1Dcache_entry, L1_TBEs[in_msg.LineAddress]);
           }
-          if (L1IcacheMemory.isTagPresent(in_msg.LineAddress)) {
+
+          Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
+          if (is_valid(L1Icache_entry)) {
             // The tag matches for the L1, so the L1 asks the L2 for it.
-            trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress);
+            trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress,
+                    L1Icache_entry, L1_TBEs[in_msg.LineAddress]);
           } else {
             if (L1IcacheMemory.cacheAvail(in_msg.LineAddress)) {
               // L1 does't have the line, but we have space for it in the L1 
so let's see if the L2 has it
-              trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress);
+              trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress,
+                      L1Icache_entry, L1_TBEs[in_msg.LineAddress]);
             } else {
               // No room in the L1, so we need to make room in the L1
-              trigger(Event:L1_Replacement, 
L1IcacheMemory.cacheProbe(in_msg.LineAddress));
+              trigger(Event:L1_Replacement, 
L1IcacheMemory.cacheProbe(in_msg.LineAddress),
+                      
getL1ICacheEntry(L1IcacheMemory.cacheProbe(in_msg.LineAddress)),
+                      L1_TBEs[L1IcacheMemory.cacheProbe(in_msg.LineAddress)]);
             }
           }
         } else {
           // *** DATA ACCESS ***
+          // Check to see if it is in the OTHER L1
+          Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
+          if (is_valid(L1Icache_entry)) {
+            // The block is in the wrong L1, put the request on the queue to 
the shared L2
+            trigger(Event:L1_Replacement, in_msg.LineAddress,
+                    L1Icache_entry, L1_TBEs[in_msg.LineAddress]);
+          }
 
-          // Check to see if it is in the OTHER L1
-          if (L1IcacheMemory.isTagPresent(in_msg.LineAddress)) {
-            // The block is in the wrong L1, put the request on the queue to 
the shared L2
-            trigger(Event:L1_Replacement, in_msg.LineAddress);
-          }
-          if (L1DcacheMemory.isTagPresent(in_msg.LineAddress)) {
+          Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
+          if (is_valid(L1Dcache_entry)) {
             // The tag matches for the L1, so the L1 ask the L2 for it
-            trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress);
+            trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress,
+                    L1Dcache_entry, L1_TBEs[in_msg.LineAddress]);
           } else {
             if (L1DcacheMemory.cacheAvail(in_msg.LineAddress)) {
               // L1 does't have the line, but we have space for it in the L1 
let's see if the L2 has it
-              trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress);
+              trigger(mandatory_request_type_to_event(in_msg.Type), 
in_msg.LineAddress,
+                      L1Dcache_entry, L1_TBEs[in_msg.LineAddress]);
             } else {
               // No room in the L1, so we need to make room in the L1
-              trigger(Event:L1_Replacement, 
L1DcacheMemory.cacheProbe(in_msg.LineAddress));
+              trigger(Event:L1_Replacement, 
L1DcacheMemory.cacheProbe(in_msg.LineAddress),
+                      
getL1DCacheEntry(L1DcacheMemory.cacheProbe(in_msg.LineAddress)),
+                      L1_TBEs[L1DcacheMemory.cacheProbe(in_msg.LineAddress)]);
             }
           }
         }
@@ -395,10 +418,11 @@
   action(d_sendDataToRequestor, "d", desc="send data to requestor") {
     peek(requestIntraChipL1Network_in, RequestMsg) {
       enqueue(responseIntraChipL1Network_out, ResponseMsg, 
latency=l1_response_latency) {
+        assert(is_valid(cache_entry));
         out_msg.Address := address;
         out_msg.Type := CoherenceResponseType:DATA;
-        out_msg.DataBlk := getL1CacheEntry(address).DataBlk;
-        out_msg.Dirty := getL1CacheEntry(address).Dirty;
+        out_msg.DataBlk := cache_entry.DataBlk;
+        out_msg.Dirty := cache_entry.Dirty;
         out_msg.Sender := machineID;
         out_msg.Destination.add(in_msg.Requestor);
         out_msg.MessageSize := MessageSizeType:Response_Data;
@@ -408,10 +432,11 @@
 
   action(d2_sendDataToL2, "d2", desc="send data to the L2 cache because of M 
downgrade") {
     enqueue(responseIntraChipL1Network_out, ResponseMsg, 
latency=l1_response_latency) {
+      assert(is_valid(cache_entry));
       out_msg.Address := address;
       out_msg.Type := CoherenceResponseType:DATA;
-      out_msg.DataBlk := getL1CacheEntry(address).DataBlk;
-      out_msg.Dirty := getL1CacheEntry(address).Dirty;
+      out_msg.DataBlk := cache_entry.DataBlk;
+      out_msg.Dirty := cache_entry.Dirty;
       out_msg.Sender := machineID;
       out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
                                                   l2_select_low_bit, 
l2_select_num_bits));
@@ -422,10 +447,11 @@
   action(dt_sendDataToRequestor_fromTBE, "dt", desc="send data to requestor") {
     peek(requestIntraChipL1Network_in, RequestMsg) {
       enqueue(responseIntraChipL1Network_out, ResponseMsg, 
latency=l1_response_latency) {
+        assert(is_valid(tbe));
         out_msg.Address := address;
         out_msg.Type := CoherenceResponseType:DATA;
-        out_msg.DataBlk := L1_TBEs[address].DataBlk;
-        out_msg.Dirty := L1_TBEs[address].Dirty;
+        out_msg.DataBlk := tbe.DataBlk;
+        out_msg.Dirty := tbe.Dirty;
         out_msg.Sender := machineID;
         out_msg.Destination.add(in_msg.Requestor);
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to