2 * Copyright (c) 2011 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->getDcachePort());
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>::recvTiming(PacketPtr pkt)
325 DPRINTF(LSQ, "Got error packet back for address: %#X\n",
327 if (pkt->isResponse()) {
328 thread[pkt->req->threadId()].completeDataAccess(pkt);
330 DPRINTF(LSQ, "received pkt for addr:%#x %s\n", pkt->getAddr(),
334 if (pkt->isInvalidate()) {
335 DPRINTF(LSQ, "received invalidation for addr:%#x\n",
337 for (ThreadID tid = 0; tid < numThreads; tid++) {
338 thread[tid].checkSnoop(pkt);
341 // to provide stronger consistency model
348 LSQ<Impl>::getCount()
352 list<ThreadID>::iterator threads = activeThreads->begin();
353 list<ThreadID>::iterator end = activeThreads->end();
355 while (threads != end) {
356 ThreadID tid = *threads++;
358 total += getCount(tid);
366 LSQ<Impl>::numLoads()
370 list<ThreadID>::iterator threads = activeThreads->begin();
371 list<ThreadID>::iterator end = activeThreads->end();
373 while (threads != end) {
374 ThreadID tid = *threads++;
376 total += numLoads(tid);
384 LSQ<Impl>::numStores()
388 list<ThreadID>::iterator threads = activeThreads->begin();
389 list<ThreadID>::iterator end = activeThreads->end();
391 while (threads != end) {
392 ThreadID tid = *threads++;
394 total += thread[tid].numStores();
402 LSQ<Impl>::numLoadsReady()
406 list<ThreadID>::iterator threads = activeThreads->begin();
407 list<ThreadID>::iterator end = activeThreads->end();
409 while (threads != end) {
410 ThreadID tid = *threads++;
412 total += thread[tid].numLoadsReady();
420 LSQ<Impl>::numFreeEntries()
424 list<ThreadID>::iterator threads = activeThreads->begin();
425 list<ThreadID>::iterator end = activeThreads->end();
427 while (threads != end) {
428 ThreadID tid = *threads++;
430 total += thread[tid].numFreeEntries();
438 LSQ<Impl>::numFreeEntries(ThreadID tid)
440 //if (lsqPolicy == Dynamic)
441 //return numFreeEntries();
443 return thread[tid].numFreeEntries();
450 list<ThreadID>::iterator threads = activeThreads->begin();
451 list<ThreadID>::iterator end = activeThreads->end();
453 while (threads != end) {
454 ThreadID tid = *threads++;
456 if (!(thread[tid].lqFull() || thread[tid].sqFull()))
465 LSQ<Impl>::isFull(ThreadID tid)
467 //@todo: Change to Calculate All Entries for
469 if (lsqPolicy == Dynamic)
472 return thread[tid].lqFull() || thread[tid].sqFull();
479 list<ThreadID>::iterator threads = activeThreads->begin();
480 list<ThreadID>::iterator end = activeThreads->end();
482 while (threads != end) {
483 ThreadID tid = *threads++;
485 if (!thread[tid].lqFull())
494 LSQ<Impl>::lqFull(ThreadID tid)
496 //@todo: Change to Calculate All Entries for
498 if (lsqPolicy == Dynamic)
501 return thread[tid].lqFull();
508 list<ThreadID>::iterator threads = activeThreads->begin();
509 list<ThreadID>::iterator end = activeThreads->end();
511 while (threads != end) {
512 ThreadID tid = *threads++;
523 LSQ<Impl>::sqFull(ThreadID tid)
525 //@todo: Change to Calculate All Entries for
527 if (lsqPolicy == Dynamic)
530 return thread[tid].sqFull();
535 LSQ<Impl>::isStalled()
537 list<ThreadID>::iterator threads = activeThreads->begin();
538 list<ThreadID>::iterator end = activeThreads->end();
540 while (threads != end) {
541 ThreadID tid = *threads++;
543 if (!thread[tid].isStalled())
552 LSQ<Impl>::isStalled(ThreadID tid)
554 if (lsqPolicy == Dynamic)
557 return thread[tid].isStalled();
562 LSQ<Impl>::hasStoresToWB()
564 list<ThreadID>::iterator threads = activeThreads->begin();
565 list<ThreadID>::iterator end = activeThreads->end();
567 while (threads != end) {
568 ThreadID tid = *threads++;
570 if (hasStoresToWB(tid))
581 list<ThreadID>::iterator threads = activeThreads->begin();
582 list<ThreadID>::iterator end = activeThreads->end();
584 while (threads != end) {
585 ThreadID tid = *threads++;
596 LSQ<Impl>::dumpInsts()
598 list<ThreadID>::iterator threads = activeThreads->begin();
599 list<ThreadID>::iterator end = activeThreads->end();
601 while (threads != end) {
602 ThreadID tid = *threads++;
604 thread[tid].dumpInsts();