gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lsq.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012, 2014 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2004-2006 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Korey Sewell
42  */
43 
44 #ifndef __CPU_O3_LSQ_HH__
45 #define __CPU_O3_LSQ_HH__
46 
47 #include <map>
48 #include <queue>
49 
50 #include "cpu/o3/lsq_unit.hh"
51 #include "cpu/inst_seq.hh"
52 #include "mem/port.hh"
53 #include "sim/sim_object.hh"
54 
55 struct DerivO3CPUParams;
56 
57 template <class Impl>
58 class LSQ {
59  public:
60  typedef typename Impl::O3CPU O3CPU;
61  typedef typename Impl::DynInstPtr DynInstPtr;
62  typedef typename Impl::CPUPol::IEW IEW;
63  typedef typename Impl::CPUPol::LSQUnit LSQUnit;
64 
66  enum LSQPolicy {
70  };
71 
73  LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params);
74  ~LSQ() {
75  if (thread) delete [] thread;
76  }
77 
79  std::string name() const;
80 
82  void regStats();
83 
86 
88  void drainSanityCheck() const;
90  bool isDrained() const;
92  void takeOverFrom();
93 
95  int entryAmount(ThreadID num_threads);
96  void removeEntries(ThreadID tid);
98  void resetEntries();
100  void resizeEntries(unsigned size, ThreadID tid);
101 
103  void tick();
105  void tick(ThreadID tid)
106  { thread[tid].tick(); }
107 
109  void insertLoad(DynInstPtr &load_inst);
111  void insertStore(DynInstPtr &store_inst);
112 
115 
118 
122  void commitLoads(InstSeqNum &youngest_inst, ThreadID tid)
123  { thread[tid].commitLoads(youngest_inst); }
124 
128  void commitStores(InstSeqNum &youngest_inst, ThreadID tid)
129  { thread[tid].commitStores(youngest_inst); }
130 
135  void writebackStores();
137  void writebackStores(ThreadID tid);
138 
142  void squash(const InstSeqNum &squashed_num, ThreadID tid)
143  { thread[tid].squash(squashed_num); }
144 
146  bool violation();
151  bool violation(ThreadID tid)
152  { return thread[tid].violation(); }
153 
156  { return thread[tid].getMemDepViolator(); }
157 
160  { return thread[tid].getLoadHead(); }
161 
164  {
165  return thread[tid].getLoadHeadSeqNum();
166  }
167 
170  { return thread[tid].getStoreHead(); }
171 
174  {
175  return thread[tid].getStoreHeadSeqNum();
176  }
177 
179  int getCount();
182  { return thread[tid].getCount(); }
183 
185  int numLoads();
188  { return thread[tid].numLoads(); }
189 
191  int numStores();
194  { return thread[tid].numStores(); }
195 
197  unsigned numFreeLoadEntries();
198 
200  unsigned numFreeStoreEntries();
201 
203  unsigned numFreeEntries(ThreadID tid);
204 
206  unsigned numFreeLoadEntries(ThreadID tid);
207 
209  unsigned numFreeStoreEntries(ThreadID tid);
210 
212  bool isFull();
217  bool isFull(ThreadID tid);
218 
220  bool isEmpty() const;
222  bool lqEmpty() const;
224  bool sqEmpty() const;
225 
227  bool lqFull();
229  bool lqFull(ThreadID tid);
230 
232  bool sqFull();
234  bool sqFull(ThreadID tid);
235 
240  bool isStalled();
245  bool isStalled(ThreadID tid);
246 
248  bool hasStoresToWB();
249 
254  { return thread[tid].hasStoresToWB(); }
255 
258  { return thread[tid].numStoresToWB(); }
259 
261  bool willWB();
265  bool willWB(ThreadID tid)
266  { return thread[tid].willWB(); }
267 
269  void dumpInsts() const;
271  void dumpInsts(ThreadID tid) const
272  { thread[tid].dumpInsts(); }
273 
277  Fault read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
278  int load_idx);
279 
283  Fault write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh,
284  uint8_t *data, int store_idx);
285 
289  void recvReqRetry();
290 
297  bool recvTimingResp(PacketPtr pkt);
298 
299  void recvTimingSnoopReq(PacketPtr pkt);
300 
303 
306 
307  protected:
310 
313 
316 
318  unsigned LQEntries;
320  unsigned SQEntries;
321 
323  unsigned maxLQEntries;
324 
326  unsigned maxSQEntries;
327 
330 };
331 
332 template <class Impl>
333 Fault
335  int load_idx)
336 {
337  ThreadID tid = cpu->contextToThread(req->contextId());
338 
339  return thread[tid].read(req, sreqLow, sreqHigh, load_idx);
340 }
341 
342 template <class Impl>
343 Fault
345  uint8_t *data, int store_idx)
346 {
347  ThreadID tid = cpu->contextToThread(req->contextId());
348 
349  return thread[tid].write(req, sreqLow, sreqHigh, data, store_idx);
350 }
351 
352 #endif // __CPU_O3_LSQ_HH__
IEW * iewStage
The IEW stage pointer.
Definition: lsq.hh:305
int getStoreHead()
Returns the index of the head store instruction.
Definition: lsq_unit.hh:534
unsigned SQEntries
Total Size of SQ Entries.
Definition: lsq.hh:320
void takeOverFrom()
Takes over execution from another CPU's thread.
Definition: lsq_impl.hh:182
void squash(const InstSeqNum &squashed_num)
Squashes all instructions younger than a specific sequence number.
void resetEntries()
Reset the max entries for each thread.
Definition: lsq_impl.hh:202
ThreadID numThreads
Number of Threads.
Definition: lsq.hh:329
int getLoadHead()
Returns the index of the head load instruction.
Definition: lsq_unit.hh:521
Impl::DynInstPtr DynInstPtr
Definition: lsq.hh:61
bool hasStoresToWB()
Returns if there are any stores to writeback.
Definition: lsq_unit.hh:218
int getCount(ThreadID tid)
Returns the number of instructions in the queues of one thread.
Definition: lsq.hh:181
unsigned LQEntries
Total Size of LQ Entries.
Definition: lsq.hh:318
bool willWB()
Returns if the LSQ will write back to memory this cycle.
Definition: lsq_impl.hh:673
void tick(ThreadID tid)
Ticks a specific LSQ Unit.
Definition: lsq.hh:105
int numStores()
Returns the number of stores in the SQ.
Definition: lsq_unit.hh:194
Fault write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, uint8_t *data, int store_idx)
Executes a store operation, using the store specified at the store index.
Definition: lsq.hh:344
ContextID contextId() const
Accessor function for context ID.
Definition: request.hh:694
unsigned maxSQEntries
Max SQ Size - Used to Enforce Sharing Policies.
Definition: lsq.hh:326
bool violation()
Returns if there is a memory ordering violation.
Definition: lsq_unit.hh:179
void dumpInsts() const
Debugging function to print out all instructions.
Definition: lsq_impl.hh:690
DynInstPtr getMemDepViolator()
Returns the memory ordering violator.
void removeEntries(ThreadID tid)
Definition: lsq_impl.hh:230
void tick()
Ticks the LSQ.
Definition: lsq_impl.hh:246
bool sqFull()
Returns if any of the SQs are full.
Definition: lsq_impl.hh:600
Fault read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, int load_idx)
Executes a read operation, using the load specified at the load index.
Definition: lsq.hh:334
std::string name() const
Returns the name of the LSQ.
Definition: lsq_impl.hh:128
bool violation()
Returns whether or not there was a memory ordering violation.
Definition: lsq_impl.hh:315
bool hasStoresToWB()
Returns whether or not there are any stores to write back to memory.
Definition: lsq_impl.hh:656
Port Object Declaration.
Fault executeLoad(DynInstPtr &inst)
Executes a load.
Definition: lsq_impl.hh:278
bool isFull()
Returns if the LSQ is full (either LQ or SQ is full).
Definition: lsq_impl.hh:501
int numLoads()
Returns the number of loads in the LQ.
Definition: lsq_unit.hh:191
Definition: lsq.hh:58
int getLoadHead(ThreadID tid)
Returns the head index of the load queue for a specific thread.
Definition: lsq.hh:159
bool hasStoresToWB(ThreadID tid)
Returns whether or not a specific thread has any stores to write back to memory.
Definition: lsq.hh:253
void writebackStores()
Attempts to write back stores until all cache ports are used or the interface becomes blocked...
Definition: lsq_impl.hh:296
const char data[]
Definition: circlebuf.cc:43
void commitStores(InstSeqNum &youngest_inst)
Commits stores older than a specific sequence number.
bool violation(ThreadID tid)
Returns whether or not there was a memory ordering violation for a specific thread.
Definition: lsq.hh:151
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: lsq_impl.hh:153
void dumpInsts(ThreadID tid) const
Debugging function to print out instructions from a specific thread.
Definition: lsq.hh:271
bool willWB(ThreadID tid)
Returns if the LSQ of a specific thread will write back to memory this cycle.
Definition: lsq.hh:265
InstSeqNum getStoreHeadSeqNum()
Returns the sequence number of the head store instruction.
Definition: lsq_unit.hh:536
Impl::CPUPol::LSQUnit LSQUnit
Definition: lsq.hh:63
bool willWB()
Returns if the LSQ unit will writeback on this cycle.
Definition: lsq_unit.hh:224
unsigned numFreeStoreEntries()
Returns the number of free store entries.
Definition: lsq_impl.hh:469
InstSeqNum getLoadHeadSeqNum(ThreadID tid)
Returns the sequence number of the head of the load queue.
Definition: lsq.hh:163
void insertStore(DynInstPtr &store_inst)
Inserts a store into the LSQ.
Definition: lsq_impl.hh:269
void resizeEntries(unsigned size, ThreadID tid)
Resize the max entries for a thread.
Definition: lsq_impl.hh:238
int numStores(ThreadID tid)
Returns the total number of stores for a single thread.
Definition: lsq.hh:193
void dumpInsts() const
Debugging function to dump instructions in the LSQ.
LSQPolicy
SMT policy.
Definition: lsq.hh:66
int numLoads()
Returns the total number of loads in the load queue.
Definition: lsq_impl.hh:415
void insertLoad(DynInstPtr &load_inst)
Inserts a load into the LSQ.
Definition: lsq_impl.hh:260
void commitLoads(InstSeqNum &youngest_inst)
Commits loads older than a specific sequence number.
Fault executeStore(DynInstPtr &inst)
Executes a store.
Definition: lsq_impl.hh:287
unsigned maxLQEntries
Max LQ Size - Used to Enforce Sharing Policies.
Definition: lsq.hh:323
int numStoresToWB(ThreadID tid)
Returns the number of stores a specific thread has to write back.
Definition: lsq.hh:257
InstSeqNum getLoadHeadSeqNum()
Returns the sequence number of the head load instruction.
Definition: lsq_unit.hh:523
uint64_t InstSeqNum
Definition: inst_seq.hh:40
LSQUnit * thread
The LSQ units for individual threads.
Definition: lsq.hh:312
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
InstSeqNum getStoreHeadSeqNum(ThreadID tid)
Returns the sequence number of the head of the store queue.
Definition: lsq.hh:173
int getCount()
Returns the number of instructions in all of the queues.
Definition: lsq_impl.hh:397
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
Impl::O3CPU O3CPU
Definition: lsq.hh:60
int size()
Definition: pagetable.hh:146
void commitStores(InstSeqNum &youngest_inst, ThreadID tid)
Commits stores up until the given sequence number for a specific thread.
Definition: lsq.hh:128
unsigned numFreeLoadEntries()
Returns the number of free load entries.
Definition: lsq_impl.hh:451
int entryAmount(ThreadID num_threads)
Number of entries needed for the given amount of threads.
Definition: lsq_impl.hh:191
void recvReqRetry()
Retry the previous send that failed.
Definition: lsq_impl.hh:333
LSQPolicy lsqPolicy
The LSQ policy for SMT mode.
Definition: lsq.hh:309
unsigned getCount()
Returns the number of instructions in the LSQ.
Definition: lsq_unit.hh:215
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets the pointer to the list of active threads.
Definition: lsq_impl.hh:145
bool isEmpty() const
Returns if the LSQ is empty (both LQ and SQ are empty).
Definition: lsq_impl.hh:530
bool sqEmpty() const
Returns if all of the SQs are empty.
Definition: lsq_impl.hh:554
LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params)
Constructs an LSQ with the given parameters.
Definition: lsq_impl.hh:61
int numStores()
Returns the total number of stores in the store queue.
Definition: lsq_impl.hh:433
bool isDrained() const
Has the LSQ drained?
Definition: lsq_impl.hh:163
void regStats()
Registers statistics of each LSQ unit.
Definition: lsq_impl.hh:135
bool recvTimingResp(PacketPtr pkt)
Handles writing back and completing the load or store that has returned from memory.
Definition: lsq_impl.hh:344
void squash(const InstSeqNum &squashed_num, ThreadID tid)
Squash instructions from a thread until the specified sequence number.
Definition: lsq.hh:142
Impl::CPUPol::IEW IEW
Definition: lsq.hh:62
Class that implements the actual LQ and SQ for each specific thread.
Definition: lsq_unit.hh:79
O3CPU * cpu
The CPU pointer.
Definition: lsq.hh:302
bool lqEmpty() const
Returns if all of the LQs are empty.
Definition: lsq_impl.hh:537
std::list< ThreadID > * activeThreads
List of Active Threads in System.
Definition: lsq.hh:315
bool isStalled()
Returns if the LSQ is stalled due to a memory operation that must be replayed.
Definition: lsq_impl.hh:629
DynInstPtr getMemDepViolator(ThreadID tid)
Gets the instruction that caused the memory ordering violation.
Definition: lsq.hh:155
void recvTimingSnoopReq(PacketPtr pkt)
Definition: lsq_impl.hh:380
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
unsigned numFreeEntries(ThreadID tid)
Returns the number of free entries for a specific thread.
int getStoreHead(ThreadID tid)
Returns the head index of the store queue.
Definition: lsq.hh:169
int numLoads(ThreadID tid)
Returns the total number of loads for a single thread.
Definition: lsq.hh:187
void commitLoads(InstSeqNum &youngest_inst, ThreadID tid)
Commits loads up until the given sequence number for a specific thread.
Definition: lsq.hh:122
~LSQ()
Definition: lsq.hh:74
int numStoresToWB()
Returns the number of stores to writeback.
Definition: lsq_unit.hh:221
bool lqFull()
Returns if any of the LQs are full.
Definition: lsq_impl.hh:571
void tick()
Ticks the LSQ unit, which in this case only resets the number of used cache ports.
Definition: lsq_unit.hh:116

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6