MOESI_hammer: Added full-bit directory support
[gem5.git] / src / mem / protocol / MOSI_SMP_bcast-dir.sm
1
2 /*
3 * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
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.
16 *
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.
28 */
29
30 /*
31 * $Id$
32 *
33 */
34
35 machine(Directory, "MOSI Broadcast Optimized") {
36
37
38 MessageBuffer addressFromDir, network="To", virtual_network="0", ordered="true";
39 MessageBuffer dataFromDir, network="To", virtual_network="1", ordered="false";
40
41 MessageBuffer addressToDir, network="From", virtual_network="0", ordered="true";
42 MessageBuffer dataToDir, network="From", virtual_network="1", ordered="false";
43
44
45 enumeration(State, desc="Directory states", default="Directory_State_C") {
46 C, desc="Cold - no processor has requested this line";
47 I, desc="Idle";
48 S, desc="Shared";
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";
53 }
54
55 // ** EVENTS **
56
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";
65 }
66
67 // TYPES
68
69 // DirectoryEntry
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";
75 }
76
77 external_type(DirectoryMemory) {
78 Entry lookup(Address);
79 bool isPresent(Address);
80 }
81
82 // ** OBJECTS **
83
84 DirectoryMemory directory, constructor_hack="i";
85
86 void profile_request(int cache_state, State directory_state, GenericRequestType request_type);
87
88 State getState(Address addr) {
89 if (directory.isPresent(addr)) {
90 return directory[addr].DirectoryState;
91 }
92 return State:C;
93 }
94
95 void setState(Address addr, State state) {
96 if (directory.isPresent(addr)) {
97 directory[addr].DirectoryState := state;
98 }
99 }
100
101 // ** OUT_PORTS **
102
103 out_port(dataNetwork_out, DataMsg, dataFromDir);
104 out_port(addressNetwork_out, AddressMsg, addressFromDir);
105
106 // ** IN_PORTS **
107
108 // Address Network
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);
123 } else {
124 trigger(Event:PUTX_NotOwner, in_msg.Address);
125 }
126 } else {
127 error("unexpected message");
128 }
129 }
130 }
131 }
132
133 // *** ACTIONS ***
134
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);
146 }
147 }
148 }
149
150 action(j_popAddressQueue, "j", desc="Pop address queue.") {
151 addressNetwork_in.dequeue();
152 }
153
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));
157 }
158 }
159
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;
164 }
165 }
166
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);
172 }
173 }
174
175 action(x_setOwnerToDirectory, "x", desc="Set owner equal to the directory"){
176 peek(addressNetwork_in, AddressMsg) {
177 directory[in_msg.Address].DirOwner := true;
178 }
179 }
180
181 // TRANSITIONS
182
183 // Ignore all address and data messages not bound for us
184 transition(C, OtherAddress) {
185 j_popAddressQueue;
186 }
187
188 // PUTX_NotOwner Transitions
189 transition({I, S, SS, OS, OSS, M}, PUTX_NotOwner) {
190 p_profile;
191 j_popAddressQueue;
192 }
193
194 // Transitions from Idle
195 transition({C, I}, {GETS,GET_INSTR}, S) {
196 d_sendDataMsg;
197 p_profile;
198 j_popAddressQueue;
199 }
200
201 transition({C, I}, GETX, M) {
202 d_sendDataMsg;
203 m_setOwnerRequestor;
204 p_profile;
205 j_popAddressQueue
206 }
207
208 // Transitions from Shared
209 transition({S, SS}, {GETS,GET_INSTR}, SS) {
210 d_sendDataMsg;
211 p_profile;
212 j_popAddressQueue;
213 }
214
215 transition({S, SS}, GETX, M) {
216 d_sendDataMsg;
217 m_setOwnerRequestor;
218 p_profile;
219 j_popAddressQueue;
220 }
221
222 // Transitions from Owned
223 transition({OS, OSS}, {GETS,GET_INSTR}, OSS) {
224 p_profile;
225 j_popAddressQueue;
226 }
227
228 transition({OS, OSS}, GETX, M) {
229 m_setOwnerRequestor;
230 p_profile;
231 j_popAddressQueue;
232 }
233
234 transition(OS, PUTX_Owner, S) {
235 x_setOwnerToDirectory;
236 r_writeDataFromRequest;
237 p_profile;
238 j_popAddressQueue;
239 }
240
241 transition(OSS, PUTX_Owner, SS) {
242 x_setOwnerToDirectory;
243 r_writeDataFromRequest;
244 p_profile;
245 j_popAddressQueue;
246 }
247
248 // Transitions from Modified
249 transition(M, {GETS,GET_INSTR}, OS) {
250 p_profile;
251 j_popAddressQueue;
252 }
253
254 transition(M, GETX) {
255 m_setOwnerRequestor;
256 p_profile;
257 j_popAddressQueue;
258 }
259
260 transition(M, PUTX_Owner, I) {
261 x_setOwnerToDirectory;
262 r_writeDataFromRequest;
263 p_profile;
264 j_popAddressQueue;
265 }
266
267 }