2 * Copyright (c) 2011-2012 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2005-2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Authors: Korey Sewell
47 #include "cpu/o3/lsq.hh"
48 #include "debug/Fetch.hh"
49 #include "debug/LSQ.hh"
50 #include "debug/Writeback.hh"
51 #include "params/DerivO3CPU.hh"
56 LSQ<Impl>::LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
57 : cpu(cpu_ptr), iewStage(iew_ptr),
58 LQEntries(params->LQEntries),
59 SQEntries(params->SQEntries),
60 numThreads(params->numThreads),
63 //**********************************************/
64 //************ Handle SMT Parameters ***********/
65 //**********************************************/
66 std::string policy = params->smtLSQPolicy;
68 //Convert string to lowercase
69 std::transform(policy.begin(), policy.end(), policy.begin(),
70 (int(*)(int)) tolower);
72 //Figure out fetch policy
73 if (policy == "dynamic") {
76 maxLQEntries = LQEntries;
77 maxSQEntries = SQEntries;
79 DPRINTF(LSQ, "LSQ sharing policy set to Dynamic\n");
80 } else if (policy == "partitioned") {
81 lsqPolicy = Partitioned;
83 //@todo:make work if part_amt doesnt divide evenly.
84 maxLQEntries = LQEntries / numThreads;
85 maxSQEntries = SQEntries / numThreads;
87 DPRINTF(Fetch, "LSQ sharing policy set to Partitioned: "
88 "%i entries per LQ | %i entries per SQ\n",
89 maxLQEntries,maxSQEntries);
90 } else if (policy == "threshold") {
91 lsqPolicy = Threshold;
93 assert(params->smtLSQThreshold > LQEntries);
94 assert(params->smtLSQThreshold > SQEntries);
96 //Divide up by threshold amount
97 //@todo: Should threads check the max and the total
99 maxLQEntries = params->smtLSQThreshold;
100 maxSQEntries = params->smtLSQThreshold;
102 DPRINTF(LSQ, "LSQ sharing policy set to Threshold: "
103 "%i entries per LQ | %i entries per SQ\n",
104 maxLQEntries,maxSQEntries);
106 assert(0 && "Invalid LSQ Sharing Policy.Options Are:{Dynamic,"
107 "Partitioned, Threshold}");
111 for (ThreadID tid = 0; tid < numThreads; tid++) {
112 thread[tid].init(cpu, iew_ptr, params, this,
113 maxLQEntries, maxSQEntries, tid);
114 thread[tid].setDcachePort(&cpu_ptr->getDataPort());
121 LSQ<Impl>::name() const
123 return iewStage->name() + ".lsq";
128 LSQ<Impl>::regStats()
131 for (ThreadID tid = 0; tid < numThreads; tid++) {
132 thread[tid].regStats();
138 LSQ<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
140 activeThreads = at_ptr;
141 assert(activeThreads != 0);
144 template <class Impl>
146 LSQ<Impl>::switchOut()
148 for (ThreadID tid = 0; tid < numThreads; tid++) {
149 thread[tid].switchOut();
153 template <class Impl>
155 LSQ<Impl>::takeOverFrom()
157 for (ThreadID tid = 0; tid < numThreads; tid++) {
158 thread[tid].takeOverFrom();
162 template <class Impl>
164 LSQ<Impl>::entryAmount(ThreadID num_threads)
166 if (lsqPolicy == Partitioned) {
167 return LQEntries / num_threads;
173 template <class Impl>
175 LSQ<Impl>::resetEntries()
177 if (lsqPolicy != Dynamic || numThreads > 1) {
178 int active_threads = activeThreads->size();
182 if (lsqPolicy == Partitioned) {
183 maxEntries = LQEntries / active_threads;
184 } else if (lsqPolicy == Threshold && active_threads == 1) {
185 maxEntries = LQEntries;
187 maxEntries = LQEntries;
190 list<ThreadID>::iterator threads = activeThreads->begin();
191 list<ThreadID>::iterator end = activeThreads->end();
193 while (threads != end) {
194 ThreadID tid = *threads++;
196 resizeEntries(maxEntries, tid);
203 LSQ<Impl>::removeEntries(ThreadID tid)
205 thread[tid].clearLQ();
206 thread[tid].clearSQ();
211 LSQ<Impl>::resizeEntries(unsigned size, ThreadID tid)
213 thread[tid].resizeLQ(size);
214 thread[tid].resizeSQ(size);
221 list<ThreadID>::iterator threads = activeThreads->begin();
222 list<ThreadID>::iterator end = activeThreads->end();
224 while (threads != end) {
225 ThreadID tid = *threads++;
233 LSQ<Impl>::insertLoad(DynInstPtr &load_inst)
235 ThreadID tid = load_inst->threadNumber;
237 thread[tid].insertLoad(load_inst);
242 LSQ<Impl>::insertStore(DynInstPtr &store_inst)
244 ThreadID tid = store_inst->threadNumber;
246 thread[tid].insertStore(store_inst);
251 LSQ<Impl>::executeLoad(DynInstPtr &inst)
253 ThreadID tid = inst->threadNumber;
255 return thread[tid].executeLoad(inst);
260 LSQ<Impl>::executeStore(DynInstPtr &inst)
262 ThreadID tid = inst->threadNumber;
264 return thread[tid].executeStore(inst);
269 LSQ<Impl>::writebackStores()
271 list<ThreadID>::iterator threads = activeThreads->begin();
272 list<ThreadID>::iterator end = activeThreads->end();
274 while (threads != end) {
275 ThreadID tid = *threads++;
277 if (numStoresToWB(tid) > 0) {
278 DPRINTF(Writeback,"[tid:%i] Writing back stores. %i stores "
279 "available for Writeback.\n", tid, numStoresToWB(tid));
282 thread[tid].writebackStores();
288 LSQ<Impl>::violation()
290 /* Answers: Does Anybody Have a Violation?*/
291 list<ThreadID>::iterator threads = activeThreads->begin();
292 list<ThreadID>::iterator end = activeThreads->end();
294 while (threads != end) {
295 ThreadID tid = *threads++;
297 if (thread[tid].violation())
304 template <class Impl>
306 LSQ<Impl>::recvRetry()
308 if (retryTid == InvalidThreadID)
310 //Squashed, so drop it
313 int curr_retry_tid = retryTid;
314 // Speculatively clear the retry Tid. This will get set again if
315 // the LSQUnit was unable to complete its access.
317 thread[curr_retry_tid].recvRetry();
320 template <class Impl>
322 LSQ<Impl>::recvTimingResp(PacketPtr pkt)
325 DPRINTF(LSQ, "Got error packet back for address: %#X\n",
327 thread[pkt->req->threadId()].completeDataAccess(pkt);
331 template <class Impl>
333 LSQ<Impl>::recvTimingSnoopReq(PacketPtr pkt)
335 DPRINTF(LSQ, "received pkt for addr:%#x %s\n", pkt->getAddr(),
339 if (pkt->isInvalidate()) {
340 DPRINTF(LSQ, "received invalidation for addr:%#x\n",
342 for (ThreadID tid = 0; tid < numThreads; tid++) {
343 thread[tid].checkSnoop(pkt);
350 LSQ<Impl>::getCount()
354 list<ThreadID>::iterator threads = activeThreads->begin();
355 list<ThreadID>::iterator end = activeThreads->end();
357 while (threads != end) {
358 ThreadID tid = *threads++;
360 total += getCount(tid);
368 LSQ<Impl>::numLoads()
372 list<ThreadID>::iterator threads = activeThreads->begin();
373 list<ThreadID>::iterator end = activeThreads->end();
375 while (threads != end) {
376 ThreadID tid = *threads++;
378 total += numLoads(tid);
386 LSQ<Impl>::numStores()
390 list<ThreadID>::iterator threads = activeThreads->begin();
391 list<ThreadID>::iterator end = activeThreads->end();
393 while (threads != end) {
394 ThreadID tid = *threads++;
396 total += thread[tid].numStores();
404 LSQ<Impl>::numFreeEntries()
408 list<ThreadID>::iterator threads = activeThreads->begin();
409 list<ThreadID>::iterator end = activeThreads->end();
411 while (threads != end) {
412 ThreadID tid = *threads++;
414 total += thread[tid].numFreeEntries();
422 LSQ<Impl>::numFreeEntries(ThreadID tid)
424 //if (lsqPolicy == Dynamic)
425 //return numFreeEntries();
427 return thread[tid].numFreeEntries();
434 list<ThreadID>::iterator threads = activeThreads->begin();
435 list<ThreadID>::iterator end = activeThreads->end();
437 while (threads != end) {
438 ThreadID tid = *threads++;
440 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
449 LSQ<Impl>::isFull(ThreadID tid)
451 //@todo: Change to Calculate All Entries for
453 if (lsqPolicy == Dynamic)
456 return thread[tid].lqFull() || thread[tid].sqFull();
463 list<ThreadID>::iterator threads = activeThreads->begin();
464 list<ThreadID>::iterator end = activeThreads->end();
466 while (threads != end) {
467 ThreadID tid = *threads++;
469 if (!thread[tid].lqFull())
478 LSQ<Impl>::lqFull(ThreadID tid)
480 //@todo: Change to Calculate All Entries for
482 if (lsqPolicy == Dynamic)
485 return thread[tid].lqFull();
492 list<ThreadID>::iterator threads = activeThreads->begin();
493 list<ThreadID>::iterator end = activeThreads->end();
495 while (threads != end) {
496 ThreadID tid = *threads++;
507 LSQ<Impl>::sqFull(ThreadID tid)
509 //@todo: Change to Calculate All Entries for
511 if (lsqPolicy == Dynamic)
514 return thread[tid].sqFull();
519 LSQ<Impl>::isStalled()
521 list<ThreadID>::iterator threads = activeThreads->begin();
522 list<ThreadID>::iterator end = activeThreads->end();
524 while (threads != end) {
525 ThreadID tid = *threads++;
527 if (!thread[tid].isStalled())
536 LSQ<Impl>::isStalled(ThreadID tid)
538 if (lsqPolicy == Dynamic)
541 return thread[tid].isStalled();
546 LSQ<Impl>::hasStoresToWB()
548 list<ThreadID>::iterator threads = activeThreads->begin();
549 list<ThreadID>::iterator end = activeThreads->end();
551 while (threads != end) {
552 ThreadID tid = *threads++;
554 if (hasStoresToWB(tid))
565 list<ThreadID>::iterator threads = activeThreads->begin();
566 list<ThreadID>::iterator end = activeThreads->end();
568 while (threads != end) {
569 ThreadID tid = *threads++;
580 LSQ<Impl>::dumpInsts()
582 list<ThreadID>::iterator threads = activeThreads->begin();
583 list<ThreadID>::iterator end = activeThreads->end();
585 while (threads != end) {
586 ThreadID tid = *threads++;
588 thread[tid].dumpInsts();