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 DPRINTF(LSQ, "Creating LSQ object.\n");
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");
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);
148 } else if (policy == "threshold") {
149 lsqPolicy = Threshold;
151 assert(params->smtLSQThreshold > LQEntries);
152 assert(params->smtLSQThreshold > SQEntries);
154 //Divide up by threshold amount
155 //@todo: Should threads check the max and the total
157 maxLQEntries = params->smtLSQThreshold;
158 maxSQEntries = params->smtLSQThreshold;
160 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
161 "%i entries per LQ | %i entries per SQ",
162 maxLQEntries,maxSQEntries);
165 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
166 "Partitioned, Threshold}");
170 for (int tid=0; tid < numThreads; tid++) {
171 thread[tid].init(params, this, maxLQEntries, maxSQEntries, tid);
172 thread[tid].setDcachePort(&dcachePort);
179 LSQ<Impl>::name() const
181 return iewStage->name() + ".lsq";
186 LSQ<Impl>::regStats()
189 for (int tid=0; tid < numThreads; tid++) {
190 thread[tid].regStats();
196 LSQ<Impl>::setActiveThreads(std::list<unsigned> *at_ptr)
198 activeThreads = at_ptr;
199 assert(activeThreads != 0);
204 LSQ<Impl>::setCPU(O3CPU *cpu_ptr)
208 dcachePort.setName(name());
210 for (int tid=0; tid < numThreads; tid++) {
211 thread[tid].setCPU(cpu_ptr);
217 LSQ<Impl>::setIEW(IEW *iew_ptr)
221 for (int tid=0; tid < numThreads; tid++) {
222 thread[tid].setIEW(iew_ptr);
226 template <class Impl>
228 LSQ<Impl>::switchOut()
230 for (int tid = 0; tid < numThreads; tid++) {
231 thread[tid].switchOut();
235 template <class Impl>
237 LSQ<Impl>::takeOverFrom()
239 for (int tid = 0; tid < numThreads; tid++) {
240 thread[tid].takeOverFrom();
244 template <class Impl>
246 LSQ<Impl>::entryAmount(int num_threads)
248 if (lsqPolicy == Partitioned) {
249 return LQEntries / num_threads;
255 template <class Impl>
257 LSQ<Impl>::resetEntries()
259 if (lsqPolicy != Dynamic || numThreads > 1) {
260 int active_threads = activeThreads->size();
264 if (lsqPolicy == Partitioned) {
265 maxEntries = LQEntries / active_threads;
266 } else if (lsqPolicy == Threshold && active_threads == 1) {
267 maxEntries = LQEntries;
269 maxEntries = LQEntries;
272 std::list<unsigned>::iterator threads = activeThreads->begin();
273 std::list<unsigned>::iterator end = activeThreads->end();
275 while (threads != end) {
276 unsigned tid = *threads++;
278 resizeEntries(maxEntries, tid);
285 LSQ<Impl>::removeEntries(unsigned tid)
287 thread[tid].clearLQ();
288 thread[tid].clearSQ();
293 LSQ<Impl>::resizeEntries(unsigned size,unsigned tid)
295 thread[tid].resizeLQ(size);
296 thread[tid].resizeSQ(size);
303 std::list<unsigned>::iterator threads = activeThreads->begin();
304 std::list<unsigned>::iterator end = activeThreads->end();
306 while (threads != end) {
307 unsigned tid = *threads++;
315 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
317 unsigned tid = load_inst->threadNumber;
319 thread[tid].insertLoad(load_inst);
324 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
326 unsigned tid = store_inst->threadNumber;
328 thread[tid].insertStore(store_inst);
333 LSQ<Impl>::executeLoad(DynInstPtr &inst)
335 unsigned tid = inst->threadNumber;
337 return thread[tid].executeLoad(inst);
342 LSQ<Impl>::executeStore(DynInstPtr &inst)
344 unsigned tid = inst->threadNumber;
346 return thread[tid].executeStore(inst);
351 LSQ<Impl>::writebackStores()
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 (numStoresToWB(tid) > 0) {
360 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
361 "available for Writeback.\n", tid, numStoresToWB(tid));
364 thread[tid].writebackStores();
370 LSQ<Impl>::violation()
372 /* Answers: Does Anybody Have a Violation?*/
373 std::list<unsigned>::iterator threads = activeThreads->begin();
374 std::list<unsigned>::iterator end = activeThreads->end();
376 while (threads != end) {
377 unsigned tid = *threads++;
379 if (thread[tid].violation())
388 LSQ<Impl>::getCount()
392 std::list<unsigned>::iterator threads = activeThreads->begin();
393 std::list<unsigned>::iterator end = activeThreads->end();
395 while (threads != end) {
396 unsigned tid = *threads++;
398 total += getCount(tid);
406 LSQ<Impl>::numLoads()
410 std::list<unsigned>::iterator threads = activeThreads->begin();
411 std::list<unsigned>::iterator end = activeThreads->end();
413 while (threads != end) {
414 unsigned tid = *threads++;
416 total += numLoads(tid);
424 LSQ<Impl>::numStores()
428 std::list<unsigned>::iterator threads = activeThreads->begin();
429 std::list<unsigned>::iterator end = activeThreads->end();
431 while (threads != end) {
432 unsigned tid = *threads++;
434 total += thread[tid].numStores();
442 LSQ<Impl>::numLoadsReady()
446 std::list<unsigned>::iterator threads = activeThreads->begin();
447 std::list<unsigned>::iterator end = activeThreads->end();
449 while (threads != end) {
450 unsigned tid = *threads++;
452 total += thread[tid].numLoadsReady();
460 LSQ<Impl>::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 total += thread[tid].numFreeEntries();
478 LSQ<Impl>::numFreeEntries(unsigned tid)
480 //if (lsqPolicy == Dynamic)
481 //return numFreeEntries();
483 return thread[tid].numFreeEntries();
490 std::list<unsigned>::iterator threads = activeThreads->begin();
491 std::list<unsigned>::iterator end = activeThreads->end();
493 while (threads != end) {
494 unsigned tid = *threads++;
496 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
505 LSQ<Impl>::isFull(unsigned tid)
507 //@todo: Change to Calculate All Entries for
509 if (lsqPolicy == Dynamic)
512 return thread[tid].lqFull() || thread[tid].sqFull();
519 std::list<unsigned>::iterator threads = activeThreads->begin();
520 std::list<unsigned>::iterator end = activeThreads->end();
522 while (threads != end) {
523 unsigned tid = *threads++;
525 if (!thread[tid].lqFull())
534 LSQ<Impl>::lqFull(unsigned tid)
536 //@todo: Change to Calculate All Entries for
538 if (lsqPolicy == Dynamic)
541 return thread[tid].lqFull();
548 std::list<unsigned>::iterator threads = activeThreads->begin();
549 std::list<unsigned>::iterator end = activeThreads->end();
551 while (threads != end) {
552 unsigned tid = *threads++;
563 LSQ<Impl>::sqFull(unsigned tid)
565 //@todo: Change to Calculate All Entries for
567 if (lsqPolicy == Dynamic)
570 return thread[tid].sqFull();
575 LSQ<Impl>::isStalled()
577 std::list<unsigned>::iterator threads = activeThreads->begin();
578 std::list<unsigned>::iterator end = activeThreads->end();
580 while (threads != end) {
581 unsigned tid = *threads++;
583 if (!thread[tid].isStalled())
592 LSQ<Impl>::isStalled(unsigned tid)
594 if (lsqPolicy == Dynamic)
597 return thread[tid].isStalled();
602 LSQ<Impl>::hasStoresToWB()
604 std::list<unsigned>::iterator threads = activeThreads->begin();
605 std::list<unsigned>::iterator end = activeThreads->end();
610 while (threads != end) {
611 unsigned tid = *threads++;
613 if (!hasStoresToWB(tid))
624 std::list<unsigned>::iterator threads = activeThreads->begin();
625 std::list<unsigned>::iterator end = activeThreads->end();
627 while (threads != end) {
628 unsigned tid = *threads++;
639 LSQ<Impl>::dumpInsts()
641 std::list<unsigned>::iterator threads = activeThreads->begin();
642 std::list<unsigned>::iterator end = activeThreads->end();
644 while (threads != end) {
645 unsigned tid = *threads++;
647 thread[tid].dumpInsts();