gem5 v24.0.0.0
Loading...
Searching...
No Matches
lsq_unit.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2014,2017-2018,2020-2021 ARM Limited
3 * All rights reserved
4 *
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.
13 *
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * Copyright (c) 2013 Advanced Micro Devices, Inc.
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
42#ifndef __CPU_O3_LSQ_UNIT_HH__
43#define __CPU_O3_LSQ_UNIT_HH__
44
45#include <algorithm>
46#include <cstring>
47#include <map>
48#include <memory>
49#include <queue>
50
54#include "cpu/base.hh"
55#include "cpu/inst_seq.hh"
56#include "cpu/o3/comm.hh"
57#include "cpu/o3/cpu.hh"
59#include "cpu/o3/lsq.hh"
60#include "cpu/timebuf.hh"
61#include "debug/HtmCpu.hh"
62#include "debug/LSQUnit.hh"
63#include "mem/packet.hh"
64#include "mem/port.hh"
65
66namespace gem5
67{
68
69struct BaseO3CPUParams;
70
71namespace o3
72{
73
74class IEW;
75
89{
90 public:
91 static constexpr auto MaxDataBytes = MaxVecRegLenInBytes;
92
94 private:
96 {
97 private:
103 uint32_t _size = 0;
105 bool _valid = false;
106
107 public:
109 {
110 if (_request != nullptr) {
112 _request = nullptr;
113 }
114 }
115
116 void
118 {
119 _inst = nullptr;
120 if (_request != nullptr) {
122 }
123 _request = nullptr;
124 _valid = false;
125 _size = 0;
126 }
127
128 void
129 set(const DynInstPtr& new_inst)
130 {
131 assert(!_valid);
132 _inst = new_inst;
133 _valid = true;
134 _size = 0;
135 }
136
139 bool hasRequest() { return _request != nullptr; }
142 bool valid() const { return _valid; }
143 uint32_t& size() { return _size; }
144 const uint32_t& size() const { return _size; }
145 const DynInstPtr& instruction() const { return _inst; }
147 };
148
149 class SQEntry : public LSQEntry
150 {
151 private:
155 bool _canWB = false;
157 bool _committed = false;
159 bool _completed = false;
164 bool _isAllZeros = false;
165
166 public:
167 static constexpr size_t DataSize = sizeof(_data);
170 {
171 std::memset(_data, 0, DataSize);
172 }
173
174 void set(const DynInstPtr& inst) { LSQEntry::set(inst); }
175
176 void
178 {
181 }
182
185 bool& canWB() { return _canWB; }
186 const bool& canWB() const { return _canWB; }
187 bool& completed() { return _completed; }
188 const bool& completed() const { return _completed; }
189 bool& committed() { return _committed; }
190 const bool& committed() const { return _committed; }
191 bool& isAllZeros() { return _isAllZeros; }
192 const bool& isAllZeros() const { return _isAllZeros; }
193 char* data() { return _data; }
194 const char* data() const { return _data; }
196 };
198
201 {
202 PartialAddrRangeCoverage, /* Two ranges partly overlap */
203 FullAddrRangeCoverage, /* One range fully covers another */
204 NoAddrRangeCoverage /* Two ranges are disjoint */
205 };
206
207 public:
210
211 public:
213 LSQUnit(uint32_t lqEntries, uint32_t sqEntries);
214
219 LSQUnit(const LSQUnit &l): stats(nullptr)
220 {
221 panic("LSQUnit is not copy-able");
222 }
223
225 void init(CPU *cpu_ptr, IEW *iew_ptr, const BaseO3CPUParams &params,
226 LSQ *lsq_ptr, unsigned id);
227
229 std::string name() const;
230
232 void setDcachePort(RequestPort *dcache_port);
233
235 void drainSanityCheck() const;
236
238 void takeOverFrom();
239
241 void insert(const DynInstPtr &inst);
243 void insertLoad(const DynInstPtr &load_inst);
245 void insertStore(const DynInstPtr &store_inst);
246
253 Fault checkViolations(typename LoadQueue::iterator& loadIt,
254 const DynInstPtr& inst);
255
260 void checkSnoop(PacketPtr pkt);
261
263 Fault executeLoad(const DynInstPtr &inst);
264
265 Fault executeLoad(int lq_idx) { panic("Not implemented"); return NoFault; }
267 Fault executeStore(const DynInstPtr &inst);
268
270 void commitLoad();
272 void commitLoads(InstSeqNum &youngest_inst);
273
275 void commitStores(InstSeqNum &youngest_inst);
276
278 void writebackStores();
279
283
285 void squash(const InstSeqNum &squashed_num);
286
290 bool violation() { return memDepViolator; }
291
294
296 unsigned numFreeLoadEntries();
297
299 unsigned numFreeStoreEntries();
300
302 int numLoads() { return loadQueue.size(); }
303
305 int numStores() { return storeQueue.size(); }
306
307 // hardware transactional memory
308 int numHtmStarts() const { return htmStarts; }
309 int numHtmStops() const { return htmStops; }
311 uint64_t getLatestHtmUid() const;
312 void
313 setLastRetiredHtmUid(uint64_t htm_uid)
314 {
315 assert(htm_uid >= lastRetiredHtmUid);
316 lastRetiredHtmUid = htm_uid;
317 }
318
319 // Stale translation checks
321 bool checkStaleTranslations() const;
322
324 bool isFull() { return lqFull() || sqFull(); }
325
327 bool isEmpty() const { return lqEmpty() && sqEmpty(); }
328
330 bool lqFull() { return loadQueue.full(); }
331
333 bool sqFull() { return storeQueue.full(); }
334
336 bool lqEmpty() const { return loadQueue.size() == 0; }
337
339 bool sqEmpty() const { return storeQueue.size() == 0; }
340
342 unsigned getCount() { return loadQueue.size() + storeQueue.size(); }
343
345 bool hasStoresToWB() { return storesToWB; }
346
348 int numStoresToWB() { return storesToWB; }
349
351 bool
353 {
354 return storeWBIt.dereferenceable() &&
355 storeWBIt->valid() &&
356 storeWBIt->canWB() &&
357 !storeWBIt->completed() &&
359 }
360
362 void recvRetry();
363
364 unsigned int cacheLineSize();
365 private:
367 void resetState();
368
370 void writeback(const DynInstPtr &inst, PacketPtr pkt);
371
374
376 void completeStore(typename StoreQueue::iterator store_idx);
377
379 void storePostSend();
380
381 public:
386 bool trySendPacket(bool isLoad, PacketPtr data_pkt);
387
388
390 void dumpInsts() const;
391
393 void schedule(Event& ev, Tick when);
394
396
397 private:
400
403
406
409
411 class WritebackEvent : public Event
412 {
413 public:
416 LSQUnit *lsq_ptr);
417
419 void process();
420
422 const char *description() const;
423
424 private:
427
430
433 };
434
435 public:
442 bool recvTimingResp(PacketPtr pkt);
443
444 private:
447 public:
450
453
454 private:
459
462
465
466 // hardware transactional memory
467 // nesting depth
470 // sanity checks and debugging
472
476 typename StoreQueue::iterator storeWBIt;
477
480
483
492
495
498
501
504
507
508 protected:
509 // Will also need how many read/write ports the Dcache has. Or keep track
510 // of that in stage that is one level up, and only call executeLoad/Store
511 // the appropriate number of times.
542
543 public:
545 Fault read(LSQRequest *request, ssize_t load_idx);
546
548 Fault write(LSQRequest *requst, uint8_t *data, ssize_t store_idx);
549
551 int getLoadHead() { return loadQueue.head(); }
552
555
557 int getStoreHead() { return storeQueue.head(); }
560
562 bool isStalled() { return stalled; }
563 public:
566};
567
568} // namespace o3
569} // namespace gem5
570
571#endif // __CPU_O3_LSQ_UNIT_HH__
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:94
IEW handles both single threaded and SMT IEW (issue/execute/writeback).
Definition iew.hh:88
bool _valid
Valid entry.
Definition lsq_unit.hh:105
DynInstPtr _inst
The instruction.
Definition lsq_unit.hh:99
void setRequest(LSQRequest *r)
Definition lsq_unit.hh:138
const DynInstPtr & instruction() const
Definition lsq_unit.hh:145
uint32_t _size
The size of the operation.
Definition lsq_unit.hh:103
bool valid() const
Member accessors.
Definition lsq_unit.hh:142
const uint32_t & size() const
Definition lsq_unit.hh:144
void set(const DynInstPtr &new_inst)
Definition lsq_unit.hh:129
LSQRequest * _request
The request.
Definition lsq_unit.hh:101
void set(const DynInstPtr &inst)
Definition lsq_unit.hh:174
bool _isAllZeros
Does this request write all zeros and thus doesn't have any data attached to it.
Definition lsq_unit.hh:164
bool _canWB
Whether or not the store can writeback.
Definition lsq_unit.hh:155
const bool & isAllZeros() const
Definition lsq_unit.hh:192
SQEntry()
Constructs an empty store queue entry.
Definition lsq_unit.hh:169
char _data[MaxDataBytes]
The store data.
Definition lsq_unit.hh:153
bool _committed
Whether or not the store is committed.
Definition lsq_unit.hh:157
const bool & canWB() const
Definition lsq_unit.hh:186
bool & canWB()
Member accessors.
Definition lsq_unit.hh:185
const bool & committed() const
Definition lsq_unit.hh:190
bool _completed
Whether or not the store is completed.
Definition lsq_unit.hh:159
const char * data() const
Definition lsq_unit.hh:194
static constexpr size_t DataSize
Definition lsq_unit.hh:167
const bool & completed() const
Definition lsq_unit.hh:188
Writeback event, specifically for when stores forward data to loads.
Definition lsq_unit.hh:412
WritebackEvent(const DynInstPtr &_inst, PacketPtr pkt, LSQUnit *lsq_ptr)
Constructs a writeback event.
Definition lsq_unit.cc:64
PacketPtr pkt
The packet that would have been sent to memory.
Definition lsq_unit.hh:429
DynInstPtr inst
Instruction whose results are being written back.
Definition lsq_unit.hh:426
const char * description() const
Returns the description of this event.
Definition lsq_unit.cc:86
LSQUnit * lsqPtr
The pointer to the LSQ unit that issued the store.
Definition lsq_unit.hh:432
void process()
Processes the writeback event.
Definition lsq_unit.cc:74
Class that implements the actual LQ and SQ for each specific thread.
Definition lsq_unit.hh:89
void insertStore(const DynInstPtr &store_inst)
Inserts a store instruction.
Definition lsq_unit.cc:379
Fault executeLoad(int lq_idx)
Definition lsq_unit.hh:265
Fault write(LSQRequest *requst, uint8_t *data, ssize_t store_idx)
Executes the store at the given index.
Definition lsq_unit.cc:1604
Addr cacheBlockMask
Address Mask for a cache block (e.g.
Definition lsq_unit.hh:479
IEW * iewStage
Pointer to the IEW stage.
Definition lsq_unit.hh:402
bool isStoreBlocked
Whehter or not a store is blocked due to the memory system.
Definition lsq_unit.hh:497
AddrRangeCoverage
Coverage of one address range with another.
Definition lsq_unit.hh:201
void takeOverFrom()
Takes over from another CPU's thread.
Definition lsq_unit.cc:297
int getLoadHead()
Returns the index of the head load instruction.
Definition lsq_unit.hh:551
bool checkLoads
Should loads be checked for dependency issues.
Definition lsq_unit.hh:461
int numHtmStops() const
Definition lsq_unit.hh:309
Fault read(LSQRequest *request, ssize_t load_idx)
Executes the load at the given index.
Definition lsq_unit.cc:1317
bool violation()
Returns if there is a memory ordering violation.
Definition lsq_unit.hh:290
bool storeInFlight
Whether or not a store is in flight.
Definition lsq_unit.hh:500
CPU * cpu
Pointer to the CPU.
Definition lsq_unit.hh:399
InstSeqNum getStoreHeadSeqNum()
Returns the sequence number of the head store instruction.
Definition lsq_unit.cc:1642
InstSeqNum getLoadHeadSeqNum()
Returns the sequence number of the head load instruction.
Definition lsq_unit.cc:1633
unsigned depCheckShift
The number of places to shift addresses in the LSQ before checking for dependency violations.
Definition lsq_unit.hh:458
void storePostSend()
Handles completing the send of a store to memory.
Definition lsq_unit.cc:1043
RequestPort * dcachePort
Pointer to the dcache port.
Definition lsq_unit.hh:408
InstSeqNum stallingStoreIsn
The store that causes the stall due to partial store to load forwarding.
Definition lsq_unit.hh:489
bool sqFull()
Returns if the SQ is full.
Definition lsq_unit.hh:333
int numStoresToWB()
Returns the number of stores to writeback.
Definition lsq_unit.hh:348
bool isStalled()
Returns whether or not the LSQ unit is stalled.
Definition lsq_unit.hh:562
void insertLoad(const DynInstPtr &load_inst)
Inserts a load instruction.
Definition lsq_unit.cc:319
Fault executeStore(const DynInstPtr &inst)
Executes a store instruction.
Definition lsq_unit.cc:657
void insert(const DynInstPtr &inst)
Inserts an instruction.
Definition lsq_unit.cc:303
unsigned getCount()
Returns the number of instructions in the LSQ.
Definition lsq_unit.hh:342
bool checkStaleTranslations() const
Definition lsq_unit.cc:1256
void setLastRetiredHtmUid(uint64_t htm_uid)
Definition lsq_unit.hh:313
uint64_t getLatestHtmUid() const
Definition lsq_unit.cc:1036
void schedule(Event &ev, Tick when)
Schedule event for the cpu.
Definition lsq_unit.cc:1306
void writebackStores()
Writes back stores.
Definition lsq_unit.cc:789
Fault checkViolations(typename LoadQueue::iterator &loadIt, const DynInstPtr &inst)
Check for ordering violations in the LSQ.
Definition lsq_unit.cc:510
StoreQueue storeQueue
The store queue.
Definition lsq_unit.hh:449
TimeBuffer< IssueStruct >::wire fromIssue
Wire to read information from the issue stage time queue.
Definition lsq_unit.hh:482
int numHtmStarts() const
Definition lsq_unit.hh:308
Fault executeLoad(const DynInstPtr &inst)
Executes a load instruction.
Definition lsq_unit.cc:590
void commitLoad()
Commits the head load.
Definition lsq_unit.cc:719
LSQUnit(uint32_t lqEntries, uint32_t sqEntries)
Constructs an LSQ unit.
Definition lsq_unit.cc:192
int getStoreHead()
Returns the index of the head store instruction.
Definition lsq_unit.hh:557
void completeStore(typename StoreQueue::iterator store_idx)
Completes the store at the specified index.
Definition lsq_unit.cc:1136
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition lsq_unit.cc:287
int numLoads()
Returns the number of loads in the LQ.
Definition lsq_unit.hh:302
void setDcachePort(RequestPort *dcache_port)
Sets the pointer to the dcache port.
Definition lsq_unit.cc:281
bool sqEmpty() const
Returns if the SQ is empty.
Definition lsq_unit.hh:339
CircularQueue< LQEntry >::iterator LQIterator
Definition lsq_unit.hh:564
unsigned int cacheLineSize()
Definition lsq_unit.cc:1311
void resetState()
Reset the LSQ state.
Definition lsq_unit.cc:226
unsigned numFreeStoreEntries()
Returns the number of free SQ entries.
Definition lsq_unit.cc:418
uint64_t lastRetiredHtmUid
Definition lsq_unit.hh:471
int numStores()
Returns the number of stores in the SQ.
Definition lsq_unit.hh:305
LSQ::LSQRequest LSQRequest
Definition lsq_unit.hh:93
LSQUnit(const LSQUnit &l)
We cannot copy LSQUnit because it has stats for which copy contructor is deleted explicitly.
Definition lsq_unit.hh:219
void dumpInsts() const
Debugging function to dump instructions in the LSQ.
Definition lsq_unit.cc:1283
bool lqFull()
Returns if the LQ is full.
Definition lsq_unit.hh:330
bool stalled
Whether or not the LSQ is stalled.
Definition lsq_unit.hh:485
ssize_t stallingLoadIdx
The index of the above store.
Definition lsq_unit.hh:491
LoadQueue loadQueue
The load queue.
Definition lsq_unit.hh:452
PacketPtr retryPkt
The packet that needs to be retried.
Definition lsq_unit.hh:494
DynInstPtr getMemDepViolator()
Returns the memory ordering violator.
Definition lsq_unit.cc:400
bool willWB()
Returns if the LSQ unit will writeback on this cycle.
Definition lsq_unit.hh:352
CircularQueue< SQEntry >::iterator SQIterator
Definition lsq_unit.hh:565
bool hasStoresToWB()
Returns if there are any stores to writeback.
Definition lsq_unit.hh:345
DynInstPtr memDepViolator
The oldest load that caused a memory ordering violation.
Definition lsq_unit.hh:503
void squash(const InstSeqNum &squashed_num)
Squashes all instructions younger than a specific sequence number.
Definition lsq_unit.cc:921
std::string name() const
Returns the name of the LSQ unit.
Definition lsq_unit.cc:245
void checkSnoop(PacketPtr pkt)
Check if an incoming invalidate hits in the lsq on a load that might have issued out of order wrt ano...
Definition lsq_unit.cc:427
static constexpr auto MaxDataBytes
Definition lsq_unit.hh:91
void recvRetry()
Handles doing the retry.
Definition lsq_unit.cc:1274
int storesToWB
The number of store instructions in the SQ waiting to writeback.
Definition lsq_unit.hh:464
unsigned numFreeLoadEntries()
Returns the number of free LQ entries.
Definition lsq_unit.cc:410
bool trySendPacket(bool isLoad, PacketPtr data_pkt)
Attempts to send a packet to the cache.
Definition lsq_unit.cc:1199
StoreQueue::iterator storeWBIt
The index of the first instruction that may be ready to be written back, and has not yet been written...
Definition lsq_unit.hh:476
BaseMMU * getMMUPtr()
Definition lsq_unit.cc:1308
void writebackBlockedStore()
Try to finish a previously blocked write back attempt.
Definition lsq_unit.cc:779
void commitLoads(InstSeqNum &youngest_inst)
Commits loads older than a specific sequence number.
Definition lsq_unit.cc:742
gem5::o3::LSQUnit::LSQUnitStats stats
void completeDataAccess(PacketPtr pkt)
Completes the data access that has been returned from the memory system.
Definition lsq_unit.cc:105
bool lqEmpty() const
Returns if the LQ is empty.
Definition lsq_unit.hh:336
bool isFull()
Returns if either the LQ or SQ is full.
Definition lsq_unit.hh:324
void startStaleTranslationFlush()
Definition lsq_unit.cc:1241
void resetHtmStartsStops()
Definition lsq_unit.hh:310
LSQ * lsq
Pointer to the LSQ.
Definition lsq_unit.hh:405
bool isEmpty() const
Returns if both the LQ and SQ are empty.
Definition lsq_unit.hh:327
bool needsTSO
Flag for memory model.
Definition lsq_unit.hh:506
void commitStores(InstSeqNum &youngest_inst)
Commits stores older than a specific sequence number.
Definition lsq_unit.cc:753
ThreadID lsqID
The LSQUnit thread id.
Definition lsq_unit.hh:446
bool recvTimingResp(PacketPtr pkt)
Handles writing back and completing the load or store that has returned from memory.
Definition lsq_unit.cc:92
Memory operation metadata.
Definition lsq.hh:190
void freeLSQEntry()
The LSQ entry is cleared.
Definition lsq.hh:509
A simple distribution stat.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
bool full() const
Is the queue full? A queue is full if the head is the 0^{th} element and the tail is the (size-1)^{th...
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Port Object Declaration.
Bitfield< 21 > writeback
Definition types.hh:126
Bitfield< 5 > l
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
constexpr decltype(nullptr) NoFault
Definition types.hh:253
constexpr unsigned MaxVecRegLenInBytes
Definition vec_reg.hh:115
uint64_t InstSeqNum
Definition inst_seq.hh:40
Declaration of the Packet class.
Iterator to the circular queue.
statistics::Scalar blockedByCache
Number of times the LSQ is blocked due to the cache.
Definition lsq_unit.hh:536
statistics::Scalar forwLoads
Total number of loads forwaded from LSQ stores.
Definition lsq_unit.hh:517
LSQUnitStats(statistics::Group *parent)
Definition lsq_unit.cc:254
statistics::Scalar ignoredResponses
Total number of responses from the memory system that are ignored due to the instruction already bein...
Definition lsq_unit.hh:524
statistics::Distribution loadToUse
Distribution of cycle latency between the first time a load is issued and its completion.
Definition lsq_unit.hh:540
statistics::Scalar rescheduledLoads
Number of loads that were rescheduled.
Definition lsq_unit.hh:533
statistics::Scalar squashedStores
Total number of squashed stores.
Definition lsq_unit.hh:530
statistics::Scalar squashedLoads
Total number of squashed loads.
Definition lsq_unit.hh:520
statistics::Scalar memOrderViolation
Tota number of memory ordering violations.
Definition lsq_unit.hh:527
Vector Registers layout specification.

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0