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(Directory, "Token protocol")
36 : DirectoryMemory * directory,
37 MemoryControl * memBuffer,
38 int l2_select_num_bits,
39 int directory_latency = 5,
40 bool distributed_persistent = true,
41 int fixed_timeout_latency = 100
44 MessageBuffer dmaResponseFromDir, network="To", virtual_network="5", ordered="true";
45 MessageBuffer responseFromDir, network="To", virtual_network="4", ordered="false";
46 MessageBuffer persistentFromDir, network="To", virtual_network="3", ordered="true";
47 MessageBuffer requestFromDir, network="To", virtual_network="1", ordered="false";
49 MessageBuffer responseToDir, network="From", virtual_network="4", ordered="false";
50 MessageBuffer persistentToDir, network="From", virtual_network="3", ordered="true";
51 MessageBuffer requestToDir, network="From", virtual_network="2", ordered="false";
52 MessageBuffer dmaRequestToDir, network="From", virtual_network="0", ordered="true";
55 enumeration(State, desc="Directory states", default="Directory_State_O") {
61 // Memory wait states - can block all messages including persistent requests
62 O_W, desc="transitioning to Owner, waiting for memory write";
63 L_O_W, desc="transitioning to Locked, waiting for memory read, could eventually return to O";
64 L_NO_W, desc="transitioning to Locked, waiting for memory read, eventually return to NO";
65 DR_L_W, desc="transitioning to Locked underneath a DMA read, waiting for memory data";
66 DW_L_W, desc="transitioning to Locked underneath a DMA write, waiting for memory ack";
67 NO_W, desc="transitioning to Not Owner, waiting for memory read";
68 O_DW_W, desc="transitioning to Owner, waiting for memory before DMA ack";
69 O_DR_W, desc="transitioning to Owner, waiting for memory before DMA data";
71 // DMA request transient states - must respond to persistent requests
72 O_DW, desc="issued GETX for DMA write, waiting for all tokens";
73 NO_DW, desc="issued GETX for DMA write, waiting for all tokens";
74 NO_DR, desc="issued GETS for DMA read, waiting for data";
76 // DMA request in progress - competing with a CPU persistent request
77 DW_L, desc="issued GETX for DMA write, CPU persistent request must complete first";
78 DR_L, desc="issued GETS for DMA read, CPU persistent request must complete first";
83 enumeration(Event, desc="Directory events") {
84 GETX, desc="A GETX arrives";
85 GETS, desc="A GETS arrives";
86 Lockdown, desc="A lockdown request arrives";
87 Unlockdown, desc="An un-lockdown request arrives";
88 Own_Lock_or_Unlock, desc="own lock or unlock";
89 Own_Lock_or_Unlock_Tokens, desc="own lock or unlock with tokens";
90 Data_Owner, desc="Data arrive";
91 Data_All_Tokens, desc="Data and all tokens";
92 Ack_Owner, desc="Owner token arrived without data because it was clean";
93 Ack_Owner_All_Tokens, desc="All tokens including owner arrived without data because it was clean";
94 Tokens, desc="Tokens arrive";
95 Ack_All_Tokens, desc="All_Tokens arrive";
96 Request_Timeout, desc="A DMA request has timed out";
99 Memory_Data, desc="Fetched data from memory arrives";
100 Memory_Ack, desc="Writeback Ack from memory arrives";
103 DMA_READ, desc="A DMA Read memory request";
104 DMA_WRITE, desc="A DMA Write memory request";
105 DMA_WRITE_All_Tokens, desc="A DMA Write memory request, directory has all tokens";
111 structure(Entry, desc="...", interface="AbstractEntry") {
112 State DirectoryState, desc="Directory state";
113 DataBlock DataBlk, desc="data for the block";
114 int Tokens, default="max_tokens()", desc="Number of tokens for the line we're holding";
116 // The following state is provided to allow for bandwidth
117 // efficient directory-like operation. However all of this state
118 // is 'soft state' that does not need to be correct (as long as
119 // you're eventually willing to resort to broadcast.)
121 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.";
122 Set Sharers, desc="Probable sharers of the line. More accurately, the set of processors who need to see a GetX";
125 external_type(PersistentTable) {
126 void persistentRequestLock(Address, MachineID, AccessType);
127 void persistentRequestUnlock(Address, MachineID);
128 bool okToIssueStarving(Address, MachineID);
129 MachineID findSmallest(Address);
130 AccessType typeOfSmallest(Address);
131 void markEntries(Address);
132 bool isLocked(Address);
133 int countStarvingForAddress(Address);
134 int countReadStarvingForAddress(Address);
137 // TBE entries for DMA requests
138 structure(TBE, desc="TBE entries for outstanding DMA requests") {
139 Address PhysicalAddress, desc="physical address";
140 State TBEState, desc="Transient State";
141 DataBlock DmaDataBlk, desc="DMA Data to be written. Partial blocks need to merged with system memory";
142 DataBlock DataBlk, desc="The current view of system memory";
144 MachineID DmaRequestor, desc="DMA requestor";
145 bool WentPersistent, desc="Did the DMA request require a persistent request";
148 external_type(TBETable) {
150 void allocate(Address);
151 void deallocate(Address);
152 bool isPresent(Address);
157 PersistentTable persistentTable;
158 TimerTable reissueTimerTable;
160 TBETable TBEs, template_hack="<Directory_TBE>";
162 bool starving, default="false";
163 int l2_select_low_bit, default="RubySystem::getBlockSizeBits()";
165 Entry getDirectoryEntry(Address addr), return_by_ref="yes" {
166 return static_cast(Entry, directory[addr]);
169 State getState(Address addr) {
170 if (TBEs.isPresent(addr)) {
171 return TBEs[addr].TBEState;
173 return getDirectoryEntry(addr).DirectoryState;
177 void setState(Address addr, State state) {
178 if (TBEs.isPresent(addr)) {
179 TBEs[addr].TBEState := state;
181 getDirectoryEntry(addr).DirectoryState := state;
183 if (state == State:L || state == State:DW_L || state == State:DR_L) {
184 assert(getDirectoryEntry(addr).Tokens == 0);
187 // We have one or zero owners
188 assert((getDirectoryEntry(addr).Owner.count() == 0) || (getDirectoryEntry(addr).Owner.count() == 1));
190 // Make sure the token count is in range
191 assert(getDirectoryEntry(addr).Tokens >= 0);
192 assert(getDirectoryEntry(addr).Tokens <= max_tokens());
194 if (state == State:O || state == State:O_W || state == State:O_DW) {
195 assert(getDirectoryEntry(addr).Tokens >= 1); // Must have at least one token
196 // assert(getDirectoryEntry(addr).Tokens >= (max_tokens() / 2)); // Only mostly true; this might not always hold
200 bool okToIssueStarving(Address addr, MachineID machinID) {
201 return persistentTable.okToIssueStarving(addr, machineID);
204 void markPersistentEntries(Address addr) {
205 persistentTable.markEntries(addr);
209 out_port(responseNetwork_out, ResponseMsg, responseFromDir);
210 out_port(persistentNetwork_out, PersistentMsg, persistentFromDir);
211 out_port(requestNetwork_out, RequestMsg, requestFromDir);
212 out_port(dmaResponseNetwork_out, DMAResponseMsg, dmaResponseFromDir);
215 // Memory buffer for memory controller to DIMM communication
217 out_port(memQueue_out, MemoryMsg, memBuffer);
221 // off-chip memory request/response is done
222 in_port(memQueue_in, MemoryMsg, memBuffer) {
223 if (memQueue_in.isReady()) {
224 peek(memQueue_in, MemoryMsg) {
225 if (in_msg.Type == MemoryRequestType:MEMORY_READ) {
226 trigger(Event:Memory_Data, in_msg.Address);
227 } else if (in_msg.Type == MemoryRequestType:MEMORY_WB) {
228 trigger(Event:Memory_Ack, in_msg.Address);
230 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
231 error("Invalid message");
238 in_port(reissueTimerTable_in, Address, reissueTimerTable) {
239 if (reissueTimerTable_in.isReady()) {
240 trigger(Event:Request_Timeout, reissueTimerTable.readyAddress());
244 in_port(responseNetwork_in, ResponseMsg, responseToDir) {
245 if (responseNetwork_in.isReady()) {
246 peek(responseNetwork_in, ResponseMsg) {
247 assert(in_msg.Destination.isElement(machineID));
248 if (getDirectoryEntry(in_msg.Address).Tokens + in_msg.Tokens == max_tokens()) {
249 if ((in_msg.Type == CoherenceResponseType:DATA_OWNER) ||
250 (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
251 trigger(Event:Data_All_Tokens, in_msg.Address);
252 } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
253 trigger(Event:Ack_Owner_All_Tokens, in_msg.Address);
254 } else if (in_msg.Type == CoherenceResponseType:ACK) {
255 trigger(Event:Ack_All_Tokens, in_msg.Address);
257 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
258 error("Invalid message");
261 if (in_msg.Type == CoherenceResponseType:DATA_OWNER) {
262 trigger(Event:Data_Owner, in_msg.Address);
263 } else if ((in_msg.Type == CoherenceResponseType:ACK) ||
264 (in_msg.Type == CoherenceResponseType:DATA_SHARED)) {
265 trigger(Event:Tokens, in_msg.Address);
266 } else if (in_msg.Type == CoherenceResponseType:ACK_OWNER) {
267 trigger(Event:Ack_Owner, in_msg.Address);
269 DPRINTF(RubySlicc, "%s\n", in_msg.Type);
270 error("Invalid message");
277 in_port(persistentNetwork_in, PersistentMsg, persistentToDir) {
278 if (persistentNetwork_in.isReady()) {
279 peek(persistentNetwork_in, PersistentMsg) {
280 assert(in_msg.Destination.isElement(machineID));
282 if (distributed_persistent) {
283 // Apply the lockdown or unlockdown message to the table
284 if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
285 persistentTable.persistentRequestLock(in_msg.Address, in_msg.Requestor, AccessType:Write);
286 } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
287 persistentTable.persistentRequestLock(in_msg.Address, in_msg.Requestor, AccessType:Read);
288 } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
289 persistentTable.persistentRequestUnlock(in_msg.Address, in_msg.Requestor);
291 error("Invalid message");
294 // React to the message based on the current state of the table
295 if (persistentTable.isLocked(in_msg.Address)) {
296 if (persistentTable.findSmallest(in_msg.Address) == machineID) {
297 if (getDirectoryEntry(in_msg.Address).Tokens > 0) {
298 trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.Address);
300 trigger(Event:Own_Lock_or_Unlock, in_msg.Address);
303 trigger(Event:Lockdown, in_msg.Address); // locked
306 trigger(Event:Unlockdown, in_msg.Address); // unlocked
310 if (persistentTable.findSmallest(in_msg.Address) == machineID) {
311 if (getDirectoryEntry(in_msg.Address).Tokens > 0) {
312 trigger(Event:Own_Lock_or_Unlock_Tokens, in_msg.Address);
314 trigger(Event:Own_Lock_or_Unlock, in_msg.Address);
316 } else if (in_msg.Type == PersistentRequestType:GETX_PERSISTENT) {
317 trigger(Event:Lockdown, in_msg.Address); // locked
318 } else if (in_msg.Type == PersistentRequestType:GETS_PERSISTENT) {
319 trigger(Event:Lockdown, in_msg.Address); // locked
320 } else if (in_msg.Type == PersistentRequestType:DEACTIVATE_PERSISTENT) {
321 trigger(Event:Unlockdown, in_msg.Address); // unlocked
323 error("Invalid message");
330 in_port(requestNetwork_in, RequestMsg, requestToDir) {
331 if (requestNetwork_in.isReady()) {
332 peek(requestNetwork_in, RequestMsg) {
333 assert(in_msg.Destination.isElement(machineID));
334 if (in_msg.Type == CoherenceRequestType:GETS) {
335 trigger(Event:GETS, in_msg.Address);
336 } else if (in_msg.Type == CoherenceRequestType:GETX) {
337 trigger(Event:GETX, in_msg.Address);
339 error("Invalid message");
345 in_port(dmaRequestQueue_in, DMARequestMsg, dmaRequestToDir) {
346 if (dmaRequestQueue_in.isReady()) {
347 peek(dmaRequestQueue_in, DMARequestMsg) {
348 if (in_msg.Type == DMARequestType:READ) {
349 trigger(Event:DMA_READ, in_msg.LineAddress);
350 } else if (in_msg.Type == DMARequestType:WRITE) {
351 if (getDirectoryEntry(in_msg.LineAddress).Tokens == max_tokens()) {
352 trigger(Event:DMA_WRITE_All_Tokens, in_msg.LineAddress);
354 trigger(Event:DMA_WRITE, in_msg.LineAddress);
357 error("Invalid message");
365 action(a_sendTokens, "a", desc="Send tokens to requestor") {
366 // Only send a message if we have tokens to send
367 if (getDirectoryEntry(address).Tokens > 0) {
368 peek(requestNetwork_in, RequestMsg) {
369 // enqueue(responseNetwork_out, ResponseMsg, latency="DIRECTORY_CACHE_LATENCY") {// FIXME?
370 enqueue(responseNetwork_out, ResponseMsg, latency=directory_latency) {// FIXME?
371 out_msg.Address := address;
372 out_msg.Type := CoherenceResponseType:ACK;
373 out_msg.Sender := machineID;
374 out_msg.Destination.add(in_msg.Requestor);
375 out_msg.Tokens := getDirectoryEntry(in_msg.Address).Tokens;
376 out_msg.MessageSize := MessageSizeType:Response_Control;
379 getDirectoryEntry(address).Tokens := 0;
383 action(px_tryIssuingPersistentGETXRequest, "px", desc="...") {
384 if (okToIssueStarving(address, machineID) && (starving == false)) {
385 enqueue(persistentNetwork_out, PersistentMsg, latency = "1") {
386 out_msg.Address := address;
387 out_msg.Type := PersistentRequestType:GETX_PERSISTENT;
388 out_msg.Requestor := machineID;
389 out_msg.Destination.broadcast(MachineType:L1Cache);
392 // Currently the configuration system limits the system to only one
393 // chip. Therefore, if we assume one shared L2 cache, then only one
394 // pertinent L2 cache exist.
396 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
398 out_msg.Destination.add(mapAddressToRange(address,
401 l2_select_num_bits));
403 out_msg.Destination.add(map_Address_to_Directory(address));
404 out_msg.MessageSize := MessageSizeType:Persistent_Control;
405 out_msg.Prefetch := PrefetchBit:No;
406 out_msg.AccessMode := AccessModeType:SupervisorMode;
408 markPersistentEntries(address);
411 TBEs[address].WentPersistent := true;
413 // Do not schedule a wakeup, a persistent requests will always complete
416 // We'd like to issue a persistent request, but are not allowed
417 // to issue a P.R. right now. This, we do not increment the
420 // Set a wakeup timer
421 reissueTimerTable.set(address, 10);
425 action(bw_broadcastWrite, "bw", desc="Broadcast GETX if we need tokens") {
426 peek(dmaRequestQueue_in, DMARequestMsg) {
428 // Assser that we only send message if we don't already have all the tokens
430 assert(getDirectoryEntry(address).Tokens != max_tokens());
431 enqueue(requestNetwork_out, RequestMsg, latency = "1") {
432 out_msg.Address := address;
433 out_msg.Type := CoherenceRequestType:GETX;
434 out_msg.Requestor := machineID;
437 // Since only one chip, assuming all L1 caches are local
439 out_msg.Destination.broadcast(MachineType:L1Cache);
440 out_msg.Destination.add(mapAddressToRange(address,
443 l2_select_num_bits));
445 out_msg.RetryNum := 0;
446 out_msg.MessageSize := MessageSizeType:Broadcast_Control;
447 out_msg.Prefetch := PrefetchBit:No;
448 out_msg.AccessMode := AccessModeType:SupervisorMode;
453 action(ps_tryIssuingPersistentGETSRequest, "ps", desc="...") {
454 if (okToIssueStarving(address, machineID) && (starving == false)) {
455 enqueue(persistentNetwork_out, PersistentMsg, latency = "1") {
456 out_msg.Address := address;
457 out_msg.Type := PersistentRequestType:GETS_PERSISTENT;
458 out_msg.Requestor := machineID;
459 out_msg.Destination.broadcast(MachineType:L1Cache);
462 // Currently the configuration system limits the system to only one
463 // chip. Therefore, if we assume one shared L2 cache, then only one
464 // pertinent L2 cache exist.
466 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
468 out_msg.Destination.add(mapAddressToRange(address,
471 l2_select_num_bits));
473 out_msg.Destination.add(map_Address_to_Directory(address));
474 out_msg.MessageSize := MessageSizeType:Persistent_Control;
475 out_msg.Prefetch := PrefetchBit:No;
476 out_msg.AccessMode := AccessModeType:SupervisorMode;
478 markPersistentEntries(address);
481 TBEs[address].WentPersistent := true;
483 // Do not schedule a wakeup, a persistent requests will always complete
486 // We'd like to issue a persistent request, but are not allowed
487 // to issue a P.R. right now. This, we do not increment the
490 // Set a wakeup timer
491 reissueTimerTable.set(address, 10);
495 action(br_broadcastRead, "br", desc="Broadcast GETS for data") {
496 peek(dmaRequestQueue_in, DMARequestMsg) {
497 enqueue(requestNetwork_out, RequestMsg, latency = "1") {
498 out_msg.Address := address;
499 out_msg.Type := CoherenceRequestType:GETS;
500 out_msg.Requestor := machineID;
503 // Since only one chip, assuming all L1 caches are local
505 out_msg.Destination.broadcast(MachineType:L1Cache);
506 out_msg.Destination.add(mapAddressToRange(address,
509 l2_select_num_bits));
511 out_msg.RetryNum := 0;
512 out_msg.MessageSize := MessageSizeType:Broadcast_Control;
513 out_msg.Prefetch := PrefetchBit:No;
514 out_msg.AccessMode := AccessModeType:SupervisorMode;
519 action(aa_sendTokensToStarver, "\a", desc="Send tokens to starver") {
520 // Only send a message if we have tokens to send
521 if (getDirectoryEntry(address).Tokens > 0) {
522 // enqueue(responseNetwork_out, ResponseMsg, latency="DIRECTORY_CACHE_LATENCY") {// FIXME?
523 enqueue(responseNetwork_out, ResponseMsg, latency=directory_latency) {// FIXME?
524 out_msg.Address := address;
525 out_msg.Type := CoherenceResponseType:ACK;
526 out_msg.Sender := machineID;
527 out_msg.Destination.add(persistentTable.findSmallest(address));
528 out_msg.Tokens := getDirectoryEntry(address).Tokens;
529 out_msg.MessageSize := MessageSizeType:Response_Control;
531 getDirectoryEntry(address).Tokens := 0;
535 action(d_sendMemoryDataWithAllTokens, "d", desc="Send data and tokens to requestor") {
536 peek(memQueue_in, MemoryMsg) {
537 enqueue(responseNetwork_out, ResponseMsg, latency="1") {
538 out_msg.Address := address;
539 out_msg.Type := CoherenceResponseType:DATA_OWNER;
540 out_msg.Sender := machineID;
541 out_msg.Destination.add(in_msg.OriginalRequestorMachId);
542 assert(getDirectoryEntry(address).Tokens > 0);
543 out_msg.Tokens := getDirectoryEntry(in_msg.Address).Tokens;
544 out_msg.DataBlk := getDirectoryEntry(in_msg.Address).DataBlk;
545 out_msg.Dirty := false;
546 out_msg.MessageSize := MessageSizeType:Response_Data;
549 getDirectoryEntry(address).Tokens := 0;
552 action(dd_sendMemDataToStarver, "\d", desc="Send data and tokens to starver") {
553 peek(memQueue_in, MemoryMsg) {
554 enqueue(responseNetwork_out, ResponseMsg, latency="1") {
555 out_msg.Address := address;
556 out_msg.Type := CoherenceResponseType:DATA_OWNER;
557 out_msg.Sender := machineID;
558 out_msg.Destination.add(persistentTable.findSmallest(address));
559 assert(getDirectoryEntry(address).Tokens > 0);
560 out_msg.Tokens := getDirectoryEntry(address).Tokens;
561 out_msg.DataBlk := getDirectoryEntry(address).DataBlk;
562 out_msg.Dirty := false;
563 out_msg.MessageSize := MessageSizeType:Response_Data;
566 getDirectoryEntry(address).Tokens := 0;
569 action(de_sendTbeDataToStarver, "de", desc="Send data and tokens to starver") {
570 enqueue(responseNetwork_out, ResponseMsg, latency="1") {
571 out_msg.Address := address;
572 out_msg.Type := CoherenceResponseType:DATA_OWNER;
573 out_msg.Sender := machineID;
574 out_msg.Destination.add(persistentTable.findSmallest(address));
575 assert(getDirectoryEntry(address).Tokens > 0);
576 out_msg.Tokens := getDirectoryEntry(address).Tokens;
577 out_msg.DataBlk := TBEs[address].DataBlk;
578 out_msg.Dirty := false;
579 out_msg.MessageSize := MessageSizeType:Response_Data;
581 getDirectoryEntry(address).Tokens := 0;
584 action(qf_queueMemoryFetchRequest, "qf", desc="Queue off-chip fetch request") {
585 peek(requestNetwork_in, RequestMsg) {
586 enqueue(memQueue_out, MemoryMsg, latency="1") {
587 out_msg.Address := address;
588 out_msg.Type := MemoryRequestType:MEMORY_READ;
589 out_msg.Sender := machineID;
590 out_msg.OriginalRequestorMachId := in_msg.Requestor;
591 out_msg.MessageSize := in_msg.MessageSize;
592 out_msg.DataBlk := getDirectoryEntry(address).DataBlk;
593 DPRINTF(RubySlicc, "%s\n", out_msg);
598 action(qp_queueMemoryForPersistent, "qp", desc="Queue off-chip fetch request") {
599 enqueue(memQueue_out, MemoryMsg, latency="1") {
600 out_msg.Address := address;
601 out_msg.Type := MemoryRequestType:MEMORY_READ;
602 out_msg.Sender := machineID;
603 out_msg.OriginalRequestorMachId := persistentTable.findSmallest(address);
604 out_msg.MessageSize := MessageSizeType:Request_Control;
605 out_msg.DataBlk := getDirectoryEntry(address).DataBlk;
606 DPRINTF(RubySlicc, "%s\n", out_msg);
610 action(fd_memoryDma, "fd", desc="Queue off-chip fetch request") {
611 peek(dmaRequestQueue_in, DMARequestMsg) {
612 enqueue(memQueue_out, MemoryMsg, latency="1") {
613 out_msg.Address := address;
614 out_msg.Type := MemoryRequestType:MEMORY_READ;
615 out_msg.Sender := machineID;
616 out_msg.OriginalRequestorMachId := in_msg.Requestor;
617 out_msg.MessageSize := in_msg.MessageSize;
618 out_msg.DataBlk := getDirectoryEntry(address).DataBlk;
619 DPRINTF(RubySlicc, "%s\n", out_msg);
624 action(lq_queueMemoryWbRequest, "lq", desc="Write data to memory") {
625 enqueue(memQueue_out, MemoryMsg, latency="1") {
626 out_msg.Address := address;
627 out_msg.Type := MemoryRequestType:MEMORY_WB;
628 DPRINTF(RubySlicc, "%s\n", out_msg);
632 action(ld_queueMemoryDmaWriteFromTbe, "ld", desc="Write DMA data to memory") {
633 enqueue(memQueue_out, MemoryMsg, latency="1") {
634 out_msg.Address := address;
635 out_msg.Type := MemoryRequestType:MEMORY_WB;
636 // first, initialize the data blk to the current version of system memory
637 out_msg.DataBlk := TBEs[address].DataBlk;
638 // then add the dma write data
639 out_msg.DataBlk.copyPartial(TBEs[address].DmaDataBlk, addressOffset(TBEs[address].PhysicalAddress), TBEs[address].Len);
640 DPRINTF(RubySlicc, "%s\n", out_msg);
644 action(lr_queueMemoryDmaReadWriteback, "lr", desc="Write DMA data from read to memory") {
645 enqueue(memQueue_out, MemoryMsg, latency="1") {
646 out_msg.Address := address;
647 out_msg.Type := MemoryRequestType:MEMORY_WB;
648 // first, initialize the data blk to the current version of system memory
649 out_msg.DataBlk := TBEs[address].DataBlk;
650 DPRINTF(RubySlicc, "%s\n", out_msg);
654 action(vd_allocateDmaRequestInTBE, "vd", desc="Record Data in TBE") {
655 peek(dmaRequestQueue_in, DMARequestMsg) {
656 TBEs.allocate(address);
657 TBEs[address].DmaDataBlk := in_msg.DataBlk;
658 TBEs[address].PhysicalAddress := in_msg.PhysicalAddress;
659 TBEs[address].Len := in_msg.Len;
660 TBEs[address].DmaRequestor := in_msg.Requestor;
661 TBEs[address].WentPersistent := false;
665 action(s_deallocateTBE, "s", desc="Deallocate TBE") {
667 if (TBEs[address].WentPersistent) {
668 assert(starving == true);
670 enqueue(persistentNetwork_out, PersistentMsg, latency = "1") {
671 out_msg.Address := address;
672 out_msg.Type := PersistentRequestType:DEACTIVATE_PERSISTENT;
673 out_msg.Requestor := machineID;
674 out_msg.Destination.broadcast(MachineType:L1Cache);
677 // Currently the configuration system limits the system to only one
678 // chip. Therefore, if we assume one shared L2 cache, then only one
679 // pertinent L2 cache exist.
681 //out_msg.Destination.addNetDest(getAllPertinentL2Banks(address));
683 out_msg.Destination.add(mapAddressToRange(address,
686 l2_select_num_bits));
688 out_msg.Destination.add(map_Address_to_Directory(address));
689 out_msg.MessageSize := MessageSizeType:Persistent_Control;
694 TBEs.deallocate(address);
697 action(rd_recordDataInTbe, "rd", desc="Record data in TBE") {
698 peek(responseNetwork_in, ResponseMsg) {
699 TBEs[address].DataBlk := in_msg.DataBlk;
703 action(cd_writeCleanDataToTbe, "cd", desc="Write clean memory data to TBE") {
704 TBEs[address].DataBlk := getDirectoryEntry(address).DataBlk;
707 action(dwt_writeDmaDataFromTBE, "dwt", desc="DMA Write data to memory from TBE") {
708 getDirectoryEntry(address).DataBlk := TBEs[address].DataBlk;
709 getDirectoryEntry(address).DataBlk.copyPartial(TBEs[address].DmaDataBlk, addressOffset(TBEs[address].PhysicalAddress), TBEs[address].Len);
712 action(f_incrementTokens, "f", desc="Increment the number of tokens we're tracking") {
713 peek(responseNetwork_in, ResponseMsg) {
714 assert(in_msg.Tokens >= 1);
715 getDirectoryEntry(address).Tokens := getDirectoryEntry(address).Tokens + in_msg.Tokens;
719 action(aat_assertAllTokens, "aat", desc="assert that we have all tokens") {
720 assert(getDirectoryEntry(address).Tokens == max_tokens());
723 action(j_popIncomingRequestQueue, "j", desc="Pop incoming request queue") {
724 requestNetwork_in.dequeue();
727 action(z_recycleRequest, "z", desc="Recycle the request queue") {
728 requestNetwork_in.recycle();
731 action(k_popIncomingResponseQueue, "k", desc="Pop incoming response queue") {
732 responseNetwork_in.dequeue();
735 action(kz_recycleResponse, "kz", desc="Recycle incoming response queue") {
736 responseNetwork_in.recycle();
739 action(l_popIncomingPersistentQueue, "l", desc="Pop incoming persistent queue") {
740 persistentNetwork_in.dequeue();
743 action(p_popDmaRequestQueue, "pd", desc="pop dma request queue") {
744 dmaRequestQueue_in.dequeue();
747 action(y_recycleDmaRequestQueue, "y", desc="recycle dma request queue") {
748 dmaRequestQueue_in.recycle();
751 action(l_popMemQueue, "q", desc="Pop off-chip request queue") {
752 memQueue_in.dequeue();
755 action(m_writeDataToMemory, "m", desc="Write dirty writeback to memory") {
756 peek(responseNetwork_in, ResponseMsg) {
757 getDirectoryEntry(in_msg.Address).DataBlk := in_msg.DataBlk;
758 DPRINTF(RubySlicc, "Address: %s, Data Block: %s\n",
759 in_msg.Address, in_msg.DataBlk);
763 action(n_checkData, "n", desc="Check incoming clean data message") {
764 peek(responseNetwork_in, ResponseMsg) {
765 assert(getDirectoryEntry(in_msg.Address).DataBlk == in_msg.DataBlk);
769 action(r_bounceResponse, "r", desc="Bounce response to starving processor") {
770 peek(responseNetwork_in, ResponseMsg) {
771 enqueue(responseNetwork_out, ResponseMsg, latency="1") {
772 out_msg.Address := address;
773 out_msg.Type := in_msg.Type;
774 out_msg.Sender := machineID;
775 out_msg.Destination.add(persistentTable.findSmallest(address));
776 out_msg.Tokens := in_msg.Tokens;
777 out_msg.MessageSize := in_msg.MessageSize;
778 out_msg.DataBlk := in_msg.DataBlk;
779 out_msg.Dirty := in_msg.Dirty;
784 action(rs_resetScheduleTimeout, "rs", desc="Reschedule Schedule Timeout") {
786 // currently only support a fixed timeout latency
788 if (reissueTimerTable.isSet(address)) {
789 reissueTimerTable.unset(address);
790 reissueTimerTable.set(address, fixed_timeout_latency);
794 action(st_scheduleTimeout, "st", desc="Schedule Timeout") {
796 // currently only support a fixed timeout latency
798 reissueTimerTable.set(address, fixed_timeout_latency);
801 action(ut_unsetReissueTimer, "ut", desc="Unset reissue timer.") {
802 if (reissueTimerTable.isSet(address)) {
803 reissueTimerTable.unset(address);
807 action(bd_bounceDatalessOwnerToken, "bd", desc="Bounce clean owner token to starving processor") {
808 peek(responseNetwork_in, ResponseMsg) {
809 assert(in_msg.Type == CoherenceResponseType:ACK_OWNER);
810 assert(in_msg.Dirty == false);
811 assert(in_msg.MessageSize == MessageSizeType:Writeback_Control);
813 // NOTE: The following check would not be valid in a real
814 // implementation. We include the data in the "dataless"
815 // message so we can assert the clean data matches the datablock
817 assert(getDirectoryEntry(in_msg.Address).DataBlk == in_msg.DataBlk);
819 // Bounce the message, but "re-associate" the data and the owner
820 // token. In essence we're converting an ACK_OWNER message to a
821 // DATA_OWNER message, keeping the number of tokens the same.
822 enqueue(responseNetwork_out, ResponseMsg, latency="1") {
823 out_msg.Address := address;
824 out_msg.Type := CoherenceResponseType:DATA_OWNER;
825 out_msg.Sender := machineID;
826 out_msg.Destination.add(persistentTable.findSmallest(address));
827 out_msg.Tokens := in_msg.Tokens;
828 out_msg.DataBlk := getDirectoryEntry(in_msg.Address).DataBlk;
829 out_msg.Dirty := in_msg.Dirty;
830 out_msg.MessageSize := MessageSizeType:Response_Data;
835 action(da_sendDmaAck, "da", desc="Send Ack to DMA controller") {
836 enqueue(dmaResponseNetwork_out, DMAResponseMsg, latency="1") {
837 out_msg.PhysicalAddress := address;
838 out_msg.LineAddress := address;
839 out_msg.Type := DMAResponseType:ACK;
840 out_msg.Destination.add(TBEs[address].DmaRequestor);
841 out_msg.MessageSize := MessageSizeType:Writeback_Control;
845 action(dm_sendMemoryDataToDma, "dm", desc="Send Data to DMA controller from memory") {
846 peek(memQueue_in, MemoryMsg) {
847 enqueue(dmaResponseNetwork_out, DMAResponseMsg, latency="1") {
848 out_msg.PhysicalAddress := address;
849 out_msg.LineAddress := address;
850 out_msg.Type := DMAResponseType:DATA;
852 // we send the entire data block and rely on the dma controller to
853 // split it up if need be
855 out_msg.DataBlk := in_msg.DataBlk;
856 out_msg.Destination.add(TBEs[address].DmaRequestor);
857 out_msg.MessageSize := MessageSizeType:Response_Data;
862 action(dd_sendDmaData, "dd", desc="Send Data to DMA controller") {
863 peek(responseNetwork_in, ResponseMsg) {
864 enqueue(dmaResponseNetwork_out, DMAResponseMsg, latency="1") {
865 out_msg.PhysicalAddress := address;
866 out_msg.LineAddress := address;
867 out_msg.Type := DMAResponseType:DATA;
869 // we send the entire data block and rely on the dma controller to
870 // split it up if need be
872 out_msg.DataBlk := in_msg.DataBlk;
873 out_msg.Destination.add(TBEs[address].DmaRequestor);
874 out_msg.MessageSize := MessageSizeType:Response_Data;
882 // Trans. from base state O
883 // the directory has valid data
885 transition(O, GETX, NO_W) {
886 qf_queueMemoryFetchRequest;
887 j_popIncomingRequestQueue;
890 transition(O, DMA_WRITE, O_DW) {
891 vd_allocateDmaRequestInTBE;
892 cd_writeCleanDataToTbe;
895 p_popDmaRequestQueue;
898 transition(O, DMA_WRITE_All_Tokens, O_DW_W) {
899 vd_allocateDmaRequestInTBE;
900 cd_writeCleanDataToTbe;
901 dwt_writeDmaDataFromTBE;
902 ld_queueMemoryDmaWriteFromTbe;
903 p_popDmaRequestQueue;
906 transition(O, GETS, NO_W) {
907 qf_queueMemoryFetchRequest;
908 j_popIncomingRequestQueue;
911 transition(O, DMA_READ, O_DR_W) {
912 vd_allocateDmaRequestInTBE;
915 p_popDmaRequestQueue;
918 transition(O, Lockdown, L_O_W) {
919 qp_queueMemoryForPersistent;
920 l_popIncomingPersistentQueue;
923 transition(O, {Tokens, Ack_All_Tokens}) {
925 k_popIncomingResponseQueue;
928 transition(O, {Data_Owner, Data_All_Tokens}) {
931 k_popIncomingResponseQueue;
934 transition({O, NO}, Unlockdown) {
935 l_popIncomingPersistentQueue;
939 // transitioning to Owner, waiting for memory before DMA ack
940 // All other events should recycle/stall
942 transition(O_DR_W, Memory_Data, O) {
943 dm_sendMemoryDataToDma;
944 ut_unsetReissueTimer;
950 // issued GETX for DMA write, waiting for all tokens
952 transition(O_DW, Request_Timeout) {
953 ut_unsetReissueTimer;
954 px_tryIssuingPersistentGETXRequest;
957 transition(O_DW, Tokens) {
959 k_popIncomingResponseQueue;
962 transition(O_DW, Data_Owner) {
965 k_popIncomingResponseQueue;
968 transition(O_DW, Ack_Owner) {
970 cd_writeCleanDataToTbe;
971 k_popIncomingResponseQueue;
974 transition(O_DW, Lockdown, DW_L) {
975 de_sendTbeDataToStarver;
976 l_popIncomingPersistentQueue;
979 transition({NO_DW, O_DW}, Data_All_Tokens, O_DW_W) {
982 dwt_writeDmaDataFromTBE;
983 ld_queueMemoryDmaWriteFromTbe;
984 ut_unsetReissueTimer;
985 k_popIncomingResponseQueue;
988 transition(O_DW, Ack_All_Tokens, O_DW_W) {
990 dwt_writeDmaDataFromTBE;
991 ld_queueMemoryDmaWriteFromTbe;
992 ut_unsetReissueTimer;
993 k_popIncomingResponseQueue;
996 transition(O_DW, Ack_Owner_All_Tokens, O_DW_W) {
998 cd_writeCleanDataToTbe;
999 dwt_writeDmaDataFromTBE;
1000 ld_queueMemoryDmaWriteFromTbe;
1001 ut_unsetReissueTimer;
1002 k_popIncomingResponseQueue;
1005 transition(O_DW_W, Memory_Ack, O) {
1013 // The direcotry does not have valid data, but may have some tokens
1015 transition(NO, GETX) {
1017 j_popIncomingRequestQueue;
1020 transition(NO, DMA_WRITE, NO_DW) {
1021 vd_allocateDmaRequestInTBE;
1024 p_popDmaRequestQueue;
1027 transition(NO, GETS) {
1028 j_popIncomingRequestQueue;
1031 transition(NO, DMA_READ, NO_DR) {
1032 vd_allocateDmaRequestInTBE;
1035 p_popDmaRequestQueue;
1038 transition(NO, Lockdown, L) {
1039 aa_sendTokensToStarver;
1040 l_popIncomingPersistentQueue;
1043 transition(NO, {Data_Owner, Data_All_Tokens}, O_W) {
1044 m_writeDataToMemory;
1046 lq_queueMemoryWbRequest;
1047 k_popIncomingResponseQueue;
1050 transition(NO, {Ack_Owner, Ack_Owner_All_Tokens}, O) {
1053 k_popIncomingResponseQueue;
1056 transition(NO, Tokens) {
1058 k_popIncomingResponseQueue;
1061 transition(NO_W, Memory_Data, NO) {
1062 d_sendMemoryDataWithAllTokens;
1066 // Trans. from NO_DW
1067 transition(NO_DW, Request_Timeout) {
1068 ut_unsetReissueTimer;
1069 px_tryIssuingPersistentGETXRequest;
1072 transition(NO_DW, Lockdown, DW_L) {
1073 aa_sendTokensToStarver;
1074 l_popIncomingPersistentQueue;
1077 // Note: NO_DW, Data_All_Tokens transition is combined with O_DW
1078 // Note: NO_DW should not receive the action Ack_All_Tokens because the
1079 // directory does not have valid data
1081 transition(NO_DW, Data_Owner, O_DW) {
1084 k_popIncomingResponseQueue;
1087 transition({NO_DW, NO_DR}, Tokens) {
1089 k_popIncomingResponseQueue;
1092 // Trans. from NO_DR
1093 transition(NO_DR, Request_Timeout) {
1094 ut_unsetReissueTimer;
1095 ps_tryIssuingPersistentGETSRequest;
1098 transition(NO_DR, Lockdown, DR_L) {
1099 aa_sendTokensToStarver;
1100 l_popIncomingPersistentQueue;
1103 transition(NO_DR, {Data_Owner, Data_All_Tokens}, O_W) {
1104 m_writeDataToMemory;
1107 lr_queueMemoryDmaReadWriteback;
1108 ut_unsetReissueTimer;
1110 k_popIncomingResponseQueue;
1114 transition({L, DW_L, DR_L}, {GETX, GETS}) {
1115 j_popIncomingRequestQueue;
1118 transition({L, DW_L, DR_L, L_O_W, L_NO_W, DR_L_W, DW_L_W}, Lockdown) {
1119 l_popIncomingPersistentQueue;
1123 // Received data for lockdown blocks
1124 // For blocks with outstanding dma requests to them
1125 // ...we could change this to write the data to memory and send it cleanly
1126 // ...we could also proactively complete our DMA requests
1127 // However, to keep my mind from spinning out-of-control, we won't for now :)
1129 transition({DW_L, DR_L, L}, {Data_Owner, Data_All_Tokens}) {
1131 k_popIncomingResponseQueue;
1134 transition({DW_L, DR_L, L}, Tokens) {
1136 k_popIncomingResponseQueue;
1139 transition({DW_L, DR_L, L}, {Ack_Owner_All_Tokens, Ack_Owner}) {
1140 bd_bounceDatalessOwnerToken;
1141 k_popIncomingResponseQueue;
1144 transition(L, {Unlockdown, Own_Lock_or_Unlock}, NO) {
1145 l_popIncomingPersistentQueue;
1148 transition(L, Own_Lock_or_Unlock_Tokens, O) {
1149 l_popIncomingPersistentQueue;
1152 transition({L_NO_W, L_O_W}, Memory_Data, L) {
1153 dd_sendMemDataToStarver;
1157 transition(L_O_W, Memory_Ack) {
1158 qp_queueMemoryForPersistent;
1162 transition(L_O_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_W) {
1163 l_popIncomingPersistentQueue;
1166 transition(L_NO_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_W) {
1167 l_popIncomingPersistentQueue;
1170 transition(DR_L_W, Memory_Data, DR_L) {
1171 dd_sendMemDataToStarver;
1175 transition(DW_L_W, Memory_Ack, L) {
1176 aat_assertAllTokens;
1179 dd_sendMemDataToStarver;
1183 transition(DW_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DW) {
1184 l_popIncomingPersistentQueue;
1187 transition(DR_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DR_W) {
1188 l_popIncomingPersistentQueue;
1191 transition(DW_L_W, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, O_DW_W) {
1192 l_popIncomingPersistentQueue;
1195 transition({DW_L, DR_L_W, DW_L_W}, Request_Timeout) {
1196 ut_unsetReissueTimer;
1197 px_tryIssuingPersistentGETXRequest;
1200 transition(DR_L, {Unlockdown, Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}, NO_DR) {
1201 l_popIncomingPersistentQueue;
1204 transition(DR_L, Request_Timeout) {
1205 ut_unsetReissueTimer;
1206 ps_tryIssuingPersistentGETSRequest;
1210 // The O_W + Memory_Data > O transistion is confusing, but it can happen if a
1211 // presistent request is issued and resolve before memory returns with data
1213 transition(O_W, {Memory_Ack, Memory_Data}, O) {
1217 transition({O, NO}, {Own_Lock_or_Unlock, Own_Lock_or_Unlock_Tokens}) {
1218 l_popIncomingPersistentQueue;
1222 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}) {
1226 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}) {
1227 y_recycleDmaRequestQueue;
1230 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}) {
1235 // If we receive a request timeout while waiting for memory, it is likely that
1236 // the request will be satisfied and issuing a presistent request will do us
1237 // no good. Just wait.
1239 transition({O_DW_W, O_DR_W}, Request_Timeout) {
1240 rs_resetScheduleTimeout;
1243 transition(NO_W, Lockdown, L_NO_W) {
1244 l_popIncomingPersistentQueue;
1247 transition(O_W, Lockdown, L_O_W) {
1248 l_popIncomingPersistentQueue;
1251 transition(O_DR_W, Lockdown, DR_L_W) {
1252 l_popIncomingPersistentQueue;
1255 transition(O_DW_W, Lockdown, DW_L_W) {
1256 l_popIncomingPersistentQueue;
1259 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}) {
1260 l_popIncomingPersistentQueue;