gem5  v22.1.0.0
scoreboard.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014, 2016-2017 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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "cpu/minor/scoreboard.hh"
39 
40 #include "cpu/reg_class.hh"
41 #include "debug/MinorScoreboard.hh"
42 #include "debug/MinorTiming.hh"
43 
44 namespace gem5
45 {
46 
48 namespace minor
49 {
50 
51 bool
52 Scoreboard::findIndex(const RegId& reg, Index &scoreboard_index)
53 {
54  bool ret = false;
55 
56  switch (reg.classValue()) {
57  case IntRegClass:
58  scoreboard_index = reg.index();
59  ret = true;
60  break;
61  case FloatRegClass:
62  scoreboard_index = floatRegOffset + reg.index();
63  ret = true;
64  break;
65  case VecRegClass:
66  case VecElemClass:
67  scoreboard_index = vecRegOffset + reg.index();
68  ret = true;
69  break;
70  case VecPredRegClass:
71  scoreboard_index = vecPredRegOffset + reg.index();
72  ret = true;
73  break;
74  case CCRegClass:
75  scoreboard_index = ccRegOffset + reg.index();
76  ret = true;
77  break;
78  case MiscRegClass:
79  /* Don't bother with Misc registers */
80  ret = false;
81  break;
82  case InvalidRegClass:
83  ret = false;
84  break;
85  default:
86  panic("Unknown register class: %d", reg.classValue());
87  }
88 
89  return ret;
90 }
91 
92 void
94  ThreadContext *thread_context, bool mark_unpredictable)
95 {
96  if (inst->isFault())
97  return;
98 
99  StaticInstPtr staticInst = inst->staticInst;
100  unsigned int num_dests = staticInst->numDestRegs();
101 
102  auto *isa = thread_context->getIsaPtr();
103 
105  for (unsigned int dest_index = 0; dest_index < num_dests;
106  dest_index++)
107  {
108  RegId reg = staticInst->destRegIdx(dest_index).flatten(*isa);
109  Index index;
110 
111  if (findIndex(reg, index)) {
112  if (mark_unpredictable)
114 
115  inst->flatDestRegIdx[dest_index] = reg;
116 
117  numResults[index]++;
118  returnCycle[index] = retire_time;
119  /* We should be able to rely on only being given accending
120  * execSeqNums, but sanity check */
121  if (inst->id.execSeqNum > writingInst[index]) {
122  writingInst[index] = inst->id.execSeqNum;
123  fuIndices[index] = inst->fuIndex;
124  }
125 
126  DPRINTF(MinorScoreboard, "Marking up inst: %s"
127  " regIndex: %d final numResults: %d returnCycle: %d\n",
128  *inst, index, numResults[index], returnCycle[index]);
129  } else {
130  /* Use an invalid ID to mark invalid/untracked dests */
131  inst->flatDestRegIdx[dest_index] = RegId();
132  }
133  }
134 }
135 
138  ThreadContext *thread_context)
139 {
140  InstSeqNum ret = 0;
141 
142  if (inst->isFault())
143  return ret;
144 
145  StaticInstPtr staticInst = inst->staticInst;
146  unsigned int num_srcs = staticInst->numSrcRegs();
147 
148  auto *isa = thread_context->getIsaPtr();
149 
150  for (unsigned int src_index = 0; src_index < num_srcs; src_index++) {
151  RegId reg = staticInst->srcRegIdx(src_index).flatten(*isa);
152  unsigned short int index;
153 
154  if (findIndex(reg, index)) {
155  if (writingInst[index] > ret)
156  ret = writingInst[index];
157  }
158  }
159 
160  DPRINTF(MinorScoreboard, "Inst: %s depends on execSeqNum: %d\n",
161  *inst, ret);
162 
163  return ret;
164 }
165 
166 void
167 Scoreboard::clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
168 {
169  if (inst->isFault())
170  return;
171 
172  StaticInstPtr staticInst = inst->staticInst;
173  unsigned int num_dests = staticInst->numDestRegs();
174 
176  for (unsigned int dest_index = 0; dest_index < num_dests;
177  dest_index++)
178  {
179  const RegId& reg = inst->flatDestRegIdx[dest_index];
180  Index index;
181 
182  if (findIndex(reg, index)) {
183  if (clear_unpredictable && numUnpredictableResults[index] != 0)
185 
186  numResults[index] --;
187 
188  if (numResults[index] == 0) {
189  returnCycle[index] = Cycles(0);
190  writingInst[index] = 0;
192  }
193 
194  DPRINTF(MinorScoreboard, "Clearing inst: %s"
195  " regIndex: %d final numResults: %d\n",
196  *inst, index, numResults[index]);
197  }
198  }
199 }
200 
201 bool
203  const std::vector<Cycles> *src_reg_relative_latencies,
204  const std::vector<bool> *cant_forward_from_fu_indices,
205  Cycles now, ThreadContext *thread_context)
206 {
207  /* Always allow fault to be issued */
208  if (inst->isFault())
209  return true;
210 
211  StaticInstPtr staticInst = inst->staticInst;
212  unsigned int num_srcs = staticInst->numSrcRegs();
213 
214  /* Default to saying you can issue */
215  bool ret = true;
216 
217  unsigned int num_relative_latencies = 0;
218  Cycles default_relative_latency = Cycles(0);
219 
220  /* Where relative latencies are given, the default is the last
221  * one as that allows the rel. lat. list to be shorted than the
222  * number of src. regs */
223  if (src_reg_relative_latencies &&
224  src_reg_relative_latencies->size() != 0)
225  {
226  num_relative_latencies = src_reg_relative_latencies->size();
227  default_relative_latency = (*src_reg_relative_latencies)
228  [num_relative_latencies-1];
229  }
230 
231  auto *isa = thread_context->getIsaPtr();
232 
233  /* For each source register, find the latest result */
234  unsigned int src_index = 0;
235  while (src_index < num_srcs && /* More registers */
236  ret /* Still possible */)
237  {
238  RegId reg = staticInst->srcRegIdx(src_index).flatten(*isa);
239  unsigned short int index;
240 
241  if (findIndex(reg, index)) {
242  int src_reg_fu = fuIndices[index];
243  bool cant_forward = src_reg_fu != invalidFUIndex &&
244  cant_forward_from_fu_indices &&
245  src_reg_fu < cant_forward_from_fu_indices->size() &&
246  (*cant_forward_from_fu_indices)[src_reg_fu];
247 
248  Cycles relative_latency = (cant_forward ? Cycles(0) :
249  (src_index >= num_relative_latencies ?
250  default_relative_latency :
251  (*src_reg_relative_latencies)[src_index]));
252 
253  if (returnCycle[index] > (now + relative_latency) ||
255  {
256  ret = false;
257  }
258  }
259  src_index++;
260  }
261 
262  if (debug::MinorTiming) {
263  if (ret && num_srcs > num_relative_latencies &&
264  num_relative_latencies != 0)
265  {
266  DPRINTF(MinorTiming, "Warning, inst: %s timing extra decode has"
267  " more src. regs: %d than relative latencies: %d\n",
268  staticInst->disassemble(0), num_srcs, num_relative_latencies);
269  }
270  }
271 
272  return ret;
273 }
274 
275 void
277 {
278  std::ostringstream result_stream;
279 
280  bool printed_element = false;
281 
282  unsigned int i = 0;
283  while (i < numRegs) {
284  unsigned short int num_results = numResults[i];
285  unsigned short int num_unpredictable_results =
287 
288  if (!(num_results == 0 && num_unpredictable_results == Cycles(0))) {
289  if (printed_element)
290  result_stream << ',';
291 
292  result_stream << '(' << i << ','
293  << num_results << '/'
294  << num_unpredictable_results << '/'
295  << returnCycle[i] << '/'
296  << writingInst[i] << ')';
297 
298  printed_element = true;
299  }
300 
301  i++;
302  }
303 
304  minor::minorTrace("busy=%s\n", result_stream.str());
305 }
306 
307 } // namespace minor
308 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
RegId flatten(const BaseISA &isa) const
Definition: reg_class.hh:277
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:60
uint8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:123
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:225
uint8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:125
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:215
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
std::vector< Index > numUnpredictableResults
Count of the number of results which can't be predicted.
Definition: scoreboard.hh:93
void clearInstDests(MinorDynInstPtr inst, bool clear_unpredictable)
Clear down the dependencies for this instruction.
Definition: scoreboard.cc:167
std::vector< Cycles > returnCycle
The estimated cycle number that the result will be presented.
Definition: scoreboard.hh:103
static constexpr int invalidFUIndex
Definition: scoreboard.hh:97
const unsigned floatRegOffset
Definition: scoreboard.hh:72
bool canInstIssue(MinorDynInstPtr inst, const std::vector< Cycles > *src_reg_relative_latencies, const std::vector< bool > *cant_forward_from_fu_indices, Cycles now, ThreadContext *thread_context)
Can this instruction be issued.
Definition: scoreboard.cc:202
InstSeqNum execSeqNumToWaitFor(MinorDynInstPtr inst, ThreadContext *thread_context)
Returns the exec sequence number of the most recent inst on which the given inst depends.
Definition: scoreboard.cc:137
const unsigned vecRegOffset
Definition: scoreboard.hh:74
unsigned short int Index
Type to use when indexing numResults.
Definition: scoreboard.hh:86
const unsigned ccRegOffset
Definition: scoreboard.hh:73
std::vector< Index > numResults
Count of the number of in-flight instructions that have results for each register.
Definition: scoreboard.hh:90
std::vector< int > fuIndices
Index of the FU generating this result.
Definition: scoreboard.hh:96
const unsigned vecPredRegOffset
Definition: scoreboard.hh:75
bool findIndex(const RegId &reg, Index &scoreboard_index)
Sets scoreboard_index to the index into numResults of the given register index.
Definition: scoreboard.cc:52
void markupInstDests(MinorDynInstPtr inst, Cycles retire_time, ThreadContext *thread_context, bool mark_unpredictable)
Mark up an instruction's effects by incrementing numResults counts.
Definition: scoreboard.cc:93
std::vector< InstSeqNum > writingInst
The execute sequence number of the most recent inst to generate this register value.
Definition: scoreboard.hh:107
void minorTrace() const
MinorTraceIF interface.
Definition: scoreboard.cc:276
const unsigned numRegs
The number of registers in the Scoreboard.
Definition: scoreboard.hh:83
STL vector class.
Definition: stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
A simple instruction scoreboard for tracking dependencies in Execute.
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 30, 0 > index
Bitfield< 5, 3 > reg
Definition: types.hh:92
void minorTrace(const char *fmt, Args ...args)
DPRINTFN for MinorTrace reporting.
Definition: trace.hh:67
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t InstSeqNum
Definition: inst_seq.hh:40
@ VecPredRegClass
Definition: reg_class.hh:66
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:67
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:65
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Minor contains all the definitions within the MinorCPU apart from the CPU class itself.

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1