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, "MOSI Broadcast Optimized") {
38 MessageBuffer addressFromDir, network="To", virtual_network="0", ordered="true";
39 MessageBuffer dataFromDir, network="To", virtual_network="1", ordered="false";
41 MessageBuffer addressToDir, network="From", virtual_network="0", ordered="true";
42 MessageBuffer dataToDir, network="From", virtual_network="1", ordered="false";
45 enumeration(State, desc="Directory states", default="Directory_State_C") {
46 C, desc="Cold - no processor has requested this line";
49 SS, desc="Shared, 2 or more shares";
50 OS, desc="Owned by a cache";
51 OSS, desc="Owned by a cache, present in at least 3 caches";
52 M, desc="Modified", format="!b";
57 enumeration(Event, desc="Directory events") {
58 // From Address network
59 OtherAddress, desc="We saw an address msg to someone else";
60 GETS, desc="A GETS arrives";
61 GET_INSTR, desc="A GETInstr arrives";
62 GETX, desc="A GETX arrives", format="!r";
63 PUTX_Owner, desc="A PUTX arrives, requestor is owner";
64 PUTX_NotOwner, desc="A PUTX arrives, requestor is not owner", format="!r";
70 structure(Entry, desc="...") {
71 State DirectoryState, desc="Directory state";
72 bool DirOwner, default="true", desc="Is dir owner?";
73 MachineID ProcOwner, desc="Processor Owner";
74 DataBlock DataBlk, desc="data for the block";
77 external_type(DirectoryMemory) {
78 Entry lookup(Address);
79 bool isPresent(Address);
84 DirectoryMemory directory, constructor_hack="i";
86 void profile_request(int cache_state, State directory_state, GenericRequestType request_type);
88 State getState(Address addr) {
89 if (directory.isPresent(addr)) {
90 return directory[addr].DirectoryState;
95 void setState(Address addr, State state) {
96 if (directory.isPresent(addr)) {
97 directory[addr].DirectoryState := state;
103 out_port(dataNetwork_out, DataMsg, dataFromDir);
104 out_port(addressNetwork_out, AddressMsg, addressFromDir);
109 in_port(addressNetwork_in, AddressMsg, addressToDir) {
110 if (addressNetwork_in.isReady()) {
111 peek(addressNetwork_in, AddressMsg) {
112 if(map_Address_to_Directory(in_msg.Address) != machineID) {
113 trigger(Event:OtherAddress, in_msg.Address);
114 } else if (in_msg.Type == CoherenceRequestType:GETS) {
115 trigger(Event:GETS, in_msg.Address);
116 } else if (in_msg.Type == CoherenceRequestType:GET_INSTR) {
117 trigger(Event:GET_INSTR, in_msg.Address);
118 } else if (in_msg.Type == CoherenceRequestType:GETX) {
119 trigger(Event:GETX, in_msg.Address);
120 } else if (in_msg.Type == CoherenceRequestType:PUTX) {
121 if (in_msg.Requestor == directory[in_msg.Address].ProcOwner && directory[in_msg.Address].DirOwner == false) {
122 trigger(Event:PUTX_Owner, in_msg.Address);
124 trigger(Event:PUTX_NotOwner, in_msg.Address);
127 error("unexpected message");
135 action(d_sendDataMsg, "d", desc="Send data message to requestor") {
136 peek(addressNetwork_in, AddressMsg) {
137 enqueue(dataNetwork_out, DataMsg, latency="MEMORY_LATENCY") {
138 out_msg.Address := in_msg.Address;
139 out_msg.Sender := machineID;
140 out_msg.Destination.add(in_msg.Requestor);
141 out_msg.DestMachine := MachineType:L1Cache;
142 out_msg.DataBlk := directory[in_msg.Address].DataBlk;
143 out_msg.MessageSize := MessageSizeType:Data;
144 DEBUG_EXPR(in_msg.Requestor);
145 DEBUG_EXPR(out_msg.DataBlk);
150 action(j_popAddressQueue, "j", desc="Pop address queue.") {
151 addressNetwork_in.dequeue();
154 action(p_profile, "p", desc="Profile this transition.") {
155 peek(addressNetwork_in, AddressMsg) {
156 profile_request(in_msg.CacheState, getState(address), convertToGenericType(in_msg.Type));
160 action(m_setOwnerRequestor, "m", desc="Set owner = requestor") {
161 peek(addressNetwork_in, AddressMsg) {
162 directory[in_msg.Address].ProcOwner := in_msg.Requestor;
163 directory[in_msg.Address].DirOwner := false;
167 action(r_writeDataFromRequest, "r", desc="Write request data to memory") {
168 peek(addressNetwork_in, AddressMsg) {
169 directory[in_msg.Address].DataBlk := in_msg.DataBlk;
170 DEBUG_EXPR(in_msg.Address);
171 DEBUG_EXPR(in_msg.DataBlk);
175 action(x_setOwnerToDirectory, "x", desc="Set owner equal to the directory"){
176 peek(addressNetwork_in, AddressMsg) {
177 directory[in_msg.Address].DirOwner := true;
183 // Ignore all address and data messages not bound for us
184 transition(C, OtherAddress) {
188 // PUTX_NotOwner Transitions
189 transition({I, S, SS, OS, OSS, M}, PUTX_NotOwner) {
194 // Transitions from Idle
195 transition({C, I}, {GETS,GET_INSTR}, S) {
201 transition({C, I}, GETX, M) {
208 // Transitions from Shared
209 transition({S, SS}, {GETS,GET_INSTR}, SS) {
215 transition({S, SS}, GETX, M) {
222 // Transitions from Owned
223 transition({OS, OSS}, {GETS,GET_INSTR}, OSS) {
228 transition({OS, OSS}, GETX, M) {
234 transition(OS, PUTX_Owner, S) {
235 x_setOwnerToDirectory;
236 r_writeDataFromRequest;
241 transition(OSS, PUTX_Owner, SS) {
242 x_setOwnerToDirectory;
243 r_writeDataFromRequest;
248 // Transitions from Modified
249 transition(M, {GETS,GET_INSTR}, OS) {
254 transition(M, GETX) {
260 transition(M, PUTX_Owner, I) {
261 x_setOwnerToDirectory;
262 r_writeDataFromRequest;