gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cpu.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014, 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/cpu.hh"
39 
40 #include "arch/utility.hh"
41 #include "cpu/minor/dyn_inst.hh"
42 #include "cpu/minor/fetch1.hh"
43 #include "cpu/minor/pipeline.hh"
44 #include "debug/Drain.hh"
45 #include "debug/MinorCPU.hh"
46 #include "debug/Quiesce.hh"
47 
48 MinorCPU::MinorCPU(const MinorCPUParams &params) :
49  BaseCPU(params),
50  threadPolicy(params.threadPolicy),
51  stats(this)
52 {
53  /* This is only written for one thread at the moment */
54  Minor::MinorThread *thread;
55 
56  for (ThreadID i = 0; i < numThreads; i++) {
57  if (FullSystem) {
58  thread = new Minor::MinorThread(this, i, params.system,
59  params.mmu, params.isa[i]);
61  } else {
62  thread = new Minor::MinorThread(this, i, params.system,
63  params.workload[i], params.mmu,
64  params.isa[i]);
65  }
66 
67  threads.push_back(thread);
68  ThreadContext *tc = thread->getTC();
69  threadContexts.push_back(tc);
70  }
71 
72 
73  if (params.checker) {
74  fatal("The Minor model doesn't support checking (yet)\n");
75  }
76 
78 
79  pipeline = new Minor::Pipeline(*this, params);
80  activityRecorder = pipeline->getActivityRecorder();
81 
82  fetchEventWrapper = NULL;
83 }
84 
86 {
87  delete pipeline;
88 
89  if (fetchEventWrapper != NULL)
90  delete fetchEventWrapper;
91 
92  for (ThreadID thread_id = 0; thread_id < threads.size(); thread_id++) {
93  delete threads[thread_id];
94  }
95 }
96 
97 void
99 {
100  BaseCPU::init();
101 
102  if (!params().switched_out &&
103  system->getMemoryMode() != Enums::timing)
104  {
105  fatal("The Minor CPU requires the memory system to be in "
106  "'timing' mode.\n");
107  }
108 
109  /* Initialise the ThreadContext's memory proxies */
110  for (ThreadID thread_id = 0; thread_id < threads.size(); thread_id++) {
111  ThreadContext *tc = getContext(thread_id);
112 
113  tc->initMemProxies(tc);
114  }
115 }
116 
118 void
120 {
122  pipeline->regStats();
123 }
124 
125 void
127 {
128  threads[thread_id]->serialize(cp);
129 }
130 
131 void
133 {
134  threads[thread_id]->unserialize(cp);
135 }
136 
137 void
139 {
140  pipeline->serialize(cp);
142 }
143 
144 void
146 {
147  pipeline->unserialize(cp);
149 }
150 
151 void
153 {
154  DPRINTF(Drain, "[tid:%d] MinorCPU wakeup\n", tid);
155  assert(tid < numThreads);
156 
157  if (threads[tid]->status() == ThreadContext::Suspended) {
158  threads[tid]->activate();
159  }
160 }
161 
162 void
164 {
165  DPRINTF(MinorCPU, "MinorCPU startup\n");
166 
168 
169  for (ThreadID tid = 0; tid < numThreads; tid++)
170  pipeline->wakeupFetch(tid);
171 }
172 
175 {
176  // Deschedule any power gating event (if any)
178 
179  if (switchedOut()) {
180  DPRINTF(Drain, "Minor CPU switched out, draining not needed.\n");
181  return DrainState::Drained;
182  }
183 
184  DPRINTF(Drain, "MinorCPU drain\n");
185 
186  /* Need to suspend all threads and wait for Execute to idle.
187  * Tell Fetch1 not to fetch */
188  if (pipeline->drain()) {
189  DPRINTF(Drain, "MinorCPU drained\n");
190  return DrainState::Drained;
191  } else {
192  DPRINTF(Drain, "MinorCPU not finished draining\n");
193  return DrainState::Draining;
194  }
195 }
196 
197 void
199 {
200  DPRINTF(Drain, "MinorCPU drain done\n");
202 }
203 
204 void
206 {
207  /* When taking over from another cpu make sure lastStopped
208  * is reset since it might have not been defined previously
209  * and might lead to a stats corruption */
210  pipeline->resetLastStopped();
211 
212  if (switchedOut()) {
213  DPRINTF(Drain, "drainResume while switched out. Ignoring\n");
214  return;
215  }
216 
217  DPRINTF(Drain, "MinorCPU drainResume\n");
218 
219  if (!system->isTimingMode()) {
220  fatal("The Minor CPU requires the memory system to be in "
221  "'timing' mode.\n");
222  }
223 
224  for (ThreadID tid = 0; tid < numThreads; tid++){
225  wakeup(tid);
226  }
227 
228  pipeline->drainResume();
229 
230  // Reschedule any power gating event (if any)
232 }
233 
234 void
236 {
237  DPRINTF(Drain, "MinorCPU memWriteback\n");
238 }
239 
240 void
242 {
243  DPRINTF(MinorCPU, "MinorCPU switchOut\n");
244 
245  assert(!switchedOut());
247 
248  /* Check that the CPU is drained? */
250 }
251 
252 void
254 {
255  DPRINTF(MinorCPU, "MinorCPU takeOverFrom\n");
256 
257  BaseCPU::takeOverFrom(old_cpu);
258 }
259 
260 void
262 {
263  DPRINTF(MinorCPU, "ActivateContext thread: %d\n", thread_id);
264 
265  /* Do some cycle accounting. lastStopped is reset to stop the
266  * wakeup call on the pipeline from adding the quiesce period
267  * to BaseCPU::numCycles */
268  stats.quiesceCycles += pipeline->cyclesSinceLastStopped();
269  pipeline->resetLastStopped();
270 
271  /* Wake up the thread, wakeup the pipeline tick */
272  threads[thread_id]->activate();
274 
275  if (!threads[thread_id]->getUseForClone())//the thread is not cloned
276  {
277  pipeline->wakeupFetch(thread_id);
278  } else { //the thread from clone
279  if (fetchEventWrapper != NULL)
280  delete fetchEventWrapper;
281  fetchEventWrapper = new EventFunctionWrapper([this, thread_id]
282  { pipeline->wakeupFetch(thread_id); }, "wakeupFetch");
284  }
285 
286  BaseCPU::activateContext(thread_id);
287 }
288 
289 void
291 {
292  DPRINTF(MinorCPU, "SuspendContext %d\n", thread_id);
293 
294  threads[thread_id]->suspend();
295 
296  BaseCPU::suspendContext(thread_id);
297 }
298 
299 void
300 MinorCPU::wakeupOnEvent(unsigned int stage_id)
301 {
302  DPRINTF(Quiesce, "Event wakeup from stage %d\n", stage_id);
303 
304  /* Mark that some activity has taken place and start the pipeline */
305  activityRecorder->activateStage(stage_id);
306  pipeline->start();
307 }
308 
309 Port &
311 {
312  return pipeline->getInstPort();
313 }
314 
315 Port &
317 {
318  return pipeline->getDataPort();
319 }
320 
321 Counter
323 {
324  Counter ret = 0;
325 
326  for (auto i = threads.begin(); i != threads.end(); i ++)
327  ret += (*i)->numInst;
328 
329  return ret;
330 }
331 
332 Counter
334 {
335  Counter ret = 0;
336 
337  for (auto i = threads.begin(); i != threads.end(); i ++)
338  ret += (*i)->numOp;
339 
340  return ret;
341 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
dyn_inst.hh
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
MinorCPU::wakeup
void wakeup(ThreadID tid) override
Definition: cpu.cc:152
BaseCPU::regStats
void regStats() override
Callback to set stat parameters.
Definition: base.cc:382
MinorCPU::totalInsts
Counter totalInsts() const override
Simple inst count interface from BaseCPU.
Definition: cpu.cc:322
MinorCPU::wakeupOnEvent
void wakeupOnEvent(unsigned int stage_id)
Interface for stages to signal that they have become active after a callback or eventq event where th...
Definition: cpu.cc:300
MinorCPU::getInstPort
Port & getInstPort() override
Return a reference to the instruction port.
Definition: cpu.cc:310
System::isTimingMode
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:264
MinorCPU::init
void init() override
Starting, waking and initialisation.
Definition: cpu.cc:98
BaseCPU::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: base.cc:269
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:233
MinorCPU::suspendContext
void suspendContext(ThreadID thread_id) override
Notify the CPU that the indicated context is now suspended.
Definition: cpu.cc:290
MinorCPU::activityRecorder
Minor::MinorActivityRecorder * activityRecorder
Activity recording for pipeline.
Definition: cpu.hh:88
cpu.hh
MinorCPU::MinorCPU
MinorCPU(const MinorCPUParams &params)
Definition: cpu.cc:48
Minor::MinorThread
SimpleThread MinorThread
Minor will use the SimpleThread state for now.
Definition: cpu.hh:58
MinorCPU::stats
Minor::MinorStats stats
Processor-specific statistics.
Definition: cpu.hh:132
BaseCPU::deschedulePowerGatingEvent
void deschedulePowerGatingEvent()
Definition: base.cc:448
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:204
BaseCPU::getContext
virtual ThreadContext * getContext(int tn)
Given a thread num get tho thread context for it.
Definition: base.hh:300
SimpleThread
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
Definition: simple_thread.hh:90
EventFunctionWrapper
Definition: eventq.hh:1112
MinorCPU::threads
std::vector< Minor::MinorThread * > threads
These are thread state-representing objects for this CPU.
Definition: cpu.hh:93
DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
Counter
int64_t Counter
Statistics counter type.
Definition: types.hh:54
MinorCPU::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: cpu.cc:163
MinorCPU::~MinorCPU
~MinorCPU()
Definition: cpu.cc:85
MinorCPU::takeOverFrom
void takeOverFrom(BaseCPU *old_cpu) override
Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be sw...
Definition: cpu.cc:253
cp
Definition: cprintf.cc:37
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1016
ThreadContext::initMemProxies
virtual void initMemProxies(ThreadContext *tc)=0
Initialise the physical and virtual port proxies and tie them to the data port of the CPU.
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
SimpleThread::setStatus
void setStatus(Status newStatus) override
Definition: simple_thread.hh:228
SimpleThread::getTC
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
Definition: simple_thread.hh:165
MinorCPU
MinorCPU is an in-order CPU model with four fixed pipeline stages:
Definition: cpu.hh:77
Minor::MinorDynInst::init
static void init()
Initialise the class.
Definition: dyn_inst.cc:79
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
ThreadContext::Halted
@ Halted
Permanently shut down.
Definition: thread_context.hh:116
MinorCPU::switchOut
void switchOut() override
Switching interface from BaseCPU.
Definition: cpu.cc:241
MinorCPU::memWriteback
void memWriteback() override
Write back dirty buffers to memory using functional writes.
Definition: cpu.cc:235
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Minor::Pipeline
The constructed pipeline.
Definition: pipeline.hh:69
pipeline.hh
MinorCPU::drainResume
void drainResume() override
Resume execution after a successful drain.
Definition: cpu.cc:205
BaseCPU::threadContexts
std::vector< ThreadContext * > threadContexts
Definition: base.hh:269
Clocked::clockEdge
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Definition: clocked_object.hh:174
BaseCPU::serialize
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
Definition: base.cc:626
BaseCPU::activateContext
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
Definition: base.cc:484
MinorCPU::activateContext
void activateContext(ThreadID thread_id) override
Thread activation interface from BaseCPU.
Definition: cpu.cc:261
Drainable::signalDrainDone
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:301
Minor::Pipeline::CPUStageId
@ CPUStageId
Definition: pipeline.hh:98
MinorCPU::pipeline
Minor::Pipeline * pipeline
pipeline is a container for the clockable pipeline stage objects.
Definition: cpu.hh:82
MinorCPU::regStats
void regStats() override
Stats interface from SimObject (by way of BaseCPU)
Definition: cpu.cc:119
ActivityRecorder::reset
void reset()
Clears the time buffer and the activity count.
Definition: activity.cc:122
MinorCPU::signalDrainDone
void signalDrainDone()
Signal from Pipeline that MinorCPU should signal that a drain is complete and set its drainState.
Definition: cpu.cc:198
MinorCPU::totalOps
Counter totalOps() const override
Definition: cpu.cc:333
MinorCPU::fetchEventWrapper
EventFunctionWrapper * fetchEventWrapper
Definition: cpu.hh:195
MinorCPU::unserializeThread
void unserializeThread(CheckpointIn &cp, ThreadID tid) override
Unserialize one thread.
Definition: cpu.cc:132
BaseCPU
Definition: base.hh:104
System::getMemoryMode
Enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition: system.hh:287
ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:107
BaseCPU::schedulePowerGatingEvent
void schedulePowerGatingEvent()
Definition: base.cc:456
BaseCPU::system
System * system
Definition: base.hh:386
BaseCPU::takeOverFrom
virtual void takeOverFrom(BaseCPU *cpu)
Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be sw...
Definition: base.cc:550
Minor::MinorStats::quiesceCycles
Stats::Scalar quiesceCycles
Number of cycles in quiescent state.
Definition: stats.hh:72
BaseCPU::switchOut
virtual void switchOut()
Prepare for another CPU to take over execution.
Definition: base.cc:536
BaseCPU::numThreads
ThreadID numThreads
Number of threads we're actually simulating (<= SMT_MAX_THREADS).
Definition: base.hh:378
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
BaseCPU::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: base.cc:312
ActivityRecorder::activateStage
void activateStage(const int idx)
Marks a stage as active.
Definition: activity.cc:88
BaseCPU::suspendContext
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
Definition: base.cc:498
MinorCPU::getDataPort
Port & getDataPort() override
Return a reference to the data port.
Definition: cpu.cc:316
SimObject::params
const Params & params() const
Definition: sim_object.hh:168
pipeline
Definition: pipeline.h:43
MinorCPU::unserialize
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Definition: cpu.cc:145
BaseCPU::switchedOut
bool switchedOut() const
Determine if the CPU is switched out.
Definition: base.hh:367
CheckpointIn
Definition: serialize.hh:68
MinorCPU::serializeThread
void serializeThread(CheckpointOut &cp, ThreadID tid) const override
Serialize a single thread.
Definition: cpu.cc:126
BaseCPU::unserialize
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Definition: base.cc:647
MinorCPU::serialize
void serialize(CheckpointOut &cp) const override
Serialize pipeline data.
Definition: cpu.cc:138
MinorCPU::drain
DrainState drain() override
Drain interface.
Definition: cpu.cc:174
fetch1.hh
DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.

Generated on Tue Mar 23 2021 19:41:18 for gem5 by doxygen 1.8.17