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"
37 #include "params/DerivO3CPU.hh"
41 LSQ<Impl>::DcachePort::setPeer(Port *port)
46 // Update the ThreadContext's memory ports (Functional/Virtual
48 lsq->updateMemPorts();
54 LSQ<Impl>::DcachePort::recvAtomic(PacketPtr pkt)
56 panic("O3CPU model does not work with atomic mode!");
62 LSQ<Impl>::DcachePort::recvFunctional(PacketPtr pkt)
64 DPRINTF(LSQ, "LSQ doesn't update things on a recvFunctional.");
69 LSQ<Impl>::DcachePort::recvStatusChange(Status status)
71 if (status == RangeChange) {
72 if (!snoopRangeSent) {
73 snoopRangeSent = true;
74 sendStatusChange(Port::RangeChange);
78 panic("O3CPU doesn't expect recvStatusChange callback!");
83 LSQ<Impl>::DcachePort::recvTiming(PacketPtr pkt)
86 DPRINTF(LSQ, "Got error packet back for address: %#X\n", pkt->getAddr());
87 if (pkt->isResponse()) {
88 lsq->thread[pkt->req->getThreadNum()].completeDataAccess(pkt);
93 // @TODO someday may need to process invalidations in LSQ here
94 // to provide stronger consistency model
101 LSQ<Impl>::DcachePort::recvRetry()
103 if (lsq->retryTid == -1)
105 //Squashed, so drop it
108 int curr_retry_tid = lsq->retryTid;
109 // Speculatively clear the retry Tid. This will get set again if
110 // the LSQUnit was unable to complete its access.
112 lsq->thread[curr_retry_tid].recvRetry();
115 template <class Impl>
116 LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
117 : cpu(cpu_ptr), iewStage(iew_ptr), dcachePort(this),
118 LQEntries(params->LQEntries),
119 SQEntries(params->SQEntries),
120 numThreads(params->numThreads),
123 dcachePort.snoopRangeSent = false;
125 //**********************************************/
126 //************ Handle SMT Parameters ***********/
127 //**********************************************/
128 std::string policy = params->smtLSQPolicy;
130 //Convert string to lowercase
131 std::transform(policy.begin(), policy.end(), policy.begin(),
132 (int(*)(int)) tolower);
134 //Figure out fetch policy
135 if (policy == "dynamic") {
138 maxLQEntries = LQEntries;
139 maxSQEntries = SQEntries;
141 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
142 } else if (policy == "partitioned") {
143 lsqPolicy = Partitioned;
145 //@todo:make work if part_amt doesnt divide evenly.
146 maxLQEntries = LQEntries / numThreads;
147 maxSQEntries = SQEntries / numThreads;
149 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
150 "%i entries per LQ | %i entries per SQ",
151 maxLQEntries,maxSQEntries);
152 } else if (policy == "threshold") {
153 lsqPolicy = Threshold;
155 assert(params->smtLSQThreshold > LQEntries);
156 assert(params->smtLSQThreshold > SQEntries);
158 //Divide up by threshold amount
159 //@todo: Should threads check the max and the total
161 maxLQEntries = params->smtLSQThreshold;
162 maxSQEntries = params->smtLSQThreshold;
164 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
165 "%i entries per LQ | %i entries per SQ",
166 maxLQEntries,maxSQEntries);
168 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
169 "Partitioned, Threshold}");
173 for (int tid=0; tid < numThreads; tid++) {
174 thread[tid].init(cpu, iew_ptr, params, this,
175 maxLQEntries, maxSQEntries, tid);
176 thread[tid].setDcachePort(&dcachePort);
183 LSQ<Impl>::name() const
185 return iewStage->name() + ".lsq";
190 LSQ<Impl>::regStats()
193 for (int tid=0; tid < numThreads; tid++) {
194 thread[tid].regStats();
200 LSQ<Impl>::setActiveThreads(std::list<unsigned> *at_ptr)
202 activeThreads = at_ptr;
203 assert(activeThreads != 0);
206 template <class Impl>
208 LSQ<Impl>::switchOut()
210 for (int tid = 0; tid < numThreads; tid++) {
211 thread[tid].switchOut();
215 template <class Impl>
217 LSQ<Impl>::takeOverFrom()
219 for (int tid = 0; tid < numThreads; tid++) {
220 thread[tid].takeOverFrom();
224 template <class Impl>
226 LSQ<Impl>::entryAmount(int num_threads)
228 if (lsqPolicy == Partitioned) {
229 return LQEntries / num_threads;
235 template <class Impl>
237 LSQ<Impl>::resetEntries()
239 if (lsqPolicy != Dynamic || numThreads > 1) {
240 int active_threads = activeThreads->size();
244 if (lsqPolicy == Partitioned) {
245 maxEntries = LQEntries / active_threads;
246 } else if (lsqPolicy == Threshold && active_threads == 1) {
247 maxEntries = LQEntries;
249 maxEntries = LQEntries;
252 std::list<unsigned>::iterator threads = activeThreads->begin();
253 std::list<unsigned>::iterator end = activeThreads->end();
255 while (threads != end) {
256 unsigned tid = *threads++;
258 resizeEntries(maxEntries, tid);
265 LSQ<Impl>::removeEntries(unsigned tid)
267 thread[tid].clearLQ();
268 thread[tid].clearSQ();
273 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
275 thread[tid].resizeLQ(size);
276 thread[tid].resizeSQ(size);
283 std::list<unsigned>::iterator threads = activeThreads->begin();
284 std::list<unsigned>::iterator end = activeThreads->end();
286 while (threads != end) {
287 unsigned tid = *threads++;
295 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
297 unsigned tid = load_inst->threadNumber;
299 thread[tid].insertLoad(load_inst);
304 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
306 unsigned tid = store_inst->threadNumber;
308 thread[tid].insertStore(store_inst);
313 LSQ<Impl>::executeLoad(DynInstPtr &inst)
315 unsigned tid = inst->threadNumber;
317 return thread[tid].executeLoad(inst);
322 LSQ<Impl>::executeStore(DynInstPtr &inst)
324 unsigned tid = inst->threadNumber;
326 return thread[tid].executeStore(inst);
331 LSQ<Impl>::writebackStores()
333 std::list<unsigned>::iterator threads = activeThreads->begin();
334 std::list<unsigned>::iterator end = activeThreads->end();
336 while (threads != end) {
337 unsigned tid = *threads++;
339 if (numStoresToWB(tid) > 0) {
340 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
341 "available for Writeback.\n", tid, numStoresToWB(tid));
344 thread[tid].writebackStores();
350 LSQ<Impl>::violation()
352 /* Answers: Does Anybody Have a Violation?*/
353 std::list<unsigned>::iterator threads = activeThreads->begin();
354 std::list<unsigned>::iterator end = activeThreads->end();
356 while (threads != end) {
357 unsigned tid = *threads++;
359 if (thread[tid].violation())
368 LSQ<Impl>::getCount()
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 total += getCount(tid);
386 LSQ<Impl>::numLoads()
390 std::list<unsigned>::iterator threads = activeThreads->begin();
391 std::list<unsigned>::iterator end = activeThreads->end();
393 while (threads != end) {
394 unsigned tid = *threads++;
396 total += numLoads(tid);
404 LSQ<Impl>::numStores()
408 std::list<unsigned>::iterator threads = activeThreads->begin();
409 std::list<unsigned>::iterator end = activeThreads->end();
411 while (threads != end) {
412 unsigned tid = *threads++;
414 total += thread[tid].numStores();
422 LSQ<Impl>::numLoadsReady()
426 std::list<unsigned>::iterator threads = activeThreads->begin();
427 std::list<unsigned>::iterator end = activeThreads->end();
429 while (threads != end) {
430 unsigned tid = *threads++;
432 total += thread[tid].numLoadsReady();
440 LSQ<Impl>::numFreeEntries()
444 std::list<unsigned>::iterator threads = activeThreads->begin();
445 std::list<unsigned>::iterator end = activeThreads->end();
447 while (threads != end) {
448 unsigned tid = *threads++;
450 total += thread[tid].numFreeEntries();
458 LSQ<Impl>::numFreeEntries(unsigned tid)
460 //if (lsqPolicy == Dynamic)
461 //return numFreeEntries();
463 return thread[tid].numFreeEntries();
470 std::list<unsigned>::iterator threads = activeThreads->begin();
471 std::list<unsigned>::iterator end = activeThreads->end();
473 while (threads != end) {
474 unsigned tid = *threads++;
476 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
485 LSQ<Impl>::isFull(unsigned tid)
487 //@todo: Change to Calculate All Entries for
489 if (lsqPolicy == Dynamic)
492 return thread[tid].lqFull() || thread[tid].sqFull();
499 std::list<unsigned>::iterator threads = activeThreads->begin();
500 std::list<unsigned>::iterator end = activeThreads->end();
502 while (threads != end) {
503 unsigned tid = *threads++;
505 if (!thread[tid].lqFull())
514 LSQ<Impl>::lqFull(unsigned tid)
516 //@todo: Change to Calculate All Entries for
518 if (lsqPolicy == Dynamic)
521 return thread[tid].lqFull();
528 std::list<unsigned>::iterator threads = activeThreads->begin();
529 std::list<unsigned>::iterator end = activeThreads->end();
531 while (threads != end) {
532 unsigned tid = *threads++;
543 LSQ<Impl>::sqFull(unsigned tid)
545 //@todo: Change to Calculate All Entries for
547 if (lsqPolicy == Dynamic)
550 return thread[tid].sqFull();
555 LSQ<Impl>::isStalled()
557 std::list<unsigned>::iterator threads = activeThreads->begin();
558 std::list<unsigned>::iterator end = activeThreads->end();
560 while (threads != end) {
561 unsigned tid = *threads++;
563 if (!thread[tid].isStalled())
572 LSQ<Impl>::isStalled(unsigned tid)
574 if (lsqPolicy == Dynamic)
577 return thread[tid].isStalled();
582 LSQ<Impl>::hasStoresToWB()
584 std::list<unsigned>::iterator threads = activeThreads->begin();
585 std::list<unsigned>::iterator end = activeThreads->end();
587 while (threads != end) {
588 unsigned tid = *threads++;
590 if (hasStoresToWB(tid))
601 std::list<unsigned>::iterator threads = activeThreads->begin();
602 std::list<unsigned>::iterator end = activeThreads->end();
604 while (threads != end) {
605 unsigned tid = *threads++;
616 LSQ<Impl>::dumpInsts()
618 std::list<unsigned>::iterator threads = activeThreads->begin();
619 std::list<unsigned>::iterator end = activeThreads->end();
621 while (threads != end) {
622 unsigned tid = *threads++;
624 thread[tid].dumpInsts();