2 * Copyright (c) 2004-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
31 #ifndef __CPU_O3_LSQ_HH__
32 #define __CPU_O3_LSQ_HH__
37 #include "config/full_system.hh"
38 #include "cpu/o3/lsq_unit.hh"
39 #include "cpu/inst_seq.hh"
40 #include "mem/port.hh"
41 #include "sim/sim_object.hh"
43 class DerivO3CPUParams;
48 typedef typename Impl::O3CPU O3CPU;
49 typedef typename Impl::DynInstPtr DynInstPtr;
50 typedef typename Impl::CPUPol::IEW IEW;
51 typedef typename Impl::CPUPol::LSQUnit LSQUnit;
60 /** Constructs an LSQ with the given parameters. */
61 LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params);
63 /** Returns the name of the LSQ. */
64 std::string name() const;
66 /** Registers statistics of each LSQ unit. */
69 /** Returns dcache port.
70 * @todo: Dcache port needs to be moved up to this level for SMT
71 * to work. For now it just returns the port from one of the
74 Port *getDcachePort() { return &dcachePort; }
76 /** Sets the pointer to the list of active threads. */
77 void setActiveThreads(std::list<ThreadID> *at_ptr);
78 /** Switches out the LSQ. */
80 /** Takes over execution from another CPU's thread. */
83 /** Number of entries needed for the given amount of threads.*/
84 int entryAmount(ThreadID num_threads);
85 void removeEntries(ThreadID tid);
86 /** Reset the max entries for each thread. */
88 /** Resize the max entries for a thread. */
89 void resizeEntries(unsigned size, ThreadID tid);
93 /** Ticks a specific LSQ Unit. */
94 void tick(ThreadID tid)
95 { thread[tid].tick(); }
97 /** Inserts a load into the LSQ. */
98 void insertLoad(DynInstPtr &load_inst);
99 /** Inserts a store into the LSQ. */
100 void insertStore(DynInstPtr &store_inst);
102 /** Executes a load. */
103 Fault executeLoad(DynInstPtr &inst);
105 /** Executes a store. */
106 Fault executeStore(DynInstPtr &inst);
109 * Commits loads up until the given sequence number for a specific thread.
111 void commitLoads(InstSeqNum &youngest_inst, ThreadID tid)
112 { thread[tid].commitLoads(youngest_inst); }
115 * Commits stores up until the given sequence number for a specific thread.
117 void commitStores(InstSeqNum &youngest_inst, ThreadID tid)
118 { thread[tid].commitStores(youngest_inst); }
121 * Attempts to write back stores until all cache ports are used or the
122 * interface becomes blocked.
124 void writebackStores();
125 /** Same as above, but only for one thread. */
126 void writebackStores(ThreadID tid);
129 * Squash instructions from a thread until the specified sequence number.
131 void squash(const InstSeqNum &squashed_num, ThreadID tid)
132 { thread[tid].squash(squashed_num); }
134 /** Returns whether or not there was a memory ordering violation. */
137 * Returns whether or not there was a memory ordering violation for a
140 bool violation(ThreadID tid)
141 { return thread[tid].violation(); }
143 /** Returns if a load is blocked due to the memory system for a specific
146 bool loadBlocked(ThreadID tid)
147 { return thread[tid].loadBlocked(); }
149 bool isLoadBlockedHandled(ThreadID tid)
150 { return thread[tid].isLoadBlockedHandled(); }
152 void setLoadBlockedHandled(ThreadID tid)
153 { thread[tid].setLoadBlockedHandled(); }
155 /** Gets the instruction that caused the memory ordering violation. */
156 DynInstPtr getMemDepViolator(ThreadID tid)
157 { return thread[tid].getMemDepViolator(); }
159 /** Returns the head index of the load queue for a specific thread. */
160 int getLoadHead(ThreadID tid)
161 { return thread[tid].getLoadHead(); }
163 /** Returns the sequence number of the head of the load queue. */
164 InstSeqNum getLoadHeadSeqNum(ThreadID tid)
166 return thread[tid].getLoadHeadSeqNum();
169 /** Returns the head index of the store queue. */
170 int getStoreHead(ThreadID tid)
171 { return thread[tid].getStoreHead(); }
173 /** Returns the sequence number of the head of the store queue. */
174 InstSeqNum getStoreHeadSeqNum(ThreadID tid)
176 return thread[tid].getStoreHeadSeqNum();
179 /** Returns the number of instructions in all of the queues. */
181 /** Returns the number of instructions in the queues of one thread. */
182 int getCount(ThreadID tid)
183 { return thread[tid].getCount(); }
185 /** Returns the total number of loads in the load queue. */
187 /** Returns the total number of loads for a single thread. */
188 int numLoads(ThreadID tid)
189 { return thread[tid].numLoads(); }
191 /** Returns the total number of stores in the store queue. */
193 /** Returns the total number of stores for a single thread. */
194 int numStores(ThreadID tid)
195 { return thread[tid].numStores(); }
197 /** Returns the total number of loads that are ready. */
199 /** Returns the number of loads that are ready for a single thread. */
200 int numLoadsReady(ThreadID tid)
201 { return thread[tid].numLoadsReady(); }
203 /** Returns the number of free entries. */
204 unsigned numFreeEntries();
205 /** Returns the number of free entries for a specific thread. */
206 unsigned numFreeEntries(ThreadID tid);
208 /** Returns if the LSQ is full (either LQ or SQ is full). */
211 * Returns if the LSQ is full for a specific thread (either LQ or SQ is
214 bool isFull(ThreadID tid);
216 /** Returns if any of the LQs are full. */
218 /** Returns if the LQ of a given thread is full. */
219 bool lqFull(ThreadID tid);
221 /** Returns if any of the SQs are full. */
223 /** Returns if the SQ of a given thread is full. */
224 bool sqFull(ThreadID tid);
227 * Returns if the LSQ is stalled due to a memory operation that must be
232 * Returns if the LSQ of a specific thread is stalled due to a memory
233 * operation that must be replayed.
235 bool isStalled(ThreadID tid);
237 /** Returns whether or not there are any stores to write back to memory. */
238 bool hasStoresToWB();
240 /** Returns whether or not a specific thread has any stores to write back
243 bool hasStoresToWB(ThreadID tid)
244 { return thread[tid].hasStoresToWB(); }
246 /** Returns the number of stores a specific thread has to write back. */
247 int numStoresToWB(ThreadID tid)
248 { return thread[tid].numStoresToWB(); }
250 /** Returns if the LSQ will write back to memory this cycle. */
252 /** Returns if the LSQ of a specific thread will write back to memory this
255 bool willWB(ThreadID tid)
256 { return thread[tid].willWB(); }
258 /** Returns if the cache is currently blocked. */
260 { return retryTid != InvalidThreadID; }
262 /** Sets the retry thread id, indicating that one of the LSQUnits
263 * tried to access the cache but the cache was blocked. */
264 void setRetryTid(ThreadID tid)
267 /** Debugging function to print out all instructions. */
269 /** Debugging function to print out instructions from a specific thread. */
270 void dumpInsts(ThreadID tid)
271 { thread[tid].dumpInsts(); }
273 /** Executes a read operation, using the load specified at the load
276 Fault read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
277 uint8_t *data, int load_idx);
279 /** Executes a store operation, using the store specified at the store
282 Fault write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
283 uint8_t *data, int store_idx);
285 /** The CPU pointer. */
288 /** The IEW stage pointer. */
291 /** DcachePort class for this LSQ. Handles doing the
292 * communication with the cache/memory.
294 class DcachePort : public Port
297 /** Pointer to LSQ. */
301 /** Default constructor. */
302 DcachePort(LSQ *_lsq)
303 : Port(_lsq->name() + "-dport", _lsq->cpu), lsq(_lsq)
308 virtual void setPeer(Port *port);
311 /** Atomic version of receive. Panics. */
312 virtual Tick recvAtomic(PacketPtr pkt);
314 /** Functional version of receive. Panics. */
315 virtual void recvFunctional(PacketPtr pkt);
317 /** Receives status change. Other than range changing, panics. */
318 virtual void recvStatusChange(Status status);
320 /** Returns the address ranges of this device. */
321 virtual void getDeviceAddressRanges(AddrRangeList &resp,
323 { resp.clear(); snoop = true; }
325 /** Timing version of receive. Handles writing back and
326 * completing the load or store that has returned from
328 virtual bool recvTiming(PacketPtr pkt);
330 /** Handles doing a retry of the previous send. */
331 virtual void recvRetry();
335 DcachePort dcachePort;
338 /** Tell the CPU to update the Phys and Virt ports. */
339 void updateMemPorts() { cpu->updateMemPorts(); }
343 /** The LSQ policy for SMT mode. */
346 /** The LSQ units for individual threads. */
347 LSQUnit thread[Impl::MaxThreads];
349 /** List of Active Threads in System. */
350 std::list<ThreadID> *activeThreads;
352 /** Total Size of LQ Entries. */
354 /** Total Size of SQ Entries. */
357 /** Max LQ Size - Used to Enforce Sharing Policies. */
358 unsigned maxLQEntries;
360 /** Max SQ Size - Used to Enforce Sharing Policies. */
361 unsigned maxSQEntries;
363 /** Number of Threads. */
366 /** The thread id of the LSQ Unit that is currently waiting for a
371 template <class Impl>
373 LSQ<Impl>::read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
374 uint8_t *data, int load_idx)
376 ThreadID tid = req->threadId();
378 return thread[tid].read(req, sreqLow, sreqHigh, data, load_idx);
381 template <class Impl>
383 LSQ<Impl>::write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
384 uint8_t *data, int store_idx)
386 ThreadID tid = req->threadId();
388 return thread[tid].write(req, sreqLow, sreqHigh, data, store_idx);
391 #endif // __CPU_O3_LSQ_HH__