store_set.cc (8232:b28d06a175be) store_set.cc (8519:ef35ce2bd73f)
1/*
2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Kevin Lim
29 */
30
31#include "base/intmath.hh"
32#include "base/misc.hh"
33#include "base/trace.hh"
34#include "cpu/o3/store_set.hh"
35#include "debug/StoreSet.hh"
36
1/*
2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Kevin Lim
29 */
30
31#include "base/intmath.hh"
32#include "base/misc.hh"
33#include "base/trace.hh"
34#include "cpu/o3/store_set.hh"
35#include "debug/StoreSet.hh"
36
37StoreSet::StoreSet(int _SSIT_size, int _LFST_size)
38 : SSITSize(_SSIT_size), LFSTSize(_LFST_size)
37StoreSet::StoreSet(uint64_t clear_period, int _SSIT_size, int _LFST_size)
38 : clearPeriod(clear_period), SSITSize(_SSIT_size), LFSTSize(_LFST_size)
39{
40 DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");
41 DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",
42 SSITSize, LFSTSize);
43
44 if (!isPowerOf2(SSITSize)) {
45 fatal("Invalid SSIT size!\n");
46 }
47
48 SSIT.resize(SSITSize);
49
50 validSSIT.resize(SSITSize);
51
52 for (int i = 0; i < SSITSize; ++i)
53 validSSIT[i] = false;
54
55 if (!isPowerOf2(LFSTSize)) {
56 fatal("Invalid LFST size!\n");
57 }
58
59 LFST.resize(LFSTSize);
60
61 validLFST.resize(LFSTSize);
62
63 for (int i = 0; i < LFSTSize; ++i) {
64 validLFST[i] = false;
65 LFST[i] = 0;
66 }
67
68 indexMask = SSITSize - 1;
69
70 offsetBits = 2;
39{
40 DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");
41 DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",
42 SSITSize, LFSTSize);
43
44 if (!isPowerOf2(SSITSize)) {
45 fatal("Invalid SSIT size!\n");
46 }
47
48 SSIT.resize(SSITSize);
49
50 validSSIT.resize(SSITSize);
51
52 for (int i = 0; i < SSITSize; ++i)
53 validSSIT[i] = false;
54
55 if (!isPowerOf2(LFSTSize)) {
56 fatal("Invalid LFST size!\n");
57 }
58
59 LFST.resize(LFSTSize);
60
61 validLFST.resize(LFSTSize);
62
63 for (int i = 0; i < LFSTSize; ++i) {
64 validLFST[i] = false;
65 LFST[i] = 0;
66 }
67
68 indexMask = SSITSize - 1;
69
70 offsetBits = 2;
71
72 memOpsPred = 0;
71}
72
73StoreSet::~StoreSet()
74{
75}
76
77void
73}
74
75StoreSet::~StoreSet()
76{
77}
78
79void
78StoreSet::init(int _SSIT_size, int _LFST_size)
80StoreSet::init(uint64_t clear_period, int _SSIT_size, int _LFST_size)
79{
80 SSITSize = _SSIT_size;
81 LFSTSize = _LFST_size;
81{
82 SSITSize = _SSIT_size;
83 LFSTSize = _LFST_size;
84 clearPeriod = clear_period;
82
83 DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");
84 DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",
85 SSITSize, LFSTSize);
86
87 SSIT.resize(SSITSize);
88
89 validSSIT.resize(SSITSize);
90
91 for (int i = 0; i < SSITSize; ++i)
92 validSSIT[i] = false;
93
94 LFST.resize(LFSTSize);
95
96 validLFST.resize(LFSTSize);
97
98 for (int i = 0; i < LFSTSize; ++i) {
99 validLFST[i] = false;
100 LFST[i] = 0;
101 }
102
103 indexMask = SSITSize - 1;
104
105 offsetBits = 2;
85
86 DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");
87 DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",
88 SSITSize, LFSTSize);
89
90 SSIT.resize(SSITSize);
91
92 validSSIT.resize(SSITSize);
93
94 for (int i = 0; i < SSITSize; ++i)
95 validSSIT[i] = false;
96
97 LFST.resize(LFSTSize);
98
99 validLFST.resize(LFSTSize);
100
101 for (int i = 0; i < LFSTSize; ++i) {
102 validLFST[i] = false;
103 LFST[i] = 0;
104 }
105
106 indexMask = SSITSize - 1;
107
108 offsetBits = 2;
109
110 memOpsPred = 0;
106}
107
108
109void
110StoreSet::violation(Addr store_PC, Addr load_PC)
111{
112 int load_index = calcIndex(load_PC);
113 int store_index = calcIndex(store_PC);
114
115 assert(load_index < SSITSize && store_index < SSITSize);
116
117 bool valid_load_SSID = validSSIT[load_index];
118 bool valid_store_SSID = validSSIT[store_index];
119
120 if (!valid_load_SSID && !valid_store_SSID) {
121 // Calculate a new SSID here.
122 SSID new_set = calcSSID(load_PC);
123
124 validSSIT[load_index] = true;
125
126 SSIT[load_index] = new_set;
127
128 validSSIT[store_index] = true;
129
130 SSIT[store_index] = new_set;
131
132 assert(new_set < LFSTSize);
133
134 DPRINTF(StoreSet, "StoreSet: Neither load nor store had a valid "
135 "storeset, creating a new one: %i for load %#x, store %#x\n",
136 new_set, load_PC, store_PC);
137 } else if (valid_load_SSID && !valid_store_SSID) {
138 SSID load_SSID = SSIT[load_index];
139
140 validSSIT[store_index] = true;
141
142 SSIT[store_index] = load_SSID;
143
144 assert(load_SSID < LFSTSize);
145
146 DPRINTF(StoreSet, "StoreSet: Load had a valid store set. Adding "
147 "store to that set: %i for load %#x, store %#x\n",
148 load_SSID, load_PC, store_PC);
149 } else if (!valid_load_SSID && valid_store_SSID) {
150 SSID store_SSID = SSIT[store_index];
151
152 validSSIT[load_index] = true;
153
154 SSIT[load_index] = store_SSID;
155
156 DPRINTF(StoreSet, "StoreSet: Store had a valid store set: %i for "
157 "load %#x, store %#x\n",
158 store_SSID, load_PC, store_PC);
159 } else {
160 SSID load_SSID = SSIT[load_index];
161 SSID store_SSID = SSIT[store_index];
162
163 assert(load_SSID < LFSTSize && store_SSID < LFSTSize);
164
165 // The store set with the lower number wins
166 if (store_SSID > load_SSID) {
167 SSIT[store_index] = load_SSID;
168
169 DPRINTF(StoreSet, "StoreSet: Load had smaller store set: %i; "
170 "for load %#x, store %#x\n",
171 load_SSID, load_PC, store_PC);
172 } else {
173 SSIT[load_index] = store_SSID;
174
175 DPRINTF(StoreSet, "StoreSet: Store had smaller store set: %i; "
176 "for load %#x, store %#x\n",
177 store_SSID, load_PC, store_PC);
178 }
179 }
180}
181
182void
111}
112
113
114void
115StoreSet::violation(Addr store_PC, Addr load_PC)
116{
117 int load_index = calcIndex(load_PC);
118 int store_index = calcIndex(store_PC);
119
120 assert(load_index < SSITSize && store_index < SSITSize);
121
122 bool valid_load_SSID = validSSIT[load_index];
123 bool valid_store_SSID = validSSIT[store_index];
124
125 if (!valid_load_SSID && !valid_store_SSID) {
126 // Calculate a new SSID here.
127 SSID new_set = calcSSID(load_PC);
128
129 validSSIT[load_index] = true;
130
131 SSIT[load_index] = new_set;
132
133 validSSIT[store_index] = true;
134
135 SSIT[store_index] = new_set;
136
137 assert(new_set < LFSTSize);
138
139 DPRINTF(StoreSet, "StoreSet: Neither load nor store had a valid "
140 "storeset, creating a new one: %i for load %#x, store %#x\n",
141 new_set, load_PC, store_PC);
142 } else if (valid_load_SSID && !valid_store_SSID) {
143 SSID load_SSID = SSIT[load_index];
144
145 validSSIT[store_index] = true;
146
147 SSIT[store_index] = load_SSID;
148
149 assert(load_SSID < LFSTSize);
150
151 DPRINTF(StoreSet, "StoreSet: Load had a valid store set. Adding "
152 "store to that set: %i for load %#x, store %#x\n",
153 load_SSID, load_PC, store_PC);
154 } else if (!valid_load_SSID && valid_store_SSID) {
155 SSID store_SSID = SSIT[store_index];
156
157 validSSIT[load_index] = true;
158
159 SSIT[load_index] = store_SSID;
160
161 DPRINTF(StoreSet, "StoreSet: Store had a valid store set: %i for "
162 "load %#x, store %#x\n",
163 store_SSID, load_PC, store_PC);
164 } else {
165 SSID load_SSID = SSIT[load_index];
166 SSID store_SSID = SSIT[store_index];
167
168 assert(load_SSID < LFSTSize && store_SSID < LFSTSize);
169
170 // The store set with the lower number wins
171 if (store_SSID > load_SSID) {
172 SSIT[store_index] = load_SSID;
173
174 DPRINTF(StoreSet, "StoreSet: Load had smaller store set: %i; "
175 "for load %#x, store %#x\n",
176 load_SSID, load_PC, store_PC);
177 } else {
178 SSIT[load_index] = store_SSID;
179
180 DPRINTF(StoreSet, "StoreSet: Store had smaller store set: %i; "
181 "for load %#x, store %#x\n",
182 store_SSID, load_PC, store_PC);
183 }
184 }
185}
186
187void
188StoreSet::checkClear()
189{
190 memOpsPred++;
191 if (memOpsPred > clearPeriod) {
192 DPRINTF(StoreSet, "Wiping predictor state beacuse %d ld/st executed\n",
193 clearPeriod);
194 memOpsPred = 0;
195 clear();
196 }
197}
198
199void
183StoreSet::insertLoad(Addr load_PC, InstSeqNum load_seq_num)
184{
200StoreSet::insertLoad(Addr load_PC, InstSeqNum load_seq_num)
201{
202 checkClear();
185 // Does nothing.
186 return;
187}
188
189void
190StoreSet::insertStore(Addr store_PC, InstSeqNum store_seq_num, ThreadID tid)
191{
192 int index = calcIndex(store_PC);
193
194 int store_SSID;
195
203 // Does nothing.
204 return;
205}
206
207void
208StoreSet::insertStore(Addr store_PC, InstSeqNum store_seq_num, ThreadID tid)
209{
210 int index = calcIndex(store_PC);
211
212 int store_SSID;
213
214 checkClear();
196 assert(index < SSITSize);
197
198 if (!validSSIT[index]) {
199 // Do nothing if there's no valid entry.
200 return;
201 } else {
202 store_SSID = SSIT[index];
203
204 assert(store_SSID < LFSTSize);
205
206 // Update the last store that was fetched with the current one.
207 LFST[store_SSID] = store_seq_num;
208
209 validLFST[store_SSID] = 1;
210
211 storeList[store_seq_num] = store_SSID;
212
213 DPRINTF(StoreSet, "Store %#x updated the LFST, SSID: %i\n",
214 store_PC, store_SSID);
215 }
216}
217
218InstSeqNum
219StoreSet::checkInst(Addr PC)
220{
221 int index = calcIndex(PC);
222
223 int inst_SSID;
224
225 assert(index < SSITSize);
226
227 if (!validSSIT[index]) {
228 DPRINTF(StoreSet, "Inst %#x with index %i had no SSID\n",
229 PC, index);
230
231 // Return 0 if there's no valid entry.
232 return 0;
233 } else {
234 inst_SSID = SSIT[index];
235
236 assert(inst_SSID < LFSTSize);
237
238 if (!validLFST[inst_SSID]) {
239
240 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had no "
241 "dependency\n", PC, index, inst_SSID);
242
243 return 0;
244 } else {
245 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had LFST "
246 "inum of %i\n", PC, index, inst_SSID, LFST[inst_SSID]);
247
248 return LFST[inst_SSID];
249 }
250 }
251}
252
253void
254StoreSet::issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store)
255{
256 // This only is updated upon a store being issued.
257 if (!is_store) {
258 return;
259 }
260
261 int index = calcIndex(issued_PC);
262
263 int store_SSID;
264
265 assert(index < SSITSize);
266
267 SeqNumMapIt store_list_it = storeList.find(issued_seq_num);
268
269 if (store_list_it != storeList.end()) {
270 storeList.erase(store_list_it);
271 }
272
273 // Make sure the SSIT still has a valid entry for the issued store.
274 if (!validSSIT[index]) {
275 return;
276 }
277
278 store_SSID = SSIT[index];
279
280 assert(store_SSID < LFSTSize);
281
282 // If the last fetched store in the store set refers to the store that
283 // was just issued, then invalidate the entry.
284 if (validLFST[store_SSID] && LFST[store_SSID] == issued_seq_num) {
285 DPRINTF(StoreSet, "StoreSet: store invalidated itself in LFST.\n");
286 validLFST[store_SSID] = false;
287 }
288}
289
290void
291StoreSet::squash(InstSeqNum squashed_num, ThreadID tid)
292{
293 DPRINTF(StoreSet, "StoreSet: Squashing until inum %i\n",
294 squashed_num);
295
296 int idx;
297 SeqNumMapIt store_list_it = storeList.begin();
298
299 //@todo:Fix to only delete from correct thread
300 while (!storeList.empty()) {
301 idx = (*store_list_it).second;
302
303 if ((*store_list_it).first <= squashed_num) {
304 break;
305 }
306
307 bool younger = LFST[idx] > squashed_num;
308
309 if (validLFST[idx] && younger) {
310 DPRINTF(StoreSet, "Squashed [sn:%lli]\n", LFST[idx]);
311 validLFST[idx] = false;
312
313 storeList.erase(store_list_it++);
314 } else if (!validLFST[idx] && younger) {
315 storeList.erase(store_list_it++);
316 }
317 }
318}
319
320void
321StoreSet::clear()
322{
323 for (int i = 0; i < SSITSize; ++i) {
324 validSSIT[i] = false;
325 }
326
327 for (int i = 0; i < LFSTSize; ++i) {
328 validLFST[i] = false;
329 }
330
331 storeList.clear();
332}
333
334void
335StoreSet::dump()
336{
337 cprintf("storeList.size(): %i\n", storeList.size());
338 SeqNumMapIt store_list_it = storeList.begin();
339
340 int num = 0;
341
342 while (store_list_it != storeList.end()) {
343 cprintf("%i: [sn:%lli] SSID:%i\n",
344 num, (*store_list_it).first, (*store_list_it).second);
345 num++;
346 store_list_it++;
347 }
348}
215 assert(index < SSITSize);
216
217 if (!validSSIT[index]) {
218 // Do nothing if there's no valid entry.
219 return;
220 } else {
221 store_SSID = SSIT[index];
222
223 assert(store_SSID < LFSTSize);
224
225 // Update the last store that was fetched with the current one.
226 LFST[store_SSID] = store_seq_num;
227
228 validLFST[store_SSID] = 1;
229
230 storeList[store_seq_num] = store_SSID;
231
232 DPRINTF(StoreSet, "Store %#x updated the LFST, SSID: %i\n",
233 store_PC, store_SSID);
234 }
235}
236
237InstSeqNum
238StoreSet::checkInst(Addr PC)
239{
240 int index = calcIndex(PC);
241
242 int inst_SSID;
243
244 assert(index < SSITSize);
245
246 if (!validSSIT[index]) {
247 DPRINTF(StoreSet, "Inst %#x with index %i had no SSID\n",
248 PC, index);
249
250 // Return 0 if there's no valid entry.
251 return 0;
252 } else {
253 inst_SSID = SSIT[index];
254
255 assert(inst_SSID < LFSTSize);
256
257 if (!validLFST[inst_SSID]) {
258
259 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had no "
260 "dependency\n", PC, index, inst_SSID);
261
262 return 0;
263 } else {
264 DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had LFST "
265 "inum of %i\n", PC, index, inst_SSID, LFST[inst_SSID]);
266
267 return LFST[inst_SSID];
268 }
269 }
270}
271
272void
273StoreSet::issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store)
274{
275 // This only is updated upon a store being issued.
276 if (!is_store) {
277 return;
278 }
279
280 int index = calcIndex(issued_PC);
281
282 int store_SSID;
283
284 assert(index < SSITSize);
285
286 SeqNumMapIt store_list_it = storeList.find(issued_seq_num);
287
288 if (store_list_it != storeList.end()) {
289 storeList.erase(store_list_it);
290 }
291
292 // Make sure the SSIT still has a valid entry for the issued store.
293 if (!validSSIT[index]) {
294 return;
295 }
296
297 store_SSID = SSIT[index];
298
299 assert(store_SSID < LFSTSize);
300
301 // If the last fetched store in the store set refers to the store that
302 // was just issued, then invalidate the entry.
303 if (validLFST[store_SSID] && LFST[store_SSID] == issued_seq_num) {
304 DPRINTF(StoreSet, "StoreSet: store invalidated itself in LFST.\n");
305 validLFST[store_SSID] = false;
306 }
307}
308
309void
310StoreSet::squash(InstSeqNum squashed_num, ThreadID tid)
311{
312 DPRINTF(StoreSet, "StoreSet: Squashing until inum %i\n",
313 squashed_num);
314
315 int idx;
316 SeqNumMapIt store_list_it = storeList.begin();
317
318 //@todo:Fix to only delete from correct thread
319 while (!storeList.empty()) {
320 idx = (*store_list_it).second;
321
322 if ((*store_list_it).first <= squashed_num) {
323 break;
324 }
325
326 bool younger = LFST[idx] > squashed_num;
327
328 if (validLFST[idx] && younger) {
329 DPRINTF(StoreSet, "Squashed [sn:%lli]\n", LFST[idx]);
330 validLFST[idx] = false;
331
332 storeList.erase(store_list_it++);
333 } else if (!validLFST[idx] && younger) {
334 storeList.erase(store_list_it++);
335 }
336 }
337}
338
339void
340StoreSet::clear()
341{
342 for (int i = 0; i < SSITSize; ++i) {
343 validSSIT[i] = false;
344 }
345
346 for (int i = 0; i < LFSTSize; ++i) {
347 validLFST[i] = false;
348 }
349
350 storeList.clear();
351}
352
353void
354StoreSet::dump()
355{
356 cprintf("storeList.size(): %i\n", storeList.size());
357 SeqNumMapIt store_list_it = storeList.begin();
358
359 int num = 0;
360
361 while (store_list_it != storeList.end()) {
362 cprintf("%i: [sn:%lli] SSID:%i\n",
363 num, (*store_list_it).first, (*store_list_it).second);
364 num++;
365 store_list_it++;
366 }
367}