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(O3CPU *cpu_ptr, IEW *iew_ptr, Params *params)
111 : cpu(cpu_ptr), iewStage(iew_ptr), dcachePort(this),
112 LQEntries(params->LQEntries),
113 SQEntries(params->SQEntries),
114 numThreads(params->numberOfThreads),
117 dcachePort.snoopRangeSent = false;
119 //**********************************************/
120 //************ Handle SMT Parameters ***********/
121 //**********************************************/
122 std::string policy = params->smtLSQPolicy;
124 //Convert string to lowercase
125 std::transform(policy.begin(), policy.end(), policy.begin(),
126 (int(*)(int)) tolower);
128 //Figure out fetch policy
129 if (policy == "dynamic") {
132 maxLQEntries = LQEntries;
133 maxSQEntries = SQEntries;
135 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
136 } else if (policy == "partitioned") {
137 lsqPolicy = Partitioned;
139 //@todo:make work if part_amt doesnt divide evenly.
140 maxLQEntries = LQEntries / numThreads;
141 maxSQEntries = SQEntries / numThreads;
143 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
144 "%i entries per LQ | %i entries per SQ",
145 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);
162 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
163 "Partitioned, Threshold}");
167 for (int tid=0; tid < numThreads; tid++) {
168 thread[tid].init(cpu, iew_ptr, params, this,
169 maxLQEntries, maxSQEntries, tid);
170 thread[tid].setDcachePort(&dcachePort);
177 LSQ<Impl>::name() const
179 return iewStage->name() + ".lsq";
184 LSQ<Impl>::regStats()
187 for (int tid=0; tid < numThreads; tid++) {
188 thread[tid].regStats();
194 LSQ<Impl>::setActiveThreads(std::list<unsigned> *at_ptr)
196 activeThreads = at_ptr;
197 assert(activeThreads != 0);
200 template <class Impl>
202 LSQ<Impl>::switchOut()
204 for (int tid = 0; tid < numThreads; tid++) {
205 thread[tid].switchOut();
209 template <class Impl>
211 LSQ<Impl>::takeOverFrom()
213 for (int tid = 0; tid < numThreads; tid++) {
214 thread[tid].takeOverFrom();
218 template <class Impl>
220 LSQ<Impl>::entryAmount(int num_threads)
222 if (lsqPolicy == Partitioned) {
223 return LQEntries / num_threads;
229 template <class Impl>
231 LSQ<Impl>::resetEntries()
233 if (lsqPolicy != Dynamic || numThreads > 1) {
234 int active_threads = activeThreads->size();
238 if (lsqPolicy == Partitioned) {
239 maxEntries = LQEntries / active_threads;
240 } else if (lsqPolicy == Threshold && active_threads == 1) {
241 maxEntries = LQEntries;
243 maxEntries = LQEntries;
246 std::list<unsigned>::iterator threads = activeThreads->begin();
247 std::list<unsigned>::iterator end = activeThreads->end();
249 while (threads != end) {
250 unsigned tid = *threads++;
252 resizeEntries(maxEntries, tid);
259 LSQ<Impl>::removeEntries(unsigned tid)
261 thread[tid].clearLQ();
262 thread[tid].clearSQ();
267 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
269 thread[tid].resizeLQ(size);
270 thread[tid].resizeSQ(size);
277 std::list<unsigned>::iterator threads = activeThreads->begin();
278 std::list<unsigned>::iterator end = activeThreads->end();
280 while (threads != end) {
281 unsigned tid = *threads++;
289 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
291 unsigned tid = load_inst->threadNumber;
293 thread[tid].insertLoad(load_inst);
298 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
300 unsigned tid = store_inst->threadNumber;
302 thread[tid].insertStore(store_inst);
307 LSQ<Impl>::executeLoad(DynInstPtr &inst)
309 unsigned tid = inst->threadNumber;
311 return thread[tid].executeLoad(inst);
316 LSQ<Impl>::executeStore(DynInstPtr &inst)
318 unsigned tid = inst->threadNumber;
320 return thread[tid].executeStore(inst);
325 LSQ<Impl>::writebackStores()
327 std::list<unsigned>::iterator threads = activeThreads->begin();
328 std::list<unsigned>::iterator end = activeThreads->end();
330 while (threads != end) {
331 unsigned tid = *threads++;
333 if (numStoresToWB(tid) > 0) {
334 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
335 "available for Writeback.\n", tid, numStoresToWB(tid));
338 thread[tid].writebackStores();
344 LSQ<Impl>::violation()
346 /* Answers: Does Anybody Have a Violation?*/
347 std::list<unsigned>::iterator threads = activeThreads->begin();
348 std::list<unsigned>::iterator end = activeThreads->end();
350 while (threads != end) {
351 unsigned tid = *threads++;
353 if (thread[tid].violation())
362 LSQ<Impl>::getCount()
366 std::list<unsigned>::iterator threads = activeThreads->begin();
367 std::list<unsigned>::iterator end = activeThreads->end();
369 while (threads != end) {
370 unsigned tid = *threads++;
372 total += getCount(tid);
380 LSQ<Impl>::numLoads()
384 std::list<unsigned>::iterator threads = activeThreads->begin();
385 std::list<unsigned>::iterator end = activeThreads->end();
387 while (threads != end) {
388 unsigned tid = *threads++;
390 total += numLoads(tid);
398 LSQ<Impl>::numStores()
402 std::list<unsigned>::iterator threads = activeThreads->begin();
403 std::list<unsigned>::iterator end = activeThreads->end();
405 while (threads != end) {
406 unsigned tid = *threads++;
408 total += thread[tid].numStores();
416 LSQ<Impl>::numLoadsReady()
420 std::list<unsigned>::iterator threads = activeThreads->begin();
421 std::list<unsigned>::iterator end = activeThreads->end();
423 while (threads != end) {
424 unsigned tid = *threads++;
426 total += thread[tid].numLoadsReady();
434 LSQ<Impl>::numFreeEntries()
438 std::list<unsigned>::iterator threads = activeThreads->begin();
439 std::list<unsigned>::iterator end = activeThreads->end();
441 while (threads != end) {
442 unsigned tid = *threads++;
444 total += thread[tid].numFreeEntries();
452 LSQ<Impl>::numFreeEntries(unsigned tid)
454 //if (lsqPolicy == Dynamic)
455 //return numFreeEntries();
457 return thread[tid].numFreeEntries();
464 std::list<unsigned>::iterator threads = activeThreads->begin();
465 std::list<unsigned>::iterator end = activeThreads->end();
467 while (threads != end) {
468 unsigned tid = *threads++;
470 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
479 LSQ<Impl>::isFull(unsigned tid)
481 //@todo: Change to Calculate All Entries for
483 if (lsqPolicy == Dynamic)
486 return thread[tid].lqFull() || thread[tid].sqFull();
493 std::list<unsigned>::iterator threads = activeThreads->begin();
494 std::list<unsigned>::iterator end = activeThreads->end();
496 while (threads != end) {
497 unsigned tid = *threads++;
499 if (!thread[tid].lqFull())
508 LSQ<Impl>::lqFull(unsigned tid)
510 //@todo: Change to Calculate All Entries for
512 if (lsqPolicy == Dynamic)
515 return thread[tid].lqFull();
522 std::list<unsigned>::iterator threads = activeThreads->begin();
523 std::list<unsigned>::iterator end = activeThreads->end();
525 while (threads != end) {
526 unsigned tid = *threads++;
537 LSQ<Impl>::sqFull(unsigned tid)
539 //@todo: Change to Calculate All Entries for
541 if (lsqPolicy == Dynamic)
544 return thread[tid].sqFull();
549 LSQ<Impl>::isStalled()
551 std::list<unsigned>::iterator threads = activeThreads->begin();
552 std::list<unsigned>::iterator end = activeThreads->end();
554 while (threads != end) {
555 unsigned tid = *threads++;
557 if (!thread[tid].isStalled())
566 LSQ<Impl>::isStalled(unsigned tid)
568 if (lsqPolicy == Dynamic)
571 return thread[tid].isStalled();
576 LSQ<Impl>::hasStoresToWB()
578 std::list<unsigned>::iterator threads = activeThreads->begin();
579 std::list<unsigned>::iterator end = activeThreads->end();
584 while (threads != end) {
585 unsigned tid = *threads++;
587 if (!hasStoresToWB(tid))
598 std::list<unsigned>::iterator threads = activeThreads->begin();
599 std::list<unsigned>::iterator end = activeThreads->end();
601 while (threads != end) {
602 unsigned tid = *threads++;
613 LSQ<Impl>::dumpInsts()
615 std::list<unsigned>::iterator threads = activeThreads->begin();
616 std::list<unsigned>::iterator end = activeThreads->end();
618 while (threads != end) {
619 unsigned tid = *threads++;
621 thread[tid].dumpInsts();