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"
39 LSQ<Impl>::DcachePort::setPeer(Port *port)
44 // Update the ThreadContext's memory ports (Functional/Virtual
46 lsq->updateMemPorts();
52 LSQ<Impl>::DcachePort::recvAtomic(PacketPtr pkt)
54 panic("O3CPU model does not work with atomic mode!");
60 LSQ<Impl>::DcachePort::recvFunctional(PacketPtr pkt)
62 DPRINTF(LSQ, "LSQ doesn't update things on a recvFunctional.");
67 LSQ<Impl>::DcachePort::recvStatusChange(Status status)
69 if (status == RangeChange) {
70 if (!snoopRangeSent) {
71 snoopRangeSent = true;
72 sendStatusChange(Port::RangeChange);
76 panic("O3CPU doesn't expect recvStatusChange callback!");
81 LSQ<Impl>::DcachePort::recvTiming(PacketPtr pkt)
83 if (pkt->isResponse()) {
84 lsq->thread[pkt->req->getThreadNum()].completeDataAccess(pkt);
89 // @TODO someday may need to process invalidations in LSQ here
90 // to provide stronger consistency model
97 LSQ<Impl>::DcachePort::recvRetry()
99 if (lsq->retryTid == -1)
101 //Squashed, so drop it
104 int curr_retry_tid = lsq->retryTid;
105 // Speculatively clear the retry Tid. This will get set again if
106 // the LSQUnit was unable to complete its access.
108 lsq->thread[curr_retry_tid].recvRetry();
111 template <class Impl>
112 LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, Params *params)
113 : cpu(cpu_ptr), iewStage(iew_ptr), dcachePort(this),
114 LQEntries(params->LQEntries),
115 SQEntries(params->SQEntries),
116 numThreads(params->numberOfThreads),
119 dcachePort.snoopRangeSent = false;
121 //**********************************************/
122 //************ Handle SMT Parameters ***********/
123 //**********************************************/
124 std::string policy = params->smtLSQPolicy;
126 //Convert string to lowercase
127 std::transform(policy.begin(), policy.end(), policy.begin(),
128 (int(*)(int)) tolower);
130 //Figure out fetch policy
131 if (policy == "dynamic") {
134 maxLQEntries = LQEntries;
135 maxSQEntries = SQEntries;
137 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
138 } else if (policy == "partitioned") {
139 lsqPolicy = Partitioned;
141 //@todo:make work if part_amt doesnt divide evenly.
142 maxLQEntries = LQEntries / numThreads;
143 maxSQEntries = SQEntries / numThreads;
145 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
146 "%i entries per LQ | %i entries per SQ",
147 maxLQEntries,maxSQEntries);
148 } else if (policy == "threshold") {
149 lsqPolicy = Threshold;
151 assert(params->smtLSQThreshold > LQEntries);
152 assert(params->smtLSQThreshold > SQEntries);
154 //Divide up by threshold amount
155 //@todo: Should threads check the max and the total
157 maxLQEntries = params->smtLSQThreshold;
158 maxSQEntries = params->smtLSQThreshold;
160 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
161 "%i entries per LQ | %i entries per SQ",
162 maxLQEntries,maxSQEntries);
164 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
165 "Partitioned, Threshold}");
169 for (int tid=0; tid < numThreads; tid++) {
170 thread[tid].init(cpu, iew_ptr, params, this,
171 maxLQEntries, maxSQEntries, tid);
172 thread[tid].setDcachePort(&dcachePort);
179 LSQ<Impl>::name() const
181 return iewStage->name() + ".lsq";
186 LSQ<Impl>::regStats()
189 for (int tid=0; tid < numThreads; tid++) {
190 thread[tid].regStats();
196 LSQ<Impl>::setActiveThreads(std::list<unsigned> *at_ptr)
198 activeThreads = at_ptr;
199 assert(activeThreads != 0);
202 template <class Impl>
204 LSQ<Impl>::switchOut()
206 for (int tid = 0; tid < numThreads; tid++) {
207 thread[tid].switchOut();
211 template <class Impl>
213 LSQ<Impl>::takeOverFrom()
215 for (int tid = 0; tid < numThreads; tid++) {
216 thread[tid].takeOverFrom();
220 template <class Impl>
222 LSQ<Impl>::entryAmount(int num_threads)
224 if (lsqPolicy == Partitioned) {
225 return LQEntries / num_threads;
231 template <class Impl>
233 LSQ<Impl>::resetEntries()
235 if (lsqPolicy != Dynamic || numThreads > 1) {
236 int active_threads = activeThreads->size();
240 if (lsqPolicy == Partitioned) {
241 maxEntries = LQEntries / active_threads;
242 } else if (lsqPolicy == Threshold && active_threads == 1) {
243 maxEntries = LQEntries;
245 maxEntries = LQEntries;
248 std::list<unsigned>::iterator threads = activeThreads->begin();
249 std::list<unsigned>::iterator end = activeThreads->end();
251 while (threads != end) {
252 unsigned tid = *threads++;
254 resizeEntries(maxEntries, tid);
261 LSQ<Impl>::removeEntries(unsigned tid)
263 thread[tid].clearLQ();
264 thread[tid].clearSQ();
269 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
271 thread[tid].resizeLQ(size);
272 thread[tid].resizeSQ(size);
279 std::list<unsigned>::iterator threads = activeThreads->begin();
280 std::list<unsigned>::iterator end = activeThreads->end();
282 while (threads != end) {
283 unsigned tid = *threads++;
291 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
293 unsigned tid = load_inst->threadNumber;
295 thread[tid].insertLoad(load_inst);
300 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
302 unsigned tid = store_inst->threadNumber;
304 thread[tid].insertStore(store_inst);
309 LSQ<Impl>::executeLoad(DynInstPtr &inst)
311 unsigned tid = inst->threadNumber;
313 return thread[tid].executeLoad(inst);
318 LSQ<Impl>::executeStore(DynInstPtr &inst)
320 unsigned tid = inst->threadNumber;
322 return thread[tid].executeStore(inst);
327 LSQ<Impl>::writebackStores()
329 std::list<unsigned>::iterator threads = activeThreads->begin();
330 std::list<unsigned>::iterator end = activeThreads->end();
332 while (threads != end) {
333 unsigned tid = *threads++;
335 if (numStoresToWB(tid) > 0) {
336 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
337 "available for Writeback.\n", tid, numStoresToWB(tid));
340 thread[tid].writebackStores();
346 LSQ<Impl>::violation()
348 /* Answers: Does Anybody Have a Violation?*/
349 std::list<unsigned>::iterator threads = activeThreads->begin();
350 std::list<unsigned>::iterator end = activeThreads->end();
352 while (threads != end) {
353 unsigned tid = *threads++;
355 if (thread[tid].violation())
364 LSQ<Impl>::getCount()
368 std::list<unsigned>::iterator threads = activeThreads->begin();
369 std::list<unsigned>::iterator end = activeThreads->end();
371 while (threads != end) {
372 unsigned tid = *threads++;
374 total += getCount(tid);
382 LSQ<Impl>::numLoads()
386 std::list<unsigned>::iterator threads = activeThreads->begin();
387 std::list<unsigned>::iterator end = activeThreads->end();
389 while (threads != end) {
390 unsigned tid = *threads++;
392 total += numLoads(tid);
400 LSQ<Impl>::numStores()
404 std::list<unsigned>::iterator threads = activeThreads->begin();
405 std::list<unsigned>::iterator end = activeThreads->end();
407 while (threads != end) {
408 unsigned tid = *threads++;
410 total += thread[tid].numStores();
418 LSQ<Impl>::numLoadsReady()
422 std::list<unsigned>::iterator threads = activeThreads->begin();
423 std::list<unsigned>::iterator end = activeThreads->end();
425 while (threads != end) {
426 unsigned tid = *threads++;
428 total += thread[tid].numLoadsReady();
436 LSQ<Impl>::numFreeEntries()
440 std::list<unsigned>::iterator threads = activeThreads->begin();
441 std::list<unsigned>::iterator end = activeThreads->end();
443 while (threads != end) {
444 unsigned tid = *threads++;
446 total += thread[tid].numFreeEntries();
454 LSQ<Impl>::numFreeEntries(unsigned tid)
456 //if (lsqPolicy == Dynamic)
457 //return numFreeEntries();
459 return thread[tid].numFreeEntries();
466 std::list<unsigned>::iterator threads = activeThreads->begin();
467 std::list<unsigned>::iterator end = activeThreads->end();
469 while (threads != end) {
470 unsigned tid = *threads++;
472 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
481 LSQ<Impl>::isFull(unsigned tid)
483 //@todo: Change to Calculate All Entries for
485 if (lsqPolicy == Dynamic)
488 return thread[tid].lqFull() || thread[tid].sqFull();
495 std::list<unsigned>::iterator threads = activeThreads->begin();
496 std::list<unsigned>::iterator end = activeThreads->end();
498 while (threads != end) {
499 unsigned tid = *threads++;
501 if (!thread[tid].lqFull())
510 LSQ<Impl>::lqFull(unsigned tid)
512 //@todo: Change to Calculate All Entries for
514 if (lsqPolicy == Dynamic)
517 return thread[tid].lqFull();
524 std::list<unsigned>::iterator threads = activeThreads->begin();
525 std::list<unsigned>::iterator end = activeThreads->end();
527 while (threads != end) {
528 unsigned tid = *threads++;
539 LSQ<Impl>::sqFull(unsigned tid)
541 //@todo: Change to Calculate All Entries for
543 if (lsqPolicy == Dynamic)
546 return thread[tid].sqFull();
551 LSQ<Impl>::isStalled()
553 std::list<unsigned>::iterator threads = activeThreads->begin();
554 std::list<unsigned>::iterator end = activeThreads->end();
556 while (threads != end) {
557 unsigned tid = *threads++;
559 if (!thread[tid].isStalled())
568 LSQ<Impl>::isStalled(unsigned tid)
570 if (lsqPolicy == Dynamic)
573 return thread[tid].isStalled();
578 LSQ<Impl>::hasStoresToWB()
580 std::list<unsigned>::iterator threads = activeThreads->begin();
581 std::list<unsigned>::iterator end = activeThreads->end();
586 while (threads != end) {
587 unsigned tid = *threads++;
589 if (!hasStoresToWB(tid))
600 std::list<unsigned>::iterator threads = activeThreads->begin();
601 std::list<unsigned>::iterator end = activeThreads->end();
603 while (threads != end) {
604 unsigned tid = *threads++;
615 LSQ<Impl>::dumpInsts()
617 std::list<unsigned>::iterator threads = activeThreads->begin();
618 std::list<unsigned>::iterator end = activeThreads->end();
620 while (threads != end) {
621 unsigned tid = *threads++;
623 thread[tid].dumpInsts();