2 * Copyright (c) 1999-2013 Mark D. Hill and David A. Wood
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 machine(Directory, "Token protocol")
30 : DirectoryMemory * directory;
31 int l2_select_num_bits;
32 Cycles directory_latency := 5;
33 bool distributed_persistent := "True";
34 Cycles fixed_timeout_latency := 100;
35 Cycles reissue_wakeup_latency := 10;
36 Cycles to_memory_controller_latency := 1;
38 // Message Queues from dir to other controllers / network
39 MessageBuffer * dmaResponseFromDir, network="To", virtual_network="5",
42 MessageBuffer * responseFromDir, network="To", virtual_network="4",
45 MessageBuffer * persistentFromDir, network="To", virtual_network="3",
46 vnet_type="persistent";
48 MessageBuffer * requestFromDir, network="To", virtual_network="1",
51 // Message Queues to dir from other controllers / network
52 MessageBuffer * responseToDir, network="From", virtual_network="4",
55 MessageBuffer * persistentToDir, network="From", virtual_network="3",
56 vnet_type="persistent";
58 MessageBuffer * requestToDir, network="From", virtual_network="2",
61 MessageBuffer * dmaRequestToDir, network="From", virtual_network="0",
64 MessageBuffer * responseFromMemory;
67 state_declaration(State, desc="Directory states", default="Directory_State_O") {
69 O, AccessPermission:Read_Only, desc="Owner, memory has valid data, but not necessarily all the tokens";
70 NO, AccessPermission:Maybe_Stale, desc="Not Owner";
71 L, AccessPermission:Busy, desc="Locked";
73 // Memory wait states - can block all messages including persistent requests
74 O_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory write";
75 L_O_W, AccessPermission:Busy, desc="transitioning to Locked, waiting for memory read, could eventually return to O";
76 L_NO_W, AccessPermission:Busy, desc="transitioning to Locked, waiting for memory read, eventually return to NO";
77 DR_L_W, AccessPermission:Busy, desc="transitioning to Locked underneath a DMA read, waiting for memory data";
78 DW_L_W, AccessPermission:Busy, desc="transitioning to Locked underneath a DMA write, waiting for memory ack";
79 NO_W, AccessPermission:Busy, desc="transitioning to Not Owner, waiting for memory read";
80 O_DW_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory before DMA ack";
81 O_DR_W, AccessPermission:Busy, desc="transitioning to Owner, waiting for memory before DMA data";
83 // DMA request transient states - must respond to persistent requests
84 O_DW, AccessPermission:Busy, desc="issued GETX for DMA write, waiting for all tokens";
85 NO_DW, AccessPermission:Busy, desc="issued GETX for DMA write, waiting for all tokens";
86 NO_DR, AccessPermission:Busy, desc="issued GETS for DMA read, waiting for data";
88 // DMA request in progress - competing with a CPU persistent request
89 DW_L, AccessPermission:Busy, desc="issued GETX for DMA write, CPU persistent request must complete first";
90 DR_L, AccessPermission:Busy, desc="issued GETS for DMA read, CPU persistent request must complete first";
95 enumeration(Event, desc="Directory events") {
96 GETX, desc="A GETX arrives";
97 GETS, desc="A GETS arrives";
98 Lockdown, desc="A lockdown request arrives";
99 Unlockdown, desc="An un-lockdown request arrives";
100 Own_Lock_or_Unlock, desc="own lock or unlock";
101 Own_Lock_or_Unlock_Tokens, desc="own lock or unlock with tokens";
102 Data_Owner, desc="Data arrive";
103 Data_All_Tokens, desc="Data and all tokens";
104 Ack_Owner, desc="Owner token arrived without data because it was clean";
105 Ack_Owner_All_Tokens, desc="All tokens including owner arrived without data because it was clean";
106 Tokens, desc="Tokens arrive";
107 Ack_All_Tokens, desc="All_Tokens arrive";
108 Request_Timeout, desc="A DMA request has timed out";
111 Memory_Data, desc="Fetched data from memory arrives";
112 Memory_Ack, desc="Writeback Ack from memory arrives";
115 DMA_READ, desc="A DMA Read memory request";
116 DMA_WRITE, desc="A DMA Write memory request";
117 DMA_WRITE_All_Tokens, desc="A DMA Write memory request, directory has all tokens";
123 structure(Entry, desc="...", interface="AbstractEntry") {
124 State DirectoryState, desc="Directory state";
125 int Tokens, default="max_tokens()", desc="Number of tokens for the line we're holding";
127 // The following state is provided to allow for bandwidth
128 // efficient directory-like operation. However all of this state
129 // is 'soft state' that does not need to be correct (as long as
130 // you're eventually willing to resort to broadcast.)
132 Set Owner, desc="Probable Owner of the line. More accurately, the set of processors who need to see a GetS or GetO. We use a Set for convenience, but only one bit is set at a time.";
133 Set Sharers, desc="Probable sharers of the line. More accurately, the set of processors who need to see a GetX";
136 structure(PersistentTable, external="yes") {
137 void persistentRequestLock(Addr, MachineID, AccessType);
138 void persistentRequestUnlock(Addr, MachineID);
139 bool okToIssueStarving(Addr, MachineID);
140 MachineID findSmallest(Addr);
141 AccessType typeOfSmallest(Addr);
142 void markEntries(Addr);
144 int countStarvingForAddress(Addr);
145 int countReadStarvingForAddress(Addr);
148 // TBE entries for DMA requests
149 structure(TBE, desc="TBE entries for outstanding DMA requests") {
150 Addr PhysicalAddress, desc="physical address";
151 State TBEState, desc="Transient State";
152 DataBlock DataBlk, desc="Current view of the associated address range";
154 MachineID DmaRequestor, desc="DMA requestor";
155 bool WentPersistent, desc="Did the DMA request require a persistent request";
158 structure(TBETable, external="yes") {
161 void deallocate(Addr);
162 bool isPresent(Addr);
167 PersistentTable persistentTable;
168 TimerTable reissueTimerTable;
170 TBETable TBEs, template="<Directory_TBE>", constructor="m_number_of_TBEs";
172 bool starving, default="false";
173 int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
176 Tick cyclesToTicks(Cycles c);
180 Entry getDirectoryEntry(Addr addr), return_by_pointer="yes" {
181 Entry dir_entry := static_cast(Entry, "pointer", directory[addr]);
183 if (is_valid(dir_entry)) {
187 dir_entry := static_cast(Entry, "pointer",
188 directory.allocate(addr, new Entry));
192 State getState(TBE tbe, Addr addr) {
196 return getDirectoryEntry(addr).DirectoryState;
200 void setState(TBE tbe, Addr addr, State state) {
202 tbe.TBEState := state;
204 getDirectoryEntry(addr).DirectoryState := state;
206 if (state == State:L || state == State:DW_L || state == State:DR_L) {
207 assert(getDirectoryEntry(addr).Tokens == 0);
210 // We have one or zero owners
211 assert((getDirectoryEntry(addr).Owner.count() == 0) || (getDirectoryEntry(addr).Owner.count() == 1));
213 // Make sure the token count is in range
214 assert(getDirectoryEntry(addr).Tokens >= 0);
215 assert(getDirectoryEntry(addr).Tokens <= max_tokens());
217 if (state == State:O || state == State:O_W || state == State:O_DW) {
218 assert(getDirectoryEntry(addr).Tokens >= 1); // Must have at least one token
219 // assert(getDirectoryEntry(addr).Tokens >= (max_tokens() / 2)); // Only mostly true; this might not always hold
223 AccessPermission getAccessPermission(Addr addr) {
224 TBE tbe := TBEs[addr];
226 return Directory_State_to_permission(tbe.TBEState);
229 if (directory.isPresent(addr)) {
230 DPRINTF(RubySlicc, "%s\n", Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState));
231 return Directory_State_to_permission(getDirectoryEntry(addr).DirectoryState);
234 DPRINTF(RubySlicc, "AccessPermission_NotPresent\n");
235 return AccessPermission:NotPresent;
238 void setAccessPermission(Addr addr, State state) {
239 getDirectoryEntry(addr).changePermission(Directory_State_to_permission(state));
242 bool okToIssueStarving(Addr addr, MachineID machinID) {
243 return persistentTable.okToIssueStarving(addr, machineID);
246 void markPersistentEntries(Addr addr) {
247 persistentTable.markEntries(addr);
250 void functionalRead(Addr addr, Packet *pkt) {
251 TBE tbe := TBEs[addr];
253 testAndRead(addr, tbe.DataBlk, pkt);
255 functionalMemoryRead(pkt);
259 int functionalWrite(Addr addr, Packet *pkt) {
260 int num_functional_writes := 0;
262 TBE tbe := TBEs[addr];
264 num_functional_writes := num_functional_writes +
265 testAndWrite(addr, tbe.DataBlk, pkt);
268 num_functional_writes := num_functional_writes + functionalMemoryWrite(pkt);
269 return num_functional_writes;
273 out_port(responseNetwork_out, ResponseMsg, responseFromDir);
274 out_port(persistentNetwork_out, PersistentMsg, persistentFromDir);
275 out_port(requestNetwork_out, RequestMsg, requestFromDir);
276 out_port(dmaResponseNetwork_out, DMAResponseMsg, dmaResponseFromDir);
279 // off-chip memory request/response is done
280 in_port(memQueue_in, MemoryMsg, responseFromMemory) {
281 if (memQueue_in.isReady(clockEdge())) {
282 peek(memQueue_in, MemoryMsg) {
283 if (in_msg.Type == MemoryRequestType:MEMORY_READ) {
284 trigger(Event:Memory_Data, in_msg.addr, TBEs[in_msg.addr]);
285 } else if (in_msg.Type == MemoryRequestType:MEMORY_WB) {
286 trigger(Event:Memory_Ack, in_msg.addr, TBEs[in_msg.addr]);
288 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
289 error("Invalid message");
296 in_port(reissueTimerTable_in, Addr, reissueTimerTable) {
297 Tick current_time := clockEdge();
298 if (reissueTimerTable_in.isReady(current_time)) {
299 Addr addr := reissueTimerTable.nextAddress();
300 trigger(Event:Request_Timeout, addr, TBEs.lookup(addr));
304 in_port(responseNetwork_in, ResponseMsg, responseToDir) {
305 if (responseNetwork_in.isReady(clockEdge())) {
306 peek(responseNetwork_in, ResponseMsg) {
307 assert(in_msg.Destination.isElement(machineID));
308 if (getDirectoryEntry(in_msg.addr).Tokens + in_msg.Tokens == max_tokens()) {
309 if ((in_msg.Type == CoherenceResponseType:DATA_OWNER) ||
310 (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
311 trigger(Event:Data_All_Tokens, in_msg.addr,
313 } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
314 trigger(Event:Ack_Owner_All_Tokens, in_msg.addr,
316 } else if (in_msg.Type == CoherenceResponseType:ACK) {
317 trigger(Event:Ack_All_Tokens, in_msg.addr,
320 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
321 error("Invalid message");
324 if (in_msg.Type == CoherenceResponseType:DATA_OWNER) {
325 trigger(Event:Data_Owner, in_msg.addr,
327 } else if ((in_msg.Type == CoherenceResponseType:ACK) ||
328 (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
329 trigger(Event:Tokens, in_msg.addr,
331 } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
332 trigger(Event:Ack_Owner, in_msg.addr,
335 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
336 error("Invalid message");
343 in_port(persistentNetwork_in, PersistentMsg, persistentToDir) {
344 if (persistentNetwork_in.isReady(clockEdge())) {
345 peek(persistentNetwork_in, PersistentMsg) {
346 assert(in_msg.Destination.isElement(machineID));
348 if (distributed_persistent) {
349 // Apply the lockdown or unlockdown message to the table
350 if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
351 persistentTable.persistentRequestLock(in_msg.addr, in_msg.Requestor, AccessType:Write);
352 } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
353 persistentTable.persistentRequestLock(in_msg.addr, in_msg.Requestor, AccessType:Read);
354 } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
355 persistentTable.persistentRequestUnlock(in_msg.addr, in_msg.Requestor);
357 error("Invalid message");
360 // React to the message based on the current state of the table
361 if (persistentTable.isLocked(in_msg.addr)) {
362 if (persistentTable.findSmallest(in_msg.addr) == machineID) {
363 if (getDirectoryEntry(in_msg.addr).Tokens > 0) {
364 trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.addr,
367 trigger(Event:Own_Lock_or_Unlock, in_msg.addr,
372 trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
376 trigger(Event:Unlockdown, in_msg.addr, TBEs[in_msg.addr]);
380 if (persistentTable.findSmallest(in_msg.addr) == machineID) {
381 if (getDirectoryEntry(in_msg.addr).Tokens > 0) {
382 trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.addr,
385 trigger(Event:Own_Lock_or_Unlock, in_msg.addr,
388 } else if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
390 trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
391 } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
393 trigger(Event:Lockdown, in_msg.addr, TBEs[in_msg.addr]);
394 } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
396 trigger(Event:Unlockdown, in_msg.addr, TBEs[in_msg.addr]);
398 error("Invalid message");
405 in_port(requestNetwork_in, RequestMsg, requestToDir) {
406 if (requestNetwork_in.isReady(clockEdge())) {
407 peek(requestNetwork_in, RequestMsg) {
408 assert(in_msg.Destination.isElement(machineID));
409 if (in_msg.Type == CoherenceRequestType:GETS) {
410 trigger(Event:GETS, in_msg.addr, TBEs[in_msg.addr]);
411 } else if (in_msg.Type == CoherenceRequestType:GETX) {
412 trigger(Event:GETX, in_msg.addr, TBEs[in_msg.addr]);
414 error("Invalid message");
420 in_port(dmaRequestQueue_in, DMARequestMsg, dmaRequestToDir) {
421 if (dmaRequestQueue_in.isReady(clockEdge())) {
422 peek(dmaRequestQueue_in, DMARequestMsg) {
423 if (in_msg.Type == DMARequestType:READ) {
424 trigger(Event:DMA_READ, in_msg.LineAddress, TBEs[in_msg.LineAddress]);
425 } else if (in_msg.Type == DMARequestType:WRITE) {
426 if (getDirectoryEntry(in_msg.LineAddress).Tokens == max_tokens()) {
427 trigger(Event:DMA_WRITE_All_Tokens, in_msg.LineAddress,
428 TBEs[in_msg.LineAddress]);
430 trigger(Event:DMA_WRITE, in_msg.LineAddress,
431 TBEs[in_msg.LineAddress]);
434 error("Invalid message");
442 action(a_sendTokens, "a", desc="Send tokens to requestor") {
443 // Only send a message if we have tokens to send
444 if (getDirectoryEntry(address).Tokens > 0) {
445 peek(requestNetwork_in, RequestMsg) {
446 enqueue(responseNetwork_out, ResponseMsg, directory_latency) {// FIXME?
447 out_msg.addr := address;
448 out_msg.Type := CoherenceResponseType:ACK;
449 out_msg.Sender := machineID;
450 out_msg.Destination.add(in_msg.Requestor);
451 out_msg.Tokens := getDirectoryEntry(in_msg.addr).Tokens;
452 out_msg.MessageSize := MessageSizeType:Response_Control;
455 getDirectoryEntry(address).Tokens := 0;
459 action(px_tryIssuingPersistentGETXRequest, "px", desc="...") {
460 if (okToIssueStarving(address, machineID) && (starving == false)) {
461 enqueue(persistentNetwork_out, PersistentMsg, 1) {
462 out_msg.addr := address;
463 out_msg.Type := PersistentRequestType:GETX_PERSISTENT;
464 out_msg.Requestor := machineID;
465 out_msg.Destination.broadcast(MachineType:L1Cache);
468 // Currently the configuration system limits the system to only one
469 // chip. Therefore, if we assume one shared L2 cache, then only one
470 // pertinent L2 cache exist.
472 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
474 out_msg.Destination.add(mapAddressToRange(address,
475 MachineType:L2Cache, l2_select_low_bit,
476 l2_select_num_bits, intToID(0)));
478 out_msg.Destination.add(map_Address_to_Directory(address));
479 out_msg.MessageSize := MessageSizeType:Persistent_Control;
480 out_msg.Prefetch := PrefetchBit:No;
481 out_msg.AccessMode := RubyAccessMode:Supervisor;
483 markPersistentEntries(address);
486 tbe.WentPersistent := true;
488 // Do not schedule a wakeup, a persistent requests will always complete
491 // We'd like to issue a persistent request, but are not allowed
492 // to issue a P.R. right now. This, we do not increment the
495 // Set a wakeup timer
496 reissueTimerTable.set(address, cyclesToTicks(reissue_wakeup_latency));
500 action(bw_broadcastWrite, "bw", desc="Broadcast GETX if we need tokens") {
501 peek(dmaRequestQueue_in, DMARequestMsg) {
503 // Assser that we only send message if we don't already have all the tokens
505 assert(getDirectoryEntry(address).Tokens != max_tokens());
506 enqueue(requestNetwork_out, RequestMsg, 1) {
507 out_msg.addr := address;
508 out_msg.Type := CoherenceRequestType:GETX;
509 out_msg.Requestor := machineID;
512 // Since only one chip, assuming all L1 caches are local
514 out_msg.Destination.broadcast(MachineType:L1Cache);
515 out_msg.Destination.add(mapAddressToRange(address,
516 MachineType:L2Cache, l2_select_low_bit,
517 l2_select_num_bits, intToID(0)));
519 out_msg.RetryNum := 0;
520 out_msg.MessageSize := MessageSizeType:Broadcast_Control;
521 out_msg.Prefetch := PrefetchBit:No;
522 out_msg.AccessMode := RubyAccessMode:Supervisor;
527 action(ps_tryIssuingPersistentGETSRequest, "ps", desc="...") {
528 if (okToIssueStarving(address, machineID) && (starving == false)) {
529 enqueue(persistentNetwork_out, PersistentMsg, 1) {
530 out_msg.addr := address;
531 out_msg.Type := PersistentRequestType:GETS_PERSISTENT;
532 out_msg.Requestor := machineID;
533 out_msg.Destination.broadcast(MachineType:L1Cache);
536 // Currently the configuration system limits the system to only one
537 // chip. Therefore, if we assume one shared L2 cache, then only one
538 // pertinent L2 cache exist.
540 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
542 out_msg.Destination.add(mapAddressToRange(address,
543 MachineType:L2Cache, l2_select_low_bit,
544 l2_select_num_bits, intToID(0)));
546 out_msg.Destination.add(map_Address_to_Directory(address));
547 out_msg.MessageSize := MessageSizeType:Persistent_Control;
548 out_msg.Prefetch := PrefetchBit:No;
549 out_msg.AccessMode := RubyAccessMode:Supervisor;
551 markPersistentEntries(address);
554 tbe.WentPersistent := true;
556 // Do not schedule a wakeup, a persistent requests will always complete
559 // We'd like to issue a persistent request, but are not allowed
560 // to issue a P.R. right now. This, we do not increment the
563 // Set a wakeup timer
564 reissueTimerTable.set(address, cyclesToTicks(reissue_wakeup_latency));
568 action(br_broadcastRead, "br", desc="Broadcast GETS for data") {
569 peek(dmaRequestQueue_in, DMARequestMsg) {
570 enqueue(requestNetwork_out, RequestMsg, 1) {
571 out_msg.addr := address;
572 out_msg.Type := CoherenceRequestType:GETS;
573 out_msg.Requestor := machineID;
576 // Since only one chip, assuming all L1 caches are local
578 out_msg.Destination.broadcast(MachineType:L1Cache);
579 out_msg.Destination.add(mapAddressToRange(address,
580 MachineType:L2Cache, l2_select_low_bit,
581 l2_select_num_bits, intToID(0)));
583 out_msg.RetryNum := 0;
584 out_msg.MessageSize := MessageSizeType:Broadcast_Control;
585 out_msg.Prefetch := PrefetchBit:No;
586 out_msg.AccessMode := RubyAccessMode:Supervisor;
591 action(aa_sendTokensToStarver, "\a", desc="Send tokens to starver") {
592 // Only send a message if we have tokens to send
593 if (getDirectoryEntry(address).Tokens > 0) {
594 enqueue(responseNetwork_out, ResponseMsg, directory_latency) {// FIXME?
595 out_msg.addr := address;
596 out_msg.Type := CoherenceResponseType:ACK;
597 out_msg.Sender := machineID;
598 out_msg.Destination.add(persistentTable.findSmallest(address));
599 out_msg.Tokens := getDirectoryEntry(address).Tokens;
600 out_msg.MessageSize := MessageSizeType:Response_Control;
602 getDirectoryEntry(address).Tokens := 0;
606 action(d_sendMemoryDataWithAllTokens, "d", desc="Send data and tokens to requestor") {
607 peek(memQueue_in, MemoryMsg) {
608 enqueue(responseNetwork_out, ResponseMsg, 1) {
609 out_msg.addr := address;
610 out_msg.Type := CoherenceResponseType:DATA_OWNER;
611 out_msg.Sender := machineID;
612 out_msg.Destination.add(in_msg.OriginalRequestorMachId);
613 assert(getDirectoryEntry(address).Tokens > 0);
614 out_msg.Tokens := getDirectoryEntry(in_msg.addr).Tokens;
615 out_msg.DataBlk := in_msg.DataBlk;
616 out_msg.Dirty := false;
617 out_msg.MessageSize := MessageSizeType:Response_Data;
620 getDirectoryEntry(address).Tokens := 0;
623 action(dd_sendMemDataToStarver, "\d", desc="Send data and tokens to starver") {
624 peek(memQueue_in, MemoryMsg) {
625 enqueue(responseNetwork_out, ResponseMsg, 1) {
626 out_msg.addr := address;
627 out_msg.Type := CoherenceResponseType:DATA_OWNER;
628 out_msg.Sender := machineID;
629 out_msg.Destination.add(persistentTable.findSmallest(address));
630 assert(getDirectoryEntry(address).Tokens > 0);
631 out_msg.Tokens := getDirectoryEntry(address).Tokens;
632 out_msg.DataBlk := in_msg.DataBlk;
633 out_msg.Dirty := false;
634 out_msg.MessageSize := MessageSizeType:Response_Data;
637 getDirectoryEntry(address).Tokens := 0;
640 action(de_sendTbeDataToStarver, "de", desc="Send data and tokens to starver") {
641 enqueue(responseNetwork_out, ResponseMsg, 1) {
642 out_msg.addr := address;
643 out_msg.Type := CoherenceResponseType:DATA_OWNER;
644 out_msg.Sender := machineID;
645 out_msg.Destination.add(persistentTable.findSmallest(address));
646 assert(getDirectoryEntry(address).Tokens > 0);
647 out_msg.Tokens := getDirectoryEntry(address).Tokens;
648 out_msg.DataBlk := tbe.DataBlk;
649 out_msg.Dirty := false;
650 out_msg.MessageSize := MessageSizeType:Response_Data;
652 getDirectoryEntry(address).Tokens := 0;
655 action(qf_queueMemoryFetchRequest, "qf", desc="Queue off-chip fetch request") {
656 peek(requestNetwork_in, RequestMsg) {
657 queueMemoryRead(in_msg.Requestor, address, to_memory_controller_latency);
661 action(qp_queueMemoryForPersistent, "qp", desc="Queue off-chip fetch request") {
662 queueMemoryRead(persistentTable.findSmallest(address), address,
663 to_memory_controller_latency);
666 action(fd_memoryDma, "fd", desc="Queue off-chip fetch request") {
667 peek(dmaRequestQueue_in, DMARequestMsg) {
668 queueMemoryRead(in_msg.Requestor, address, to_memory_controller_latency);
672 action(lq_queueMemoryWbRequest, "lq", desc="Write data to memory") {
673 peek(responseNetwork_in, ResponseMsg) {
674 queueMemoryWrite(in_msg.Sender, address, to_memory_controller_latency,
679 action(ld_queueMemoryDmaWriteFromTbe, "ld", desc="Write DMA data to memory") {
680 queueMemoryWritePartial(tbe.DmaRequestor, address,
681 to_memory_controller_latency, tbe.DataBlk,
685 action(lr_queueMemoryDmaReadWriteback, "lr",
686 desc="Write DMA data from read to memory") {
687 peek(responseNetwork_in, ResponseMsg) {
688 queueMemoryWrite(machineID, address, to_memory_controller_latency,
693 action(vd_allocateDmaRequestInTBE, "vd", desc="Record Data in TBE") {
694 peek(dmaRequestQueue_in, DMARequestMsg) {
695 TBEs.allocate(address);
696 set_tbe(TBEs[address]);
697 tbe.DataBlk := in_msg.DataBlk;
698 tbe.PhysicalAddress := in_msg.PhysicalAddress;
699 tbe.Len := in_msg.Len;
700 tbe.DmaRequestor := in_msg.Requestor;
701 tbe.WentPersistent := false;
705 action(s_deallocateTBE, "s", desc="Deallocate TBE") {
707 if (tbe.WentPersistent) {
710 enqueue(persistentNetwork_out, PersistentMsg, 1) {
711 out_msg.addr := address;
712 out_msg.Type := PersistentRequestType:DEACTIVATE_PERSISTENT;
713 out_msg.Requestor := machineID;
714 out_msg.Destination.broadcast(MachineType:L1Cache);
717 // Currently the configuration system limits the system to only one
718 // chip. Therefore, if we assume one shared L2 cache, then only one
719 // pertinent L2 cache exist.
721 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
723 out_msg.Destination.add(mapAddressToRange(address,
724 MachineType:L2Cache, l2_select_low_bit,
725 l2_select_num_bits, intToID(0)));
727 out_msg.Destination.add(map_Address_to_Directory(address));
728 out_msg.MessageSize := MessageSizeType:Persistent_Control;
733 TBEs.deallocate(address);
737 action(rd_recordDataInTbe, "rd", desc="Record data in TBE") {
738 peek(responseNetwork_in, ResponseMsg) {
739 DataBlock DataBlk := tbe.DataBlk;
740 tbe.DataBlk := in_msg.DataBlk;
741 tbe.DataBlk.copyPartial(DataBlk, getOffset(tbe.PhysicalAddress),
746 action(f_incrementTokens, "f", desc="Increment the number of tokens we're tracking") {
747 peek(responseNetwork_in, ResponseMsg) {
748 assert(in_msg.Tokens >= 1);
749 getDirectoryEntry(address).Tokens := getDirectoryEntry(address).Tokens + in_msg.Tokens;
753 action(aat_assertAllTokens, "aat", desc="assert that we have all tokens") {
754 assert(getDirectoryEntry(address).Tokens == max_tokens());
757 action(j_popIncomingRequestQueue, "j", desc="Pop incoming request queue") {
758 requestNetwork_in.dequeue(clockEdge());
761 action(z_recycleRequest, "z", desc="Recycle the request queue") {
762 requestNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
765 action(k_popIncomingResponseQueue, "k", desc="Pop incoming response queue") {
766 responseNetwork_in.dequeue(clockEdge());
769 action(kz_recycleResponse, "kz", desc="Recycle incoming response queue") {
770 responseNetwork_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
773 action(l_popIncomingPersistentQueue, "l", desc="Pop incoming persistent queue") {
774 persistentNetwork_in.dequeue(clockEdge());
777 action(p_popDmaRequestQueue, "pd", desc="pop dma request queue") {
778 dmaRequestQueue_in.dequeue(clockEdge());
781 action(y_recycleDmaRequestQueue, "y", desc="recycle dma request queue") {
782 dmaRequestQueue_in.recycle(clockEdge(), cyclesToTicks(recycle_latency));
785 action(l_popMemQueue, "q", desc="Pop off-chip request queue") {
786 memQueue_in.dequeue(clockEdge());
789 action(r_bounceResponse, "r", desc="Bounce response to starving processor") {
790 peek(responseNetwork_in, ResponseMsg) {
791 enqueue(responseNetwork_out, ResponseMsg, 1) {
792 out_msg.addr := address;
793 out_msg.Type := in_msg.Type;
794 out_msg.Sender := machineID;
795 out_msg.Destination.add(persistentTable.findSmallest(address));
796 out_msg.Tokens := in_msg.Tokens;
797 out_msg.MessageSize := in_msg.MessageSize;
798 out_msg.DataBlk := in_msg.DataBlk;
799 out_msg.Dirty := in_msg.Dirty;
804 action(rs_resetScheduleTimeout, "rs", desc="Reschedule Schedule Timeout") {
806 // currently only support a fixed timeout latency
808 if (reissueTimerTable.isSet(address)) {
809 reissueTimerTable.unset(address);
810 reissueTimerTable.set(address, cyclesToTicks(fixed_timeout_latency));
814 action(st_scheduleTimeout, "st", desc="Schedule Timeout") {
816 // currently only support a fixed timeout latency
818 reissueTimerTable.set(address, cyclesToTicks(fixed_timeout_latency));
821 action(ut_unsetReissueTimer, "ut", desc="Unset reissue timer.") {
822 if (reissueTimerTable.isSet(address)) {
823 reissueTimerTable.unset(address);
827 action(bd_bounceDatalessOwnerToken, "bd", desc="Bounce clean owner token to starving processor") {
828 peek(responseNetwork_in, ResponseMsg) {
829 assert(in_msg.Type == CoherenceResponseType:ACK_OWNER);
830 assert(in_msg.Dirty == false);
831 assert(in_msg.MessageSize == MessageSizeType:Writeback_Control);
833 // Bounce the message, but "re-associate" the data and the owner
834 // token. In essence we're converting an ACK_OWNER message to a
835 // DATA_OWNER message, keeping the number of tokens the same.
836 enqueue(responseNetwork_out, ResponseMsg, 1) {
837 out_msg.addr := address;
838 out_msg.Type := CoherenceResponseType:DATA_OWNER;
839 out_msg.Sender := machineID;
840 out_msg.Destination.add(persistentTable.findSmallest(address));
841 out_msg.Tokens := in_msg.Tokens;
842 out_msg.Dirty := in_msg.Dirty;
843 out_msg.MessageSize := MessageSizeType:Response_Data;
848 action(da_sendDmaAck, "da", desc="Send Ack to DMA controller") {
849 enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
850 out_msg.PhysicalAddress := address;
851 out_msg.LineAddress := address;
852 out_msg.Type := DMAResponseType:ACK;
853 out_msg.Destination.add(tbe.DmaRequestor);
854 out_msg.MessageSize := MessageSizeType:Writeback_Control;
858 action(dm_sendMemoryDataToDma, "dm", desc="Send Data to DMA controller from memory") {
859 peek(memQueue_in, MemoryMsg) {
860 enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
861 out_msg.PhysicalAddress := address;
862 out_msg.LineAddress := address;
863 out_msg.Type := DMAResponseType:DATA;
865 // we send the entire data block and rely on the dma controller to
866 // split it up if need be
868 out_msg.DataBlk := in_msg.DataBlk;
869 out_msg.Destination.add(tbe.DmaRequestor);
870 out_msg.MessageSize := MessageSizeType:Response_Data;
875 action(dd_sendDmaData, "dd", desc="Send Data to DMA controller") {
876 peek(responseNetwork_in, ResponseMsg) {
877 enqueue(dmaResponseNetwork_out, DMAResponseMsg, 1) {
878 out_msg.PhysicalAddress := address;
879 out_msg.LineAddress := address;
880 out_msg.Type := DMAResponseType:DATA;
882 // we send the entire data block and rely on the dma controller to
883 // split it up if need be
885 out_msg.DataBlk := in_msg.DataBlk;
886 out_msg.Destination.add(tbe.DmaRequestor);
887 out_msg.MessageSize := MessageSizeType:Response_Data;
895 // Trans. from base state O
896 // the directory has valid data
898 transition(O, GETX, NO_W) {
899 qf_queueMemoryFetchRequest;
900 j_popIncomingRequestQueue;
903 transition(O, DMA_WRITE, O_DW) {
904 vd_allocateDmaRequestInTBE;
907 p_popDmaRequestQueue;
910 transition(O, DMA_WRITE_All_Tokens, O_DW_W) {
911 vd_allocateDmaRequestInTBE;
912 ld_queueMemoryDmaWriteFromTbe;
913 p_popDmaRequestQueue;
916 transition(O, GETS, NO_W) {
917 qf_queueMemoryFetchRequest;
918 j_popIncomingRequestQueue;
921 transition(O, DMA_READ, O_DR_W) {
922 vd_allocateDmaRequestInTBE;
925 p_popDmaRequestQueue;
928 transition(O, Lockdown, L_O_W) {
929 qp_queueMemoryForPersistent;
930 l_popIncomingPersistentQueue;
933 transition(O, {Tokens, Ack_All_Tokens}) {
935 k_popIncomingResponseQueue;
938 transition(O, {Data_Owner, Data_All_Tokens}) {
940 k_popIncomingResponseQueue;
943 transition({O, NO}, Unlockdown) {
944 l_popIncomingPersistentQueue;
948 // transitioning to Owner, waiting for memory before DMA ack
949 // All other events should recycle/stall
951 transition(O_DR_W, Memory_Data, O) {
952 dm_sendMemoryDataToDma;
953 ut_unsetReissueTimer;
959 // issued GETX for DMA write, waiting for all tokens
961 transition(O_DW, Request_Timeout) {
962 ut_unsetReissueTimer;
963 px_tryIssuingPersistentGETXRequest;
966 transition(O_DW, Tokens) {
968 k_popIncomingResponseQueue;
971 transition(O_DW, Data_Owner) {
974 k_popIncomingResponseQueue;
977 transition(O_DW, Ack_Owner) {
979 k_popIncomingResponseQueue;
982 transition(O_DW, Lockdown, DW_L) {
983 de_sendTbeDataToStarver;
984 l_popIncomingPersistentQueue;
987 transition({NO_DW, O_DW}, Data_All_Tokens, O_DW_W) {
990 ld_queueMemoryDmaWriteFromTbe;
991 ut_unsetReissueTimer;
992 k_popIncomingResponseQueue;
995 transition(O_DW, Ack_All_Tokens, O_DW_W) {
997 ld_queueMemoryDmaWriteFromTbe;
998 ut_unsetReissueTimer;
999 k_popIncomingResponseQueue;
1002 transition(O_DW, Ack_Owner_All_Tokens, O_DW_W) {
1004 ld_queueMemoryDmaWriteFromTbe;
1005 ut_unsetReissueTimer;
1006 k_popIncomingResponseQueue;
1009 transition(O_DW_W, Memory_Ack, O) {
1017 // The direcotry does not have valid data, but may have some tokens
1019 transition(NO, GETX) {
1021 j_popIncomingRequestQueue;
1024 transition(NO, DMA_WRITE, NO_DW) {
1025 vd_allocateDmaRequestInTBE;
1028 p_popDmaRequestQueue;
1031 transition(NO, GETS) {
1032 j_popIncomingRequestQueue;
1035 transition(NO, DMA_READ, NO_DR) {
1036 vd_allocateDmaRequestInTBE;
1039 p_popDmaRequestQueue;
1042 transition(NO, Lockdown, L) {
1043 aa_sendTokensToStarver;
1044 l_popIncomingPersistentQueue;
1047 transition(NO, {Data_Owner, Data_All_Tokens}, O_W) {
1049 lq_queueMemoryWbRequest;
1050 k_popIncomingResponseQueue;
1053 transition(NO, {Ack_Owner, Ack_Owner_All_Tokens}, O) {
1055 k_popIncomingResponseQueue;
1058 transition(NO, Tokens) {
1060 k_popIncomingResponseQueue;
1063 transition(NO_W, Memory_Data, NO) {
1064 d_sendMemoryDataWithAllTokens;
1068 // Trans. from NO_DW
1069 transition(NO_DW, Request_Timeout) {
1070 ut_unsetReissueTimer;
1071 px_tryIssuingPersistentGETXRequest;
1074 transition(NO_DW, Lockdown, DW_L) {
1075 aa_sendTokensToStarver;
1076 l_popIncomingPersistentQueue;
1079 // Note: NO_DW, Data_All_Tokens transition is combined with O_DW
1080 // Note: NO_DW should not receive the action Ack_All_Tokens because the
1081 // directory does not have valid data
1083 transition(NO_DW, Data_Owner, O_DW) {
1086 k_popIncomingResponseQueue;
1089 transition({NO_DW, NO_DR}, Tokens) {
1091 k_popIncomingResponseQueue;
1094 // Trans. from NO_DR
1095 transition(NO_DR, Request_Timeout) {
1096 ut_unsetReissueTimer;
1097 ps_tryIssuingPersistentGETSRequest;
1100 transition(NO_DR, Lockdown, DR_L) {
1101 aa_sendTokensToStarver;
1102 l_popIncomingPersistentQueue;
1105 transition(NO_DR, {Data_Owner, Data_All_Tokens}, O_W) {
1108 lr_queueMemoryDmaReadWriteback;
1109 ut_unsetReissueTimer;
1111 k_popIncomingResponseQueue;
1115 transition({L, DW_L, DR_L}, {GETX, GETS}) {
1116 j_popIncomingRequestQueue;
1119 transition({L, DW_L, DR_L, L_O_W, L_NO_W, DR_L_W, DW_L_W}, Lockdown) {
1120 l_popIncomingPersistentQueue;
1124 // Received data for lockdown blocks
1125 // For blocks with outstanding dma requests to them
1126 // ...we could change this to write the data to memory and send it cleanly
1127 // ...we could also proactively complete our DMA requests
1128 // However, to keep my mind from spinning out-of-control, we won't for now :)
1130 transition({DW_L, DR_L, L}, {Data_Owner, Data_All_Tokens}) {
1132 k_popIncomingResponseQueue;
1135 transition({DW_L, DR_L, L}, Tokens) {
1137 k_popIncomingResponseQueue;
1140 transition({DW_L, DR_L}, {Ack_Owner_All_Tokens, Ack_Owner}) {
1141 bd_bounceDatalessOwnerToken;
1142 k_popIncomingResponseQueue;
1145 transition(L, {Ack_Owner_All_Tokens, Ack_Owner}, L_O_W) {
1147 qp_queueMemoryForPersistent;
1148 k_popIncomingResponseQueue;
1151 transition(L, {Unlockdown, Own_Lock_or_Unlock}, NO) {
1152 l_popIncomingPersistentQueue;
1155 transition(L, Own_Lock_or_Unlock_Tokens, O) {
1156 l_popIncomingPersistentQueue;
1159 transition({L_NO_W, L_O_W}, Memory_Data, L) {
1160 dd_sendMemDataToStarver;
1164 transition(L_O_W, Memory_Ack) {
1165 qp_queueMemoryForPersistent;
1169 transition(L_O_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_W) {
1170 l_popIncomingPersistentQueue;
1173 transition(L_NO_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_W) {
1174 l_popIncomingPersistentQueue;
1177 transition(DR_L_W, Memory_Data, DR_L) {
1178 dd_sendMemDataToStarver;
1182 transition(DW_L_W, Memory_Ack, L) {
1183 aat_assertAllTokens;
1186 dd_sendMemDataToStarver;
1190 transition(DW_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DW) {
1191 l_popIncomingPersistentQueue;
1194 transition(DR_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DR_W) {
1195 l_popIncomingPersistentQueue;
1198 transition(DW_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DW_W) {
1199 l_popIncomingPersistentQueue;
1202 transition({DW_L, DR_L_W, DW_L_W}, Request_Timeout) {
1203 ut_unsetReissueTimer;
1204 px_tryIssuingPersistentGETXRequest;
1207 transition(DR_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DR) {
1208 l_popIncomingPersistentQueue;
1211 transition(DR_L, Request_Timeout) {
1212 ut_unsetReissueTimer;
1213 ps_tryIssuingPersistentGETSRequest;
1217 // The O_W + Memory_Data > O transistion is confusing, but it can happen if a
1218 // presistent request is issued and resolve before memory returns with data
1220 transition(O_W, {Memory_Ack, Memory_Data}, O) {
1224 transition({O, NO}, {Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}) {
1225 l_popIncomingPersistentQueue;
1229 transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W, O_DW, NO_DW, NO_DR}, {GETX, GETS}) {
1233 transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W, O_DW, NO_DW, NO_DR, L, DW_L, DR_L}, {DMA_READ, DMA_WRITE, DMA_WRITE_All_Tokens}) {
1234 y_recycleDmaRequestQueue;
1237 transition({NO_W, O_W, L_O_W, L_NO_W, DR_L_W, DW_L_W, O_DW_W, O_DR_W}, {Data_Owner, Ack_Owner, Tokens, Data_All_Tokens, Ack_All_Tokens}) {
1242 // If we receive a request timeout while waiting for memory, it is likely that
1243 // the request will be satisfied and issuing a presistent request will do us
1244 // no good. Just wait.
1246 transition({O_DW_W, O_DR_W}, Request_Timeout) {
1247 rs_resetScheduleTimeout;
1250 transition(NO_W, Lockdown, L_NO_W) {
1251 l_popIncomingPersistentQueue;
1254 transition(O_W, Lockdown, L_O_W) {
1255 l_popIncomingPersistentQueue;
1258 transition(O_DR_W, Lockdown, DR_L_W) {
1259 l_popIncomingPersistentQueue;
1262 transition(O_DW_W, Lockdown, DW_L_W) {
1263 l_popIncomingPersistentQueue;
1266 transition({NO_W, O_W, O_DR_W, O_DW_W, O_DW, NO_DR, NO_DW}, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}) {
1267 l_popIncomingPersistentQueue;