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
34 #include "cpu/o3/lsq.hh"
40 LSQ<Impl>::DcachePort::recvAtomic(PacketPtr pkt)
42 panic("O3CPU model does not work with atomic mode!");
48 LSQ<Impl>::DcachePort::recvFunctional(PacketPtr pkt)
50 panic("O3CPU doesn't expect recvFunctional callback!");
55 LSQ<Impl>::DcachePort::recvStatusChange(Status status)
57 if (status == RangeChange)
60 panic("O3CPU doesn't expect recvStatusChange callback!");
65 LSQ<Impl>::DcachePort::recvTiming(PacketPtr pkt)
67 lsq->thread[pkt->req->getThreadNum()].completeDataAccess(pkt);
73 LSQ<Impl>::DcachePort::recvRetry()
75 lsq->thread[lsq->retryTid].recvRetry();
76 // Speculatively clear the retry Tid. This will get set again if
77 // the LSQUnit was unable to complete its access.
82 LSQ<Impl>::LSQ(Params *params)
83 : dcachePort(this), LQEntries(params->LQEntries),
84 SQEntries(params->SQEntries), numThreads(params->numberOfThreads),
87 DPRINTF(LSQ, "Creating LSQ object.\n");
89 //**********************************************/
90 //************ Handle SMT Parameters ***********/
91 //**********************************************/
92 string policy = params->smtLSQPolicy;
94 //Convert string to lowercase
95 std::transform(policy.begin(), policy.end(), policy.begin(),
96 (int(*)(int)) tolower);
98 //Figure out fetch policy
99 if (policy == "dynamic") {
102 maxLQEntries = LQEntries;
103 maxSQEntries = SQEntries;
105 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
107 } else if (policy == "partitioned") {
108 lsqPolicy = Partitioned;
110 //@todo:make work if part_amt doesnt divide evenly.
111 maxLQEntries = LQEntries / numThreads;
112 maxSQEntries = SQEntries / numThreads;
114 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
115 "%i entries per LQ | %i entries per SQ",
116 maxLQEntries,maxSQEntries);
118 } else if (policy == "threshold") {
119 lsqPolicy = Threshold;
121 assert(params->smtLSQThreshold > LQEntries);
122 assert(params->smtLSQThreshold > SQEntries);
124 //Divide up by threshold amount
125 //@todo: Should threads check the max and the total
127 maxLQEntries = params->smtLSQThreshold;
128 maxSQEntries = params->smtLSQThreshold;
130 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
131 "%i entries per LQ | %i entries per SQ",
132 maxLQEntries,maxSQEntries);
135 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
136 "Partitioned, Threshold}");
140 for (int tid=0; tid < numThreads; tid++) {
141 thread[tid].init(params, this, maxLQEntries, maxSQEntries, tid);
142 thread[tid].setDcachePort(&dcachePort);
149 LSQ<Impl>::name() const
151 return iewStage->name() + ".lsq";
156 LSQ<Impl>::regStats()
159 for (int tid=0; tid < numThreads; tid++) {
160 thread[tid].regStats();
166 LSQ<Impl>::setActiveThreads(list<unsigned> *at_ptr)
168 activeThreads = at_ptr;
169 assert(activeThreads != 0);
174 LSQ<Impl>::setCPU(O3CPU *cpu_ptr)
178 dcachePort.setName(name());
180 for (int tid=0; tid < numThreads; tid++) {
181 thread[tid].setCPU(cpu_ptr);
187 LSQ<Impl>::setIEW(IEW *iew_ptr)
191 for (int tid=0; tid < numThreads; tid++) {
192 thread[tid].setIEW(iew_ptr);
196 template <class Impl>
198 LSQ<Impl>::switchOut()
200 for (int tid = 0; tid < numThreads; tid++) {
201 thread[tid].switchOut();
205 template <class Impl>
207 LSQ<Impl>::takeOverFrom()
209 for (int tid = 0; tid < numThreads; tid++) {
210 thread[tid].takeOverFrom();
214 template <class Impl>
216 LSQ<Impl>::entryAmount(int num_threads)
218 if (lsqPolicy == Partitioned) {
219 return LQEntries / num_threads;
225 template <class Impl>
227 LSQ<Impl>::resetEntries()
229 if (lsqPolicy != Dynamic || numThreads > 1) {
230 int active_threads = (*activeThreads).size();
232 list<unsigned>::iterator threads = (*activeThreads).begin();
233 list<unsigned>::iterator list_end = (*activeThreads).end();
237 if (lsqPolicy == Partitioned) {
238 maxEntries = LQEntries / active_threads;
239 } else if (lsqPolicy == Threshold && active_threads == 1) {
240 maxEntries = LQEntries;
242 maxEntries = LQEntries;
245 while (threads != list_end) {
246 resizeEntries(maxEntries,*threads++);
253 LSQ<Impl>::removeEntries(unsigned tid)
255 thread[tid].clearLQ();
256 thread[tid].clearSQ();
261 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
263 thread[tid].resizeLQ(size);
264 thread[tid].resizeSQ(size);
271 list<unsigned>::iterator active_threads = (*activeThreads).begin();
273 while (active_threads != (*activeThreads).end()) {
274 unsigned tid = *active_threads++;
282 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
284 unsigned tid = load_inst->threadNumber;
286 thread[tid].insertLoad(load_inst);
291 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
293 unsigned tid = store_inst->threadNumber;
295 thread[tid].insertStore(store_inst);
300 LSQ<Impl>::executeLoad(DynInstPtr &inst)
302 unsigned tid = inst->threadNumber;
304 return thread[tid].executeLoad(inst);
309 LSQ<Impl>::executeStore(DynInstPtr &inst)
311 unsigned tid = inst->threadNumber;
313 return thread[tid].executeStore(inst);
318 LSQ<Impl>::writebackStores()
320 list<unsigned>::iterator active_threads = (*activeThreads).begin();
322 while (active_threads != (*activeThreads).end()) {
323 unsigned tid = *active_threads++;
325 if (numStoresToWB(tid) > 0) {
326 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
327 "available for Writeback.\n", tid, numStoresToWB(tid));
330 thread[tid].writebackStores();
336 LSQ<Impl>::violation()
338 /* Answers: Does Anybody Have a Violation?*/
339 list<unsigned>::iterator active_threads = (*activeThreads).begin();
341 while (active_threads != (*activeThreads).end()) {
342 unsigned tid = *active_threads++;
343 if (thread[tid].violation())
352 LSQ<Impl>::getCount()
356 list<unsigned>::iterator active_threads = (*activeThreads).begin();
358 while (active_threads != (*activeThreads).end()) {
359 unsigned tid = *active_threads++;
360 total += getCount(tid);
368 LSQ<Impl>::numLoads()
372 list<unsigned>::iterator active_threads = (*activeThreads).begin();
374 while (active_threads != (*activeThreads).end()) {
375 unsigned tid = *active_threads++;
376 total += numLoads(tid);
384 LSQ<Impl>::numStores()
388 list<unsigned>::iterator active_threads = (*activeThreads).begin();
390 while (active_threads != (*activeThreads).end()) {
391 unsigned tid = *active_threads++;
392 total += thread[tid].numStores();
400 LSQ<Impl>::numLoadsReady()
404 list<unsigned>::iterator active_threads = (*activeThreads).begin();
406 while (active_threads != (*activeThreads).end()) {
407 unsigned tid = *active_threads++;
408 total += thread[tid].numLoadsReady();
416 LSQ<Impl>::numFreeEntries()
420 list<unsigned>::iterator active_threads = (*activeThreads).begin();
422 while (active_threads != (*activeThreads).end()) {
423 unsigned tid = *active_threads++;
424 total += thread[tid].numFreeEntries();
432 LSQ<Impl>::numFreeEntries(unsigned tid)
434 //if( lsqPolicy == Dynamic )
435 //return numFreeEntries();
437 return thread[tid].numFreeEntries();
444 list<unsigned>::iterator active_threads = (*activeThreads).begin();
446 while (active_threads != (*activeThreads).end()) {
447 unsigned tid = *active_threads++;
448 if (! (thread[tid].lqFull() || thread[tid].sqFull()) )
457 LSQ<Impl>::isFull(unsigned tid)
459 //@todo: Change to Calculate All Entries for
461 if( lsqPolicy == Dynamic )
464 return thread[tid].lqFull() || thread[tid].sqFull();
471 list<unsigned>::iterator active_threads = (*activeThreads).begin();
473 while (active_threads != (*activeThreads).end()) {
474 unsigned tid = *active_threads++;
475 if (!thread[tid].lqFull())
484 LSQ<Impl>::lqFull(unsigned tid)
486 //@todo: Change to Calculate All Entries for
488 if( lsqPolicy == Dynamic )
491 return thread[tid].lqFull();
498 list<unsigned>::iterator active_threads = (*activeThreads).begin();
500 while (active_threads != (*activeThreads).end()) {
501 unsigned tid = *active_threads++;
511 LSQ<Impl>::sqFull(unsigned tid)
513 //@todo: Change to Calculate All Entries for
515 if( lsqPolicy == Dynamic )
518 return thread[tid].sqFull();
523 LSQ<Impl>::isStalled()
525 list<unsigned>::iterator active_threads = (*activeThreads).begin();
527 while (active_threads != (*activeThreads).end()) {
528 unsigned tid = *active_threads++;
529 if (!thread[tid].isStalled())
538 LSQ<Impl>::isStalled(unsigned tid)
540 if( lsqPolicy == Dynamic )
543 return thread[tid].isStalled();
548 LSQ<Impl>::hasStoresToWB()
550 list<unsigned>::iterator active_threads = (*activeThreads).begin();
552 if ((*activeThreads).empty())
555 while (active_threads != (*activeThreads).end()) {
556 unsigned tid = *active_threads++;
557 if (!hasStoresToWB(tid))
568 list<unsigned>::iterator active_threads = (*activeThreads).begin();
570 while (active_threads != (*activeThreads).end()) {
571 unsigned tid = *active_threads++;
581 LSQ<Impl>::dumpInsts()
583 list<unsigned>::iterator active_threads = (*activeThreads).begin();
585 while (active_threads != (*activeThreads).end()) {
586 unsigned tid = *active_threads++;
587 thread[tid].dumpInsts();