2 * Copyright (c) 2012-2014, 2017 ARM Limited
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.
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.
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.
38 #include "cpu/minor/cpu.hh"
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"
48 MinorCPU::MinorCPU(MinorCPUParams
*params
) :
50 threadPolicy(params
->threadPolicy
)
52 /* This is only written for one thread at the moment */
53 Minor::MinorThread
*thread
;
55 for (ThreadID i
= 0; i
< numThreads
; i
++) {
57 thread
= new Minor::MinorThread(this, i
, params
->system
,
58 params
->itb
, params
->dtb
, params
->isa
[i
]);
59 thread
->setStatus(ThreadContext::Halted
);
61 thread
= new Minor::MinorThread(this, i
, params
->system
,
62 params
->workload
[i
], params
->itb
, params
->dtb
,
66 threads
.push_back(thread
);
67 ThreadContext
*tc
= thread
->getTC();
68 threadContexts
.push_back(tc
);
72 if (params
->checker
) {
73 fatal("The Minor model doesn't support checking (yet)\n");
76 Minor::MinorDynInst::init();
78 pipeline
= new Minor::Pipeline(*this, *params
);
79 activityRecorder
= pipeline
->getActivityRecorder();
86 for (ThreadID thread_id
= 0; thread_id
< threads
.size(); thread_id
++) {
87 delete threads
[thread_id
];
96 if (!params()->switched_out
&&
97 system
->getMemoryMode() != Enums::timing
)
99 fatal("The Minor CPU requires the memory system to be in "
103 /* Initialise the ThreadContext's memory proxies */
104 for (ThreadID thread_id
= 0; thread_id
< threads
.size(); thread_id
++) {
105 ThreadContext
*tc
= getContext(thread_id
);
107 tc
->initMemProxies(tc
);
111 /** Stats interface from SimObject (by way of BaseCPU) */
116 stats
.regStats(name(), *this);
117 pipeline
->regStats();
121 MinorCPU::serializeThread(CheckpointOut
&cp
, ThreadID thread_id
) const
123 threads
[thread_id
]->serialize(cp
);
127 MinorCPU::unserializeThread(CheckpointIn
&cp
, ThreadID thread_id
)
129 threads
[thread_id
]->unserialize(cp
);
133 MinorCPU::serialize(CheckpointOut
&cp
) const
135 pipeline
->serialize(cp
);
136 BaseCPU::serialize(cp
);
140 MinorCPU::unserialize(CheckpointIn
&cp
)
142 pipeline
->unserialize(cp
);
143 BaseCPU::unserialize(cp
);
147 MinorCPU::wakeup(ThreadID tid
)
149 DPRINTF(Drain
, "[tid:%d] MinorCPU wakeup\n", tid
);
150 assert(tid
< numThreads
);
152 if (threads
[tid
]->status() == ThreadContext::Suspended
) {
153 threads
[tid
]->activate();
160 DPRINTF(MinorCPU
, "MinorCPU startup\n");
164 for (ThreadID tid
= 0; tid
< numThreads
; tid
++)
165 pipeline
->wakeupFetch(tid
);
171 // Deschedule any power gating event (if any)
172 deschedulePowerGatingEvent();
175 DPRINTF(Drain
, "Minor CPU switched out, draining not needed.\n");
176 return DrainState::Drained
;
179 DPRINTF(Drain
, "MinorCPU drain\n");
181 /* Need to suspend all threads and wait for Execute to idle.
182 * Tell Fetch1 not to fetch */
183 if (pipeline
->drain()) {
184 DPRINTF(Drain
, "MinorCPU drained\n");
185 return DrainState::Drained
;
187 DPRINTF(Drain
, "MinorCPU not finished draining\n");
188 return DrainState::Draining
;
193 MinorCPU::signalDrainDone()
195 DPRINTF(Drain
, "MinorCPU drain done\n");
196 Drainable::signalDrainDone();
200 MinorCPU::drainResume()
202 /* When taking over from another cpu make sure lastStopped
203 * is reset since it might have not been defined previously
204 * and might lead to a stats corruption */
205 pipeline
->resetLastStopped();
208 DPRINTF(Drain
, "drainResume while switched out. Ignoring\n");
212 DPRINTF(Drain
, "MinorCPU drainResume\n");
214 if (!system
->isTimingMode()) {
215 fatal("The Minor CPU requires the memory system to be in "
219 for (ThreadID tid
= 0; tid
< numThreads
; tid
++){
223 pipeline
->drainResume();
225 // Reschedule any power gating event (if any)
226 schedulePowerGatingEvent();
230 MinorCPU::memWriteback()
232 DPRINTF(Drain
, "MinorCPU memWriteback\n");
236 MinorCPU::switchOut()
238 DPRINTF(MinorCPU
, "MinorCPU switchOut\n");
240 assert(!switchedOut());
241 BaseCPU::switchOut();
243 /* Check that the CPU is drained? */
244 activityRecorder
->reset();
248 MinorCPU::takeOverFrom(BaseCPU
*old_cpu
)
250 DPRINTF(MinorCPU
, "MinorCPU takeOverFrom\n");
252 BaseCPU::takeOverFrom(old_cpu
);
256 MinorCPU::activateContext(ThreadID thread_id
)
258 DPRINTF(MinorCPU
, "ActivateContext thread: %d\n", thread_id
);
260 /* Do some cycle accounting. lastStopped is reset to stop the
261 * wakeup call on the pipeline from adding the quiesce period
262 * to BaseCPU::numCycles */
263 stats
.quiesceCycles
+= pipeline
->cyclesSinceLastStopped();
264 pipeline
->resetLastStopped();
266 /* Wake up the thread, wakeup the pipeline tick */
267 threads
[thread_id
]->activate();
268 wakeupOnEvent(Minor::Pipeline::CPUStageId
);
269 pipeline
->wakeupFetch(thread_id
);
271 BaseCPU::activateContext(thread_id
);
275 MinorCPU::suspendContext(ThreadID thread_id
)
277 DPRINTF(MinorCPU
, "SuspendContext %d\n", thread_id
);
279 threads
[thread_id
]->suspend();
281 BaseCPU::suspendContext(thread_id
);
285 MinorCPU::wakeupOnEvent(unsigned int stage_id
)
287 DPRINTF(Quiesce
, "Event wakeup from stage %d\n", stage_id
);
289 /* Mark that some activity has taken place and start the pipeline */
290 activityRecorder
->activateStage(stage_id
);
295 MinorCPUParams::create()
297 return new MinorCPU(this);
301 MinorCPU::getInstPort()
303 return pipeline
->getInstPort();
307 MinorCPU::getDataPort()
309 return pipeline
->getDataPort();
313 MinorCPU::totalInsts() const
317 for (auto i
= threads
.begin(); i
!= threads
.end(); i
++)
318 ret
+= (*i
)->numInst
;
324 MinorCPU::totalOps() const
328 for (auto i
= threads
.begin(); i
!= threads
.end(); i
++)