gem5  v20.1.0.0
pipeline.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 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/pipeline.hh"
39 
40 #include <algorithm>
41 
42 #include "cpu/minor/decode.hh"
43 #include "cpu/minor/execute.hh"
44 #include "cpu/minor/fetch1.hh"
45 #include "cpu/minor/fetch2.hh"
46 #include "debug/Drain.hh"
47 #include "debug/MinorCPU.hh"
48 #include "debug/MinorTrace.hh"
49 #include "debug/Quiesce.hh"
50 
51 namespace Minor
52 {
53 
54 Pipeline::Pipeline(MinorCPU &cpu_, MinorCPUParams &params) :
55  Ticked(cpu_, &(cpu_.BaseCPU::numCycles)),
56  cpu(cpu_),
57  allow_idling(params.enableIdling),
58  f1ToF2(cpu.name() + ".f1ToF2", "lines",
59  params.fetch1ToFetch2ForwardDelay),
60  f2ToF1(cpu.name() + ".f2ToF1", "prediction",
61  params.fetch1ToFetch2BackwardDelay, true),
62  f2ToD(cpu.name() + ".f2ToD", "insts",
63  params.fetch2ToDecodeForwardDelay),
64  dToE(cpu.name() + ".dToE", "insts",
65  params.decodeToExecuteForwardDelay),
66  eToF1(cpu.name() + ".eToF1", "branch",
67  params.executeBranchDelay),
68  execute(cpu.name() + ".execute", cpu, params,
69  dToE.output(), eToF1.input()),
70  decode(cpu.name() + ".decode", cpu, params,
71  f2ToD.output(), dToE.input(), execute.inputBuffer),
72  fetch2(cpu.name() + ".fetch2", cpu, params,
73  f1ToF2.output(), eToF1.output(), f2ToF1.input(), f2ToD.input(),
74  decode.inputBuffer),
75  fetch1(cpu.name() + ".fetch1", cpu, params,
76  eToF1.output(), f1ToF2.input(), f2ToF1.output(), fetch2.inputBuffer),
77  activityRecorder(cpu.name() + ".activity", Num_StageId,
78  /* The max depth of inter-stage FIFOs */
79  std::max(params.fetch1ToFetch2ForwardDelay,
80  std::max(params.fetch2ToDecodeForwardDelay,
81  std::max(params.decodeToExecuteForwardDelay,
82  params.executeBranchDelay)))),
83  needToSignalDrained(false)
84 {
85  if (params.fetch1ToFetch2ForwardDelay < 1) {
86  fatal("%s: fetch1ToFetch2ForwardDelay must be >= 1 (%d)\n",
87  cpu.name(), params.fetch1ToFetch2ForwardDelay);
88  }
89 
90  if (params.fetch2ToDecodeForwardDelay < 1) {
91  fatal("%s: fetch2ToDecodeForwardDelay must be >= 1 (%d)\n",
92  cpu.name(), params.fetch2ToDecodeForwardDelay);
93  }
94 
95  if (params.decodeToExecuteForwardDelay < 1) {
96  fatal("%s: decodeToExecuteForwardDelay must be >= 1 (%d)\n",
97  cpu.name(), params.decodeToExecuteForwardDelay);
98  }
99 
100  if (params.executeBranchDelay < 1) {
101  fatal("%s: executeBranchDelay must be >= 1\n",
102  cpu.name(), params.executeBranchDelay);
103  }
104 }
105 
106 void
108 {
109  fetch1.minorTrace();
110  f1ToF2.minorTrace();
111  f2ToF1.minorTrace();
112  fetch2.minorTrace();
113  f2ToD.minorTrace();
114  decode.minorTrace();
115  dToE.minorTrace();
117  eToF1.minorTrace();
119 }
120 
121 void
123 {
124  /* Note that it's important to evaluate the stages in order to allow
125  * 'immediate', 0-time-offset TimeBuffer activity to be visible from
126  * later stages to earlier ones in the same cycle */
127  execute.evaluate();
128  decode.evaluate();
129  fetch2.evaluate();
130  fetch1.evaluate();
131 
132  if (DTRACE(MinorTrace))
133  minorTrace();
134 
135  /* Update the time buffers after the stages */
136  f1ToF2.evaluate();
137  f2ToF1.evaluate();
138  f2ToD.evaluate();
139  dToE.evaluate();
140  eToF1.evaluate();
141 
142  /* The activity recorder must be be called after all the stages and
143  * before the idler (which acts on the advice of the activity recorder */
145 
146  if (allow_idling) {
147  /* Become idle if we can but are not draining */
149  DPRINTF(Quiesce, "Suspending as the processor is idle\n");
150  stop();
151  }
152 
153  /* Deactivate all stages. Note that the stages *could*
154  * activate and deactivate themselves but that's fraught
155  * with additional difficulty.
156  * As organised herre */
162  }
163 
164  if (needToSignalDrained) /* Must be draining */
165  {
166  DPRINTF(Drain, "Still draining\n");
167  if (isDrained()) {
168  DPRINTF(Drain, "Signalling end of draining\n");
170  needToSignalDrained = false;
171  stop();
172  }
173  }
174 }
175 
178 {
179  return fetch1.getIcachePort();
180 }
181 
184 {
185  return execute.getDcachePort();
186 }
187 
188 void
190 {
191  fetch1.wakeupFetch(tid);
192 }
193 
194 bool
196 {
197  DPRINTF(MinorCPU, "Draining pipeline by halting inst fetches. "
198  " Execution should drain naturally\n");
199 
200  execute.drain();
201 
202  /* Make sure that needToSignalDrained isn't accidentally set if we
203  * are 'pre-drained' */
204  bool drained = isDrained();
205  needToSignalDrained = !drained;
206 
207  return drained;
208 }
209 
210 void
212 {
213  DPRINTF(Drain, "Drain resume\n");
214 
215  for (ThreadID tid = 0; tid < cpu.numThreads; tid++) {
216  fetch1.wakeupFetch(tid);
217  }
218 
220 }
221 
222 bool
224 {
225  bool fetch1_drained = fetch1.isDrained();
226  bool fetch2_drained = fetch2.isDrained();
227  bool decode_drained = decode.isDrained();
228  bool execute_drained = execute.isDrained();
229 
230  bool f1_to_f2_drained = f1ToF2.empty();
231  bool f2_to_f1_drained = f2ToF1.empty();
232  bool f2_to_d_drained = f2ToD.empty();
233  bool d_to_e_drained = dToE.empty();
234 
235  bool ret = fetch1_drained && fetch2_drained &&
236  decode_drained && execute_drained &&
237  f1_to_f2_drained && f2_to_f1_drained &&
238  f2_to_d_drained && d_to_e_drained;
239 
240  DPRINTF(MinorCPU, "Pipeline undrained stages state:%s%s%s%s%s%s%s%s\n",
241  (fetch1_drained ? "" : " Fetch1"),
242  (fetch2_drained ? "" : " Fetch2"),
243  (decode_drained ? "" : " Decode"),
244  (execute_drained ? "" : " Execute"),
245  (f1_to_f2_drained ? "" : " F1->F2"),
246  (f2_to_f1_drained ? "" : " F2->F1"),
247  (f2_to_d_drained ? "" : " F2->D"),
248  (d_to_e_drained ? "" : " D->E")
249  );
250 
251  return ret;
252 }
253 
254 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
Minor::Pipeline::getDataPort
MinorCPU::MinorCPUPort & getDataPort()
Return the DcachePort belonging to Execute for the CPU.
Definition: pipeline.cc:183
output
static void output(const char *filename)
Definition: debug.cc:60
Minor::Fetch1::evaluate
void evaluate()
Pass on input/buffer data to the output if you can.
Definition: fetch1.cc:563
Minor::Pipeline::activityRecorder
MinorActivityRecorder activityRecorder
Activity recording for the pipeline.
Definition: pipeline.hh:91
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
Minor::Decode::evaluate
void evaluate()
Pass on input/buffer data to the output if you can.
Definition: decode.cc:122
Minor::Pipeline::drain
bool drain()
Try to drain the CPU.
Definition: pipeline.cc:195
Minor::Pipeline::isDrained
bool isDrained()
Test to see if the CPU is drained.
Definition: pipeline.cc:223
Minor::Pipeline::f1ToF2
Latch< ForwardLineData > f1ToF2
Definition: pipeline.hh:77
Minor::Pipeline::ExecuteStageId
@ ExecuteStageId
Definition: pipeline.hh:100
Minor::Pipeline::Fetch2StageId
@ Fetch2StageId
Definition: pipeline.hh:100
Minor::Execute::minorTrace
void minorTrace() const
Definition: execute.cc:1653
Minor::Pipeline::needToSignalDrained
bool needToSignalDrained
True after drain is called but draining isn't complete.
Definition: pipeline.hh:105
DTRACE
#define DTRACE(x)
Definition: debug.hh:146
Minor::Pipeline::f2ToD
Latch< ForwardInstData > f2ToD
Definition: pipeline.hh:79
Minor
Definition: activity.cc:44
ActivityRecorder::active
bool active()
Returns if the CPU should be active.
Definition: activity.hh:88
execute.hh
Minor::Execute::isDrained
bool isDrained()
After thread suspension, has Execute been drained of in-flight instructions and memory accesses.
Definition: execute.cc:1846
Minor::Fetch2::evaluate
void evaluate()
Pass on input/buffer data to the output if you can.
Definition: fetch2.cc:237
fetch2.hh
Minor::Execute::getDcachePort
MinorCPU::MinorCPUPort & getDcachePort()
Returns the DcachePort owned by this Execute to pass upwards.
Definition: execute.cc:1889
Minor::Fetch1::wakeupFetch
void wakeupFetch(ThreadID tid)
Initiate fetch1 fetching.
Definition: fetch1.cc:704
Minor::Fetch1::getIcachePort
MinorCPU::MinorCPUPort & getIcachePort()
Returns the IcachePort owned by this Fetch1.
Definition: fetch1.hh:393
decode.hh
Minor::Pipeline::f2ToF1
Latch< BranchData > f2ToF1
Definition: pipeline.hh:78
Minor::Decode::minorTrace
void minorTrace() const
Definition: decode.cc:336
Minor::Pipeline::allow_idling
bool allow_idling
Allow cycles to be skipped when the pipeline is idle.
Definition: pipeline.hh:75
Minor::Pipeline::execute
Execute execute
Definition: pipeline.hh:83
MinorCPU
MinorCPU is an in-order CPU model with four fixed pipeline stages:
Definition: cpu.hh:77
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Minor::Execute::evaluate
void evaluate()
Pass on input/buffer data to the output if you can.
Definition: execute.cc:1421
Ticked::stop
void stop()
Cancel the next tick event and issue no more.
Definition: ticked_object.hh:130
Minor::Execute::drain
unsigned int drain()
Like the drain interface on SimObject.
Definition: execute.cc:1824
Ticked
Ticked attaches gem5's event queue/scheduler to evaluate calls and provides a start/stop interface to...
Definition: ticked_object.hh:58
pipeline.hh
Minor::Pipeline::Pipeline
Pipeline(MinorCPU &cpu_, MinorCPUParams &params)
Definition: pipeline.cc:54
Minor::MinorActivityRecorder::minorTrace
void minorTrace() const
Definition: activity.cc:48
Minor::Pipeline::DecodeStageId
@ DecodeStageId
Definition: pipeline.hh:100
Minor::Pipeline::eToF1
Latch< BranchData > eToF1
Definition: pipeline.hh:81
Minor::Decode::isDrained
bool isDrained()
Is this stage drained? For Decoed, draining is initiated by Execute halting Fetch1 causing Fetch2 to ...
Definition: decode.cc:325
MinorCPU::MinorCPUPort
Provide a non-protected base class for Minor's Ports as derived classes are created by Fetch1 and Exe...
Definition: cpu.hh:98
Minor::Pipeline::dToE
Latch< ForwardInstData > dToE
Definition: pipeline.hh:80
Minor::Pipeline::Fetch1StageId
@ Fetch1StageId
Definition: pipeline.hh:100
Minor::Pipeline::CPUStageId
@ CPUStageId
Definition: pipeline.hh:98
Minor::Pipeline::minorTrace
void minorTrace() const
Definition: pipeline.cc:107
MinorCPU::signalDrainDone
void signalDrainDone()
Signal from Pipeline that MinorCPU should signal that a drain is complete and set its drainState.
Definition: cpu.cc:193
name
const std::string & name()
Definition: trace.cc:50
BaseCPU
Definition: cpu_dummy.hh:43
Minor::Pipeline::cpu
MinorCPU & cpu
Definition: pipeline.hh:72
Minor::MinorActivityRecorder::evaluate
void evaluate()
Ticked interface.
Definition: activity.hh:58
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Minor::Pipeline::evaluate
void evaluate() override
A custom evaluate allows report in the right place (between stages and pipeline advance)
Definition: pipeline.cc:122
Minor::Fetch1::minorTrace
void minorTrace() const
Definition: fetch1.cc:752
Minor::Fetch1::isDrained
bool isDrained()
Is this stage drained? For Fetch1, draining is initiated by Execute signalling a branch with the reas...
Definition: fetch1.cc:718
Minor::Pipeline::wakeupFetch
void wakeupFetch(ThreadID tid)
Wake up the Fetch unit.
Definition: pipeline.cc:189
Minor::Pipeline::fetch1
Fetch1 fetch1
Definition: pipeline.hh:86
Minor::Pipeline::drainResume
void drainResume()
Definition: pipeline.cc:211
Minor::Pipeline::decode
Decode decode
Definition: pipeline.hh:84
BaseCPU::numThreads
ThreadID numThreads
Number of threads we're actually simulating (<= SMT_MAX_THREADS).
Definition: base.hh:363
Minor::Fetch2::isDrained
bool isDrained()
Is this stage drained? For Fetch2, draining is initiated by Execute halting Fetch1 causing Fetch2 to ...
Definition: fetch2.cc:594
Minor::Execute::drainResume
void drainResume()
Definition: execute.cc:1781
ActivityRecorder::deactivateStage
void deactivateStage(const int idx)
Deactivates a stage.
Definition: activity.cc:107
fetch1.hh
Minor::Fetch2::minorTrace
void minorTrace() const
Definition: fetch2.cc:635
Minor::Pipeline::getInstPort
MinorCPU::MinorCPUPort & getInstPort()
Functions below here are BaseCPU operations passed on to pipeline stages.
Definition: pipeline.cc:177
Minor::Pipeline::fetch2
Fetch2 fetch2
Definition: pipeline.hh:85

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17