gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
pipeline.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-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 * 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
51namespace gem5
52{
53
54namespace minor
55{
56
57Pipeline::Pipeline(MinorCPU &cpu_, const BaseMinorCPUParams &params) :
58 Ticked(cpu_, &(cpu_.BaseCPU::baseStats.numCycles)),
59 cpu(cpu_),
60 allow_idling(params.enableIdling),
61 f1ToF2(cpu.name() + ".f1ToF2", "lines",
62 params.fetch1ToFetch2ForwardDelay),
63 f2ToF1(cpu.name() + ".f2ToF1", "prediction",
64 params.fetch1ToFetch2BackwardDelay, true),
65 f2ToD(cpu.name() + ".f2ToD", "insts",
66 params.fetch2ToDecodeForwardDelay),
67 dToE(cpu.name() + ".dToE", "insts",
68 params.decodeToExecuteForwardDelay),
69 eToF1(cpu.name() + ".eToF1", "branch",
70 params.executeBranchDelay),
71 execute(cpu.name() + ".execute", cpu, params,
72 dToE.output(), eToF1.input()),
73 decode(cpu.name() + ".decode", cpu, params,
74 f2ToD.output(), dToE.input(), execute.inputBuffer),
75 fetch2(cpu.name() + ".fetch2", cpu, params,
76 f1ToF2.output(), eToF1.output(), f2ToF1.input(), f2ToD.input(),
77 decode.inputBuffer),
78 fetch1(cpu.name() + ".fetch1", cpu, params,
79 eToF1.output(), f1ToF2.input(), f2ToF1.output(), fetch2.inputBuffer),
80 activityRecorder(cpu.name() + ".activity", Num_StageId,
81 /* The max depth of inter-stage FIFOs */
82 std::max(params.fetch1ToFetch2ForwardDelay,
83 std::max(params.fetch2ToDecodeForwardDelay,
84 std::max(params.decodeToExecuteForwardDelay,
85 params.executeBranchDelay)))),
87{
88 if (params.fetch1ToFetch2ForwardDelay < 1) {
89 fatal("%s: fetch1ToFetch2ForwardDelay must be >= 1 (%d)\n",
90 cpu.name(), params.fetch1ToFetch2ForwardDelay);
91 }
92
93 if (params.fetch2ToDecodeForwardDelay < 1) {
94 fatal("%s: fetch2ToDecodeForwardDelay must be >= 1 (%d)\n",
95 cpu.name(), params.fetch2ToDecodeForwardDelay);
96 }
97
98 if (params.decodeToExecuteForwardDelay < 1) {
99 fatal("%s: decodeToExecuteForwardDelay must be >= 1 (%d)\n",
100 cpu.name(), params.decodeToExecuteForwardDelay);
101 }
102
103 if (params.executeBranchDelay < 1) {
104 fatal("%s: executeBranchDelay must be >= 1\n",
105 cpu.name(), params.executeBranchDelay);
106 }
107}
108
109void
111{
112 fetch1.minorTrace();
113 f1ToF2.minorTrace();
114 f2ToF1.minorTrace();
115 fetch2.minorTrace();
116 f2ToD.minorTrace();
117 decode.minorTrace();
118 dToE.minorTrace();
119 execute.minorTrace();
120 eToF1.minorTrace();
121 activityRecorder.minorTrace();
122}
123
124void
126{
128 cpu.tick();
129
130 /* Note that it's important to evaluate the stages in order to allow
131 * 'immediate', 0-time-offset TimeBuffer activity to be visible from
132 * later stages to earlier ones in the same cycle */
133 execute.evaluate();
134 decode.evaluate();
135 fetch2.evaluate();
136 fetch1.evaluate();
137
138 if (debug::MinorTrace)
139 minorTrace();
140
141 /* Update the time buffers after the stages */
142 f1ToF2.evaluate();
143 f2ToF1.evaluate();
144 f2ToD.evaluate();
145 dToE.evaluate();
146 eToF1.evaluate();
147
148 /* The activity recorder must be be called after all the stages and
149 * before the idler (which acts on the advice of the activity recorder */
150 activityRecorder.evaluate();
151
152 if (allow_idling) {
153 /* Become idle if we can but are not draining */
154 if (!activityRecorder.active() && !needToSignalDrained) {
155 DPRINTF(Quiesce, "Suspending as the processor is idle\n");
156 stop();
157 }
158
159 /* Deactivate all stages. Note that the stages *could*
160 * activate and deactivate themselves but that's fraught
161 * with additional difficulty.
162 * As organised herre */
163 activityRecorder.deactivateStage(Pipeline::CPUStageId);
168 }
169
170 if (needToSignalDrained) /* Must be draining */
171 {
172 DPRINTF(Drain, "Still draining\n");
173 if (isDrained()) {
174 DPRINTF(Drain, "Signalling end of draining\n");
175 cpu.signalDrainDone();
176 needToSignalDrained = false;
177 stop();
178 }
179 }
180}
181
184{
185 return fetch1.getIcachePort();
186}
187
190{
191 return execute.getDcachePort();
192}
193
194void
196{
197 fetch1.wakeupFetch(tid);
198}
199
200bool
202{
203 DPRINTF(MinorCPU, "Draining pipeline by halting inst fetches. "
204 " Execution should drain naturally\n");
205
206 execute.drain();
207
208 /* Make sure that needToSignalDrained isn't accidentally set if we
209 * are 'pre-drained' */
210 bool drained = isDrained();
211 needToSignalDrained = !drained;
212
213 return drained;
214}
215
216void
218{
219 DPRINTF(Drain, "Drain resume\n");
220
221 for (ThreadID tid = 0; tid < cpu.numThreads; tid++) {
222 fetch1.wakeupFetch(tid);
223 }
224
225 execute.drainResume();
226}
227
228bool
230{
231 bool fetch1_drained = fetch1.isDrained();
232 bool fetch2_drained = fetch2.isDrained();
233 bool decode_drained = decode.isDrained();
234 bool execute_drained = execute.isDrained();
235
236 bool f1_to_f2_drained = f1ToF2.empty();
237 bool f2_to_f1_drained = f2ToF1.empty();
238 bool f2_to_d_drained = f2ToD.empty();
239 bool d_to_e_drained = dToE.empty();
240
241 bool ret = fetch1_drained && fetch2_drained &&
242 decode_drained && execute_drained &&
243 f1_to_f2_drained && f2_to_f1_drained &&
244 f2_to_d_drained && d_to_e_drained;
245
246 DPRINTF(MinorCPU, "Pipeline undrained stages state:%s%s%s%s%s%s%s%s\n",
247 (fetch1_drained ? "" : " Fetch1"),
248 (fetch2_drained ? "" : " Fetch2"),
249 (decode_drained ? "" : " Decode"),
250 (execute_drained ? "" : " Execute"),
251 (f1_to_f2_drained ? "" : " F1->F2"),
252 (f2_to_f1_drained ? "" : " F2->F1"),
253 (f2_to_d_drained ? "" : " F2->D"),
254 (d_to_e_drained ? "" : " D->E")
255 );
256
257 return ret;
258}
259
260} // namespace minor
261} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Provide a non-protected base class for Minor's Ports as derived classes are created by Fetch1 and Exe...
Definition cpu.hh:108
MinorCPU is an in-order CPU model with four fixed pipeline stages:
Definition cpu.hh:85
Ticked(ClockedObject &object_, statistics::Scalar *imported_num_cycles=NULL, Event::Priority priority=Event::CPU_Tick_Pri)
statistics::Scalar & numCycles
Total number of cycles either ticked or spend stopped.
void stop()
Cancel the next tick event and issue no more.
Latch< BranchData > f2ToF1
Definition pipeline.hh:81
Pipeline(MinorCPU &cpu_, const BaseMinorCPUParams &params)
Definition pipeline.cc:57
Latch< ForwardLineData > f1ToF2
Definition pipeline.hh:80
void minorTrace() const
Definition pipeline.cc:110
MinorCPU::MinorCPUPort & getDataPort()
Return the DcachePort belonging to Execute for the CPU.
Definition pipeline.cc:189
bool allow_idling
Allow cycles to be skipped when the pipeline is idle.
Definition pipeline.hh:78
bool needToSignalDrained
True after drain is called but draining isn't complete.
Definition pipeline.hh:108
MinorActivityRecorder activityRecorder
Activity recording for the pipeline.
Definition pipeline.hh:94
void evaluate() override
A custom evaluate allows report in the right place (between stages and pipeline advance)
Definition pipeline.cc:125
MinorCPU::MinorCPUPort & getInstPort()
Functions below here are BaseCPU operations passed on to pipeline stages.
Definition pipeline.cc:183
void wakeupFetch(ThreadID tid)
Wake up the Fetch unit.
Definition pipeline.cc:195
Latch< BranchData > eToF1
Definition pipeline.hh:84
Latch< ForwardInstData > dToE
Definition pipeline.hh:83
bool drain()
Try to drain the CPU.
Definition pipeline.cc:201
Latch< ForwardInstData > f2ToD
Definition pipeline.hh:82
bool isDrained()
Test to see if the CPU is drained.
Definition pipeline.cc:229
All the fun of executing instructions from Decode and sending branch/new instruction stream info.
Fetch1 is responsible for fetching "lines" from memory and passing them to Fetch2.
Fetch2 receives lines of data from Fetch1, separates them into instructions and passes them to Decode...
Decode collects macro-ops from Fetch2 and splits them into micro-ops passed to Execute.
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
static void output(const char *filename)
Definition debug.cc:60
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81
The constructed pipeline.
const std::string & name()
Definition trace.cc:48

Generated on Mon May 26 2025 09:19:07 for gem5 by doxygen 1.13.2