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);
87 //else it is a coherence request, maybe you need to do something
88 warn("Recieved a coherence request (Invalidate?), 03CPU doesn't"
89 "update LSQ for these\n");
96 LSQ<Impl>::DcachePort::recvRetry()
98 if (lsq->retryTid == -1)
100 //Squashed, so drop it
103 lsq->thread[lsq->retryTid].recvRetry();
104 // Speculatively clear the retry Tid. This will get set again if
105 // the LSQUnit was unable to complete its access.
109 template <class Impl>
110 LSQ<Impl>::LSQ(Params *params)
111 : dcachePort(this), LQEntries(params->LQEntries),
112 SQEntries(params->SQEntries), numThreads(params->numberOfThreads),
115 dcachePort.snoopRangeSent = false;
117 //**********************************************/
118 //************ Handle SMT Parameters ***********/
119 //**********************************************/
120 std::string policy = params->smtLSQPolicy;
122 //Convert string to lowercase
123 std::transform(policy.begin(), policy.end(), policy.begin(),
124 (int(*)(int)) tolower);
126 //Figure out fetch policy
127 if (policy == "dynamic") {
130 maxLQEntries = LQEntries;
131 maxSQEntries = SQEntries;
133 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
135 } else if (policy == "partitioned") {
136 lsqPolicy = Partitioned;
138 //@todo:make work if part_amt doesnt divide evenly.
139 maxLQEntries = LQEntries / numThreads;
140 maxSQEntries = SQEntries / numThreads;
142 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
143 "%i entries per LQ | %i entries per SQ",
144 maxLQEntries,maxSQEntries);
146 } else if (policy == "threshold") {
147 lsqPolicy = Threshold;
149 assert(params->smtLSQThreshold > LQEntries);
150 assert(params->smtLSQThreshold > SQEntries);
152 //Divide up by threshold amount
153 //@todo: Should threads check the max and the total
155 maxLQEntries = params->smtLSQThreshold;
156 maxSQEntries = params->smtLSQThreshold;
158 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
159 "%i entries per LQ | %i entries per SQ",
160 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(params, this, maxLQEntries, maxSQEntries, tid);
171 thread[tid].setDcachePort(&dcachePort);
178 LSQ<Impl>::name() const
180 return iewStage->name() + ".lsq";
185 LSQ<Impl>::regStats()
188 for (int tid=0; tid < numThreads; tid++) {
189 thread[tid].regStats();
195 LSQ<Impl>::setActiveThreads(std::list<unsigned> *at_ptr)
197 activeThreads = at_ptr;
198 assert(activeThreads != 0);
203 LSQ<Impl>::setCPU(O3CPU *cpu_ptr)
207 dcachePort.setName(name());
209 for (int tid=0; tid < numThreads; tid++) {
210 thread[tid].setCPU(cpu_ptr);
216 LSQ<Impl>::setIEW(IEW *iew_ptr)
220 for (int tid=0; tid < numThreads; tid++) {
221 thread[tid].setIEW(iew_ptr);
225 template <class Impl>
227 LSQ<Impl>::switchOut()
229 for (int tid = 0; tid < numThreads; tid++) {
230 thread[tid].switchOut();
234 template <class Impl>
236 LSQ<Impl>::takeOverFrom()
238 for (int tid = 0; tid < numThreads; tid++) {
239 thread[tid].takeOverFrom();
243 template <class Impl>
245 LSQ<Impl>::entryAmount(int num_threads)
247 if (lsqPolicy == Partitioned) {
248 return LQEntries / num_threads;
254 template <class Impl>
256 LSQ<Impl>::resetEntries()
258 if (lsqPolicy != Dynamic || numThreads > 1) {
259 int active_threads = activeThreads->size();
263 if (lsqPolicy == Partitioned) {
264 maxEntries = LQEntries / active_threads;
265 } else if (lsqPolicy == Threshold && active_threads == 1) {
266 maxEntries = LQEntries;
268 maxEntries = LQEntries;
271 std::list<unsigned>::iterator threads = activeThreads->begin();
272 std::list<unsigned>::iterator end = activeThreads->end();
274 while (threads != end) {
275 unsigned tid = *threads++;
277 resizeEntries(maxEntries, tid);
284 LSQ<Impl>::removeEntries(unsigned tid)
286 thread[tid].clearLQ();
287 thread[tid].clearSQ();
292 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
294 thread[tid].resizeLQ(size);
295 thread[tid].resizeSQ(size);
302 std::list<unsigned>::iterator threads = activeThreads->begin();
303 std::list<unsigned>::iterator end = activeThreads->end();
305 while (threads != end) {
306 unsigned tid = *threads++;
314 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
316 unsigned tid = load_inst->threadNumber;
318 thread[tid].insertLoad(load_inst);
323 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
325 unsigned tid = store_inst->threadNumber;
327 thread[tid].insertStore(store_inst);
332 LSQ<Impl>::executeLoad(DynInstPtr &inst)
334 unsigned tid = inst->threadNumber;
336 return thread[tid].executeLoad(inst);
341 LSQ<Impl>::executeStore(DynInstPtr &inst)
343 unsigned tid = inst->threadNumber;
345 return thread[tid].executeStore(inst);
350 LSQ<Impl>::writebackStores()
352 std::list<unsigned>::iterator threads = activeThreads->begin();
353 std::list<unsigned>::iterator end = activeThreads->end();
355 while (threads != end) {
356 unsigned tid = *threads++;
358 if (numStoresToWB(tid) > 0) {
359 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
360 "available for Writeback.\n", tid, numStoresToWB(tid));
363 thread[tid].writebackStores();
369 LSQ<Impl>::violation()
371 /* Answers: Does Anybody Have a Violation?*/
372 std::list<unsigned>::iterator threads = activeThreads->begin();
373 std::list<unsigned>::iterator end = activeThreads->end();
375 while (threads != end) {
376 unsigned tid = *threads++;
378 if (thread[tid].violation())
387 LSQ<Impl>::getCount()
391 std::list<unsigned>::iterator threads = activeThreads->begin();
392 std::list<unsigned>::iterator end = activeThreads->end();
394 while (threads != end) {
395 unsigned tid = *threads++;
397 total += getCount(tid);
405 LSQ<Impl>::numLoads()
409 std::list<unsigned>::iterator threads = activeThreads->begin();
410 std::list<unsigned>::iterator end = activeThreads->end();
412 while (threads != end) {
413 unsigned tid = *threads++;
415 total += numLoads(tid);
423 LSQ<Impl>::numStores()
427 std::list<unsigned>::iterator threads = activeThreads->begin();
428 std::list<unsigned>::iterator end = activeThreads->end();
430 while (threads != end) {
431 unsigned tid = *threads++;
433 total += thread[tid].numStores();
441 LSQ<Impl>::numLoadsReady()
445 std::list<unsigned>::iterator threads = activeThreads->begin();
446 std::list<unsigned>::iterator end = activeThreads->end();
448 while (threads != end) {
449 unsigned tid = *threads++;
451 total += thread[tid].numLoadsReady();
459 LSQ<Impl>::numFreeEntries()
463 std::list<unsigned>::iterator threads = activeThreads->begin();
464 std::list<unsigned>::iterator end = activeThreads->end();
466 while (threads != end) {
467 unsigned tid = *threads++;
469 total += thread[tid].numFreeEntries();
477 LSQ<Impl>::numFreeEntries(unsigned tid)
479 //if (lsqPolicy == Dynamic)
480 //return numFreeEntries();
482 return thread[tid].numFreeEntries();
489 std::list<unsigned>::iterator threads = activeThreads->begin();
490 std::list<unsigned>::iterator end = activeThreads->end();
492 while (threads != end) {
493 unsigned tid = *threads++;
495 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
504 LSQ<Impl>::isFull(unsigned tid)
506 //@todo: Change to Calculate All Entries for
508 if (lsqPolicy == Dynamic)
511 return thread[tid].lqFull() || thread[tid].sqFull();
518 std::list<unsigned>::iterator threads = activeThreads->begin();
519 std::list<unsigned>::iterator end = activeThreads->end();
521 while (threads != end) {
522 unsigned tid = *threads++;
524 if (!thread[tid].lqFull())
533 LSQ<Impl>::lqFull(unsigned tid)
535 //@todo: Change to Calculate All Entries for
537 if (lsqPolicy == Dynamic)
540 return thread[tid].lqFull();
547 std::list<unsigned>::iterator threads = activeThreads->begin();
548 std::list<unsigned>::iterator end = activeThreads->end();
550 while (threads != end) {
551 unsigned tid = *threads++;
562 LSQ<Impl>::sqFull(unsigned tid)
564 //@todo: Change to Calculate All Entries for
566 if (lsqPolicy == Dynamic)
569 return thread[tid].sqFull();
574 LSQ<Impl>::isStalled()
576 std::list<unsigned>::iterator threads = activeThreads->begin();
577 std::list<unsigned>::iterator end = activeThreads->end();
579 while (threads != end) {
580 unsigned tid = *threads++;
582 if (!thread[tid].isStalled())
591 LSQ<Impl>::isStalled(unsigned tid)
593 if (lsqPolicy == Dynamic)
596 return thread[tid].isStalled();
601 LSQ<Impl>::hasStoresToWB()
603 std::list<unsigned>::iterator threads = activeThreads->begin();
604 std::list<unsigned>::iterator end = activeThreads->end();
609 while (threads != end) {
610 unsigned tid = *threads++;
612 if (!hasStoresToWB(tid))
623 std::list<unsigned>::iterator threads = activeThreads->begin();
624 std::list<unsigned>::iterator end = activeThreads->end();
626 while (threads != end) {
627 unsigned tid = *threads++;
638 LSQ<Impl>::dumpInsts()
640 std::list<unsigned>::iterator threads = activeThreads->begin();
641 std::list<unsigned>::iterator end = activeThreads->end();
643 while (threads != end) {
644 unsigned tid = *threads++;
646 thread[tid].dumpInsts();