3 * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 machine(L1Cache, "Directory protocol")
36 : Sequencer * sequencer,
37 CacheMemory * L1IcacheMemory,
38 CacheMemory * L1DcacheMemory,
39 int l2_select_num_bits,
40 int request_latency = 2
44 // From this node's L1 cache TO the network
45 // a local L1 -> this L2 bank, currently ordered with directory forwarded requests
46 MessageBuffer requestFromL1Cache, network="To", virtual_network="0", ordered="false";
47 // a local L1 -> this L2 bank
48 MessageBuffer responseFromL1Cache, network="To", virtual_network="2", ordered="false";
49 // MessageBuffer writebackFromL1Cache, network="To", virtual_network="3", ordered="false";
52 // To this node's L1 cache FROM the network
53 // a L2 bank -> this L1
54 MessageBuffer requestToL1Cache, network="From", virtual_network="0", ordered="false";
55 // a L2 bank -> this L1
56 MessageBuffer responseToL1Cache, network="From", virtual_network="2", ordered="false";
61 state_declaration(State, desc="Cache states", default="L1Cache_State_I") {
63 I, AccessPermission:Invalid, desc="Idle";
64 S, AccessPermission:Read_Only, desc="Shared";
65 O, AccessPermission:Read_Only, desc="Owned";
66 M, AccessPermission:Read_Only, desc="Modified (dirty)";
67 M_W, AccessPermission:Read_Only, desc="Modified (dirty)";
68 MM, AccessPermission:Read_Write, desc="Modified (dirty and locally modified)";
69 MM_W, AccessPermission:Read_Write, desc="Modified (dirty and locally modified)";
72 IM, AccessPermission:Busy, "IM", desc="Issued GetX";
73 SM, AccessPermission:Read_Only, "SM", desc="Issued GetX, we still have an old copy of the line";
74 OM, AccessPermission:Read_Only, "SM", desc="Issued GetX, received data";
75 IS, AccessPermission:Busy, "IS", desc="Issued GetS";
76 SI, AccessPermission:Busy, "OI", desc="Issued PutS, waiting for ack";
77 OI, AccessPermission:Busy, "OI", desc="Issued PutO, waiting for ack";
78 MI, AccessPermission:Busy, "MI", desc="Issued PutX, waiting for ack";
79 II, AccessPermission:Busy, "II", desc="Issued PutX/O, saw Fwd_GETS or Fwd_GETX, waiting for ack";
83 enumeration(Event, desc="Cache events") {
84 Load, desc="Load request from the processor";
85 Ifetch, desc="I-fetch request from the processor";
86 Store, desc="Store request from the processor";
87 L1_Replacement, desc="Replacement";
90 Own_GETX, desc="We observe our own GetX forwarded back to us";
91 Fwd_GETX, desc="A GetX from another processor";
92 Fwd_GETS, desc="A GetS from another processor";
93 Fwd_DMA, desc="A GetS from another processor";
94 Inv, desc="Invalidations from the directory";
97 Ack, desc="Received an ack message";
98 Data, desc="Received a data message, responder has a shared copy";
99 Exclusive_Data, desc="Received a data message";
101 Writeback_Ack, desc="Writeback O.K. from directory";
102 Writeback_Ack_Data, desc="Writeback O.K. from directory";
103 Writeback_Nack, desc="Writeback not O.K. from directory";
106 All_acks, desc="Received all required data and message acks";
109 Use_Timeout, desc="lockout period ended";
115 structure(Entry, desc="...", interface="AbstractCacheEntry") {
116 State CacheState, desc="cache state";
117 bool Dirty, desc="Is the data dirty (different than memory)?";
118 DataBlock DataBlk, desc="data for the block";
122 structure(TBE, desc="...") {
123 Address Address, desc="Physical address for this TBE";
124 State TBEState, desc="Transient state";
125 DataBlock DataBlk, desc="data for the block, required for concurrent writebacks";
126 bool Dirty, desc="Is the data dirty (different than memory)?";
127 int NumPendingMsgs, default="0", desc="Number of acks/data messages that this processor is waiting for";
130 external_type(TBETable) {
132 void allocate(Address);
133 void deallocate(Address);
134 bool isPresent(Address);
137 void set_cache_entry(AbstractCacheEntry b);
138 void unset_cache_entry();
142 MessageBuffer mandatoryQueue, ordered="false", abstract_chip_ptr="true";
144 TBETable TBEs, template_hack="<L1Cache_TBE>";
145 TimerTable useTimerTable;
146 int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
148 Entry getCacheEntry(Address addr), return_by_pointer="yes" {
149 Entry L1Dcache_entry := static_cast(Entry, "pointer", L1DcacheMemory.lookup(addr));
150 if(is_valid(L1Dcache_entry)) {
151 return L1Dcache_entry;
154 Entry L1Icache_entry := static_cast(Entry, "pointer", L1IcacheMemory.lookup(addr));
155 return L1Icache_entry;
158 Entry getL1DCacheEntry(Address addr), return_by_pointer="yes" {
159 return static_cast(Entry, "pointer", L1DcacheMemory.lookup(addr));
162 Entry getL1ICacheEntry(Address addr), return_by_pointer="yes" {
163 return static_cast(Entry, "pointer", L1IcacheMemory.lookup(addr));
166 State getState(TBE tbe, Entry cache_entry, Address addr) {
169 } else if (is_valid(cache_entry)) {
170 return cache_entry.CacheState;
175 void setState(TBE tbe, Entry cache_entry, Address addr, State state) {
176 assert((L1DcacheMemory.isTagPresent(addr) && L1IcacheMemory.isTagPresent(addr)) == false);
179 tbe.TBEState := state;
182 if (is_valid(cache_entry)) {
183 if ( ((cache_entry.CacheState != State:M) && (state == State:M)) ||
184 ((cache_entry.CacheState != State:MM) && (state == State:MM)) ||
185 ((cache_entry.CacheState != State:S) && (state == State:S)) ||
186 ((cache_entry.CacheState != State:O) && (state == State:O)) ) {
188 cache_entry.CacheState := state;
189 sequencer.checkCoherence(addr);
192 cache_entry.CacheState := state;
197 Event mandatory_request_type_to_event(CacheRequestType type) {
198 if (type == CacheRequestType:LD) {
200 } else if (type == CacheRequestType:IFETCH) {
202 } else if ((type == CacheRequestType:ST) || (type == CacheRequestType:ATOMIC)) {
205 error("Invalid CacheRequestType");
209 MessageBuffer triggerQueue, ordered="true";
213 out_port(requestNetwork_out, RequestMsg, requestFromL1Cache);
214 out_port(responseNetwork_out, ResponseMsg, responseFromL1Cache);
215 out_port(triggerQueue_out, TriggerMsg, triggerQueue);
220 in_port(useTimerTable_in, Address, useTimerTable) {
221 if (useTimerTable_in.isReady()) {
222 trigger(Event:Use_Timeout, useTimerTable.readyAddress(),
223 getCacheEntry(useTimerTable.readyAddress()),
224 TBEs[useTimerTable.readyAddress()]);
229 in_port(triggerQueue_in, TriggerMsg, triggerQueue) {
230 if (triggerQueue_in.isReady()) {
231 peek(triggerQueue_in, TriggerMsg) {
232 if (in_msg.Type == TriggerType:ALL_ACKS) {
233 trigger(Event:All_acks, in_msg.Address,
234 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
236 error("Unexpected message");
242 // Nothing from the request network
245 in_port(requestNetwork_in, RequestMsg, requestToL1Cache) {
246 if (requestNetwork_in.isReady()) {
247 peek(requestNetwork_in, RequestMsg, block_on="Address") {
248 assert(in_msg.Destination.isElement(machineID));
249 DPRINTF(RubySlicc, "L1 received: %s\n", in_msg.Type);
251 if (in_msg.Type == CoherenceRequestType:GETX || in_msg.Type == CoherenceRequestType:DMA_WRITE) {
252 if (in_msg.Requestor == machineID && in_msg.RequestorMachine == MachineType:L1Cache) {
253 trigger(Event:Own_GETX, in_msg.Address,
254 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
256 trigger(Event:Fwd_GETX, in_msg.Address,
257 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
259 } else if (in_msg.Type == CoherenceRequestType:GETS) {
260 trigger(Event:Fwd_GETS, in_msg.Address,
261 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
262 } else if (in_msg.Type == CoherenceRequestType:DMA_READ) {
263 trigger(Event:Fwd_DMA, in_msg.Address,
264 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
265 } else if (in_msg.Type == CoherenceRequestType:WB_ACK) {
266 trigger(Event:Writeback_Ack, in_msg.Address,
267 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
268 } else if (in_msg.Type == CoherenceRequestType:WB_ACK_DATA) {
269 trigger(Event:Writeback_Ack_Data, in_msg.Address,
270 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
271 } else if (in_msg.Type == CoherenceRequestType:WB_NACK) {
272 trigger(Event:Writeback_Nack, in_msg.Address,
273 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
274 } else if (in_msg.Type == CoherenceRequestType:INV) {
275 trigger(Event:Inv, in_msg.Address,
276 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
278 error("Unexpected message");
285 in_port(responseToL1Cache_in, ResponseMsg, responseToL1Cache) {
286 if (responseToL1Cache_in.isReady()) {
287 peek(responseToL1Cache_in, ResponseMsg, block_on="Address") {
288 if (in_msg.Type == CoherenceResponseType:ACK) {
289 trigger(Event:Ack, in_msg.Address,
290 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
291 } else if (in_msg.Type == CoherenceResponseType:DATA) {
292 trigger(Event:Data, in_msg.Address,
293 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
294 } else if (in_msg.Type == CoherenceResponseType:DATA_EXCLUSIVE) {
295 trigger(Event:Exclusive_Data, in_msg.Address,
296 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
298 error("Unexpected message");
304 // Nothing from the unblock network
305 // Mandatory Queue betweens Node's CPU and it's L1 caches
306 in_port(mandatoryQueue_in, CacheMsg, mandatoryQueue, desc="...") {
307 if (mandatoryQueue_in.isReady()) {
308 peek(mandatoryQueue_in, CacheMsg, block_on="LineAddress") {
310 // Check for data access to blocks in I-cache and ifetchs to blocks in D-cache
312 if (in_msg.Type == CacheRequestType:IFETCH) {
313 // ** INSTRUCTION ACCESS ***
315 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
316 if (is_valid(L1Icache_entry)) {
317 // The tag matches for the L1, so the L1 asks the L2 for it.
318 trigger(mandatory_request_type_to_event(in_msg.Type),
319 in_msg.LineAddress, L1Icache_entry,
320 TBEs[in_msg.LineAddress]);
323 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
324 // Check to see if it is in the OTHER L1
325 if (is_valid(L1Dcache_entry)) {
326 // The block is in the wrong L1, put the request on the queue to the shared L2
327 trigger(Event:L1_Replacement, in_msg.LineAddress, L1Dcache_entry,
328 TBEs[in_msg.LineAddress]);
330 if (L1IcacheMemory.cacheAvail(in_msg.LineAddress)) {
331 // L1 does't have the line, but we have space for it in the L1 so let's see if the L2 has it
332 trigger(mandatory_request_type_to_event(in_msg.Type),
333 in_msg.LineAddress, L1Icache_entry,
334 TBEs[in_msg.LineAddress]);
336 // No room in the L1, so we need to make room in the L1
337 trigger(Event:L1_Replacement,
338 L1IcacheMemory.cacheProbe(in_msg.LineAddress),
339 getL1ICacheEntry(L1IcacheMemory.cacheProbe(in_msg.LineAddress)),
340 TBEs[L1IcacheMemory.cacheProbe(in_msg.LineAddress)]);
344 // *** DATA ACCESS ***
346 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
347 if (is_valid(L1Dcache_entry)) {
348 // The tag matches for the L1, so the L1 ask the L2 for it
349 trigger(mandatory_request_type_to_event(in_msg.Type),
350 in_msg.LineAddress, L1Dcache_entry,
351 TBEs[in_msg.LineAddress]);
354 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
355 // Check to see if it is in the OTHER L1
356 if (is_valid(L1Icache_entry)) {
357 // The block is in the wrong L1, put the request on the queue to the shared L2
358 trigger(Event:L1_Replacement, in_msg.LineAddress,
359 L1Icache_entry, TBEs[in_msg.LineAddress]);
361 if (L1DcacheMemory.cacheAvail(in_msg.LineAddress)) {
362 // L1 does't have the line, but we have space for it in the L1 let's see if the L2 has it
363 trigger(mandatory_request_type_to_event(in_msg.Type),
364 in_msg.LineAddress, L1Dcache_entry,
365 TBEs[in_msg.LineAddress]);
367 // No room in the L1, so we need to make room in the L1
368 trigger(Event:L1_Replacement,
369 L1DcacheMemory.cacheProbe(in_msg.LineAddress),
370 getL1DCacheEntry(L1DcacheMemory.cacheProbe(in_msg.LineAddress)),
371 TBEs[L1DcacheMemory.cacheProbe(in_msg.LineAddress)]);
382 action(a_issueGETS, "a", desc="Issue GETS") {
383 peek(mandatoryQueue_in, CacheMsg) {
384 enqueue(requestNetwork_out, RequestMsg, latency= request_latency) {
385 out_msg.Address := address;
386 out_msg.Type := CoherenceRequestType:GETS;
387 out_msg.Requestor := machineID;
388 out_msg.RequestorMachine := MachineType:L1Cache;
389 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
390 l2_select_low_bit, l2_select_num_bits));
391 out_msg.MessageSize := MessageSizeType:Request_Control;
392 out_msg.AccessMode := in_msg.AccessMode;
393 out_msg.Prefetch := in_msg.Prefetch;
398 action(b_issueGETX, "b", desc="Issue GETX") {
399 peek(mandatoryQueue_in, CacheMsg) {
400 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
401 out_msg.Address := address;
402 out_msg.Type := CoherenceRequestType:GETX;
403 out_msg.Requestor := machineID;
404 out_msg.RequestorMachine := MachineType:L1Cache;
405 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
406 l2_select_low_bit, l2_select_num_bits));
407 out_msg.MessageSize := MessageSizeType:Request_Control;
408 out_msg.AccessMode := in_msg.AccessMode;
409 out_msg.Prefetch := in_msg.Prefetch;
414 action(d_issuePUTX, "d", desc="Issue PUTX") {
415 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
416 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
417 out_msg.Address := address;
418 out_msg.Type := CoherenceRequestType:PUTX;
419 out_msg.Requestor := machineID;
420 out_msg.RequestorMachine := MachineType:L1Cache;
421 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
422 l2_select_low_bit, l2_select_num_bits));
423 out_msg.MessageSize := MessageSizeType:Writeback_Control;
427 action(dd_issuePUTO, "\d", desc="Issue PUTO") {
428 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
429 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
430 out_msg.Address := address;
431 out_msg.Type := CoherenceRequestType:PUTO;
432 out_msg.Requestor := machineID;
433 out_msg.RequestorMachine := MachineType:L1Cache;
434 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
435 l2_select_low_bit, l2_select_num_bits));
436 out_msg.MessageSize := MessageSizeType:Writeback_Control;
440 action(dd_issuePUTS, "\ds", desc="Issue PUTS") {
441 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
442 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
443 out_msg.Address := address;
444 out_msg.Type := CoherenceRequestType:PUTS;
445 out_msg.Requestor := machineID;
446 out_msg.RequestorMachine := MachineType:L1Cache;
447 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
448 l2_select_low_bit, l2_select_num_bits));
449 out_msg.MessageSize := MessageSizeType:Writeback_Control;
453 action(e_sendData, "e", desc="Send data from cache to requestor") {
454 peek(requestNetwork_in, RequestMsg) {
455 assert(is_valid(cache_entry));
456 if (in_msg.RequestorMachine == MachineType:L2Cache) {
457 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
458 out_msg.Address := address;
459 out_msg.Type := CoherenceResponseType:DATA;
460 out_msg.Sender := machineID;
461 out_msg.SenderMachine := MachineType:L1Cache;
462 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
463 l2_select_low_bit, l2_select_num_bits));
464 out_msg.DataBlk := cache_entry.DataBlk;
465 // out_msg.Dirty := cache_entry.Dirty;
466 out_msg.Dirty := false;
467 out_msg.Acks := in_msg.Acks;
468 out_msg.MessageSize := MessageSizeType:Response_Data;
470 DPRINTF(RubySlicc, "Sending data to L2: %s\n", in_msg.Address);
473 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
474 out_msg.Address := address;
475 out_msg.Type := CoherenceResponseType:DATA;
476 out_msg.Sender := machineID;
477 out_msg.SenderMachine := MachineType:L1Cache;
478 out_msg.Destination.add(in_msg.Requestor);
479 out_msg.DataBlk := cache_entry.DataBlk;
480 // out_msg.Dirty := cache_entry.Dirty;
481 out_msg.Dirty := false;
482 out_msg.Acks := in_msg.Acks;
483 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
485 DPRINTF(RubySlicc, "Sending data to L1\n");
490 action(e_sendDataToL2, "ee", desc="Send data from cache to requestor") {
491 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
492 assert(is_valid(cache_entry));
493 out_msg.Address := address;
494 out_msg.Type := CoherenceResponseType:DATA;
495 out_msg.Sender := machineID;
496 out_msg.SenderMachine := MachineType:L1Cache;
497 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
498 l2_select_low_bit, l2_select_num_bits));
499 out_msg.DataBlk := cache_entry.DataBlk;
500 out_msg.Dirty := cache_entry.Dirty;
501 out_msg.Acks := 0; // irrelevant
502 out_msg.MessageSize := MessageSizeType:Response_Data;
507 action(ee_sendDataExclusive, "\e", desc="Send data from cache to requestor, don't keep a shared copy") {
508 peek(requestNetwork_in, RequestMsg) {
509 assert(is_valid(cache_entry));
510 if (in_msg.RequestorMachine == MachineType:L2Cache) {
511 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
512 out_msg.Address := address;
513 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
514 out_msg.Sender := machineID;
515 out_msg.SenderMachine := MachineType:L1Cache;
516 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
517 l2_select_low_bit, l2_select_num_bits));
518 out_msg.DataBlk := cache_entry.DataBlk;
519 out_msg.Dirty := cache_entry.Dirty;
520 out_msg.Acks := in_msg.Acks;
521 out_msg.MessageSize := MessageSizeType:Response_Data;
523 DPRINTF(RubySlicc, "Sending exclusive data to L2\n");
526 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
527 out_msg.Address := address;
528 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
529 out_msg.Sender := machineID;
530 out_msg.SenderMachine := MachineType:L1Cache;
531 out_msg.Destination.add(in_msg.Requestor);
532 out_msg.DataBlk := cache_entry.DataBlk;
533 out_msg.Dirty := cache_entry.Dirty;
534 out_msg.Acks := in_msg.Acks;
535 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
537 DPRINTF(RubySlicc, "Sending exclusive data to L1\n");
542 action(f_sendAck, "f", desc="Send ack from cache to requestor") {
543 peek(requestNetwork_in, RequestMsg) {
544 if (in_msg.RequestorMachine == MachineType:L1Cache) {
545 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
546 out_msg.Address := address;
547 out_msg.Type := CoherenceResponseType:ACK;
548 out_msg.Sender := machineID;
549 out_msg.SenderMachine := MachineType:L1Cache;
550 out_msg.Destination.add(in_msg.Requestor);
551 out_msg.Acks := 0 - 1; // -1
552 out_msg.MessageSize := MessageSizeType:Response_Control;
556 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
557 out_msg.Address := address;
558 out_msg.Type := CoherenceResponseType:ACK;
559 out_msg.Sender := machineID;
560 out_msg.SenderMachine := MachineType:L1Cache;
561 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
562 l2_select_low_bit, l2_select_num_bits));
563 out_msg.Acks := 0 - 1; // -1
564 out_msg.MessageSize := MessageSizeType:Response_Control;
570 action(g_sendUnblock, "g", desc="Send unblock to memory") {
571 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
572 out_msg.Address := address;
573 out_msg.Type := CoherenceResponseType:UNBLOCK;
574 out_msg.Sender := machineID;
575 out_msg.SenderMachine := MachineType:L1Cache;
576 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
577 l2_select_low_bit, l2_select_num_bits));
578 out_msg.MessageSize := MessageSizeType:Unblock_Control;
582 action(gg_sendUnblockExclusive, "\g", desc="Send unblock exclusive to memory") {
583 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
584 out_msg.Address := address;
585 out_msg.Type := CoherenceResponseType:UNBLOCK_EXCLUSIVE;
586 out_msg.Sender := machineID;
587 out_msg.SenderMachine := MachineType:L1Cache;
588 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
589 l2_select_low_bit, l2_select_num_bits));
590 out_msg.MessageSize := MessageSizeType:Unblock_Control;
594 action(h_load_hit, "h", desc="Notify sequencer the load completed.") {
595 assert(is_valid(cache_entry));
596 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
597 sequencer.readCallback(address, cache_entry.DataBlk);
600 action(hh_store_hit, "\h", desc="Notify sequencer that store completed.") {
601 assert(is_valid(cache_entry));
602 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
603 sequencer.writeCallback(address, cache_entry.DataBlk);
604 cache_entry.Dirty := true;
607 action(i_allocateTBE, "i", desc="Allocate TBE") {
608 check_allocate(TBEs);
609 TBEs.allocate(address);
610 set_tbe(TBEs[address]);
611 assert(is_valid(cache_entry));
612 tbe.DataBlk := cache_entry.DataBlk; // Data only used for writebacks
613 tbe.Dirty := cache_entry.Dirty;
616 action(j_popTriggerQueue, "j", desc="Pop trigger queue.") {
617 triggerQueue_in.dequeue();
620 action(jj_unsetUseTimer, "\jj", desc="Unset use timer.") {
621 useTimerTable.unset(address);
624 action(k_popMandatoryQueue, "k", desc="Pop mandatory queue.") {
625 mandatoryQueue_in.dequeue();
628 action(l_popForwardQueue, "l", desc="Pop forwareded request queue.") {
629 requestNetwork_in.dequeue();
632 action(m_decrementNumberOfMessages, "m", desc="Decrement the number of messages for which we're waiting") {
633 peek(responseToL1Cache_in, ResponseMsg) {
634 assert(is_valid(tbe));
635 DPRINTF(RubySlicc, "L1 decrementNumberOfMessages: %d\n", in_msg.Acks);
636 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
640 action(mm_decrementNumberOfMessages, "\m", desc="Decrement the number of messages for which we're waiting") {
641 peek(requestNetwork_in, RequestMsg) {
642 assert(is_valid(tbe));
643 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
647 action(n_popResponseQueue, "n", desc="Pop response queue") {
648 responseToL1Cache_in.dequeue();
651 action(o_checkForCompletion, "o", desc="Check if we have received all the messages required for completion") {
652 assert(is_valid(tbe));
653 if (tbe.NumPendingMsgs == 0) {
654 enqueue(triggerQueue_out, TriggerMsg) {
655 out_msg.Address := address;
656 out_msg.Type := TriggerType:ALL_ACKS;
661 action(o_scheduleUseTimeout, "oo", desc="Schedule a use timeout.") {
662 useTimerTable.set(address, 50);
666 action(q_sendDataFromTBEToCache, "q", desc="Send data from TBE to cache") {
667 peek(requestNetwork_in, RequestMsg) {
668 assert(is_valid(tbe));
669 if (in_msg.RequestorMachine == MachineType:L1Cache) {
670 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
671 out_msg.Address := address;
672 out_msg.Type := CoherenceResponseType:DATA;
673 out_msg.Sender := machineID;
674 out_msg.SenderMachine := MachineType:L1Cache;
675 out_msg.Destination.add(in_msg.Requestor);
676 out_msg.DataBlk := tbe.DataBlk;
677 // out_msg.Dirty := tbe.Dirty;
678 out_msg.Dirty := false;
679 out_msg.Acks := in_msg.Acks;
680 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
684 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
685 out_msg.Address := address;
686 out_msg.Type := CoherenceResponseType:DATA;
687 out_msg.Sender := machineID;
688 out_msg.SenderMachine := MachineType:L1Cache;
689 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
690 l2_select_low_bit, l2_select_num_bits));
691 out_msg.DataBlk := tbe.DataBlk;
692 // out_msg.Dirty := tbe.Dirty;
693 out_msg.Dirty := false;
694 out_msg.Acks := in_msg.Acks;
695 out_msg.MessageSize := MessageSizeType:Response_Data;
701 action(q_sendExclusiveDataFromTBEToCache, "qq", desc="Send data from TBE to cache") {
702 peek(requestNetwork_in, RequestMsg) {
703 assert(is_valid(tbe));
704 if (in_msg.RequestorMachine == MachineType:L1Cache) {
705 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
706 out_msg.Address := address;
707 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
708 out_msg.Sender := machineID;
709 out_msg.SenderMachine := MachineType:L1Cache;
710 out_msg.Destination.add(in_msg.Requestor);
711 out_msg.DataBlk := tbe.DataBlk;
712 out_msg.Dirty := tbe.Dirty;
713 out_msg.Acks := in_msg.Acks;
714 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
718 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
719 out_msg.Address := address;
720 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
721 out_msg.Sender := machineID;
722 out_msg.SenderMachine := MachineType:L1Cache;
723 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
724 l2_select_low_bit, l2_select_num_bits));
725 out_msg.DataBlk := tbe.DataBlk;
726 out_msg.Dirty := tbe.Dirty;
727 out_msg.Acks := in_msg.Acks;
728 out_msg.MessageSize := MessageSizeType:Response_Data;
735 // L2 will usually request data for a writeback
736 action(qq_sendWBDataFromTBEToL2, "\q", desc="Send data from TBE to L2") {
737 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
738 assert(is_valid(tbe));
739 out_msg.Address := address;
740 out_msg.Sender := machineID;
741 out_msg.SenderMachine := MachineType:L1Cache;
742 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
743 l2_select_low_bit, l2_select_num_bits));
744 out_msg.Dirty := tbe.Dirty;
746 out_msg.Type := CoherenceResponseType:WRITEBACK_DIRTY_DATA;
748 out_msg.Type := CoherenceResponseType:WRITEBACK_CLEAN_DATA;
750 out_msg.DataBlk := tbe.DataBlk;
751 out_msg.MessageSize := MessageSizeType:Writeback_Data;
755 action(s_deallocateTBE, "s", desc="Deallocate TBE") {
756 TBEs.deallocate(address);
760 action(u_writeDataToCache, "u", desc="Write data to cache") {
761 peek(responseToL1Cache_in, ResponseMsg) {
762 assert(is_valid(cache_entry));
763 cache_entry.DataBlk := in_msg.DataBlk;
764 cache_entry.Dirty := in_msg.Dirty;
766 if (in_msg.Type == CoherenceResponseType:DATA) {
767 //assert(in_msg.Dirty == false);
773 action(v_writeDataToCacheVerify, "v", desc="Write data to cache, assert it was same as before") {
774 peek(responseToL1Cache_in, ResponseMsg) {
775 assert(is_valid(cache_entry));
776 assert(cache_entry.DataBlk == in_msg.DataBlk);
777 cache_entry.DataBlk := in_msg.DataBlk;
778 cache_entry.Dirty := in_msg.Dirty;
782 action(kk_deallocateL1CacheBlock, "\k", desc="Deallocate cache block. Sets the cache to invalid, allowing a replacement in parallel with a fetch.") {
783 if (L1DcacheMemory.isTagPresent(address)) {
784 L1DcacheMemory.deallocate(address);
786 L1IcacheMemory.deallocate(address);
791 action(ii_allocateL1DCacheBlock, "\i", desc="Set L1 D-cache tag equal to tag of block B.") {
792 if ((is_invalid(cache_entry))) {
793 set_cache_entry(L1DcacheMemory.allocate(address, new Entry));
797 action(jj_allocateL1ICacheBlock, "\j", desc="Set L1 I-cache tag equal to tag of block B.") {
798 if ((is_invalid(cache_entry))) {
799 set_cache_entry(L1IcacheMemory.allocate(address, new Entry));
805 action(uu_profileMiss, "\u", desc="Profile the demand miss") {
806 peek(mandatoryQueue_in, CacheMsg) {
807 // profile_miss(in_msg);
811 action(z_recycleRequestQueue, "z", desc="Send the head of the mandatory queue to the back of the queue.") {
812 requestNetwork_in.recycle();
815 action(zz_recycleMandatoryQueue, "\z", desc="Send the head of the mandatory queue to the back of the queue.") {
816 mandatoryQueue_in.recycle();
819 //*****************************************************
821 //*****************************************************
823 // Transitions for Load/Store/L2_Replacement from transient states
824 transition({IM, SM, OM, IS, OI, SI, MI, II}, {Store, L1_Replacement}) {
825 zz_recycleMandatoryQueue;
828 transition({M_W, MM_W}, L1_Replacement) {
829 zz_recycleMandatoryQueue;
832 transition({M_W, MM_W}, {Fwd_GETS, Fwd_DMA, Fwd_GETX, Own_GETX, Inv}) {
833 z_recycleRequestQueue;
836 transition({IM, IS, OI, MI, SI, II}, {Load, Ifetch}) {
837 zz_recycleMandatoryQueue;
840 // Transitions from Idle
841 transition(I, Load, IS) {
842 ii_allocateL1DCacheBlock;
849 transition(I, Ifetch, IS) {
850 jj_allocateL1ICacheBlock;
857 transition(I, Store, IM) {
858 ii_allocateL1DCacheBlock;
865 transition(I, L1_Replacement) {
866 kk_deallocateL1CacheBlock;
874 // Transitions from Shared
875 transition({S, SM}, {Load, Ifetch}) {
880 transition(S, Store, SM) {
887 transition(S, L1_Replacement, SI) {
890 kk_deallocateL1CacheBlock;
893 transition(S, Inv, I) {
898 transition(S, {Fwd_GETS, Fwd_DMA}) {
903 // Transitions from Owned
904 transition({O, OM}, {Load, Ifetch}) {
909 transition(O, Store, OM) {
916 transition(O, L1_Replacement, OI) {
919 kk_deallocateL1CacheBlock;
922 transition(O, Fwd_GETX, I) {
923 ee_sendDataExclusive;
927 transition(O, {Fwd_GETS, Fwd_DMA}) {
932 // Transitions from MM
933 transition({MM, MM_W}, {Load, Ifetch}) {
938 transition({MM, MM_W}, Store) {
943 transition(MM, L1_Replacement, MI) {
946 kk_deallocateL1CacheBlock;
949 transition(MM, Fwd_GETX, I) {
950 ee_sendDataExclusive;
954 transition(MM, Fwd_GETS, I) {
955 ee_sendDataExclusive;
959 transition(MM, Fwd_DMA, MM) {
960 //ee_sendDataExclusive;
965 // Transitions from M
966 transition({M, M_W}, {Load, Ifetch}) {
971 transition(M, Store, MM) {
976 transition(M_W, Store, MM_W) {
981 transition(M, L1_Replacement, MI) {
984 kk_deallocateL1CacheBlock;
987 transition(M, Fwd_GETX, I) {
989 ee_sendDataExclusive;
993 transition(M, Fwd_GETS, O) {
998 transition(M, Fwd_DMA, M) {
1003 // Transitions from IM
1005 transition(IM, Inv) {
1010 transition(IM, Ack) {
1011 m_decrementNumberOfMessages;
1012 o_checkForCompletion;
1016 transition(IM, {Exclusive_Data, Data}, OM) {
1018 m_decrementNumberOfMessages;
1019 o_checkForCompletion;
1023 // Transitions from SM
1024 transition(SM, Inv, IM) {
1029 transition(SM, Ack) {
1030 m_decrementNumberOfMessages;
1031 o_checkForCompletion;
1035 transition(SM, {Data, Exclusive_Data}, OM) {
1036 // v_writeDataToCacheVerify;
1037 m_decrementNumberOfMessages;
1038 o_checkForCompletion;
1042 transition(SM, {Fwd_DMA, Fwd_GETS}) {
1047 // Transitions from OM
1048 transition(OM, Own_GETX) {
1049 mm_decrementNumberOfMessages;
1050 o_checkForCompletion;
1055 // transition(OM, Fwd_GETX, OMF) {
1056 transition(OM, Fwd_GETX, IM) {
1057 ee_sendDataExclusive;
1061 transition(OM, {Fwd_DMA, Fwd_GETS}, OM) {
1066 //transition({OM, OMF}, Ack) {
1067 transition(OM, Ack) {
1068 m_decrementNumberOfMessages;
1069 o_checkForCompletion;
1073 transition(OM, All_acks, MM_W) {
1075 gg_sendUnblockExclusive;
1077 o_scheduleUseTimeout;
1081 transition(MM_W, Use_Timeout, MM) {
1085 // Transitions from IS
1087 transition(IS, Inv) {
1092 transition(IS, Data, S) {
1094 m_decrementNumberOfMessages;
1101 transition(IS, Exclusive_Data, M_W) {
1103 m_decrementNumberOfMessages;
1105 gg_sendUnblockExclusive;
1106 o_scheduleUseTimeout;
1111 transition(M_W, Use_Timeout, M) {
1115 // Transitions from OI/MI
1117 transition(MI, Fwd_GETS, OI) {
1118 q_sendDataFromTBEToCache;
1122 transition(MI, Fwd_DMA, MI) {
1123 q_sendDataFromTBEToCache;
1127 transition(MI, Fwd_GETX, II) {
1128 q_sendExclusiveDataFromTBEToCache;
1132 transition({SI, OI}, {Fwd_DMA, Fwd_GETS}) {
1133 q_sendDataFromTBEToCache;
1137 transition(OI, Fwd_GETX, II) {
1138 q_sendExclusiveDataFromTBEToCache;
1142 transition({SI, OI, MI}, Writeback_Ack_Data, I) {
1143 qq_sendWBDataFromTBEToL2; // always send data
1148 transition({SI, OI, MI}, Writeback_Ack, I) {
1154 transition({MI, OI}, Writeback_Nack, OI) {
1155 // FIXME: This might cause deadlock by re-using the writeback
1156 // channel, we should handle this case differently.
1161 // Transitions from II
1162 transition(II, {Writeback_Ack, Writeback_Ack_Data}, I) {
1168 // transition({II, SI}, Writeback_Nack, I) {
1169 transition(II, Writeback_Nack, I) {
1174 transition(SI, Writeback_Nack) {
1179 transition(II, Inv) {
1184 transition(SI, Inv, II) {