lsq_impl.hh (9444:ab47fe7f03f0) lsq_impl.hh (9868:44a67004d6b4)
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2005-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Korey Sewell
41 */
42
43#include <algorithm>
44#include <list>
45#include <string>
46
47#include "cpu/o3/lsq.hh"
48#include "debug/Drain.hh"
49#include "debug/Fetch.hh"
50#include "debug/LSQ.hh"
51#include "debug/Writeback.hh"
52#include "params/DerivO3CPU.hh"
53
54using namespace std;
55
56template <class Impl>
57LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
58 : cpu(cpu_ptr), iewStage(iew_ptr),
59 LQEntries(params->LQEntries),
60 SQEntries(params->SQEntries),
61 numThreads(params->numThreads),
62 retryTid(-1)
63{
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2005-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Korey Sewell
41 */
42
43#include <algorithm>
44#include <list>
45#include <string>
46
47#include "cpu/o3/lsq.hh"
48#include "debug/Drain.hh"
49#include "debug/Fetch.hh"
50#include "debug/LSQ.hh"
51#include "debug/Writeback.hh"
52#include "params/DerivO3CPU.hh"
53
54using namespace std;
55
56template <class Impl>
57LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
58 : cpu(cpu_ptr), iewStage(iew_ptr),
59 LQEntries(params->LQEntries),
60 SQEntries(params->SQEntries),
61 numThreads(params->numThreads),
62 retryTid(-1)
63{
64 assert(numThreads > 0 && numThreads <= Impl::MaxThreads);
65
64 //**********************************************/
65 //************ Handle SMT Parameters ***********/
66 //**********************************************/
67 std::string policy = params->smtLSQPolicy;
68
69 //Convert string to lowercase
70 std::transform(policy.begin(), policy.end(), policy.begin(),
71 (int(*)(int)) tolower);
72
73 //Figure out fetch policy
74 if (policy == "dynamic") {
75 lsqPolicy = Dynamic;
76
77 maxLQEntries = LQEntries;
78 maxSQEntries = SQEntries;
79
80 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
81 } else if (policy == "partitioned") {
82 lsqPolicy = Partitioned;
83
84 //@todo:make work if part_amt doesnt divide evenly.
85 maxLQEntries = LQEntries / numThreads;
86 maxSQEntries = SQEntries / numThreads;
87
88 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
89 "%i entries per LQ | %i entries per SQ\n",
90 maxLQEntries,maxSQEntries);
91 } else if (policy == "threshold") {
92 lsqPolicy = Threshold;
93
94 assert(params->smtLSQThreshold > LQEntries);
95 assert(params->smtLSQThreshold > SQEntries);
96
97 //Divide up by threshold amount
98 //@todo: Should threads check the max and the total
99 //amount of the LSQ
100 maxLQEntries = params->smtLSQThreshold;
101 maxSQEntries = params->smtLSQThreshold;
102
103 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
104 "%i entries per LQ | %i entries per SQ\n",
105 maxLQEntries,maxSQEntries);
106 } else {
107 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
108 "Partitioned, Threshold}");
109 }
110
111 //Initialize LSQs
66 //**********************************************/
67 //************ Handle SMT Parameters ***********/
68 //**********************************************/
69 std::string policy = params->smtLSQPolicy;
70
71 //Convert string to lowercase
72 std::transform(policy.begin(), policy.end(), policy.begin(),
73 (int(*)(int)) tolower);
74
75 //Figure out fetch policy
76 if (policy == "dynamic") {
77 lsqPolicy = Dynamic;
78
79 maxLQEntries = LQEntries;
80 maxSQEntries = SQEntries;
81
82 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
83 } else if (policy == "partitioned") {
84 lsqPolicy = Partitioned;
85
86 //@todo:make work if part_amt doesnt divide evenly.
87 maxLQEntries = LQEntries / numThreads;
88 maxSQEntries = SQEntries / numThreads;
89
90 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
91 "%i entries per LQ | %i entries per SQ\n",
92 maxLQEntries,maxSQEntries);
93 } else if (policy == "threshold") {
94 lsqPolicy = Threshold;
95
96 assert(params->smtLSQThreshold > LQEntries);
97 assert(params->smtLSQThreshold > SQEntries);
98
99 //Divide up by threshold amount
100 //@todo: Should threads check the max and the total
101 //amount of the LSQ
102 maxLQEntries = params->smtLSQThreshold;
103 maxSQEntries = params->smtLSQThreshold;
104
105 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
106 "%i entries per LQ | %i entries per SQ\n",
107 maxLQEntries,maxSQEntries);
108 } else {
109 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
110 "Partitioned, Threshold}");
111 }
112
113 //Initialize LSQs
114 thread = new LSQUnit[numThreads];
112 for (ThreadID tid = 0; tid < numThreads; tid++) {
113 thread[tid].init(cpu, iew_ptr, params, this,
114 maxLQEntries, maxSQEntries, tid);
115 thread[tid].setDcachePort(&cpu_ptr->getDataPort());
116 }
117}
118
119
120template<class Impl>
121std::string
122LSQ<Impl>::name() const
123{
124 return iewStage->name() + ".lsq";
125}
126
127template<class Impl>
128void
129LSQ<Impl>::regStats()
130{
131 //Initialize LSQs
132 for (ThreadID tid = 0; tid < numThreads; tid++) {
133 thread[tid].regStats();
134 }
135}
136
137template<class Impl>
138void
139LSQ<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
140{
141 activeThreads = at_ptr;
142 assert(activeThreads != 0);
143}
144
145template <class Impl>
146void
147LSQ<Impl>::drainSanityCheck() const
148{
149 assert(isDrained());
150
151 for (ThreadID tid = 0; tid < numThreads; tid++)
152 thread[tid].drainSanityCheck();
153}
154
155template <class Impl>
156bool
157LSQ<Impl>::isDrained() const
158{
159 bool drained(true);
160
161 if (!lqEmpty()) {
162 DPRINTF(Drain, "Not drained, LQ not empty.\n");
163 drained = false;
164 }
165
166 if (!sqEmpty()) {
167 DPRINTF(Drain, "Not drained, SQ not empty.\n");
168 drained = false;
169 }
170
171 if (retryTid != InvalidThreadID) {
172 DPRINTF(Drain, "Not drained, the LSQ has blocked the caches.\n");
173 drained = false;
174 }
175
176 return drained;
177}
178
179template <class Impl>
180void
181LSQ<Impl>::takeOverFrom()
182{
183 for (ThreadID tid = 0; tid < numThreads; tid++) {
184 thread[tid].takeOverFrom();
185 }
186}
187
188template <class Impl>
189int
190LSQ<Impl>::entryAmount(ThreadID num_threads)
191{
192 if (lsqPolicy == Partitioned) {
193 return LQEntries / num_threads;
194 } else {
195 return 0;
196 }
197}
198
199template <class Impl>
200void
201LSQ<Impl>::resetEntries()
202{
203 if (lsqPolicy != Dynamic || numThreads > 1) {
204 int active_threads = activeThreads->size();
205
206 int maxEntries;
207
208 if (lsqPolicy == Partitioned) {
209 maxEntries = LQEntries / active_threads;
210 } else if (lsqPolicy == Threshold && active_threads == 1) {
211 maxEntries = LQEntries;
212 } else {
213 maxEntries = LQEntries;
214 }
215
216 list<ThreadID>::iterator threads = activeThreads->begin();
217 list<ThreadID>::iterator end = activeThreads->end();
218
219 while (threads != end) {
220 ThreadID tid = *threads++;
221
222 resizeEntries(maxEntries, tid);
223 }
224 }
225}
226
227template<class Impl>
228void
229LSQ<Impl>::removeEntries(ThreadID tid)
230{
231 thread[tid].clearLQ();
232 thread[tid].clearSQ();
233}
234
235template<class Impl>
236void
237LSQ<Impl>::resizeEntries(unsigned size, ThreadID tid)
238{
239 thread[tid].resizeLQ(size);
240 thread[tid].resizeSQ(size);
241}
242
243template<class Impl>
244void
245LSQ<Impl>::tick()
246{
247 list<ThreadID>::iterator threads = activeThreads->begin();
248 list<ThreadID>::iterator end = activeThreads->end();
249
250 while (threads != end) {
251 ThreadID tid = *threads++;
252
253 thread[tid].tick();
254 }
255}
256
257template<class Impl>
258void
259LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
260{
261 ThreadID tid = load_inst->threadNumber;
262
263 thread[tid].insertLoad(load_inst);
264}
265
266template<class Impl>
267void
268LSQ<Impl>::insertStore(DynInstPtr &store_inst)
269{
270 ThreadID tid = store_inst->threadNumber;
271
272 thread[tid].insertStore(store_inst);
273}
274
275template<class Impl>
276Fault
277LSQ<Impl>::executeLoad(DynInstPtr &inst)
278{
279 ThreadID tid = inst->threadNumber;
280
281 return thread[tid].executeLoad(inst);
282}
283
284template<class Impl>
285Fault
286LSQ<Impl>::executeStore(DynInstPtr &inst)
287{
288 ThreadID tid = inst->threadNumber;
289
290 return thread[tid].executeStore(inst);
291}
292
293template<class Impl>
294void
295LSQ<Impl>::writebackStores()
296{
297 list<ThreadID>::iterator threads = activeThreads->begin();
298 list<ThreadID>::iterator end = activeThreads->end();
299
300 while (threads != end) {
301 ThreadID tid = *threads++;
302
303 if (numStoresToWB(tid) > 0) {
304 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
305 "available for Writeback.\n", tid, numStoresToWB(tid));
306 }
307
308 thread[tid].writebackStores();
309 }
310}
311
312template<class Impl>
313bool
314LSQ<Impl>::violation()
315{
316 /* Answers: Does Anybody Have a Violation?*/
317 list<ThreadID>::iterator threads = activeThreads->begin();
318 list<ThreadID>::iterator end = activeThreads->end();
319
320 while (threads != end) {
321 ThreadID tid = *threads++;
322
323 if (thread[tid].violation())
324 return true;
325 }
326
327 return false;
328}
329
330template <class Impl>
331void
332LSQ<Impl>::recvRetry()
333{
334 if (retryTid == InvalidThreadID)
335 {
336 //Squashed, so drop it
337 return;
338 }
339 int curr_retry_tid = retryTid;
340 // Speculatively clear the retry Tid. This will get set again if
341 // the LSQUnit was unable to complete its access.
342 retryTid = -1;
343 thread[curr_retry_tid].recvRetry();
344}
345
346template <class Impl>
347bool
348LSQ<Impl>::recvTimingResp(PacketPtr pkt)
349{
350 if (pkt->isError())
351 DPRINTF(LSQ, "Got error packet back for address: %#X\n",
352 pkt->getAddr());
353 thread[pkt->req->threadId()].completeDataAccess(pkt);
354 return true;
355}
356
357template <class Impl>
358void
359LSQ<Impl>::recvTimingSnoopReq(PacketPtr pkt)
360{
361 DPRINTF(LSQ, "received pkt for addr:%#x %s\n", pkt->getAddr(),
362 pkt->cmdString());
363
364 // must be a snoop
365 if (pkt->isInvalidate()) {
366 DPRINTF(LSQ, "received invalidation for addr:%#x\n",
367 pkt->getAddr());
368 for (ThreadID tid = 0; tid < numThreads; tid++) {
369 thread[tid].checkSnoop(pkt);
370 }
371 }
372}
373
374template<class Impl>
375int
376LSQ<Impl>::getCount()
377{
378 unsigned total = 0;
379
380 list<ThreadID>::iterator threads = activeThreads->begin();
381 list<ThreadID>::iterator end = activeThreads->end();
382
383 while (threads != end) {
384 ThreadID tid = *threads++;
385
386 total += getCount(tid);
387 }
388
389 return total;
390}
391
392template<class Impl>
393int
394LSQ<Impl>::numLoads()
395{
396 unsigned total = 0;
397
398 list<ThreadID>::iterator threads = activeThreads->begin();
399 list<ThreadID>::iterator end = activeThreads->end();
400
401 while (threads != end) {
402 ThreadID tid = *threads++;
403
404 total += numLoads(tid);
405 }
406
407 return total;
408}
409
410template<class Impl>
411int
412LSQ<Impl>::numStores()
413{
414 unsigned total = 0;
415
416 list<ThreadID>::iterator threads = activeThreads->begin();
417 list<ThreadID>::iterator end = activeThreads->end();
418
419 while (threads != end) {
420 ThreadID tid = *threads++;
421
422 total += thread[tid].numStores();
423 }
424
425 return total;
426}
427
428template<class Impl>
429unsigned
430LSQ<Impl>::numFreeEntries()
431{
432 unsigned total = 0;
433
434 list<ThreadID>::iterator threads = activeThreads->begin();
435 list<ThreadID>::iterator end = activeThreads->end();
436
437 while (threads != end) {
438 ThreadID tid = *threads++;
439
440 total += thread[tid].numFreeEntries();
441 }
442
443 return total;
444}
445
446template<class Impl>
447unsigned
448LSQ<Impl>::numFreeEntries(ThreadID tid)
449{
450 //if (lsqPolicy == Dynamic)
451 //return numFreeEntries();
452 //else
453 return thread[tid].numFreeEntries();
454}
455
456template<class Impl>
457bool
458LSQ<Impl>::isFull()
459{
460 list<ThreadID>::iterator threads = activeThreads->begin();
461 list<ThreadID>::iterator end = activeThreads->end();
462
463 while (threads != end) {
464 ThreadID tid = *threads++;
465
466 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
467 return false;
468 }
469
470 return true;
471}
472
473template<class Impl>
474bool
475LSQ<Impl>::isFull(ThreadID tid)
476{
477 //@todo: Change to Calculate All Entries for
478 //Dynamic Policy
479 if (lsqPolicy == Dynamic)
480 return isFull();
481 else
482 return thread[tid].lqFull() || thread[tid].sqFull();
483}
484
485template<class Impl>
486bool
487LSQ<Impl>::isEmpty() const
488{
489 return lqEmpty() && sqEmpty();
490}
491
492template<class Impl>
493bool
494LSQ<Impl>::lqEmpty() const
495{
496 list<ThreadID>::const_iterator threads = activeThreads->begin();
497 list<ThreadID>::const_iterator end = activeThreads->end();
498
499 while (threads != end) {
500 ThreadID tid = *threads++;
501
502 if (!thread[tid].lqEmpty())
503 return false;
504 }
505
506 return true;
507}
508
509template<class Impl>
510bool
511LSQ<Impl>::sqEmpty() const
512{
513 list<ThreadID>::const_iterator threads = activeThreads->begin();
514 list<ThreadID>::const_iterator end = activeThreads->end();
515
516 while (threads != end) {
517 ThreadID tid = *threads++;
518
519 if (!thread[tid].sqEmpty())
520 return false;
521 }
522
523 return true;
524}
525
526template<class Impl>
527bool
528LSQ<Impl>::lqFull()
529{
530 list<ThreadID>::iterator threads = activeThreads->begin();
531 list<ThreadID>::iterator end = activeThreads->end();
532
533 while (threads != end) {
534 ThreadID tid = *threads++;
535
536 if (!thread[tid].lqFull())
537 return false;
538 }
539
540 return true;
541}
542
543template<class Impl>
544bool
545LSQ<Impl>::lqFull(ThreadID tid)
546{
547 //@todo: Change to Calculate All Entries for
548 //Dynamic Policy
549 if (lsqPolicy == Dynamic)
550 return lqFull();
551 else
552 return thread[tid].lqFull();
553}
554
555template<class Impl>
556bool
557LSQ<Impl>::sqFull()
558{
559 list<ThreadID>::iterator threads = activeThreads->begin();
560 list<ThreadID>::iterator end = activeThreads->end();
561
562 while (threads != end) {
563 ThreadID tid = *threads++;
564
565 if (!sqFull(tid))
566 return false;
567 }
568
569 return true;
570}
571
572template<class Impl>
573bool
574LSQ<Impl>::sqFull(ThreadID tid)
575{
576 //@todo: Change to Calculate All Entries for
577 //Dynamic Policy
578 if (lsqPolicy == Dynamic)
579 return sqFull();
580 else
581 return thread[tid].sqFull();
582}
583
584template<class Impl>
585bool
586LSQ<Impl>::isStalled()
587{
588 list<ThreadID>::iterator threads = activeThreads->begin();
589 list<ThreadID>::iterator end = activeThreads->end();
590
591 while (threads != end) {
592 ThreadID tid = *threads++;
593
594 if (!thread[tid].isStalled())
595 return false;
596 }
597
598 return true;
599}
600
601template<class Impl>
602bool
603LSQ<Impl>::isStalled(ThreadID tid)
604{
605 if (lsqPolicy == Dynamic)
606 return isStalled();
607 else
608 return thread[tid].isStalled();
609}
610
611template<class Impl>
612bool
613LSQ<Impl>::hasStoresToWB()
614{
615 list<ThreadID>::iterator threads = activeThreads->begin();
616 list<ThreadID>::iterator end = activeThreads->end();
617
618 while (threads != end) {
619 ThreadID tid = *threads++;
620
621 if (hasStoresToWB(tid))
622 return true;
623 }
624
625 return false;
626}
627
628template<class Impl>
629bool
630LSQ<Impl>::willWB()
631{
632 list<ThreadID>::iterator threads = activeThreads->begin();
633 list<ThreadID>::iterator end = activeThreads->end();
634
635 while (threads != end) {
636 ThreadID tid = *threads++;
637
638 if (willWB(tid))
639 return true;
640 }
641
642 return false;
643}
644
645template<class Impl>
646void
647LSQ<Impl>::dumpInsts() const
648{
649 list<ThreadID>::const_iterator threads = activeThreads->begin();
650 list<ThreadID>::const_iterator end = activeThreads->end();
651
652 while (threads != end) {
653 ThreadID tid = *threads++;
654
655 thread[tid].dumpInsts();
656 }
657}
115 for (ThreadID tid = 0; tid < numThreads; tid++) {
116 thread[tid].init(cpu, iew_ptr, params, this,
117 maxLQEntries, maxSQEntries, tid);
118 thread[tid].setDcachePort(&cpu_ptr->getDataPort());
119 }
120}
121
122
123template<class Impl>
124std::string
125LSQ<Impl>::name() const
126{
127 return iewStage->name() + ".lsq";
128}
129
130template<class Impl>
131void
132LSQ<Impl>::regStats()
133{
134 //Initialize LSQs
135 for (ThreadID tid = 0; tid < numThreads; tid++) {
136 thread[tid].regStats();
137 }
138}
139
140template<class Impl>
141void
142LSQ<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
143{
144 activeThreads = at_ptr;
145 assert(activeThreads != 0);
146}
147
148template <class Impl>
149void
150LSQ<Impl>::drainSanityCheck() const
151{
152 assert(isDrained());
153
154 for (ThreadID tid = 0; tid < numThreads; tid++)
155 thread[tid].drainSanityCheck();
156}
157
158template <class Impl>
159bool
160LSQ<Impl>::isDrained() const
161{
162 bool drained(true);
163
164 if (!lqEmpty()) {
165 DPRINTF(Drain, "Not drained, LQ not empty.\n");
166 drained = false;
167 }
168
169 if (!sqEmpty()) {
170 DPRINTF(Drain, "Not drained, SQ not empty.\n");
171 drained = false;
172 }
173
174 if (retryTid != InvalidThreadID) {
175 DPRINTF(Drain, "Not drained, the LSQ has blocked the caches.\n");
176 drained = false;
177 }
178
179 return drained;
180}
181
182template <class Impl>
183void
184LSQ<Impl>::takeOverFrom()
185{
186 for (ThreadID tid = 0; tid < numThreads; tid++) {
187 thread[tid].takeOverFrom();
188 }
189}
190
191template <class Impl>
192int
193LSQ<Impl>::entryAmount(ThreadID num_threads)
194{
195 if (lsqPolicy == Partitioned) {
196 return LQEntries / num_threads;
197 } else {
198 return 0;
199 }
200}
201
202template <class Impl>
203void
204LSQ<Impl>::resetEntries()
205{
206 if (lsqPolicy != Dynamic || numThreads > 1) {
207 int active_threads = activeThreads->size();
208
209 int maxEntries;
210
211 if (lsqPolicy == Partitioned) {
212 maxEntries = LQEntries / active_threads;
213 } else if (lsqPolicy == Threshold && active_threads == 1) {
214 maxEntries = LQEntries;
215 } else {
216 maxEntries = LQEntries;
217 }
218
219 list<ThreadID>::iterator threads = activeThreads->begin();
220 list<ThreadID>::iterator end = activeThreads->end();
221
222 while (threads != end) {
223 ThreadID tid = *threads++;
224
225 resizeEntries(maxEntries, tid);
226 }
227 }
228}
229
230template<class Impl>
231void
232LSQ<Impl>::removeEntries(ThreadID tid)
233{
234 thread[tid].clearLQ();
235 thread[tid].clearSQ();
236}
237
238template<class Impl>
239void
240LSQ<Impl>::resizeEntries(unsigned size, ThreadID tid)
241{
242 thread[tid].resizeLQ(size);
243 thread[tid].resizeSQ(size);
244}
245
246template<class Impl>
247void
248LSQ<Impl>::tick()
249{
250 list<ThreadID>::iterator threads = activeThreads->begin();
251 list<ThreadID>::iterator end = activeThreads->end();
252
253 while (threads != end) {
254 ThreadID tid = *threads++;
255
256 thread[tid].tick();
257 }
258}
259
260template<class Impl>
261void
262LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
263{
264 ThreadID tid = load_inst->threadNumber;
265
266 thread[tid].insertLoad(load_inst);
267}
268
269template<class Impl>
270void
271LSQ<Impl>::insertStore(DynInstPtr &store_inst)
272{
273 ThreadID tid = store_inst->threadNumber;
274
275 thread[tid].insertStore(store_inst);
276}
277
278template<class Impl>
279Fault
280LSQ<Impl>::executeLoad(DynInstPtr &inst)
281{
282 ThreadID tid = inst->threadNumber;
283
284 return thread[tid].executeLoad(inst);
285}
286
287template<class Impl>
288Fault
289LSQ<Impl>::executeStore(DynInstPtr &inst)
290{
291 ThreadID tid = inst->threadNumber;
292
293 return thread[tid].executeStore(inst);
294}
295
296template<class Impl>
297void
298LSQ<Impl>::writebackStores()
299{
300 list<ThreadID>::iterator threads = activeThreads->begin();
301 list<ThreadID>::iterator end = activeThreads->end();
302
303 while (threads != end) {
304 ThreadID tid = *threads++;
305
306 if (numStoresToWB(tid) > 0) {
307 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
308 "available for Writeback.\n", tid, numStoresToWB(tid));
309 }
310
311 thread[tid].writebackStores();
312 }
313}
314
315template<class Impl>
316bool
317LSQ<Impl>::violation()
318{
319 /* Answers: Does Anybody Have a Violation?*/
320 list<ThreadID>::iterator threads = activeThreads->begin();
321 list<ThreadID>::iterator end = activeThreads->end();
322
323 while (threads != end) {
324 ThreadID tid = *threads++;
325
326 if (thread[tid].violation())
327 return true;
328 }
329
330 return false;
331}
332
333template <class Impl>
334void
335LSQ<Impl>::recvRetry()
336{
337 if (retryTid == InvalidThreadID)
338 {
339 //Squashed, so drop it
340 return;
341 }
342 int curr_retry_tid = retryTid;
343 // Speculatively clear the retry Tid. This will get set again if
344 // the LSQUnit was unable to complete its access.
345 retryTid = -1;
346 thread[curr_retry_tid].recvRetry();
347}
348
349template <class Impl>
350bool
351LSQ<Impl>::recvTimingResp(PacketPtr pkt)
352{
353 if (pkt->isError())
354 DPRINTF(LSQ, "Got error packet back for address: %#X\n",
355 pkt->getAddr());
356 thread[pkt->req->threadId()].completeDataAccess(pkt);
357 return true;
358}
359
360template <class Impl>
361void
362LSQ<Impl>::recvTimingSnoopReq(PacketPtr pkt)
363{
364 DPRINTF(LSQ, "received pkt for addr:%#x %s\n", pkt->getAddr(),
365 pkt->cmdString());
366
367 // must be a snoop
368 if (pkt->isInvalidate()) {
369 DPRINTF(LSQ, "received invalidation for addr:%#x\n",
370 pkt->getAddr());
371 for (ThreadID tid = 0; tid < numThreads; tid++) {
372 thread[tid].checkSnoop(pkt);
373 }
374 }
375}
376
377template<class Impl>
378int
379LSQ<Impl>::getCount()
380{
381 unsigned total = 0;
382
383 list<ThreadID>::iterator threads = activeThreads->begin();
384 list<ThreadID>::iterator end = activeThreads->end();
385
386 while (threads != end) {
387 ThreadID tid = *threads++;
388
389 total += getCount(tid);
390 }
391
392 return total;
393}
394
395template<class Impl>
396int
397LSQ<Impl>::numLoads()
398{
399 unsigned total = 0;
400
401 list<ThreadID>::iterator threads = activeThreads->begin();
402 list<ThreadID>::iterator end = activeThreads->end();
403
404 while (threads != end) {
405 ThreadID tid = *threads++;
406
407 total += numLoads(tid);
408 }
409
410 return total;
411}
412
413template<class Impl>
414int
415LSQ<Impl>::numStores()
416{
417 unsigned total = 0;
418
419 list<ThreadID>::iterator threads = activeThreads->begin();
420 list<ThreadID>::iterator end = activeThreads->end();
421
422 while (threads != end) {
423 ThreadID tid = *threads++;
424
425 total += thread[tid].numStores();
426 }
427
428 return total;
429}
430
431template<class Impl>
432unsigned
433LSQ<Impl>::numFreeEntries()
434{
435 unsigned total = 0;
436
437 list<ThreadID>::iterator threads = activeThreads->begin();
438 list<ThreadID>::iterator end = activeThreads->end();
439
440 while (threads != end) {
441 ThreadID tid = *threads++;
442
443 total += thread[tid].numFreeEntries();
444 }
445
446 return total;
447}
448
449template<class Impl>
450unsigned
451LSQ<Impl>::numFreeEntries(ThreadID tid)
452{
453 //if (lsqPolicy == Dynamic)
454 //return numFreeEntries();
455 //else
456 return thread[tid].numFreeEntries();
457}
458
459template<class Impl>
460bool
461LSQ<Impl>::isFull()
462{
463 list<ThreadID>::iterator threads = activeThreads->begin();
464 list<ThreadID>::iterator end = activeThreads->end();
465
466 while (threads != end) {
467 ThreadID tid = *threads++;
468
469 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
470 return false;
471 }
472
473 return true;
474}
475
476template<class Impl>
477bool
478LSQ<Impl>::isFull(ThreadID tid)
479{
480 //@todo: Change to Calculate All Entries for
481 //Dynamic Policy
482 if (lsqPolicy == Dynamic)
483 return isFull();
484 else
485 return thread[tid].lqFull() || thread[tid].sqFull();
486}
487
488template<class Impl>
489bool
490LSQ<Impl>::isEmpty() const
491{
492 return lqEmpty() && sqEmpty();
493}
494
495template<class Impl>
496bool
497LSQ<Impl>::lqEmpty() const
498{
499 list<ThreadID>::const_iterator threads = activeThreads->begin();
500 list<ThreadID>::const_iterator end = activeThreads->end();
501
502 while (threads != end) {
503 ThreadID tid = *threads++;
504
505 if (!thread[tid].lqEmpty())
506 return false;
507 }
508
509 return true;
510}
511
512template<class Impl>
513bool
514LSQ<Impl>::sqEmpty() const
515{
516 list<ThreadID>::const_iterator threads = activeThreads->begin();
517 list<ThreadID>::const_iterator end = activeThreads->end();
518
519 while (threads != end) {
520 ThreadID tid = *threads++;
521
522 if (!thread[tid].sqEmpty())
523 return false;
524 }
525
526 return true;
527}
528
529template<class Impl>
530bool
531LSQ<Impl>::lqFull()
532{
533 list<ThreadID>::iterator threads = activeThreads->begin();
534 list<ThreadID>::iterator end = activeThreads->end();
535
536 while (threads != end) {
537 ThreadID tid = *threads++;
538
539 if (!thread[tid].lqFull())
540 return false;
541 }
542
543 return true;
544}
545
546template<class Impl>
547bool
548LSQ<Impl>::lqFull(ThreadID tid)
549{
550 //@todo: Change to Calculate All Entries for
551 //Dynamic Policy
552 if (lsqPolicy == Dynamic)
553 return lqFull();
554 else
555 return thread[tid].lqFull();
556}
557
558template<class Impl>
559bool
560LSQ<Impl>::sqFull()
561{
562 list<ThreadID>::iterator threads = activeThreads->begin();
563 list<ThreadID>::iterator end = activeThreads->end();
564
565 while (threads != end) {
566 ThreadID tid = *threads++;
567
568 if (!sqFull(tid))
569 return false;
570 }
571
572 return true;
573}
574
575template<class Impl>
576bool
577LSQ<Impl>::sqFull(ThreadID tid)
578{
579 //@todo: Change to Calculate All Entries for
580 //Dynamic Policy
581 if (lsqPolicy == Dynamic)
582 return sqFull();
583 else
584 return thread[tid].sqFull();
585}
586
587template<class Impl>
588bool
589LSQ<Impl>::isStalled()
590{
591 list<ThreadID>::iterator threads = activeThreads->begin();
592 list<ThreadID>::iterator end = activeThreads->end();
593
594 while (threads != end) {
595 ThreadID tid = *threads++;
596
597 if (!thread[tid].isStalled())
598 return false;
599 }
600
601 return true;
602}
603
604template<class Impl>
605bool
606LSQ<Impl>::isStalled(ThreadID tid)
607{
608 if (lsqPolicy == Dynamic)
609 return isStalled();
610 else
611 return thread[tid].isStalled();
612}
613
614template<class Impl>
615bool
616LSQ<Impl>::hasStoresToWB()
617{
618 list<ThreadID>::iterator threads = activeThreads->begin();
619 list<ThreadID>::iterator end = activeThreads->end();
620
621 while (threads != end) {
622 ThreadID tid = *threads++;
623
624 if (hasStoresToWB(tid))
625 return true;
626 }
627
628 return false;
629}
630
631template<class Impl>
632bool
633LSQ<Impl>::willWB()
634{
635 list<ThreadID>::iterator threads = activeThreads->begin();
636 list<ThreadID>::iterator end = activeThreads->end();
637
638 while (threads != end) {
639 ThreadID tid = *threads++;
640
641 if (willWB(tid))
642 return true;
643 }
644
645 return false;
646}
647
648template<class Impl>
649void
650LSQ<Impl>::dumpInsts() const
651{
652 list<ThreadID>::const_iterator threads = activeThreads->begin();
653 list<ThreadID>::const_iterator end = activeThreads->end();
654
655 while (threads != end) {
656 ThreadID tid = *threads++;
657
658 thread[tid].dumpInsts();
659 }
660}