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.
34 machine(Directory, "Directory protocol") {
36 MessageBuffer forwardFromDir, network="To", virtual_network="1", ordered="false";
37 MessageBuffer responseFromDir, network="To", virtual_network="2", ordered="false";
39 MessageBuffer requestToDir, network="From", virtual_network="0", ordered="false";
40 MessageBuffer unblockToDir, network="From", virtual_network="3", ordered="false";
43 enumeration(State, desc="Directory states", default="Directory_State_I") {
50 IS, desc="Blocked, was in idle";
51 SS, desc="Blocked, was in shared";
52 OO, desc="Blocked, was in owned";
53 MO, desc="Blocked, going to owner or maybe modified";
54 MM, desc="Blocked, going to modified";
56 MI, desc="Blocked on a writeback";
57 OS, desc="Blocked on a writeback";
61 enumeration(Event, desc="Directory events") {
62 GETX, desc="A GETX arrives";
63 GETS, desc="A GETS arrives";
64 PUTX, desc="A PUTX arrives";
65 PUTO, desc="A PUTO arrives";
66 Unblock, desc="An unblock message arrives";
67 Last_Unblock, desc="An unblock message arrives, we're not waiting for any additional unblocks";
68 Exclusive_Unblock, desc="The processor become the exclusive owner (E or M) of the line";
69 Clean_Writeback, desc="The final message as part of a PutX/PutS, no data";
70 Dirty_Writeback, desc="The final message as part of a PutX/PutS, contains data";
76 structure(Entry, desc="...") {
77 State DirectoryState, desc="Directory state";
78 DataBlock DataBlk, desc="data for the block";
79 NetDest Sharers, desc="Sharers for this block";
80 NetDest Owner, desc="Owner of this block";
81 int WaitingUnblocks, desc="Number of acks we're waiting for";
84 external_type(DirectoryMemory) {
85 Entry lookup(Address);
86 bool isPresent(Address);
90 void profile_sharing(Address addr, AccessType type, NodeID requestor, Set sharers, Set owner);
94 DirectoryMemory directory, constructor_hack="i";
96 State getState(Address addr) {
97 return directory[addr].DirectoryState;
100 void setState(Address addr, State state) {
101 if (directory.isPresent(addr)) {
103 if ((state == State:I) || (state == State:IS)) {
104 assert(directory[addr].Owner.count() == 0);
105 assert(directory[addr].Sharers.count() == 0);
108 if ((state == State:S) || (state == State:SS)) {
109 assert(directory[addr].Owner.count() == 0);
110 assert(directory[addr].Sharers.count() != 0);
113 if ((state == State:O) || (state == State:OO)) {
114 assert(directory[addr].Owner.count() == 1);
115 assert(directory[addr].Sharers.isSuperset(directory[addr].Owner) == false);
118 if (state == State:M) {
119 assert(directory[addr].Owner.count() == 1);
120 assert(directory[addr].Sharers.count() == 0);
123 if ((state != State:SS) && (state != State:OO)) {
124 assert(directory[addr].WaitingUnblocks == 0);
127 directory[addr].DirectoryState := state;
132 out_port(forwardNetwork_out, RequestMsg, forwardFromDir);
133 out_port(responseNetwork_out, ResponseMsg, responseFromDir);
134 out_port(requestQueue_out, ResponseMsg, requestToDir); // For recycling requests
138 in_port(unblockNetwork_in, ResponseMsg, unblockToDir) {
139 if (unblockNetwork_in.isReady()) {
140 peek(unblockNetwork_in, ResponseMsg) {
141 if (in_msg.Type == CoherenceResponseType:UNBLOCK) {
142 if (directory[in_msg.Address].WaitingUnblocks == 1) {
143 trigger(Event:Last_Unblock, in_msg.Address);
145 trigger(Event:Unblock, in_msg.Address);
147 } else if (in_msg.Type == CoherenceResponseType:UNBLOCK_EXCLUSIVE) {
148 trigger(Event:Exclusive_Unblock, in_msg.Address);
149 } else if (in_msg.Type == CoherenceResponseType:WRITEBACK_DIRTY) {
150 trigger(Event:Dirty_Writeback, in_msg.Address);
151 } else if (in_msg.Type == CoherenceResponseType:WRITEBACK_CLEAN) {
152 trigger(Event:Clean_Writeback, in_msg.Address);
154 error("Invalid message");
160 in_port(requestQueue_in, RequestMsg, requestToDir) {
161 if (requestQueue_in.isReady()) {
162 peek(requestQueue_in, RequestMsg) {
163 if (in_msg.Type == CoherenceRequestType:GETS) {
164 trigger(Event:GETS, in_msg.Address);
165 } else if (in_msg.Type == CoherenceRequestType:GETX) {
166 trigger(Event:GETX, in_msg.Address);
167 } else if (in_msg.Type == CoherenceRequestType:PUTX) {
168 trigger(Event:PUTX, in_msg.Address);
169 } else if (in_msg.Type == CoherenceRequestType:PUTO) {
170 trigger(Event:PUTO, in_msg.Address);
172 error("Invalid message");
180 action(a_sendWriteBackAck, "a", desc="Send writeback ack to requestor") {
181 peek(requestQueue_in, RequestMsg) {
182 enqueue(forwardNetwork_out, RequestMsg, latency="DIRECTORY_LATENCY") {
183 out_msg.Address := address;
184 out_msg.Type := CoherenceRequestType:WB_ACK;
185 out_msg.Requestor := in_msg.Requestor;
186 out_msg.Destination.add(in_msg.Requestor);
187 out_msg.MessageSize := MessageSizeType:Writeback_Control;
192 action(b_sendWriteBackNack, "b", desc="Send writeback nack to requestor") {
193 peek(requestQueue_in, RequestMsg) {
194 enqueue(forwardNetwork_out, RequestMsg, latency="DIRECTORY_LATENCY") {
195 out_msg.Address := address;
196 out_msg.Type := CoherenceRequestType:WB_NACK;
197 out_msg.Requestor := in_msg.Requestor;
198 out_msg.Destination.add(in_msg.Requestor);
199 out_msg.MessageSize := MessageSizeType:Writeback_Control;
204 action(c_clearOwner, "c", desc="Clear the owner field") {
205 directory[address].Owner.clear();
208 action(cc_clearSharers, "\c", desc="Clear the sharers field") {
209 directory[address].Sharers.clear();
212 action(d_sendData, "d", desc="Send data to requestor") {
213 peek(requestQueue_in, RequestMsg) {
214 enqueue(responseNetwork_out, ResponseMsg, latency="MEMORY_LATENCY") {
215 out_msg.Address := address;
217 if (in_msg.Type == CoherenceRequestType:GETS && directory[address].Sharers.count() == 0) {
218 out_msg.Type := CoherenceResponseType:DATA_EXCLUSIVE_CLEAN;
220 out_msg.Type := CoherenceResponseType:DATA;
223 out_msg.Sender := machineID;
224 out_msg.Destination.add(in_msg.Requestor);
225 out_msg.DataBlk := directory[in_msg.Address].DataBlk;
226 out_msg.Dirty := false; // By definition, the block is now clean
227 out_msg.Acks := directory[address].Sharers.count();
228 if (directory[address].Sharers.isElement(in_msg.Requestor)) {
229 out_msg.Acks := out_msg.Acks - 1;
231 out_msg.MessageSize := MessageSizeType:Response_Data;
236 action(e_ownerIsUnblocker, "e", desc="The owner is now the unblocker") {
237 peek(unblockNetwork_in, ResponseMsg) {
238 directory[address].Owner.clear();
239 directory[address].Owner.add(in_msg.Sender);
243 action(f_forwardRequest, "f", desc="Forward request to owner") {
244 peek(requestQueue_in, RequestMsg) {
245 enqueue(forwardNetwork_out, RequestMsg, latency="DIRECTORY_LATENCY") {
246 out_msg.Address := address;
247 out_msg.Type := in_msg.Type;
248 out_msg.Requestor := in_msg.Requestor;
249 out_msg.Destination := directory[in_msg.Address].Owner;
250 out_msg.Acks := directory[address].Sharers.count();
251 if (directory[address].Sharers.isElement(in_msg.Requestor)) {
252 out_msg.Acks := out_msg.Acks - 1;
254 out_msg.MessageSize := MessageSizeType:Forwarded_Control;
259 action(g_sendInvalidations, "g", desc="Send invalidations to sharers, not including the requester") {
260 peek(requestQueue_in, RequestMsg) {
261 if ((directory[in_msg.Address].Sharers.count() > 1) ||
262 ((directory[in_msg.Address].Sharers.count() > 0) && (directory[in_msg.Address].Sharers.isElement(in_msg.Requestor) == false))) {
263 enqueue(forwardNetwork_out, RequestMsg, latency="DIRECTORY_LATENCY") {
264 out_msg.Address := address;
265 out_msg.Type := CoherenceRequestType:INV;
266 out_msg.Requestor := in_msg.Requestor;
267 out_msg.Destination := directory[in_msg.Address].Sharers;
268 out_msg.Destination.remove(in_msg.Requestor);
269 out_msg.MessageSize := MessageSizeType:Forwarded_Control;
275 action(i_popIncomingRequestQueue, "i", desc="Pop incoming request queue") {
276 // Profile the request
277 peek(requestQueue_in, RequestMsg) {
278 if (in_msg.Type == CoherenceRequestType:GETX) {
279 // profile_sharing(address, AccessType:Write, machineIDToNodeID(in_msg.Requestor), directory[address].Sharers, directory[address].Owner);
280 } else if (in_msg.Type == CoherenceRequestType:GETS) {
281 // profile_sharing(address, AccessType:Read, machineIDToNodeID(in_msg.Requestor), directory[address].Sharers, directory[address].Owner);
285 requestQueue_in.dequeue();
288 action(j_popIncomingUnblockQueue, "j", desc="Pop incoming unblock queue") {
289 unblockNetwork_in.dequeue();
292 action(l_writeDataToMemory, "l", desc="Write PUTX/PUTO data to memory") {
293 peek(unblockNetwork_in, ResponseMsg) {
294 assert(in_msg.Dirty);
295 assert(in_msg.MessageSize == MessageSizeType:Writeback_Data);
296 directory[in_msg.Address].DataBlk := in_msg.DataBlk;
297 DEBUG_EXPR(in_msg.Address);
298 DEBUG_EXPR(in_msg.DataBlk);
302 action(ll_checkDataInMemory, "\l", desc="Check PUTX/PUTO data is same as in the memory") {
303 peek(unblockNetwork_in, ResponseMsg) {
304 assert(in_msg.Dirty == false);
305 assert(in_msg.MessageSize == MessageSizeType:Writeback_Control);
307 // NOTE: The following check would not be valid in a real
308 // implementation. We include the data in the "dataless"
309 // message so we can assert the clean data matches the datablock
311 assert(directory[in_msg.Address].DataBlk == in_msg.DataBlk);
315 action(m_addUnlockerToSharers, "m", desc="Add the unlocker to the sharer list") {
316 peek(unblockNetwork_in, ResponseMsg) {
317 directory[address].Sharers.add(in_msg.Sender);
321 action(n_incrementOutstanding, "n", desc="Increment outstanding requests") {
322 directory[address].WaitingUnblocks := directory[address].WaitingUnblocks + 1;
325 action(o_decrementOutstanding, "o", desc="Decrement outstanding requests") {
326 directory[address].WaitingUnblocks := directory[address].WaitingUnblocks - 1;
327 assert(directory[address].WaitingUnblocks >= 0);
330 // action(z_stall, "z", desc="Cannot be handled right now.") {
331 // Special name recognized as do nothing case
334 action(zz_recycleRequest, "\z", desc="Recycle the request queue") {
335 requestQueue_in.recycle();
340 transition(I, GETX, MM) {
342 i_popIncomingRequestQueue;
345 transition(S, GETX, MM) {
348 i_popIncomingRequestQueue;
351 transition(I, GETS, IS) {
353 i_popIncomingRequestQueue;
356 transition({S, SS}, GETS, SS) {
358 n_incrementOutstanding;
359 i_popIncomingRequestQueue;
362 transition({I, S, M}, PUTO) {
364 i_popIncomingRequestQueue;
367 transition({I, S, O}, PUTX) {
369 i_popIncomingRequestQueue;
372 transition(O, GETX, MM) {
375 i_popIncomingRequestQueue;
378 transition({O, OO}, GETS, OO) {
380 n_incrementOutstanding;
381 i_popIncomingRequestQueue;
384 transition(M, GETX, MM) {
386 i_popIncomingRequestQueue;
389 transition(M, GETS, MO) {
391 i_popIncomingRequestQueue;
394 transition(M, PUTX, MI) {
396 i_popIncomingRequestQueue;
399 transition(O, PUTO, OS) {
401 i_popIncomingRequestQueue;
404 transition({MM, MO, MI, OS}, {GETS, GETX, PUTO, PUTX}) {
408 transition({MM, MO}, Exclusive_Unblock, M) {
411 j_popIncomingUnblockQueue;
414 transition(MO, Unblock, O) {
415 m_addUnlockerToSharers;
416 j_popIncomingUnblockQueue;
419 transition({IS, SS, OO}, {GETX, PUTO, PUTX}) {
423 transition(IS, GETS) {
427 transition(IS, Unblock, S) {
428 m_addUnlockerToSharers;
429 j_popIncomingUnblockQueue;
432 transition(IS, Exclusive_Unblock, M) {
435 j_popIncomingUnblockQueue;
438 transition(SS, Unblock) {
439 m_addUnlockerToSharers;
440 o_decrementOutstanding;
441 j_popIncomingUnblockQueue;
444 transition(SS, Last_Unblock, S) {
445 m_addUnlockerToSharers;
446 o_decrementOutstanding;
447 j_popIncomingUnblockQueue;
450 transition(OO, Unblock) {
451 m_addUnlockerToSharers;
452 o_decrementOutstanding;
453 j_popIncomingUnblockQueue;
456 transition(OO, Last_Unblock, O) {
457 m_addUnlockerToSharers;
458 o_decrementOutstanding;
459 j_popIncomingUnblockQueue;
462 transition(MI, Dirty_Writeback, I) {
466 j_popIncomingUnblockQueue;
469 transition(OS, Dirty_Writeback, S) {
472 j_popIncomingUnblockQueue;
475 transition(MI, Clean_Writeback, I) {
478 ll_checkDataInMemory;
479 j_popIncomingUnblockQueue;
482 transition(OS, Clean_Writeback, S) {
484 ll_checkDataInMemory;
485 j_popIncomingUnblockQueue;
488 transition(MI, Unblock, M) {
489 j_popIncomingUnblockQueue;
492 transition(OS, Unblock, O) {
493 j_popIncomingUnblockQueue;