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 MessageBuffer foo, network="To", virtual_network="1", ordered="false";
48 // a local L1 -> this L2 bank
49 MessageBuffer responseFromL1Cache, network="To", virtual_network="2", ordered="false";
50 // MessageBuffer writebackFromL1Cache, network="To", virtual_network="3", ordered="false";
53 // To this node's L1 cache FROM the network
54 // a L2 bank -> this L1
55 MessageBuffer requestToL1Cache, network="From", virtual_network="0", ordered="false";
56 MessageBuffer goo, network="From", virtual_network="1", ordered="false";
57 // a L2 bank -> this L1
58 MessageBuffer responseToL1Cache, network="From", virtual_network="2", ordered="false";
63 enumeration(State, desc="Cache states", default="L1Cache_State_I") {
68 M, desc="Modified (dirty)";
69 M_W, desc="Modified (dirty)";
70 MM, desc="Modified (dirty and locally modified)";
71 MM_W, desc="Modified (dirty and locally modified)";
74 IM, "IM", desc="Issued GetX";
75 SM, "SM", desc="Issued GetX, we still have an old copy of the line";
76 OM, "SM", desc="Issued GetX, received data";
77 IS, "IS", desc="Issued GetS";
78 SI, "OI", desc="Issued PutS, waiting for ack";
79 OI, "OI", desc="Issued PutO, waiting for ack";
80 MI, "MI", desc="Issued PutX, waiting for ack";
81 II, "II", desc="Issued PutX/O, saw Fwd_GETS or Fwd_GETX, waiting for ack";
85 enumeration(Event, desc="Cache events") {
86 Load, desc="Load request from the processor";
87 Ifetch, desc="I-fetch request from the processor";
88 Store, desc="Store request from the processor";
89 L1_Replacement, desc="Replacement";
92 Own_GETX, desc="We observe our own GetX forwarded back to us";
93 Fwd_GETX, desc="A GetX from another processor";
94 Fwd_GETS, desc="A GetS from another processor";
95 Fwd_DMA, desc="A GetS from another processor";
96 Inv, desc="Invalidations from the directory";
99 Ack, desc="Received an ack message";
100 Data, desc="Received a data message, responder has a shared copy";
101 Exclusive_Data, desc="Received a data message";
103 Writeback_Ack, desc="Writeback O.K. from directory";
104 Writeback_Ack_Data, desc="Writeback O.K. from directory";
105 Writeback_Nack, desc="Writeback not O.K. from directory";
108 All_acks, desc="Received all required data and message acks";
111 Use_Timeout, desc="lockout period ended";
117 structure(Entry, desc="...", interface="AbstractCacheEntry") {
118 State CacheState, desc="cache state";
119 bool Dirty, desc="Is the data dirty (different than memory)?";
120 DataBlock DataBlk, desc="data for the block";
124 structure(TBE, desc="...") {
125 Address Address, desc="Physical address for this TBE";
126 State TBEState, desc="Transient state";
127 DataBlock DataBlk, desc="data for the block, required for concurrent writebacks";
128 bool Dirty, desc="Is the data dirty (different than memory)?";
129 int NumPendingMsgs, default="0", desc="Number of acks/data messages that this processor is waiting for";
132 external_type(TBETable) {
134 void allocate(Address);
135 void deallocate(Address);
136 bool isPresent(Address);
139 void set_cache_entry(AbstractCacheEntry b);
140 void unset_cache_entry();
144 MessageBuffer mandatoryQueue, ordered="false", abstract_chip_ptr="true";
146 TBETable TBEs, template_hack="<L1Cache_TBE>";
147 TimerTable useTimerTable;
148 int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
150 Entry getCacheEntry(Address addr), return_by_pointer="yes" {
151 Entry L1Dcache_entry := static_cast(Entry, "pointer", L1DcacheMemory.lookup(addr));
152 if(is_valid(L1Dcache_entry)) {
153 return L1Dcache_entry;
156 Entry L1Icache_entry := static_cast(Entry, "pointer", L1IcacheMemory.lookup(addr));
157 return L1Icache_entry;
160 Entry getL1DCacheEntry(Address addr), return_by_pointer="yes" {
161 return static_cast(Entry, "pointer", L1DcacheMemory.lookup(addr));
164 Entry getL1ICacheEntry(Address addr), return_by_pointer="yes" {
165 return static_cast(Entry, "pointer", L1IcacheMemory.lookup(addr));
168 State getState(TBE tbe, Entry cache_entry, Address addr) {
171 } else if (is_valid(cache_entry)) {
172 return cache_entry.CacheState;
177 void setState(TBE tbe, Entry cache_entry, Address addr, State state) {
178 assert((L1DcacheMemory.isTagPresent(addr) && L1IcacheMemory.isTagPresent(addr)) == false);
181 tbe.TBEState := state;
184 if (is_valid(cache_entry)) {
185 if ( ((cache_entry.CacheState != State:M) && (state == State:M)) ||
186 ((cache_entry.CacheState != State:MM) && (state == State:MM)) ||
187 ((cache_entry.CacheState != State:S) && (state == State:S)) ||
188 ((cache_entry.CacheState != State:O) && (state == State:O)) ) {
190 cache_entry.CacheState := state;
191 sequencer.checkCoherence(addr);
194 cache_entry.CacheState := state;
198 if (state == State:MM || state == State:MM_W) {
199 cache_entry.changePermission(AccessPermission:Read_Write);
200 } else if ((state == State:S) ||
201 (state == State:O) ||
202 (state == State:M) ||
203 (state == State:M_W) ||
204 (state == State:SM) ||
205 (state == State:OM)) {
206 cache_entry.changePermission(AccessPermission:Read_Only);
208 cache_entry.changePermission(AccessPermission:Invalid);
213 Event mandatory_request_type_to_event(CacheRequestType type) {
214 if (type == CacheRequestType:LD) {
216 } else if (type == CacheRequestType:IFETCH) {
218 } else if ((type == CacheRequestType:ST) || (type == CacheRequestType:ATOMIC)) {
221 error("Invalid CacheRequestType");
225 MessageBuffer triggerQueue, ordered="true";
229 out_port(requestNetwork_out, RequestMsg, requestFromL1Cache);
230 out_port(responseNetwork_out, ResponseMsg, responseFromL1Cache);
231 out_port(triggerQueue_out, TriggerMsg, triggerQueue);
232 out_port(foo_out, ResponseMsg, foo);
237 in_port(useTimerTable_in, Address, useTimerTable) {
238 if (useTimerTable_in.isReady()) {
239 trigger(Event:Use_Timeout, useTimerTable.readyAddress(),
240 getCacheEntry(useTimerTable.readyAddress()),
241 TBEs[useTimerTable.readyAddress()]);
246 in_port(goo_in, RequestMsg, goo) {
247 if (goo_in.isReady()) {
248 peek(goo_in, RequestMsg) {
255 in_port(triggerQueue_in, TriggerMsg, triggerQueue) {
256 if (triggerQueue_in.isReady()) {
257 peek(triggerQueue_in, TriggerMsg) {
258 if (in_msg.Type == TriggerType:ALL_ACKS) {
259 trigger(Event:All_acks, in_msg.Address,
260 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
262 error("Unexpected message");
268 // Nothing from the request network
271 in_port(requestNetwork_in, RequestMsg, requestToL1Cache) {
272 if (requestNetwork_in.isReady()) {
273 peek(requestNetwork_in, RequestMsg, block_on="Address") {
274 assert(in_msg.Destination.isElement(machineID));
275 DPRINTF(RubySlicc, "L1 received: %s\n", in_msg.Type);
277 if (in_msg.Type == CoherenceRequestType:GETX || in_msg.Type == CoherenceRequestType:DMA_WRITE) {
278 if (in_msg.Requestor == machineID && in_msg.RequestorMachine == MachineType:L1Cache) {
279 trigger(Event:Own_GETX, in_msg.Address,
280 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
282 trigger(Event:Fwd_GETX, in_msg.Address,
283 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
285 } else if (in_msg.Type == CoherenceRequestType:GETS) {
286 trigger(Event:Fwd_GETS, in_msg.Address,
287 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
288 } else if (in_msg.Type == CoherenceRequestType:DMA_READ) {
289 trigger(Event:Fwd_DMA, in_msg.Address,
290 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
291 } else if (in_msg.Type == CoherenceRequestType:WB_ACK) {
292 trigger(Event:Writeback_Ack, in_msg.Address,
293 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
294 } else if (in_msg.Type == CoherenceRequestType:WB_ACK_DATA) {
295 trigger(Event:Writeback_Ack_Data, in_msg.Address,
296 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
297 } else if (in_msg.Type == CoherenceRequestType:WB_NACK) {
298 trigger(Event:Writeback_Nack, in_msg.Address,
299 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
300 } else if (in_msg.Type == CoherenceRequestType:INV) {
301 trigger(Event:Inv, in_msg.Address,
302 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
304 error("Unexpected message");
311 in_port(responseToL1Cache_in, ResponseMsg, responseToL1Cache) {
312 if (responseToL1Cache_in.isReady()) {
313 peek(responseToL1Cache_in, ResponseMsg, block_on="Address") {
314 if (in_msg.Type == CoherenceResponseType:ACK) {
315 trigger(Event:Ack, in_msg.Address,
316 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
317 } else if (in_msg.Type == CoherenceResponseType:DATA) {
318 trigger(Event:Data, in_msg.Address,
319 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
320 } else if (in_msg.Type == CoherenceResponseType:DATA_EXCLUSIVE) {
321 trigger(Event:Exclusive_Data, in_msg.Address,
322 getCacheEntry(in_msg.Address), TBEs[in_msg.Address]);
324 error("Unexpected message");
330 // Nothing from the unblock network
331 // Mandatory Queue betweens Node's CPU and it's L1 caches
332 in_port(mandatoryQueue_in, CacheMsg, mandatoryQueue, desc="...") {
333 if (mandatoryQueue_in.isReady()) {
334 peek(mandatoryQueue_in, CacheMsg, block_on="LineAddress") {
336 // Check for data access to blocks in I-cache and ifetchs to blocks in D-cache
338 if (in_msg.Type == CacheRequestType:IFETCH) {
339 // ** INSTRUCTION ACCESS ***
341 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
342 // Check to see if it is in the OTHER L1
343 if (is_valid(L1Dcache_entry)) {
344 // The block is in the wrong L1, put the request on the queue to the shared L2
345 trigger(Event:L1_Replacement, in_msg.LineAddress, L1Dcache_entry,
346 TBEs[in_msg.LineAddress]);
349 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
350 if (is_valid(L1Icache_entry)) {
351 // The tag matches for the L1, so the L1 asks the L2 for it.
352 trigger(mandatory_request_type_to_event(in_msg.Type),
353 in_msg.LineAddress, L1Icache_entry,
354 TBEs[in_msg.LineAddress]);
356 if (L1IcacheMemory.cacheAvail(in_msg.LineAddress)) {
357 // L1 does't have the line, but we have space for it in the L1 so let's see if the L2 has it
358 trigger(mandatory_request_type_to_event(in_msg.Type),
359 in_msg.LineAddress, L1Icache_entry,
360 TBEs[in_msg.LineAddress]);
362 // No room in the L1, so we need to make room in the L1
363 trigger(Event:L1_Replacement,
364 L1IcacheMemory.cacheProbe(in_msg.LineAddress),
365 getL1ICacheEntry(L1IcacheMemory.cacheProbe(in_msg.LineAddress)),
366 TBEs[L1IcacheMemory.cacheProbe(in_msg.LineAddress)]);
370 // *** DATA ACCESS ***
372 Entry L1Icache_entry := getL1ICacheEntry(in_msg.LineAddress);
373 // Check to see if it is in the OTHER L1
374 if (is_valid(L1Icache_entry)) {
375 // The block is in the wrong L1, put the request on the queue to the shared L2
376 trigger(Event:L1_Replacement, in_msg.LineAddress,
377 L1Icache_entry, TBEs[in_msg.LineAddress]);
380 Entry L1Dcache_entry := getL1DCacheEntry(in_msg.LineAddress);
381 if (is_valid(L1Dcache_entry)) {
382 // The tag matches for the L1, so the L1 ask the L2 for it
383 trigger(mandatory_request_type_to_event(in_msg.Type),
384 in_msg.LineAddress, L1Dcache_entry,
385 TBEs[in_msg.LineAddress]);
387 if (L1DcacheMemory.cacheAvail(in_msg.LineAddress)) {
388 // L1 does't have the line, but we have space for it in the L1 let's see if the L2 has it
389 trigger(mandatory_request_type_to_event(in_msg.Type),
390 in_msg.LineAddress, L1Dcache_entry,
391 TBEs[in_msg.LineAddress]);
393 // No room in the L1, so we need to make room in the L1
394 trigger(Event:L1_Replacement,
395 L1DcacheMemory.cacheProbe(in_msg.LineAddress),
396 getL1DCacheEntry(L1DcacheMemory.cacheProbe(in_msg.LineAddress)),
397 TBEs[L1DcacheMemory.cacheProbe(in_msg.LineAddress)]);
408 action(a_issueGETS, "a", desc="Issue GETS") {
409 peek(mandatoryQueue_in, CacheMsg) {
410 enqueue(requestNetwork_out, RequestMsg, latency= request_latency) {
411 out_msg.Address := address;
412 out_msg.Type := CoherenceRequestType:GETS;
413 out_msg.Requestor := machineID;
414 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
415 l2_select_low_bit, l2_select_num_bits));
416 out_msg.MessageSize := MessageSizeType:Request_Control;
417 out_msg.AccessMode := in_msg.AccessMode;
418 out_msg.Prefetch := in_msg.Prefetch;
423 action(b_issueGETX, "b", desc="Issue GETX") {
424 peek(mandatoryQueue_in, CacheMsg) {
425 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
426 out_msg.Address := address;
427 out_msg.Type := CoherenceRequestType:GETX;
428 out_msg.Requestor := machineID;
429 out_msg.RequestorMachine := MachineType:L1Cache;
430 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
431 l2_select_low_bit, l2_select_num_bits));
432 out_msg.MessageSize := MessageSizeType:Request_Control;
433 out_msg.AccessMode := in_msg.AccessMode;
434 out_msg.Prefetch := in_msg.Prefetch;
439 action(d_issuePUTX, "d", desc="Issue PUTX") {
440 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
441 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
442 out_msg.Address := address;
443 out_msg.Type := CoherenceRequestType:PUTX;
444 out_msg.Requestor := machineID;
445 out_msg.RequestorMachine := MachineType:L1Cache;
446 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
447 l2_select_low_bit, l2_select_num_bits));
448 out_msg.MessageSize := MessageSizeType:Writeback_Control;
452 action(dd_issuePUTO, "\d", desc="Issue PUTO") {
453 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
454 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
455 out_msg.Address := address;
456 out_msg.Type := CoherenceRequestType:PUTO;
457 out_msg.Requestor := machineID;
458 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
459 l2_select_low_bit, l2_select_num_bits));
460 out_msg.MessageSize := MessageSizeType:Writeback_Control;
464 action(dd_issuePUTS, "\ds", desc="Issue PUTS") {
465 // enqueue(writebackNetwork_out, RequestMsg, latency=request_latency) {
466 enqueue(requestNetwork_out, RequestMsg, latency=request_latency) {
467 out_msg.Address := address;
468 out_msg.Type := CoherenceRequestType:PUTS;
469 out_msg.Requestor := machineID;
470 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
471 l2_select_low_bit, l2_select_num_bits));
472 out_msg.MessageSize := MessageSizeType:Writeback_Control;
476 action(e_sendData, "e", desc="Send data from cache to requestor") {
477 peek(requestNetwork_in, RequestMsg) {
478 assert(is_valid(cache_entry));
479 if (in_msg.RequestorMachine == MachineType:L2Cache) {
480 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
481 out_msg.Address := address;
482 out_msg.Type := CoherenceResponseType:DATA;
483 out_msg.Sender := machineID;
484 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
485 l2_select_low_bit, l2_select_num_bits));
486 out_msg.DataBlk := cache_entry.DataBlk;
487 // out_msg.Dirty := cache_entry.Dirty;
488 out_msg.Dirty := false;
489 out_msg.Acks := in_msg.Acks;
490 out_msg.MessageSize := MessageSizeType:Response_Data;
492 DPRINTF(RubySlicc, "Sending data to L2: %s\n", in_msg.Address);
495 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
496 out_msg.Address := address;
497 out_msg.Type := CoherenceResponseType:DATA;
498 out_msg.Sender := machineID;
499 out_msg.Destination.add(in_msg.Requestor);
500 out_msg.DataBlk := cache_entry.DataBlk;
501 // out_msg.Dirty := cache_entry.Dirty;
502 out_msg.Dirty := false;
503 out_msg.Acks := in_msg.Acks;
504 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
506 DPRINTF(RubySlicc, "Sending data to L1\n");
511 action(e_sendDataToL2, "ee", desc="Send data from cache to requestor") {
512 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
513 assert(is_valid(cache_entry));
514 out_msg.Address := address;
515 out_msg.Type := CoherenceResponseType:DATA;
516 out_msg.Sender := machineID;
517 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
518 l2_select_low_bit, l2_select_num_bits));
519 out_msg.DataBlk := cache_entry.DataBlk;
520 out_msg.Dirty := cache_entry.Dirty;
521 out_msg.Acks := 0; // irrelevant
522 out_msg.MessageSize := MessageSizeType:Response_Data;
527 action(ee_sendDataExclusive, "\e", desc="Send data from cache to requestor, don't keep a shared copy") {
528 peek(requestNetwork_in, RequestMsg) {
529 assert(is_valid(cache_entry));
530 if (in_msg.RequestorMachine == MachineType:L2Cache) {
531 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
532 out_msg.Address := address;
533 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
534 out_msg.Sender := machineID;
535 out_msg.SenderMachine := MachineType:L1Cache;
536 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
537 l2_select_low_bit, l2_select_num_bits));
538 out_msg.DataBlk := cache_entry.DataBlk;
539 out_msg.Dirty := cache_entry.Dirty;
540 out_msg.Acks := in_msg.Acks;
541 out_msg.MessageSize := MessageSizeType:Response_Data;
543 DPRINTF(RubySlicc, "Sending exclusive data to L2\n");
546 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
547 out_msg.Address := address;
548 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
549 out_msg.Sender := machineID;
550 out_msg.SenderMachine := MachineType:L1Cache;
551 out_msg.Destination.add(in_msg.Requestor);
552 out_msg.DataBlk := cache_entry.DataBlk;
553 out_msg.Dirty := cache_entry.Dirty;
554 out_msg.Acks := in_msg.Acks;
555 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
557 DPRINTF(RubySlicc, "Sending exclusive data to L1\n");
562 action(f_sendAck, "f", desc="Send ack from cache to requestor") {
563 peek(requestNetwork_in, RequestMsg) {
564 if (in_msg.RequestorMachine == MachineType:L1Cache) {
565 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
566 out_msg.Address := address;
567 out_msg.Type := CoherenceResponseType:ACK;
568 out_msg.Sender := machineID;
569 out_msg.SenderMachine := MachineType:L1Cache;
570 out_msg.Destination.add(in_msg.Requestor);
571 out_msg.Acks := 0 - 1; // -1
572 out_msg.MessageSize := MessageSizeType:Response_Control;
576 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
577 out_msg.Address := address;
578 out_msg.Type := CoherenceResponseType:ACK;
579 out_msg.Sender := machineID;
580 out_msg.SenderMachine := MachineType:L1Cache;
581 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
582 l2_select_low_bit, l2_select_num_bits));
583 out_msg.Acks := 0 - 1; // -1
584 out_msg.MessageSize := MessageSizeType:Response_Control;
590 action(g_sendUnblock, "g", desc="Send unblock to memory") {
591 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
592 out_msg.Address := address;
593 out_msg.Type := CoherenceResponseType:UNBLOCK;
594 out_msg.Sender := machineID;
595 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
596 l2_select_low_bit, l2_select_num_bits));
597 out_msg.MessageSize := MessageSizeType:Unblock_Control;
601 action(gg_sendUnblockExclusive, "\g", desc="Send unblock exclusive to memory") {
602 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
603 out_msg.Address := address;
604 out_msg.Type := CoherenceResponseType:UNBLOCK_EXCLUSIVE;
605 out_msg.Sender := machineID;
606 out_msg.SenderMachine := MachineType:L1Cache;
607 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
608 l2_select_low_bit, l2_select_num_bits));
609 out_msg.MessageSize := MessageSizeType:Unblock_Control;
613 action(h_load_hit, "h", desc="Notify sequencer the load completed.") {
614 assert(is_valid(cache_entry));
615 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
616 sequencer.readCallback(address, cache_entry.DataBlk);
619 action(hh_store_hit, "\h", desc="Notify sequencer that store completed.") {
620 assert(is_valid(cache_entry));
621 DPRINTF(RubySlicc, "%s\n", cache_entry.DataBlk);
622 sequencer.writeCallback(address, cache_entry.DataBlk);
623 cache_entry.Dirty := true;
626 action(i_allocateTBE, "i", desc="Allocate TBE") {
627 check_allocate(TBEs);
628 TBEs.allocate(address);
629 set_tbe(TBEs[address]);
630 assert(is_valid(cache_entry));
631 tbe.DataBlk := cache_entry.DataBlk; // Data only used for writebacks
632 tbe.Dirty := cache_entry.Dirty;
635 action(j_popTriggerQueue, "j", desc="Pop trigger queue.") {
636 triggerQueue_in.dequeue();
639 action(jj_unsetUseTimer, "\jj", desc="Unset use timer.") {
640 useTimerTable.unset(address);
643 action(k_popMandatoryQueue, "k", desc="Pop mandatory queue.") {
644 mandatoryQueue_in.dequeue();
647 action(l_popForwardQueue, "l", desc="Pop forwareded request queue.") {
648 requestNetwork_in.dequeue();
651 action(m_decrementNumberOfMessages, "m", desc="Decrement the number of messages for which we're waiting") {
652 peek(responseToL1Cache_in, ResponseMsg) {
653 assert(is_valid(tbe));
654 DPRINTF(RubySlicc, "L1 decrementNumberOfMessages: %d\n", in_msg.Acks);
655 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
659 action(mm_decrementNumberOfMessages, "\m", desc="Decrement the number of messages for which we're waiting") {
660 peek(requestNetwork_in, RequestMsg) {
661 assert(is_valid(tbe));
662 tbe.NumPendingMsgs := tbe.NumPendingMsgs - in_msg.Acks;
666 action(n_popResponseQueue, "n", desc="Pop response queue") {
667 responseToL1Cache_in.dequeue();
670 action(o_checkForCompletion, "o", desc="Check if we have received all the messages required for completion") {
671 assert(is_valid(tbe));
672 if (tbe.NumPendingMsgs == 0) {
673 enqueue(triggerQueue_out, TriggerMsg) {
674 out_msg.Address := address;
675 out_msg.Type := TriggerType:ALL_ACKS;
680 action(o_scheduleUseTimeout, "oo", desc="Schedule a use timeout.") {
681 useTimerTable.set(address, 50);
685 action(q_sendDataFromTBEToCache, "q", desc="Send data from TBE to cache") {
686 peek(requestNetwork_in, RequestMsg) {
687 assert(is_valid(tbe));
688 if (in_msg.RequestorMachine == MachineType:L1Cache) {
689 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
690 out_msg.Address := address;
691 out_msg.Type := CoherenceResponseType:DATA;
692 out_msg.Sender := machineID;
693 out_msg.Destination.add(in_msg.Requestor);
694 out_msg.DataBlk := tbe.DataBlk;
695 // out_msg.Dirty := tbe.Dirty;
696 out_msg.Dirty := false;
697 out_msg.Acks := in_msg.Acks;
698 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
702 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
703 out_msg.Address := address;
704 out_msg.Type := CoherenceResponseType:DATA;
705 out_msg.Sender := machineID;
706 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
707 l2_select_low_bit, l2_select_num_bits));
708 out_msg.DataBlk := tbe.DataBlk;
709 // out_msg.Dirty := tbe.Dirty;
710 out_msg.Dirty := false;
711 out_msg.Acks := in_msg.Acks;
712 out_msg.MessageSize := MessageSizeType:Response_Data;
718 action(q_sendExclusiveDataFromTBEToCache, "qq", desc="Send data from TBE to cache") {
719 peek(requestNetwork_in, RequestMsg) {
720 assert(is_valid(tbe));
721 if (in_msg.RequestorMachine == MachineType:L1Cache) {
722 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
723 out_msg.Address := address;
724 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
725 out_msg.Sender := machineID;
726 out_msg.Destination.add(in_msg.Requestor);
727 out_msg.DataBlk := tbe.DataBlk;
728 out_msg.Dirty := tbe.Dirty;
729 out_msg.Acks := in_msg.Acks;
730 out_msg.MessageSize := MessageSizeType:ResponseLocal_Data;
734 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
735 out_msg.Address := address;
736 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE;
737 out_msg.Sender := machineID;
738 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
739 l2_select_low_bit, l2_select_num_bits));
740 out_msg.DataBlk := tbe.DataBlk;
741 out_msg.Dirty := tbe.Dirty;
742 out_msg.Acks := in_msg.Acks;
743 out_msg.MessageSize := MessageSizeType:Response_Data;
750 // L2 will usually request data for a writeback
751 action(qq_sendWBDataFromTBEToL2, "\q", desc="Send data from TBE to L2") {
752 enqueue(responseNetwork_out, ResponseMsg, latency=request_latency) {
753 assert(is_valid(tbe));
754 out_msg.Address := address;
755 out_msg.Sender := machineID;
756 out_msg.SenderMachine := MachineType:L1Cache;
757 out_msg.Destination.add(mapAddressToRange(address, MachineType:L2Cache,
758 l2_select_low_bit, l2_select_num_bits));
759 out_msg.Dirty := tbe.Dirty;
761 out_msg.Type := CoherenceResponseType:WRITEBACK_DIRTY_DATA;
763 out_msg.Type := CoherenceResponseType:WRITEBACK_CLEAN_DATA;
765 out_msg.DataBlk := tbe.DataBlk;
766 out_msg.MessageSize := MessageSizeType:Writeback_Data;
770 action(s_deallocateTBE, "s", desc="Deallocate TBE") {
771 TBEs.deallocate(address);
775 action(u_writeDataToCache, "u", desc="Write data to cache") {
776 peek(responseToL1Cache_in, ResponseMsg) {
777 assert(is_valid(cache_entry));
778 cache_entry.DataBlk := in_msg.DataBlk;
779 cache_entry.Dirty := in_msg.Dirty;
781 if (in_msg.Type == CoherenceResponseType:DATA) {
782 //assert(in_msg.Dirty == false);
788 action(v_writeDataToCacheVerify, "v", desc="Write data to cache, assert it was same as before") {
789 peek(responseToL1Cache_in, ResponseMsg) {
790 assert(is_valid(cache_entry));
791 assert(cache_entry.DataBlk == in_msg.DataBlk);
792 cache_entry.DataBlk := in_msg.DataBlk;
793 cache_entry.Dirty := in_msg.Dirty;
797 action(kk_deallocateL1CacheBlock, "\k", desc="Deallocate cache block. Sets the cache to invalid, allowing a replacement in parallel with a fetch.") {
798 if (L1DcacheMemory.isTagPresent(address)) {
799 L1DcacheMemory.deallocate(address);
801 L1IcacheMemory.deallocate(address);
806 action(ii_allocateL1DCacheBlock, "\i", desc="Set L1 D-cache tag equal to tag of block B.") {
807 if ((is_invalid(cache_entry))) {
808 set_cache_entry(L1DcacheMemory.allocate(address, new Entry));
812 action(jj_allocateL1ICacheBlock, "\j", desc="Set L1 I-cache tag equal to tag of block B.") {
813 if ((is_invalid(cache_entry))) {
814 set_cache_entry(L1IcacheMemory.allocate(address, new Entry));
820 action(uu_profileMiss, "\u", desc="Profile the demand miss") {
821 peek(mandatoryQueue_in, CacheMsg) {
822 // profile_miss(in_msg);
826 action(z_recycleRequestQueue, "z", desc="Send the head of the mandatory queue to the back of the queue.") {
827 requestNetwork_in.recycle();
830 action(zz_recycleMandatoryQueue, "\z", desc="Send the head of the mandatory queue to the back of the queue.") {
831 mandatoryQueue_in.recycle();
834 //*****************************************************
836 //*****************************************************
838 // Transitions for Load/Store/L2_Replacement from transient states
839 transition({IM, SM, OM, IS, OI, SI, MI, II}, {Store, L1_Replacement}) {
840 zz_recycleMandatoryQueue;
843 transition({M_W, MM_W}, L1_Replacement) {
844 zz_recycleMandatoryQueue;
847 transition({M_W, MM_W}, {Fwd_GETS, Fwd_DMA, Fwd_GETX, Own_GETX, Inv}) {
848 z_recycleRequestQueue;
851 transition({IM, IS, OI, MI, SI, II}, {Load, Ifetch}) {
852 zz_recycleMandatoryQueue;
855 // Transitions from Idle
856 transition(I, Load, IS) {
857 ii_allocateL1DCacheBlock;
864 transition(I, Ifetch, IS) {
865 jj_allocateL1ICacheBlock;
872 transition(I, Store, IM) {
873 ii_allocateL1DCacheBlock;
880 transition(I, L1_Replacement) {
881 kk_deallocateL1CacheBlock;
889 // Transitions from Shared
890 transition({S, SM}, {Load, Ifetch}) {
895 transition(S, Store, SM) {
902 transition(S, L1_Replacement, SI) {
905 kk_deallocateL1CacheBlock;
908 transition(S, Inv, I) {
913 transition(S, {Fwd_GETS, Fwd_DMA}) {
918 // Transitions from Owned
919 transition({O, OM}, {Load, Ifetch}) {
924 transition(O, Store, OM) {
931 transition(O, L1_Replacement, OI) {
934 kk_deallocateL1CacheBlock;
937 transition(O, Fwd_GETX, I) {
938 ee_sendDataExclusive;
942 transition(O, {Fwd_GETS, Fwd_DMA}) {
947 // Transitions from MM
948 transition({MM, MM_W}, {Load, Ifetch}) {
953 transition({MM, MM_W}, Store) {
958 transition(MM, L1_Replacement, MI) {
961 kk_deallocateL1CacheBlock;
964 transition(MM, Fwd_GETX, I) {
965 ee_sendDataExclusive;
969 transition(MM, Fwd_GETS, I) {
970 ee_sendDataExclusive;
974 transition(MM, Fwd_DMA, MM) {
975 //ee_sendDataExclusive;
980 // Transitions from M
981 transition({M, M_W}, {Load, Ifetch}) {
986 transition(M, Store, MM) {
991 transition(M_W, Store, MM_W) {
996 transition(M, L1_Replacement, MI) {
999 kk_deallocateL1CacheBlock;
1002 transition(M, Fwd_GETX, I) {
1004 ee_sendDataExclusive;
1008 transition(M, Fwd_GETS, O) {
1013 transition(M, Fwd_DMA, M) {
1018 // Transitions from IM
1020 transition(IM, Inv) {
1025 transition(IM, Ack) {
1026 m_decrementNumberOfMessages;
1027 o_checkForCompletion;
1031 transition(IM, {Exclusive_Data, Data}, OM) {
1033 m_decrementNumberOfMessages;
1034 o_checkForCompletion;
1038 // Transitions from SM
1039 transition(SM, Inv, IM) {
1044 transition(SM, Ack) {
1045 m_decrementNumberOfMessages;
1046 o_checkForCompletion;
1050 transition(SM, {Data, Exclusive_Data}, OM) {
1051 // v_writeDataToCacheVerify;
1052 m_decrementNumberOfMessages;
1053 o_checkForCompletion;
1057 transition(SM, {Fwd_DMA, Fwd_GETS}) {
1062 // Transitions from OM
1063 transition(OM, Own_GETX) {
1064 mm_decrementNumberOfMessages;
1065 o_checkForCompletion;
1070 // transition(OM, Fwd_GETX, OMF) {
1071 transition(OM, Fwd_GETX, IM) {
1072 ee_sendDataExclusive;
1076 transition(OM, {Fwd_DMA, Fwd_GETS}, OM) {
1081 //transition({OM, OMF}, Ack) {
1082 transition(OM, Ack) {
1083 m_decrementNumberOfMessages;
1084 o_checkForCompletion;
1088 transition(OM, All_acks, MM_W) {
1090 gg_sendUnblockExclusive;
1092 o_scheduleUseTimeout;
1096 transition(MM_W, Use_Timeout, MM) {
1100 // Transitions from IS
1102 transition(IS, Inv) {
1107 transition(IS, Data, S) {
1109 m_decrementNumberOfMessages;
1116 transition(IS, Exclusive_Data, M_W) {
1118 m_decrementNumberOfMessages;
1120 gg_sendUnblockExclusive;
1121 o_scheduleUseTimeout;
1126 transition(M_W, Use_Timeout, M) {
1130 // Transitions from OI/MI
1132 transition(MI, Fwd_GETS, OI) {
1133 q_sendDataFromTBEToCache;
1137 transition(MI, Fwd_DMA, MI) {
1138 q_sendDataFromTBEToCache;
1142 transition(MI, Fwd_GETX, II) {
1143 q_sendExclusiveDataFromTBEToCache;
1147 transition({SI, OI}, {Fwd_DMA, Fwd_GETS}) {
1148 q_sendDataFromTBEToCache;
1152 transition(OI, Fwd_GETX, II) {
1153 q_sendExclusiveDataFromTBEToCache;
1157 transition({SI, OI, MI}, Writeback_Ack_Data, I) {
1158 qq_sendWBDataFromTBEToL2; // always send data
1163 transition({SI, OI, MI}, Writeback_Ack, I) {
1169 transition({MI, OI}, Writeback_Nack, OI) {
1170 // FIXME: This might cause deadlock by re-using the writeback
1171 // channel, we should handle this case differently.
1176 // Transitions from II
1177 transition(II, {Writeback_Ack, Writeback_Ack_Data}, I) {
1183 // transition({II, SI}, Writeback_Nack, I) {
1184 transition(II, Writeback_Nack, I) {
1189 transition(SI, Writeback_Nack) {
1194 transition(II, Inv) {
1199 transition(SI, Inv, II) {