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 lsq->thread[lsq->retryTid].recvRetry();
105 // Speculatively clear the retry Tid. This will get set again if
106 // the LSQUnit was unable to complete its access.
110 template <class Impl>
111 LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, Params *params)
112 : cpu(cpu_ptr), iewStage(iew_ptr), dcachePort(this),
113 LQEntries(params->LQEntries),
114 SQEntries(params->SQEntries),
115 numThreads(params->numberOfThreads),
118 dcachePort.snoopRangeSent = false;
120 //**********************************************/
121 //************ Handle SMT Parameters ***********/
122 //**********************************************/
123 std::string policy = params->smtLSQPolicy;
125 //Convert string to lowercase
126 std::transform(policy.begin(), policy.end(), policy.begin(),
127 (int(*)(int)) tolower);
129 //Figure out fetch policy
130 if (policy == "dynamic") {
133 maxLQEntries = LQEntries;
134 maxSQEntries = SQEntries;
136 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
137 } else if (policy == "partitioned") {
138 lsqPolicy = Partitioned;
140 //@todo:make work if part_amt doesnt divide evenly.
141 maxLQEntries = LQEntries / numThreads;
142 maxSQEntries = SQEntries / numThreads;
144 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
145 "%i entries per LQ | %i entries per SQ",
146 maxLQEntries,maxSQEntries);
147 } else if (policy == "threshold") {
148 lsqPolicy = Threshold;
150 assert(params->smtLSQThreshold > LQEntries);
151 assert(params->smtLSQThreshold > SQEntries);
153 //Divide up by threshold amount
154 //@todo: Should threads check the max and the total
156 maxLQEntries = params->smtLSQThreshold;
157 maxSQEntries = params->smtLSQThreshold;
159 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
160 "%i entries per LQ | %i entries per SQ",
161 maxLQEntries,maxSQEntries);
163 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
164 "Partitioned, Threshold}");
168 for (int tid=0; tid < numThreads; tid++) {
169 thread[tid].init(cpu, iew_ptr, params, this,
170 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);
201 template <class Impl>
203 LSQ<Impl>::switchOut()
205 for (int tid = 0; tid < numThreads; tid++) {
206 thread[tid].switchOut();
210 template <class Impl>
212 LSQ<Impl>::takeOverFrom()
214 for (int tid = 0; tid < numThreads; tid++) {
215 thread[tid].takeOverFrom();
219 template <class Impl>
221 LSQ<Impl>::entryAmount(int num_threads)
223 if (lsqPolicy == Partitioned) {
224 return LQEntries / num_threads;
230 template <class Impl>
232 LSQ<Impl>::resetEntries()
234 if (lsqPolicy != Dynamic || numThreads > 1) {
235 int active_threads = activeThreads->size();
239 if (lsqPolicy == Partitioned) {
240 maxEntries = LQEntries / active_threads;
241 } else if (lsqPolicy == Threshold && active_threads == 1) {
242 maxEntries = LQEntries;
244 maxEntries = LQEntries;
247 std::list<unsigned>::iterator threads = activeThreads->begin();
248 std::list<unsigned>::iterator end = activeThreads->end();
250 while (threads != end) {
251 unsigned tid = *threads++;
253 resizeEntries(maxEntries, tid);
260 LSQ<Impl>::removeEntries(unsigned tid)
262 thread[tid].clearLQ();
263 thread[tid].clearSQ();
268 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
270 thread[tid].resizeLQ(size);
271 thread[tid].resizeSQ(size);
278 std::list<unsigned>::iterator threads = activeThreads->begin();
279 std::list<unsigned>::iterator end = activeThreads->end();
281 while (threads != end) {
282 unsigned tid = *threads++;
290 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
292 unsigned tid = load_inst->threadNumber;
294 thread[tid].insertLoad(load_inst);
299 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
301 unsigned tid = store_inst->threadNumber;
303 thread[tid].insertStore(store_inst);
308 LSQ<Impl>::executeLoad(DynInstPtr &inst)
310 unsigned tid = inst->threadNumber;
312 return thread[tid].executeLoad(inst);
317 LSQ<Impl>::executeStore(DynInstPtr &inst)
319 unsigned tid = inst->threadNumber;
321 return thread[tid].executeStore(inst);
326 LSQ<Impl>::writebackStores()
328 std::list<unsigned>::iterator threads = activeThreads->begin();
329 std::list<unsigned>::iterator end = activeThreads->end();
331 while (threads != end) {
332 unsigned tid = *threads++;
334 if (numStoresToWB(tid) > 0) {
335 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
336 "available for Writeback.\n", tid, numStoresToWB(tid));
339 thread[tid].writebackStores();
345 LSQ<Impl>::violation()
347 /* Answers: Does Anybody Have a Violation?*/
348 std::list<unsigned>::iterator threads = activeThreads->begin();
349 std::list<unsigned>::iterator end = activeThreads->end();
351 while (threads != end) {
352 unsigned tid = *threads++;
354 if (thread[tid].violation())
363 LSQ<Impl>::getCount()
367 std::list<unsigned>::iterator threads = activeThreads->begin();
368 std::list<unsigned>::iterator end = activeThreads->end();
370 while (threads != end) {
371 unsigned tid = *threads++;
373 total += getCount(tid);
381 LSQ<Impl>::numLoads()
385 std::list<unsigned>::iterator threads = activeThreads->begin();
386 std::list<unsigned>::iterator end = activeThreads->end();
388 while (threads != end) {
389 unsigned tid = *threads++;
391 total += numLoads(tid);
399 LSQ<Impl>::numStores()
403 std::list<unsigned>::iterator threads = activeThreads->begin();
404 std::list<unsigned>::iterator end = activeThreads->end();
406 while (threads != end) {
407 unsigned tid = *threads++;
409 total += thread[tid].numStores();
417 LSQ<Impl>::numLoadsReady()
421 std::list<unsigned>::iterator threads = activeThreads->begin();
422 std::list<unsigned>::iterator end = activeThreads->end();
424 while (threads != end) {
425 unsigned tid = *threads++;
427 total += thread[tid].numLoadsReady();
435 LSQ<Impl>::numFreeEntries()
439 std::list<unsigned>::iterator threads = activeThreads->begin();
440 std::list<unsigned>::iterator end = activeThreads->end();
442 while (threads != end) {
443 unsigned tid = *threads++;
445 total += thread[tid].numFreeEntries();
453 LSQ<Impl>::numFreeEntries(unsigned tid)
455 //if (lsqPolicy == Dynamic)
456 //return numFreeEntries();
458 return thread[tid].numFreeEntries();
465 std::list<unsigned>::iterator threads = activeThreads->begin();
466 std::list<unsigned>::iterator end = activeThreads->end();
468 while (threads != end) {
469 unsigned tid = *threads++;
471 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
480 LSQ<Impl>::isFull(unsigned tid)
482 //@todo: Change to Calculate All Entries for
484 if (lsqPolicy == Dynamic)
487 return thread[tid].lqFull() || thread[tid].sqFull();
494 std::list<unsigned>::iterator threads = activeThreads->begin();
495 std::list<unsigned>::iterator end = activeThreads->end();
497 while (threads != end) {
498 unsigned tid = *threads++;
500 if (!thread[tid].lqFull())
509 LSQ<Impl>::lqFull(unsigned tid)
511 //@todo: Change to Calculate All Entries for
513 if (lsqPolicy == Dynamic)
516 return thread[tid].lqFull();
523 std::list<unsigned>::iterator threads = activeThreads->begin();
524 std::list<unsigned>::iterator end = activeThreads->end();
526 while (threads != end) {
527 unsigned tid = *threads++;
538 LSQ<Impl>::sqFull(unsigned tid)
540 //@todo: Change to Calculate All Entries for
542 if (lsqPolicy == Dynamic)
545 return thread[tid].sqFull();
550 LSQ<Impl>::isStalled()
552 std::list<unsigned>::iterator threads = activeThreads->begin();
553 std::list<unsigned>::iterator end = activeThreads->end();
555 while (threads != end) {
556 unsigned tid = *threads++;
558 if (!thread[tid].isStalled())
567 LSQ<Impl>::isStalled(unsigned tid)
569 if (lsqPolicy == Dynamic)
572 return thread[tid].isStalled();
577 LSQ<Impl>::hasStoresToWB()
579 std::list<unsigned>::iterator threads = activeThreads->begin();
580 std::list<unsigned>::iterator end = activeThreads->end();
585 while (threads != end) {
586 unsigned tid = *threads++;
588 if (!hasStoresToWB(tid))
599 std::list<unsigned>::iterator threads = activeThreads->begin();
600 std::list<unsigned>::iterator end = activeThreads->end();
602 while (threads != end) {
603 unsigned tid = *threads++;
614 LSQ<Impl>::dumpInsts()
616 std::list<unsigned>::iterator threads = activeThreads->begin();
617 std::list<unsigned>::iterator end = activeThreads->end();
619 while (threads != end) {
620 unsigned tid = *threads++;
622 thread[tid].dumpInsts();