2 * Copyright (c) 2005-2006 The Regents of The University of Michigan
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.
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.
28 * Authors: Korey Sewell
35 #include "cpu/o3/lsq.hh"
36 #include "debug/Fetch.hh"
37 #include "debug/LSQ.hh"
38 #include "debug/Writeback.hh"
39 #include "params/DerivO3CPU.hh"
45 LSQ<Impl>::DcachePort::setPeer(Port *port)
49 // Update the ThreadContext's memory ports (Functional/Virtual
51 lsq->updateMemPorts();
56 LSQ<Impl>::DcachePort::recvAtomic(PacketPtr pkt)
58 panic("O3CPU model does not work with atomic mode!");
64 LSQ<Impl>::DcachePort::recvFunctional(PacketPtr pkt)
66 DPRINTF(LSQ, "LSQ doesn't update things on a recvFunctional.\n");
71 LSQ<Impl>::DcachePort::recvStatusChange(Status status)
73 if (status == RangeChange) {
74 if (!snoopRangeSent) {
75 snoopRangeSent = true;
76 sendStatusChange(Port::RangeChange);
80 panic("O3CPU doesn't expect recvStatusChange callback!");
85 LSQ<Impl>::DcachePort::recvTiming(PacketPtr pkt)
88 DPRINTF(LSQ, "Got error packet back for address: %#X\n", pkt->getAddr());
89 if (pkt->isResponse()) {
90 lsq->thread[pkt->req->threadId()].completeDataAccess(pkt);
92 DPRINTF(LSQ, "received pkt for addr:%#x %s\n", pkt->getAddr(),
96 if (pkt->isInvalidate()) {
97 DPRINTF(LSQ, "received invalidation for addr:%#x\n", pkt->getAddr());
98 for (ThreadID tid = 0; tid < lsq->numThreads; tid++) {
99 lsq->thread[tid].checkSnoop(pkt);
102 // to provide stronger consistency model
107 template <class Impl>
109 LSQ<Impl>::DcachePort::recvRetry()
111 if (lsq->retryTid == -1)
113 //Squashed, so drop it
116 int curr_retry_tid = lsq->retryTid;
117 // Speculatively clear the retry Tid. This will get set again if
118 // the LSQUnit was unable to complete its access.
120 lsq->thread[curr_retry_tid].recvRetry();
123 template <class Impl>
124 LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
125 : cpu(cpu_ptr), iewStage(iew_ptr), dcachePort(this),
126 LQEntries(params->LQEntries),
127 SQEntries(params->SQEntries),
128 numThreads(params->numThreads),
131 dcachePort.snoopRangeSent = false;
133 //**********************************************/
134 //************ Handle SMT Parameters ***********/
135 //**********************************************/
136 std::string policy = params->smtLSQPolicy;
138 //Convert string to lowercase
139 std::transform(policy.begin(), policy.end(), policy.begin(),
140 (int(*)(int)) tolower);
142 //Figure out fetch policy
143 if (policy == "dynamic") {
146 maxLQEntries = LQEntries;
147 maxSQEntries = SQEntries;
149 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
150 } else if (policy == "partitioned") {
151 lsqPolicy = Partitioned;
153 //@todo:make work if part_amt doesnt divide evenly.
154 maxLQEntries = LQEntries / numThreads;
155 maxSQEntries = SQEntries / numThreads;
157 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
158 "%i entries per LQ | %i entries per SQ\n",
159 maxLQEntries,maxSQEntries);
160 } else if (policy == "threshold") {
161 lsqPolicy = Threshold;
163 assert(params->smtLSQThreshold > LQEntries);
164 assert(params->smtLSQThreshold > SQEntries);
166 //Divide up by threshold amount
167 //@todo: Should threads check the max and the total
169 maxLQEntries = params->smtLSQThreshold;
170 maxSQEntries = params->smtLSQThreshold;
172 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
173 "%i entries per LQ | %i entries per SQ\n",
174 maxLQEntries,maxSQEntries);
176 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
177 "Partitioned, Threshold}");
181 for (ThreadID tid = 0; tid < numThreads; tid++) {
182 thread[tid].init(cpu, iew_ptr, params, this,
183 maxLQEntries, maxSQEntries, tid);
184 thread[tid].setDcachePort(&dcachePort);
191 LSQ<Impl>::name() const
193 return iewStage->name() + ".lsq";
198 LSQ<Impl>::regStats()
201 for (ThreadID tid = 0; tid < numThreads; tid++) {
202 thread[tid].regStats();
208 LSQ<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
210 activeThreads = at_ptr;
211 assert(activeThreads != 0);
214 template <class Impl>
216 LSQ<Impl>::switchOut()
218 for (ThreadID tid = 0; tid < numThreads; tid++) {
219 thread[tid].switchOut();
223 template <class Impl>
225 LSQ<Impl>::takeOverFrom()
227 for (ThreadID tid = 0; tid < numThreads; tid++) {
228 thread[tid].takeOverFrom();
232 template <class Impl>
234 LSQ<Impl>::entryAmount(ThreadID num_threads)
236 if (lsqPolicy == Partitioned) {
237 return LQEntries / num_threads;
243 template <class Impl>
245 LSQ<Impl>::resetEntries()
247 if (lsqPolicy != Dynamic || numThreads > 1) {
248 int active_threads = activeThreads->size();
252 if (lsqPolicy == Partitioned) {
253 maxEntries = LQEntries / active_threads;
254 } else if (lsqPolicy == Threshold && active_threads == 1) {
255 maxEntries = LQEntries;
257 maxEntries = LQEntries;
260 list<ThreadID>::iterator threads = activeThreads->begin();
261 list<ThreadID>::iterator end = activeThreads->end();
263 while (threads != end) {
264 ThreadID tid = *threads++;
266 resizeEntries(maxEntries, tid);
273 LSQ<Impl>::removeEntries(ThreadID tid)
275 thread[tid].clearLQ();
276 thread[tid].clearSQ();
281 LSQ<Impl>::resizeEntries(unsigned size, ThreadID tid)
283 thread[tid].resizeLQ(size);
284 thread[tid].resizeSQ(size);
291 list<ThreadID>::iterator threads = activeThreads->begin();
292 list<ThreadID>::iterator end = activeThreads->end();
294 while (threads != end) {
295 ThreadID tid = *threads++;
303 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
305 ThreadID tid = load_inst->threadNumber;
307 thread[tid].insertLoad(load_inst);
312 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
314 ThreadID tid = store_inst->threadNumber;
316 thread[tid].insertStore(store_inst);
321 LSQ<Impl>::executeLoad(DynInstPtr &inst)
323 ThreadID tid = inst->threadNumber;
325 return thread[tid].executeLoad(inst);
330 LSQ<Impl>::executeStore(DynInstPtr &inst)
332 ThreadID tid = inst->threadNumber;
334 return thread[tid].executeStore(inst);
339 LSQ<Impl>::writebackStores()
341 list<ThreadID>::iterator threads = activeThreads->begin();
342 list<ThreadID>::iterator end = activeThreads->end();
344 while (threads != end) {
345 ThreadID tid = *threads++;
347 if (numStoresToWB(tid) > 0) {
348 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
349 "available for Writeback.\n", tid, numStoresToWB(tid));
352 thread[tid].writebackStores();
358 LSQ<Impl>::violation()
360 /* Answers: Does Anybody Have a Violation?*/
361 list<ThreadID>::iterator threads = activeThreads->begin();
362 list<ThreadID>::iterator end = activeThreads->end();
364 while (threads != end) {
365 ThreadID tid = *threads++;
367 if (thread[tid].violation())
376 LSQ<Impl>::getCount()
380 list<ThreadID>::iterator threads = activeThreads->begin();
381 list<ThreadID>::iterator end = activeThreads->end();
383 while (threads != end) {
384 ThreadID tid = *threads++;
386 total += getCount(tid);
394 LSQ<Impl>::numLoads()
398 list<ThreadID>::iterator threads = activeThreads->begin();
399 list<ThreadID>::iterator end = activeThreads->end();
401 while (threads != end) {
402 ThreadID tid = *threads++;
404 total += numLoads(tid);
412 LSQ<Impl>::numStores()
416 list<ThreadID>::iterator threads = activeThreads->begin();
417 list<ThreadID>::iterator end = activeThreads->end();
419 while (threads != end) {
420 ThreadID tid = *threads++;
422 total += thread[tid].numStores();
430 LSQ<Impl>::numLoadsReady()
434 list<ThreadID>::iterator threads = activeThreads->begin();
435 list<ThreadID>::iterator end = activeThreads->end();
437 while (threads != end) {
438 ThreadID tid = *threads++;
440 total += thread[tid].numLoadsReady();
448 LSQ<Impl>::numFreeEntries()
452 list<ThreadID>::iterator threads = activeThreads->begin();
453 list<ThreadID>::iterator end = activeThreads->end();
455 while (threads != end) {
456 ThreadID tid = *threads++;
458 total += thread[tid].numFreeEntries();
466 LSQ<Impl>::numFreeEntries(ThreadID tid)
468 //if (lsqPolicy == Dynamic)
469 //return numFreeEntries();
471 return thread[tid].numFreeEntries();
478 list<ThreadID>::iterator threads = activeThreads->begin();
479 list<ThreadID>::iterator end = activeThreads->end();
481 while (threads != end) {
482 ThreadID tid = *threads++;
484 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
493 LSQ<Impl>::isFull(ThreadID tid)
495 //@todo: Change to Calculate All Entries for
497 if (lsqPolicy == Dynamic)
500 return thread[tid].lqFull() || thread[tid].sqFull();
507 list<ThreadID>::iterator threads = activeThreads->begin();
508 list<ThreadID>::iterator end = activeThreads->end();
510 while (threads != end) {
511 ThreadID tid = *threads++;
513 if (!thread[tid].lqFull())
522 LSQ<Impl>::lqFull(ThreadID tid)
524 //@todo: Change to Calculate All Entries for
526 if (lsqPolicy == Dynamic)
529 return thread[tid].lqFull();
536 list<ThreadID>::iterator threads = activeThreads->begin();
537 list<ThreadID>::iterator end = activeThreads->end();
539 while (threads != end) {
540 ThreadID tid = *threads++;
551 LSQ<Impl>::sqFull(ThreadID tid)
553 //@todo: Change to Calculate All Entries for
555 if (lsqPolicy == Dynamic)
558 return thread[tid].sqFull();
563 LSQ<Impl>::isStalled()
565 list<ThreadID>::iterator threads = activeThreads->begin();
566 list<ThreadID>::iterator end = activeThreads->end();
568 while (threads != end) {
569 ThreadID tid = *threads++;
571 if (!thread[tid].isStalled())
580 LSQ<Impl>::isStalled(ThreadID tid)
582 if (lsqPolicy == Dynamic)
585 return thread[tid].isStalled();
590 LSQ<Impl>::hasStoresToWB()
592 list<ThreadID>::iterator threads = activeThreads->begin();
593 list<ThreadID>::iterator end = activeThreads->end();
595 while (threads != end) {
596 ThreadID tid = *threads++;
598 if (hasStoresToWB(tid))
609 list<ThreadID>::iterator threads = activeThreads->begin();
610 list<ThreadID>::iterator end = activeThreads->end();
612 while (threads != end) {
613 ThreadID tid = *threads++;
624 LSQ<Impl>::dumpInsts()
626 list<ThreadID>::iterator threads = activeThreads->begin();
627 list<ThreadID>::iterator end = activeThreads->end();
629 while (threads != end) {
630 ThreadID tid = *threads++;
632 thread[tid].dumpInsts();