gem5 v24.0.0.0
Loading...
Searching...
No Matches
mem_dep_unit.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, 2014, 2020 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 * All rights reserved.
16 *
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.
27 *
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.
39 */
40
41#ifndef __CPU_O3_MEM_DEP_UNIT_HH__
42#define __CPU_O3_MEM_DEP_UNIT_HH__
43
44#include <list>
45#include <memory>
46#include <set>
47#include <unordered_map>
48#include <unordered_set>
49
50#include "base/statistics.hh"
51#include "cpu/inst_seq.hh"
53#include "cpu/o3/limits.hh"
54#include "cpu/o3/store_set.hh"
55#include "debug/MemDepUnit.hh"
56
57namespace gem5
58{
59
60struct SNHash
61{
62 size_t
63 operator()(const InstSeqNum &seq_num) const
64 {
65 unsigned a = (unsigned)seq_num;
66 unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF;
67 return hash;
68 }
69};
70
71struct BaseO3CPUParams;
72
73namespace o3
74{
75
76class CPU;
77class InstructionQueue;
78
91{
92 protected:
93 std::string _name;
94
95 public:
97 MemDepUnit();
98
100 MemDepUnit(const BaseO3CPUParams &params);
101
103 ~MemDepUnit();
104
106 std::string name() const { return _name; }
107
109 void init(const BaseO3CPUParams &params, ThreadID tid, CPU *cpu);
110
112 bool isDrained() const;
113
115 void drainSanityCheck() const;
116
118 void takeOverFrom();
119
121 void setIQ(InstructionQueue *iq_ptr);
122
124 void insert(const DynInstPtr &inst);
125
127 void insertNonSpec(const DynInstPtr &inst);
128
130 void insertBarrier(const DynInstPtr &barr_inst);
131
133 void regsReady(const DynInstPtr &inst);
134
136 void nonSpecInstReady(const DynInstPtr &inst);
137
139 void reschedule(const DynInstPtr &inst);
140
144 void replay();
145
147 void completeInst(const DynInstPtr &inst);
148
152 void squash(const InstSeqNum &squashed_num, ThreadID tid);
153
155 void violation(const DynInstPtr &store_inst,
156 const DynInstPtr &violating_load);
157
159 void issue(const DynInstPtr &inst);
160
162 void dumpLists();
163
164 private:
165
167 void completed(const DynInstPtr &inst);
168
170 void wakeDependents(const DynInstPtr &inst);
171
173
174 class MemDepEntry;
175
176 typedef std::shared_ptr<MemDepEntry> MemDepEntryPtr;
177
183 {
184 public:
186 MemDepEntry(const DynInstPtr &new_inst);
187
189 ~MemDepEntry();
190
192 std::string name() const { return "memdepentry"; }
193
196
199
202
204 bool regsReady = false;
206 int memDeps = 0;
208 bool completed = false;
210 bool squashed = false;
211
213#ifdef GEM5_DEBUG
214 static int memdep_count;
215 static int memdep_insert;
216 static int memdep_erase;
217#endif
218 };
219
222
224 void moveToReady(MemDepEntryPtr &ready_inst_entry);
225
226 typedef std::unordered_map<InstSeqNum, MemDepEntryPtr, SNHash> MemDepHash;
227
228 typedef typename MemDepHash::iterator MemDepHashIt;
229
232
235
238
245
247 std::unordered_set<InstSeqNum> loadBarrierSNs;
248
250 std::unordered_set<InstSeqNum> storeBarrierSNs;
251
253 bool hasLoadBarrier() const { return !loadBarrierSNs.empty(); }
254
256 bool hasStoreBarrier() const { return !storeBarrierSNs.empty(); }
257
259 void insertBarrierSN(const DynInstPtr &barr_inst);
260
263
265 int id;
280};
281
282} // namespace o3
283} // namespace gem5
284
285#endif // __CPU_O3_MEM_DEP_UNIT_HH__
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:94
A standard instruction queue class.
Definition inst_queue.hh:99
Memory dependence entries that track memory operations, marking when the instruction is ready to exec...
bool completed
If the instruction is completed.
std::vector< MemDepEntryPtr > dependInsts
A vector of any dependent instructions.
int memDeps
Number of memory dependencies that need to be satisfied.
~MemDepEntry()
Frees any pointers.
MemDepEntry(const DynInstPtr &new_inst)
Constructs a memory dependence entry.
ListIt listIt
The iterator to the instruction's location inside the list.
bool squashed
If the instruction is squashed.
std::string name() const
Returns the name of the memory dependence entry.
DynInstPtr inst
The instruction being tracked.
bool regsReady
If the registers are ready or not.
Memory dependency unit class.
bool isDrained() const
Determine if we are drained.
void completeInst(const DynInstPtr &inst)
Notifies completion of an instruction.
std::string name() const
Returns the name of the memory dependence unit.
void takeOverFrom()
Takes over from another CPU's thread.
std::list< DynInstPtr > instList[MaxThreads]
A list of all instructions in the memory dependence unit.
void moveToReady(MemDepEntryPtr &ready_inst_entry)
Moves an entry to the ready list.
bool hasStoreBarrier() const
Is there an outstanding store barrier that loads must wait on.
void nonSpecInstReady(const DynInstPtr &inst)
Indicate that a non-speculative instruction is ready.
std::shared_ptr< MemDepEntry > MemDepEntryPtr
std::list< DynInstPtr >::iterator ListIt
MemDepUnit()
Empty constructor.
void completed(const DynInstPtr &inst)
Completes a memory instruction.
~MemDepUnit()
Frees up any memory allocated.
void dumpLists()
Debugging function to dump the lists of instructions.
std::unordered_set< InstSeqNum > loadBarrierSNs
Sequence numbers of outstanding load barriers.
void issue(const DynInstPtr &inst)
Issues the given instruction.
void insert(const DynInstPtr &inst)
Inserts a memory instruction.
void squash(const InstSeqNum &squashed_num, ThreadID tid)
Squashes all instructions up until a given sequence number for a specific thread.
void violation(const DynInstPtr &store_inst, const DynInstPtr &violating_load)
Indicates an ordering violation between a store and a younger load.
StoreSet depPred
The memory dependence predictor.
void replay()
Replays all instructions that have been rescheduled by moving them to the ready list.
void wakeDependents(const DynInstPtr &inst)
Wakes any dependents of a memory instruction.
MemDepHash memDepHash
A hash map of all memory dependence entries.
std::list< DynInstPtr > instsToReplay
A list of all instructions that are going to be replayed.
std::unordered_map< InstSeqNum, MemDepEntryPtr, SNHash > MemDepHash
void regsReady(const DynInstPtr &inst)
Indicate that an instruction has its registers ready.
void insertBarrierSN(const DynInstPtr &barr_inst)
Inserts the SN of a barrier inst.
std::unordered_set< InstSeqNum > storeBarrierSNs
Sequence numbers of outstanding store barriers.
bool hasLoadBarrier() const
Is there an outstanding load barrier that loads must wait on.
MemDepEntryPtr & findInHash(const DynInstConstPtr &inst)
Finds the memory dependence entry in the hash map.
InstructionQueue * iqPtr
Pointer to the IQ.
int id
The thread id of this memory dependence unit.
MemDepHash::iterator MemDepHashIt
gem5::o3::MemDepUnit::MemDepUnitStats stats
void insertNonSpec(const DynInstPtr &inst)
Inserts a non-speculative memory instruction.
void drainSanityCheck() const
Perform sanity checks after a drain.
void reschedule(const DynInstPtr &inst)
Reschedules an instruction to be re-executed.
void insertBarrier(const DynInstPtr &barr_inst)
Inserts a barrier instruction.
void setIQ(InstructionQueue *iq_ptr)
Sets the pointer to the IQ.
Implements a store set predictor for determining if memory instructions are dependent upon each other...
Definition store_set.hh:63
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
Bitfield< 8 > a
Definition misc_types.hh:66
static constexpr int MaxThreads
Definition limits.hh:38
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
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
uint64_t InstSeqNum
Definition inst_seq.hh:40
Declaration of Statistics objects.
size_t operator()(const InstSeqNum &seq_num) const
statistics::Scalar conflictingLoads
Stat for number of conflicting loads that had to wait for a store.
MemDepUnitStats(statistics::Group *parent)
statistics::Scalar conflictingStores
Stat for number of conflicting stores that had to wait for a store.
statistics::Scalar insertedLoads
Stat for number of inserted loads.
statistics::Scalar insertedStores
Stat for number of inserted stores.

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