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 enumeration(State, desc="Cache states", default="L1Cache_State_I") {
66 M, desc="Modified (dirty)";
67 M_W, desc="Modified (dirty)";
68 MM, desc="Modified (dirty and locally modified)";
69 MM_W, desc="Modified (dirty and locally modified)";
72 IM, "IM", desc="Issued GetX";
73 SM, "SM", desc="Issued GetX, we still have an old copy of the line";
74 OM, "SM", desc="Issued GetX, received data";
75 IS, "IS", desc="Issued GetS";
76 SI, "OI", desc="Issued PutS, waiting for ack";
77 OI, "OI", desc="Issued PutO, waiting for ack";
78 MI, "MI", desc="Issued PutX, waiting for ack";
79 II, "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;
196 if (state == State:MM || state == State:MM_W) {
197 cache_entry.changePermission(AccessPermission:Read_Write);
198 } else if ((state == State:S) ||
199 (state == State:O) ||
200 (state == State:M) ||
201 (state == State:M_W) ||
202 (state == State:SM) ||
203 (state == State:OM)) {
204 cache_entry.changePermission(AccessPermission:Read_Only);
206 cache_entry.changePermission(AccessPermission:Invalid);
211 Event mandatory_request_type_to_event(CacheRequestType type) {
212 if (type == CacheRequestType:LD) {
214 } else if (type == CacheRequestType:IFETCH) {
216 } else if ((type == CacheRequestType:ST) || (type == CacheRequestType:ATOMIC)) {
219 error("Invalid CacheRequestType");
223 MessageBuffer triggerQueue, ordered="true";
227 out_port(requestNetwork_out, RequestMsg, requestFromL1Cache);
228 out_port(responseNetwork_out, ResponseMsg, responseFromL1Cache);
229 out_port(triggerQueue_out, TriggerMsg, triggerQueue);
234 in_port(useTimerTable_in, Address, useTimerTable) {
235 if (useTimerTable_in.isReady()) {
236 trigger(Event:Use_Timeout, useTimerTable.readyAddress(),
237 getCacheEntry(useTimerTable.readyAddress()),
238 TBEs[useTimerTable.readyAddress()]);
243 in_port(triggerQueue_in, TriggerMsg, triggerQueue) {
244 if (triggerQueue_in.isReady()) {
245 peek(triggerQueue_in, TriggerMsg) {
246 if (in_msg.Type == TriggerType:ALL_ACKS) {
247 trigger(Event:All_acks, in_msg.Address,
248 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
250 error("Unexpected message");
256 // Nothing from the request network
259 in_port(requestNetwork_in, RequestMsg, requestToL1Cache) {
260 if (requestNetwork_in.isReady()) {
261 peek(requestNetwork_in, RequestMsg, block_on="Address") {
262 assert(in_msg.Destination.isElement(machineID));
263 DPRINTF(RubySlicc, "L1 received: %s\n", in_msg.Type);
265 if (in_msg.Type == CoherenceRequestType:GETX || in_msg.Type == CoherenceRequestType:DMA_WRITE) {
266 if (in_msg.Requestor == machineID && in_msg.RequestorMachine == MachineType:L1Cache) {
267 trigger(Event:Own_GETX, in_msg.Address,
268 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
270 trigger(Event:Fwd_GETX, in_msg.Address,
271 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
273 } else if (in_msg.Type == CoherenceRequestType:GETS) {
274 trigger(Event:Fwd_GETS, in_msg.Address,
275 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
276 } else if (in_msg.Type == CoherenceRequestType:DMA_READ) {
277 trigger(Event:Fwd_DMA, in_msg.Address,
278 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
279 } else if (in_msg.Type == CoherenceRequestType:WB_ACK) {
280 trigger(Event:Writeback_Ack, in_msg.Address,
281 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
282 } else if (in_msg.Type == CoherenceRequestType:WB_ACK_DATA) {
283 trigger(Event:Writeback_Ack_Data, in_msg.Address,
284 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
285 } else if (in_msg.Type == CoherenceRequestType:WB_NACK) {
286 trigger(Event:Writeback_Nack, in_msg.Address,
287 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
288 } else if (in_msg.Type == CoherenceRequestType:INV) {
289 trigger(Event:Inv, in_msg.Address,
290 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
292 error("Unexpected message");
299 in_port(responseToL1Cache_in, ResponseMsg, responseToL1Cache) {
300 if (responseToL1Cache_in.isReady()) {
301 peek(responseToL1Cache_in, ResponseMsg, block_on="Address") {
302 if (in_msg.Type == CoherenceResponseType:ACK) {
303 trigger(Event:Ack, in_msg.Address,
304 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
305 } else if (in_msg.Type == CoherenceResponseType:DATA) {
306 trigger(Event:Data, in_msg.Address,
307 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
308 } else if (in_msg.Type == CoherenceResponseType:DATA_EXCLUSIVE) {
309 trigger(Event:Exclusive_Data, in_msg.Address,
310 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
312 error("Unexpected message");
318 // Nothing from the unblock network
319 // Mandatory Queue betweens Node's CPU and it's L1 caches
320 in_port(mandatoryQueue_in, CacheMsg, mandatoryQueue, desc="...") {
321 if (mandatoryQueue_in.isReady()) {
322 peek(mandatoryQueue_in, CacheMsg, block_on="LineAddress") {
324 // Check for data access to blocks in I-cache and ifetchs to blocks in D-cache
326 if (in_msg.Type == CacheRequestType:IFETCH) {
327 // ** INSTRUCTION ACCESS ***
329 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
330 if (is_valid(L1Icache_entry)) {
331 // The tag matches for the L1, so the L1 asks the L2 for it.
332 trigger(mandatory_request_type_to_event(in_msg.Type),
333 in_msg.LineAddress, L1Icache_entry,
334 TBEs[in_msg.LineAddress]);
337 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
338 // Check to see if it is in the OTHER L1
339 if (is_valid(L1Dcache_entry)) {
340 // The block is in the wrong L1, put the request on the queue to the shared L2
341 trigger(Event:L1_Replacement, in_msg.LineAddress, L1Dcache_entry,
342 TBEs[in_msg.LineAddress]);
344 if (L1IcacheMemory.cacheAvail(in_msg.LineAddress)) {
345 // L1 does't have the line, but we have space for it in the L1 so let's see if the L2 has it
346 trigger(mandatory_request_type_to_event(in_msg.Type),
347 in_msg.LineAddress, L1Icache_entry,
348 TBEs[in_msg.LineAddress]);
350 // No room in the L1, so we need to make room in the L1
351 trigger(Event:L1_Replacement,
352 L1IcacheMemory.cacheProbe(in_msg.LineAddress),
353 getL1ICacheEntry(L1IcacheMemory.cacheProbe(in_msg.LineAddress)),
354 TBEs[L1IcacheMemory.cacheProbe(in_msg.LineAddress)]);
358 // *** DATA ACCESS ***
360 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
361 if (is_valid(L1Dcache_entry)) {
362 // The tag matches for the L1, so the L1 ask the L2 for it
363 trigger(mandatory_request_type_to_event(in_msg.Type),
364 in_msg.LineAddress, L1Dcache_entry,
365 TBEs[in_msg.LineAddress]);
368 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
369 // Check to see if it is in the OTHER L1
370 if (is_valid(L1Icache_entry)) {
371 // The block is in the wrong L1, put the request on the queue to the shared L2
372 trigger(Event:L1_Replacement, in_msg.LineAddress,
373 L1Icache_entry, TBEs[in_msg.LineAddress]);
375 if (L1DcacheMemory.cacheAvail(in_msg.LineAddress)) {
376 // L1 does't have the line, but we have space for it in the L1 let's see if the L2 has it
377 trigger(mandatory_request_type_to_event(in_msg.Type),
378 in_msg.LineAddress, L1Dcache_entry,
379 TBEs[in_msg.LineAddress]);
381 // No room in the L1, so we need to make room in the L1
382 trigger(Event:L1_Replacement,
383 L1DcacheMemory.cacheProbe(in_msg.LineAddress),
384 getL1DCacheEntry(L1DcacheMemory.cacheProbe(in_msg.LineAddress)),
385 TBEs[L1DcacheMemory.cacheProbe(in_msg.LineAddress)]);
396 action(a_issueGETS, "a", desc="Issue GETS") {
397 peek(mandatoryQueue_in, CacheMsg) {
398 enqueue(requestNetwork_out, RequestMsg, latency= request_latency) {
399 out_msg.Address := address;
400 out_msg.Type := CoherenceRequestType:GETS;
401 out_msg.Requestor := machineID;
402 out_msg.RequestorMachine := MachineType:L1Cache;
403 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
404 l2_select_low_bit, l2_select_num_bits));
405 out_msg.MessageSize := MessageSizeType:Request_Control;
406 out_msg.AccessMode := in_msg.AccessMode;
407 out_msg.Prefetch := in_msg.Prefetch;
412 action(b_issueGETX, "b", desc="Issue GETX") {
413 peek(mandatoryQueue_in, CacheMsg) {
414 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
415 out_msg.Address := address;
416 out_msg.Type := CoherenceRequestType:GETX;
417 out_msg.Requestor := machineID;
418 out_msg.RequestorMachine := MachineType:L1Cache;
419 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
420 l2_select_low_bit, l2_select_num_bits));
421 out_msg.MessageSize := MessageSizeType:Request_Control;
422 out_msg.AccessMode := in_msg.AccessMode;
423 out_msg.Prefetch := in_msg.Prefetch;
428 action(d_issuePUTX, "d", desc="Issue PUTX") {
429 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
430 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
431 out_msg.Address := address;
432 out_msg.Type := CoherenceRequestType:PUTX;
433 out_msg.Requestor := machineID;
434 out_msg.RequestorMachine := MachineType:L1Cache;
435 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
436 l2_select_low_bit, l2_select_num_bits));
437 out_msg.MessageSize := MessageSizeType:Writeback_Control;
441 action(dd_issuePUTO, "\d", desc="Issue PUTO") {
442 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
443 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
444 out_msg.Address := address;
445 out_msg.Type := CoherenceRequestType:PUTO;
446 out_msg.Requestor := machineID;
447 out_msg.RequestorMachine := MachineType:L1Cache;
448 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
449 l2_select_low_bit, l2_select_num_bits));
450 out_msg.MessageSize := MessageSizeType:Writeback_Control;
454 action(dd_issuePUTS, "\ds", desc="Issue PUTS") {
455 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
456 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
457 out_msg.Address := address;
458 out_msg.Type := CoherenceRequestType:PUTS;
459 out_msg.Requestor := machineID;
460 out_msg.RequestorMachine := MachineType:L1Cache;
461 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
462 l2_select_low_bit, l2_select_num_bits));
463 out_msg.MessageSize := MessageSizeType:Writeback_Control;
467 action(e_sendData, "e", desc="Send data from cache to requestor") {
468 peek(requestNetwork_in, RequestMsg) {
469 assert(is_valid(cache_entry));
470 if (in_msg.RequestorMachine == MachineType:L2Cache) {
471 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
472 out_msg.Address := address;
473 out_msg.Type := CoherenceResponseType:DATA;
474 out_msg.Sender := machineID;
475 out_msg.SenderMachine := MachineType:L1Cache;
476 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
477 l2_select_low_bit, l2_select_num_bits));
478 out_msg.DataBlk := cache_entry.DataBlk;
479 // out_msg.Dirty := cache_entry.Dirty;
480 out_msg.Dirty := false;
481 out_msg.Acks := in_msg.Acks;
482 out_msg.MessageSize := MessageSizeType:Response_Data;
484 DPRINTF(RubySlicc, "Sending data to L2: %s\n", in_msg.Address);
487 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
488 out_msg.Address := address;
489 out_msg.Type := CoherenceResponseType:DATA;
490 out_msg.Sender := machineID;
491 out_msg.SenderMachine := MachineType:L1Cache;
492 out_msg.Destination.add(in_msg.Requestor);
493 out_msg.DataBlk := cache_entry.DataBlk;
494 // out_msg.Dirty := cache_entry.Dirty;
495 out_msg.Dirty := false;
496 out_msg.Acks := in_msg.Acks;
497 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
499 DPRINTF(RubySlicc, "Sending data to L1\n");
504 action(e_sendDataToL2, "ee", desc="Send data from cache to requestor") {
505 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
506 assert(is_valid(cache_entry));
507 out_msg.Address := address;
508 out_msg.Type := CoherenceResponseType:DATA;
509 out_msg.Sender := machineID;
510 out_msg.SenderMachine := MachineType:L1Cache;
511 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
512 l2_select_low_bit, l2_select_num_bits));
513 out_msg.DataBlk := cache_entry.DataBlk;
514 out_msg.Dirty := cache_entry.Dirty;
515 out_msg.Acks := 0; // irrelevant
516 out_msg.MessageSize := MessageSizeType:Response_Data;
521 action(ee_sendDataExclusive, "\e", desc="Send data from cache to requestor, don't keep a shared copy") {
522 peek(requestNetwork_in, RequestMsg) {
523 assert(is_valid(cache_entry));
524 if (in_msg.RequestorMachine == MachineType:L2Cache) {
525 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
526 out_msg.Address := address;
527 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
528 out_msg.Sender := machineID;
529 out_msg.SenderMachine := MachineType:L1Cache;
530 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
531 l2_select_low_bit, l2_select_num_bits));
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:Response_Data;
537 DPRINTF(RubySlicc, "Sending exclusive data to L2\n");
540 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
541 out_msg.Address := address;
542 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
543 out_msg.Sender := machineID;
544 out_msg.SenderMachine := MachineType:L1Cache;
545 out_msg.Destination.add(in_msg.Requestor);
546 out_msg.DataBlk := cache_entry.DataBlk;
547 out_msg.Dirty := cache_entry.Dirty;
548 out_msg.Acks := in_msg.Acks;
549 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
551 DPRINTF(RubySlicc, "Sending exclusive data to L1\n");
556 action(f_sendAck, "f", desc="Send ack from cache to requestor") {
557 peek(requestNetwork_in, RequestMsg) {
558 if (in_msg.RequestorMachine == MachineType:L1Cache) {
559 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
560 out_msg.Address := address;
561 out_msg.Type := CoherenceResponseType:ACK;
562 out_msg.Sender := machineID;
563 out_msg.SenderMachine := MachineType:L1Cache;
564 out_msg.Destination.add(in_msg.Requestor);
565 out_msg.Acks := 0 - 1; // -1
566 out_msg.MessageSize := MessageSizeType:Response_Control;
570 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
571 out_msg.Address := address;
572 out_msg.Type := CoherenceResponseType:ACK;
573 out_msg.Sender := machineID;
574 out_msg.SenderMachine := MachineType:L1Cache;
575 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
576 l2_select_low_bit, l2_select_num_bits));
577 out_msg.Acks := 0 - 1; // -1
578 out_msg.MessageSize := MessageSizeType:Response_Control;
584 action(g_sendUnblock, "g", desc="Send unblock to memory") {
585 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
586 out_msg.Address := address;
587 out_msg.Type := CoherenceResponseType:UNBLOCK;
588 out_msg.Sender := machineID;
589 out_msg.SenderMachine := MachineType:L1Cache;
590 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
591 l2_select_low_bit, l2_select_num_bits));
592 out_msg.MessageSize := MessageSizeType:Unblock_Control;
596 action(gg_sendUnblockExclusive, "\g", desc="Send unblock exclusive to memory") {
597 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
598 out_msg.Address := address;
599 out_msg.Type := CoherenceResponseType:UNBLOCK_EXCLUSIVE;
600 out_msg.Sender := machineID;
601 out_msg.SenderMachine := MachineType:L1Cache;
602 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
603 l2_select_low_bit, l2_select_num_bits));
604 out_msg.MessageSize := MessageSizeType:Unblock_Control;
608 action(h_load_hit, "h", desc="Notify sequencer the load completed.") {
609 assert(is_valid(cache_entry));
610 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
611 sequencer.readCallback(address, cache_entry.DataBlk);
614 action(hh_store_hit, "\h", desc="Notify sequencer that store completed.") {
615 assert(is_valid(cache_entry));
616 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
617 sequencer.writeCallback(address, cache_entry.DataBlk);
618 cache_entry.Dirty := true;
621 action(i_allocateTBE, "i", desc="Allocate TBE") {
622 check_allocate(TBEs);
623 TBEs.allocate(address);
624 set_tbe(TBEs[address]);
625 assert(is_valid(cache_entry));
626 tbe.DataBlk := cache_entry.DataBlk; // Data only used for writebacks
627 tbe.Dirty := cache_entry.Dirty;
630 action(j_popTriggerQueue, "j", desc="Pop trigger queue.") {
631 triggerQueue_in.dequeue();
634 action(jj_unsetUseTimer, "\jj", desc="Unset use timer.") {
635 useTimerTable.unset(address);
638 action(k_popMandatoryQueue, "k", desc="Pop mandatory queue.") {
639 mandatoryQueue_in.dequeue();
642 action(l_popForwardQueue, "l", desc="Pop forwareded request queue.") {
643 requestNetwork_in.dequeue();
646 action(m_decrementNumberOfMessages, "m", desc="Decrement the number of messages for which we're waiting") {
647 peek(responseToL1Cache_in, ResponseMsg) {
648 assert(is_valid(tbe));
649 DPRINTF(RubySlicc, "L1 decrementNumberOfMessages: %d\n", in_msg.Acks);
650 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
654 action(mm_decrementNumberOfMessages, "\m", desc="Decrement the number of messages for which we're waiting") {
655 peek(requestNetwork_in, RequestMsg) {
656 assert(is_valid(tbe));
657 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
661 action(n_popResponseQueue, "n", desc="Pop response queue") {
662 responseToL1Cache_in.dequeue();
665 action(o_checkForCompletion, "o", desc="Check if we have received all the messages required for completion") {
666 assert(is_valid(tbe));
667 if (tbe.NumPendingMsgs == 0) {
668 enqueue(triggerQueue_out, TriggerMsg) {
669 out_msg.Address := address;
670 out_msg.Type := TriggerType:ALL_ACKS;
675 action(o_scheduleUseTimeout, "oo", desc="Schedule a use timeout.") {
676 useTimerTable.set(address, 50);
680 action(q_sendDataFromTBEToCache, "q", desc="Send data from TBE to cache") {
681 peek(requestNetwork_in, RequestMsg) {
682 assert(is_valid(tbe));
683 if (in_msg.RequestorMachine == MachineType:L1Cache) {
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(in_msg.Requestor);
690 out_msg.DataBlk := tbe.DataBlk;
691 // out_msg.Dirty := tbe.Dirty;
692 out_msg.Dirty := false;
693 out_msg.Acks := in_msg.Acks;
694 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
698 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
699 out_msg.Address := address;
700 out_msg.Type := CoherenceResponseType:DATA;
701 out_msg.Sender := machineID;
702 out_msg.SenderMachine := MachineType:L1Cache;
703 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
704 l2_select_low_bit, l2_select_num_bits));
705 out_msg.DataBlk := tbe.DataBlk;
706 // out_msg.Dirty := tbe.Dirty;
707 out_msg.Dirty := false;
708 out_msg.Acks := in_msg.Acks;
709 out_msg.MessageSize := MessageSizeType:Response_Data;
715 action(q_sendExclusiveDataFromTBEToCache, "qq", desc="Send data from TBE to cache") {
716 peek(requestNetwork_in, RequestMsg) {
717 assert(is_valid(tbe));
718 if (in_msg.RequestorMachine == MachineType:L1Cache) {
719 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
720 out_msg.Address := address;
721 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
722 out_msg.Sender := machineID;
723 out_msg.SenderMachine := MachineType:L1Cache;
724 out_msg.Destination.add(in_msg.Requestor);
725 out_msg.DataBlk := tbe.DataBlk;
726 out_msg.Dirty := tbe.Dirty;
727 out_msg.Acks := in_msg.Acks;
728 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
732 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
733 out_msg.Address := address;
734 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
735 out_msg.Sender := machineID;
736 out_msg.SenderMachine := MachineType:L1Cache;
737 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
738 l2_select_low_bit, l2_select_num_bits));
739 out_msg.DataBlk := tbe.DataBlk;
740 out_msg.Dirty := tbe.Dirty;
741 out_msg.Acks := in_msg.Acks;
742 out_msg.MessageSize := MessageSizeType:Response_Data;
749 // L2 will usually request data for a writeback
750 action(qq_sendWBDataFromTBEToL2, "\q", desc="Send data from TBE to L2") {
751 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
752 assert(is_valid(tbe));
753 out_msg.Address := address;
754 out_msg.Sender := machineID;
755 out_msg.SenderMachine := MachineType:L1Cache;
756 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
757 l2_select_low_bit, l2_select_num_bits));
758 out_msg.Dirty := tbe.Dirty;
760 out_msg.Type := CoherenceResponseType:WRITEBACK_DIRTY_DATA;
762 out_msg.Type := CoherenceResponseType:WRITEBACK_CLEAN_DATA;
764 out_msg.DataBlk := tbe.DataBlk;
765 out_msg.MessageSize := MessageSizeType:Writeback_Data;
769 action(s_deallocateTBE, "s", desc="Deallocate TBE") {
770 TBEs.deallocate(address);
774 action(u_writeDataToCache, "u", desc="Write data to cache") {
775 peek(responseToL1Cache_in, ResponseMsg) {
776 assert(is_valid(cache_entry));
777 cache_entry.DataBlk := in_msg.DataBlk;
778 cache_entry.Dirty := in_msg.Dirty;
780 if (in_msg.Type == CoherenceResponseType:DATA) {
781 //assert(in_msg.Dirty == false);
787 action(v_writeDataToCacheVerify, "v", desc="Write data to cache, assert it was same as before") {
788 peek(responseToL1Cache_in, ResponseMsg) {
789 assert(is_valid(cache_entry));
790 assert(cache_entry.DataBlk == in_msg.DataBlk);
791 cache_entry.DataBlk := in_msg.DataBlk;
792 cache_entry.Dirty := in_msg.Dirty;
796 action(kk_deallocateL1CacheBlock, "\k", desc="Deallocate cache block. Sets the cache to invalid, allowing a replacement in parallel with a fetch.") {
797 if (L1DcacheMemory.isTagPresent(address)) {
798 L1DcacheMemory.deallocate(address);
800 L1IcacheMemory.deallocate(address);
805 action(ii_allocateL1DCacheBlock, "\i", desc="Set L1 D-cache tag equal to tag of block B.") {
806 if ((is_invalid(cache_entry))) {
807 set_cache_entry(L1DcacheMemory.allocate(address, new Entry));
811 action(jj_allocateL1ICacheBlock, "\j", desc="Set L1 I-cache tag equal to tag of block B.") {
812 if ((is_invalid(cache_entry))) {
813 set_cache_entry(L1IcacheMemory.allocate(address, new Entry));
819 action(uu_profileMiss, "\u", desc="Profile the demand miss") {
820 peek(mandatoryQueue_in, CacheMsg) {
821 // profile_miss(in_msg);
825 action(z_recycleRequestQueue, "z", desc="Send the head of the mandatory queue to the back of the queue.") {
826 requestNetwork_in.recycle();
829 action(zz_recycleMandatoryQueue, "\z", desc="Send the head of the mandatory queue to the back of the queue.") {
830 mandatoryQueue_in.recycle();
833 //*****************************************************
835 //*****************************************************
837 // Transitions for Load/Store/L2_Replacement from transient states
838 transition({IM, SM, OM, IS, OI, SI, MI, II}, {Store, L1_Replacement}) {
839 zz_recycleMandatoryQueue;
842 transition({M_W, MM_W}, L1_Replacement) {
843 zz_recycleMandatoryQueue;
846 transition({M_W, MM_W}, {Fwd_GETS, Fwd_DMA, Fwd_GETX, Own_GETX, Inv}) {
847 z_recycleRequestQueue;
850 transition({IM, IS, OI, MI, SI, II}, {Load, Ifetch}) {
851 zz_recycleMandatoryQueue;
854 // Transitions from Idle
855 transition(I, Load, IS) {
856 ii_allocateL1DCacheBlock;
863 transition(I, Ifetch, IS) {
864 jj_allocateL1ICacheBlock;
871 transition(I, Store, IM) {
872 ii_allocateL1DCacheBlock;
879 transition(I, L1_Replacement) {
880 kk_deallocateL1CacheBlock;
888 // Transitions from Shared
889 transition({S, SM}, {Load, Ifetch}) {
894 transition(S, Store, SM) {
901 transition(S, L1_Replacement, SI) {
904 kk_deallocateL1CacheBlock;
907 transition(S, Inv, I) {
912 transition(S, {Fwd_GETS, Fwd_DMA}) {
917 // Transitions from Owned
918 transition({O, OM}, {Load, Ifetch}) {
923 transition(O, Store, OM) {
930 transition(O, L1_Replacement, OI) {
933 kk_deallocateL1CacheBlock;
936 transition(O, Fwd_GETX, I) {
937 ee_sendDataExclusive;
941 transition(O, {Fwd_GETS, Fwd_DMA}) {
946 // Transitions from MM
947 transition({MM, MM_W}, {Load, Ifetch}) {
952 transition({MM, MM_W}, Store) {
957 transition(MM, L1_Replacement, MI) {
960 kk_deallocateL1CacheBlock;
963 transition(MM, Fwd_GETX, I) {
964 ee_sendDataExclusive;
968 transition(MM, Fwd_GETS, I) {
969 ee_sendDataExclusive;
973 transition(MM, Fwd_DMA, MM) {
974 //ee_sendDataExclusive;
979 // Transitions from M
980 transition({M, M_W}, {Load, Ifetch}) {
985 transition(M, Store, MM) {
990 transition(M_W, Store, MM_W) {
995 transition(M, L1_Replacement, MI) {
998 kk_deallocateL1CacheBlock;
1001 transition(M, Fwd_GETX, I) {
1003 ee_sendDataExclusive;
1007 transition(M, Fwd_GETS, O) {
1012 transition(M, Fwd_DMA, M) {
1017 // Transitions from IM
1019 transition(IM, Inv) {
1024 transition(IM, Ack) {
1025 m_decrementNumberOfMessages;
1026 o_checkForCompletion;
1030 transition(IM, {Exclusive_Data, Data}, OM) {
1032 m_decrementNumberOfMessages;
1033 o_checkForCompletion;
1037 // Transitions from SM
1038 transition(SM, Inv, IM) {
1043 transition(SM, Ack) {
1044 m_decrementNumberOfMessages;
1045 o_checkForCompletion;
1049 transition(SM, {Data, Exclusive_Data}, OM) {
1050 // v_writeDataToCacheVerify;
1051 m_decrementNumberOfMessages;
1052 o_checkForCompletion;
1056 transition(SM, {Fwd_DMA, Fwd_GETS}) {
1061 // Transitions from OM
1062 transition(OM, Own_GETX) {
1063 mm_decrementNumberOfMessages;
1064 o_checkForCompletion;
1069 // transition(OM, Fwd_GETX, OMF) {
1070 transition(OM, Fwd_GETX, IM) {
1071 ee_sendDataExclusive;
1075 transition(OM, {Fwd_DMA, Fwd_GETS}, OM) {
1080 //transition({OM, OMF}, Ack) {
1081 transition(OM, Ack) {
1082 m_decrementNumberOfMessages;
1083 o_checkForCompletion;
1087 transition(OM, All_acks, MM_W) {
1089 gg_sendUnblockExclusive;
1091 o_scheduleUseTimeout;
1095 transition(MM_W, Use_Timeout, MM) {
1099 // Transitions from IS
1101 transition(IS, Inv) {
1106 transition(IS, Data, S) {
1108 m_decrementNumberOfMessages;
1115 transition(IS, Exclusive_Data, M_W) {
1117 m_decrementNumberOfMessages;
1119 gg_sendUnblockExclusive;
1120 o_scheduleUseTimeout;
1125 transition(M_W, Use_Timeout, M) {
1129 // Transitions from OI/MI
1131 transition(MI, Fwd_GETS, OI) {
1132 q_sendDataFromTBEToCache;
1136 transition(MI, Fwd_DMA, MI) {
1137 q_sendDataFromTBEToCache;
1141 transition(MI, Fwd_GETX, II) {
1142 q_sendExclusiveDataFromTBEToCache;
1146 transition({SI, OI}, {Fwd_DMA, Fwd_GETS}) {
1147 q_sendDataFromTBEToCache;
1151 transition(OI, Fwd_GETX, II) {
1152 q_sendExclusiveDataFromTBEToCache;
1156 transition({SI, OI, MI}, Writeback_Ack_Data, I) {
1157 qq_sendWBDataFromTBEToL2; // always send data
1162 transition({SI, OI, MI}, Writeback_Ack, I) {
1168 transition({MI, OI}, Writeback_Nack, OI) {
1169 // FIXME: This might cause deadlock by re-using the writeback
1170 // channel, we should handle this case differently.
1175 // Transitions from II
1176 transition(II, {Writeback_Ack, Writeback_Ack_Data}, I) {
1182 // transition({II, SI}, Writeback_Nack, I) {
1183 transition(II, Writeback_Nack, I) {
1188 transition(SI, Writeback_Nack) {
1193 transition(II, Inv) {
1198 transition(SI, Inv, II) {