cpu: Make accesses to comInstEventQueue indirect through methods.
[gem5.git] / src / cpu / base.cc
1 /*
2 * Copyright (c) 2011-2012,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 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2011 Regents of the University of California
16 * Copyright (c) 2013 Advanced Micro Devices, Inc.
17 * Copyright (c) 2013 Mark D. Hill and David A. Wood
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are
22 * met: redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer;
24 * redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution;
27 * neither the name of the copyright holders nor the names of its
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * Authors: Steve Reinhardt
44 * Nathan Binkert
45 * Rick Strong
46 */
47
48 #include "cpu/base.hh"
49
50 #include <iostream>
51 #include <sstream>
52 #include <string>
53
54 #include "arch/generic/tlb.hh"
55 #include "base/cprintf.hh"
56 #include "base/loader/symtab.hh"
57 #include "base/logging.hh"
58 #include "base/output.hh"
59 #include "base/trace.hh"
60 #include "cpu/checker/cpu.hh"
61 #include "cpu/cpuevent.hh"
62 #include "cpu/profile.hh"
63 #include "cpu/thread_context.hh"
64 #include "debug/Mwait.hh"
65 #include "debug/SyscallVerbose.hh"
66 #include "mem/page_table.hh"
67 #include "params/BaseCPU.hh"
68 #include "sim/clocked_object.hh"
69 #include "sim/full_system.hh"
70 #include "sim/process.hh"
71 #include "sim/sim_events.hh"
72 #include "sim/sim_exit.hh"
73 #include "sim/system.hh"
74
75 // Hack
76 #include "sim/stat_control.hh"
77
78 using namespace std;
79
80 vector<BaseCPU *> BaseCPU::cpuList;
81
82 // This variable reflects the max number of threads in any CPU. Be
83 // careful to only use it once all the CPUs that you care about have
84 // been initialized
85 int maxThreadsPerCPU = 1;
86
87 CPUProgressEvent::CPUProgressEvent(BaseCPU *_cpu, Tick ival)
88 : Event(Event::Progress_Event_Pri), _interval(ival), lastNumInst(0),
89 cpu(_cpu), _repeatEvent(true)
90 {
91 if (_interval)
92 cpu->schedule(this, curTick() + _interval);
93 }
94
95 void
96 CPUProgressEvent::process()
97 {
98 Counter temp = cpu->totalOps();
99
100 if (_repeatEvent)
101 cpu->schedule(this, curTick() + _interval);
102
103 if (cpu->switchedOut()) {
104 return;
105 }
106
107 #ifndef NDEBUG
108 double ipc = double(temp - lastNumInst) / (_interval / cpu->clockPeriod());
109
110 DPRINTFN("%s progress event, total committed:%i, progress insts committed: "
111 "%lli, IPC: %0.8d\n", cpu->name(), temp, temp - lastNumInst,
112 ipc);
113 ipc = 0.0;
114 #else
115 cprintf("%lli: %s progress event, total committed:%i, progress insts "
116 "committed: %lli\n", curTick(), cpu->name(), temp,
117 temp - lastNumInst);
118 #endif
119 lastNumInst = temp;
120 }
121
122 const char *
123 CPUProgressEvent::description() const
124 {
125 return "CPU Progress";
126 }
127
128 BaseCPU::BaseCPU(Params *p, bool is_checker)
129 : ClockedObject(p), instCnt(0), _cpuId(p->cpu_id), _socketId(p->socket_id),
130 _instMasterId(p->system->getMasterId(this, "inst")),
131 _dataMasterId(p->system->getMasterId(this, "data")),
132 _taskId(ContextSwitchTaskId::Unknown), _pid(invldPid),
133 _switchedOut(p->switched_out), _cacheLineSize(p->system->cacheLineSize()),
134 interrupts(p->interrupts), profileEvent(NULL),
135 numThreads(p->numThreads), system(p->system),
136 previousCycle(0), previousState(CPU_STATE_SLEEP),
137 functionTraceStream(nullptr), currentFunctionStart(0),
138 currentFunctionEnd(0), functionEntryTick(0),
139 addressMonitor(p->numThreads),
140 syscallRetryLatency(p->syscallRetryLatency),
141 pwrGatingLatency(p->pwr_gating_latency),
142 powerGatingOnIdle(p->power_gating_on_idle),
143 enterPwrGatingEvent([this]{ enterPwrGating(); }, name())
144 {
145 // if Python did not provide a valid ID, do it here
146 if (_cpuId == -1 ) {
147 _cpuId = cpuList.size();
148 }
149
150 // add self to global list of CPUs
151 cpuList.push_back(this);
152
153 DPRINTF(SyscallVerbose, "Constructing CPU with id %d, socket id %d\n",
154 _cpuId, _socketId);
155
156 if (numThreads > maxThreadsPerCPU)
157 maxThreadsPerCPU = numThreads;
158
159 // allocate per-thread instruction-based event queues
160 comInstEventQueue = new EventQueue *[numThreads];
161 for (ThreadID tid = 0; tid < numThreads; ++tid)
162 comInstEventQueue[tid] =
163 new EventQueue("instruction-based event queue");
164
165 //
166 // set up instruction-count-based termination events, if any
167 //
168 if (p->max_insts_any_thread != 0) {
169 const char *cause = "a thread reached the max instruction count";
170 for (ThreadID tid = 0; tid < numThreads; ++tid)
171 scheduleInstStop(tid, p->max_insts_any_thread, cause);
172 }
173
174 // Set up instruction-count-based termination events for SimPoints
175 // Typically, there are more than one action points.
176 // Simulation.py is responsible to take the necessary actions upon
177 // exitting the simulation loop.
178 if (!p->simpoint_start_insts.empty()) {
179 const char *cause = "simpoint starting point found";
180 for (size_t i = 0; i < p->simpoint_start_insts.size(); ++i)
181 scheduleInstStop(0, p->simpoint_start_insts[i], cause);
182 }
183
184 if (p->max_insts_all_threads != 0) {
185 const char *cause = "all threads reached the max instruction count";
186
187 // allocate & initialize shared downcounter: each event will
188 // decrement this when triggered; simulation will terminate
189 // when counter reaches 0
190 int *counter = new int;
191 *counter = numThreads;
192 for (ThreadID tid = 0; tid < numThreads; ++tid) {
193 Event *event = new CountedExitEvent(cause, *counter);
194 scheduleInstCountEvent(tid, event, p->max_insts_all_threads);
195 }
196 }
197
198 //
199 // set up instruction-count-based termination events, if any
200 //
201
202 functionTracingEnabled = false;
203 if (p->function_trace) {
204 const string fname = csprintf("ftrace.%s", name());
205 functionTraceStream = simout.findOrCreate(fname)->stream();
206
207 currentFunctionStart = currentFunctionEnd = 0;
208 functionEntryTick = p->function_trace_start;
209
210 if (p->function_trace_start == 0) {
211 functionTracingEnabled = true;
212 } else {
213 Event *event = new EventFunctionWrapper(
214 [this]{ enableFunctionTrace(); }, name(), true);
215 schedule(event, p->function_trace_start);
216 }
217 }
218
219 // The interrupts should always be present unless this CPU is
220 // switched in later or in case it is a checker CPU
221 if (!params()->switched_out && !is_checker) {
222 fatal_if(interrupts.size() != numThreads,
223 "CPU %s has %i interrupt controllers, but is expecting one "
224 "per thread (%i)\n",
225 name(), interrupts.size(), numThreads);
226 for (ThreadID tid = 0; tid < numThreads; tid++)
227 interrupts[tid]->setCPU(this);
228 }
229
230 if (FullSystem) {
231 if (params()->profile)
232 profileEvent = new EventFunctionWrapper(
233 [this]{ processProfileEvent(); },
234 name());
235 }
236 tracer = params()->tracer;
237
238 if (params()->isa.size() != numThreads) {
239 fatal("Number of ISAs (%i) assigned to the CPU does not equal number "
240 "of threads (%i).\n", params()->isa.size(), numThreads);
241 }
242 }
243
244 void
245 BaseCPU::enableFunctionTrace()
246 {
247 functionTracingEnabled = true;
248 }
249
250 BaseCPU::~BaseCPU()
251 {
252 delete profileEvent;
253 delete[] comInstEventQueue;
254 }
255
256 void
257 BaseCPU::armMonitor(ThreadID tid, Addr address)
258 {
259 assert(tid < numThreads);
260 AddressMonitor &monitor = addressMonitor[tid];
261
262 monitor.armed = true;
263 monitor.vAddr = address;
264 monitor.pAddr = 0x0;
265 DPRINTF(Mwait,"[tid:%d] Armed monitor (vAddr=0x%lx)\n", tid, address);
266 }
267
268 bool
269 BaseCPU::mwait(ThreadID tid, PacketPtr pkt)
270 {
271 assert(tid < numThreads);
272 AddressMonitor &monitor = addressMonitor[tid];
273
274 if (!monitor.gotWakeup) {
275 int block_size = cacheLineSize();
276 uint64_t mask = ~((uint64_t)(block_size - 1));
277
278 assert(pkt->req->hasPaddr());
279 monitor.pAddr = pkt->getAddr() & mask;
280 monitor.waiting = true;
281
282 DPRINTF(Mwait,"[tid:%d] mwait called (vAddr=0x%lx, "
283 "line's paddr=0x%lx)\n", tid, monitor.vAddr, monitor.pAddr);
284 return true;
285 } else {
286 monitor.gotWakeup = false;
287 return false;
288 }
289 }
290
291 void
292 BaseCPU::mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseTLB *dtb)
293 {
294 assert(tid < numThreads);
295 AddressMonitor &monitor = addressMonitor[tid];
296
297 RequestPtr req = std::make_shared<Request>();
298
299 Addr addr = monitor.vAddr;
300 int block_size = cacheLineSize();
301 uint64_t mask = ~((uint64_t)(block_size - 1));
302 int size = block_size;
303
304 //The address of the next line if it crosses a cache line boundary.
305 Addr secondAddr = roundDown(addr + size - 1, block_size);
306
307 if (secondAddr > addr)
308 size = secondAddr - addr;
309
310 req->setVirt(0, addr, size, 0x0, dataMasterId(), tc->instAddr());
311
312 // translate to physical address
313 Fault fault = dtb->translateAtomic(req, tc, BaseTLB::Read);
314 assert(fault == NoFault);
315
316 monitor.pAddr = req->getPaddr() & mask;
317 monitor.waiting = true;
318
319 DPRINTF(Mwait,"[tid:%d] mwait called (vAddr=0x%lx, line's paddr=0x%lx)\n",
320 tid, monitor.vAddr, monitor.pAddr);
321 }
322
323 void
324 BaseCPU::init()
325 {
326 if (!params()->switched_out) {
327 registerThreadContexts();
328
329 verifyMemoryMode();
330 }
331 }
332
333 void
334 BaseCPU::startup()
335 {
336 if (FullSystem) {
337 if (!params()->switched_out && profileEvent)
338 schedule(profileEvent, curTick());
339 }
340
341 if (params()->progress_interval) {
342 new CPUProgressEvent(this, params()->progress_interval);
343 }
344
345 if (_switchedOut)
346 ClockedObject::pwrState(Enums::PwrState::OFF);
347
348 // Assumption CPU start to operate instantaneously without any latency
349 if (ClockedObject::pwrState() == Enums::PwrState::UNDEFINED)
350 ClockedObject::pwrState(Enums::PwrState::ON);
351
352 }
353
354 ProbePoints::PMUUPtr
355 BaseCPU::pmuProbePoint(const char *name)
356 {
357 ProbePoints::PMUUPtr ptr;
358 ptr.reset(new ProbePoints::PMU(getProbeManager(), name));
359
360 return ptr;
361 }
362
363 void
364 BaseCPU::regProbePoints()
365 {
366 ppAllCycles = pmuProbePoint("Cycles");
367 ppActiveCycles = pmuProbePoint("ActiveCycles");
368
369 ppRetiredInsts = pmuProbePoint("RetiredInsts");
370 ppRetiredInstsPC = pmuProbePoint("RetiredInstsPC");
371 ppRetiredLoads = pmuProbePoint("RetiredLoads");
372 ppRetiredStores = pmuProbePoint("RetiredStores");
373 ppRetiredBranches = pmuProbePoint("RetiredBranches");
374
375 ppSleeping = new ProbePointArg<bool>(this->getProbeManager(),
376 "Sleeping");
377 }
378
379 void
380 BaseCPU::probeInstCommit(const StaticInstPtr &inst, Addr pc)
381 {
382 if (!inst->isMicroop() || inst->isLastMicroop()) {
383 ppRetiredInsts->notify(1);
384 ppRetiredInstsPC->notify(pc);
385 }
386
387 if (inst->isLoad())
388 ppRetiredLoads->notify(1);
389
390 if (inst->isStore() || inst->isAtomic())
391 ppRetiredStores->notify(1);
392
393 if (inst->isControl())
394 ppRetiredBranches->notify(1);
395 }
396
397 void
398 BaseCPU::regStats()
399 {
400 ClockedObject::regStats();
401
402 using namespace Stats;
403
404 numCycles
405 .name(name() + ".numCycles")
406 .desc("number of cpu cycles simulated")
407 ;
408
409 numWorkItemsStarted
410 .name(name() + ".numWorkItemsStarted")
411 .desc("number of work items this cpu started")
412 ;
413
414 numWorkItemsCompleted
415 .name(name() + ".numWorkItemsCompleted")
416 .desc("number of work items this cpu completed")
417 ;
418
419 int size = threadContexts.size();
420 if (size > 1) {
421 for (int i = 0; i < size; ++i) {
422 stringstream namestr;
423 ccprintf(namestr, "%s.ctx%d", name(), i);
424 threadContexts[i]->regStats(namestr.str());
425 }
426 } else if (size == 1)
427 threadContexts[0]->regStats(name());
428 }
429
430 Port &
431 BaseCPU::getPort(const string &if_name, PortID idx)
432 {
433 // Get the right port based on name. This applies to all the
434 // subclasses of the base CPU and relies on their implementation
435 // of getDataPort and getInstPort.
436 if (if_name == "dcache_port")
437 return getDataPort();
438 else if (if_name == "icache_port")
439 return getInstPort();
440 else
441 return ClockedObject::getPort(if_name, idx);
442 }
443
444 void
445 BaseCPU::registerThreadContexts()
446 {
447 assert(system->multiThread || numThreads == 1);
448
449 ThreadID size = threadContexts.size();
450 for (ThreadID tid = 0; tid < size; ++tid) {
451 ThreadContext *tc = threadContexts[tid];
452
453 if (system->multiThread) {
454 tc->setContextId(system->registerThreadContext(tc));
455 } else {
456 tc->setContextId(system->registerThreadContext(tc, _cpuId));
457 }
458
459 if (!FullSystem)
460 tc->getProcessPtr()->assignThreadContext(tc->contextId());
461 }
462 }
463
464 void
465 BaseCPU::deschedulePowerGatingEvent()
466 {
467 if (enterPwrGatingEvent.scheduled()){
468 deschedule(enterPwrGatingEvent);
469 }
470 }
471
472 void
473 BaseCPU::schedulePowerGatingEvent()
474 {
475 for (auto tc : threadContexts) {
476 if (tc->status() == ThreadContext::Active)
477 return;
478 }
479
480 if (ClockedObject::pwrState() == Enums::PwrState::CLK_GATED &&
481 powerGatingOnIdle) {
482 assert(!enterPwrGatingEvent.scheduled());
483 // Schedule a power gating event when clock gated for the specified
484 // amount of time
485 schedule(enterPwrGatingEvent, clockEdge(pwrGatingLatency));
486 }
487 }
488
489 int
490 BaseCPU::findContext(ThreadContext *tc)
491 {
492 ThreadID size = threadContexts.size();
493 for (ThreadID tid = 0; tid < size; ++tid) {
494 if (tc == threadContexts[tid])
495 return tid;
496 }
497 return 0;
498 }
499
500 void
501 BaseCPU::activateContext(ThreadID thread_num)
502 {
503 // Squash enter power gating event while cpu gets activated
504 if (enterPwrGatingEvent.scheduled())
505 deschedule(enterPwrGatingEvent);
506 // For any active thread running, update CPU power state to active (ON)
507 ClockedObject::pwrState(Enums::PwrState::ON);
508
509 updateCycleCounters(CPU_STATE_WAKEUP);
510 }
511
512 void
513 BaseCPU::suspendContext(ThreadID thread_num)
514 {
515 // Check if all threads are suspended
516 for (auto t : threadContexts) {
517 if (t->status() != ThreadContext::Suspended) {
518 return;
519 }
520 }
521
522 // All CPU thread are suspended, update cycle count
523 updateCycleCounters(CPU_STATE_SLEEP);
524
525 // All CPU threads suspended, enter lower power state for the CPU
526 ClockedObject::pwrState(Enums::PwrState::CLK_GATED);
527
528 // If pwrGatingLatency is set to 0 then this mechanism is disabled
529 if (powerGatingOnIdle) {
530 // Schedule power gating event when clock gated for pwrGatingLatency
531 // cycles
532 schedule(enterPwrGatingEvent, clockEdge(pwrGatingLatency));
533 }
534 }
535
536 void
537 BaseCPU::haltContext(ThreadID thread_num)
538 {
539 updateCycleCounters(BaseCPU::CPU_STATE_SLEEP);
540 }
541
542 void
543 BaseCPU::enterPwrGating(void)
544 {
545 ClockedObject::pwrState(Enums::PwrState::OFF);
546 }
547
548 void
549 BaseCPU::switchOut()
550 {
551 assert(!_switchedOut);
552 _switchedOut = true;
553 if (profileEvent && profileEvent->scheduled())
554 deschedule(profileEvent);
555
556 // Flush all TLBs in the CPU to avoid having stale translations if
557 // it gets switched in later.
558 flushTLBs();
559
560 // Go to the power gating state
561 ClockedObject::pwrState(Enums::PwrState::OFF);
562 }
563
564 void
565 BaseCPU::takeOverFrom(BaseCPU *oldCPU)
566 {
567 assert(threadContexts.size() == oldCPU->threadContexts.size());
568 assert(_cpuId == oldCPU->cpuId());
569 assert(_switchedOut);
570 assert(oldCPU != this);
571 _pid = oldCPU->getPid();
572 _taskId = oldCPU->taskId();
573 // Take over the power state of the switchedOut CPU
574 ClockedObject::pwrState(oldCPU->pwrState());
575
576 previousState = oldCPU->previousState;
577 previousCycle = oldCPU->previousCycle;
578
579 _switchedOut = false;
580
581 ThreadID size = threadContexts.size();
582 for (ThreadID i = 0; i < size; ++i) {
583 ThreadContext *newTC = threadContexts[i];
584 ThreadContext *oldTC = oldCPU->threadContexts[i];
585
586 newTC->takeOverFrom(oldTC);
587
588 CpuEvent::replaceThreadContext(oldTC, newTC);
589
590 assert(newTC->contextId() == oldTC->contextId());
591 assert(newTC->threadId() == oldTC->threadId());
592 system->replaceThreadContext(newTC, newTC->contextId());
593
594 /* This code no longer works since the zero register (e.g.,
595 * r31 on Alpha) doesn't necessarily contain zero at this
596 * point.
597 if (DTRACE(Context))
598 ThreadContext::compare(oldTC, newTC);
599 */
600
601 Port *old_itb_port = oldTC->getITBPtr()->getTableWalkerPort();
602 Port *old_dtb_port = oldTC->getDTBPtr()->getTableWalkerPort();
603 Port *new_itb_port = newTC->getITBPtr()->getTableWalkerPort();
604 Port *new_dtb_port = newTC->getDTBPtr()->getTableWalkerPort();
605
606 // Move over any table walker ports if they exist
607 if (new_itb_port)
608 new_itb_port->takeOverFrom(old_itb_port);
609 if (new_dtb_port)
610 new_dtb_port->takeOverFrom(old_dtb_port);
611 newTC->getITBPtr()->takeOverFrom(oldTC->getITBPtr());
612 newTC->getDTBPtr()->takeOverFrom(oldTC->getDTBPtr());
613
614 // Checker whether or not we have to transfer CheckerCPU
615 // objects over in the switch
616 CheckerCPU *oldChecker = oldTC->getCheckerCpuPtr();
617 CheckerCPU *newChecker = newTC->getCheckerCpuPtr();
618 if (oldChecker && newChecker) {
619 Port *old_checker_itb_port =
620 oldChecker->getITBPtr()->getTableWalkerPort();
621 Port *old_checker_dtb_port =
622 oldChecker->getDTBPtr()->getTableWalkerPort();
623 Port *new_checker_itb_port =
624 newChecker->getITBPtr()->getTableWalkerPort();
625 Port *new_checker_dtb_port =
626 newChecker->getDTBPtr()->getTableWalkerPort();
627
628 newChecker->getITBPtr()->takeOverFrom(oldChecker->getITBPtr());
629 newChecker->getDTBPtr()->takeOverFrom(oldChecker->getDTBPtr());
630
631 // Move over any table walker ports if they exist for checker
632 if (new_checker_itb_port)
633 new_checker_itb_port->takeOverFrom(old_checker_itb_port);
634 if (new_checker_dtb_port)
635 new_checker_dtb_port->takeOverFrom(old_checker_dtb_port);
636 }
637 }
638
639 interrupts = oldCPU->interrupts;
640 for (ThreadID tid = 0; tid < numThreads; tid++) {
641 interrupts[tid]->setCPU(this);
642 }
643 oldCPU->interrupts.clear();
644
645 if (FullSystem) {
646 for (ThreadID i = 0; i < size; ++i)
647 threadContexts[i]->profileClear();
648
649 if (profileEvent)
650 schedule(profileEvent, curTick());
651 }
652
653 // All CPUs have an instruction and a data port, and the new CPU's
654 // ports are dangling while the old CPU has its ports connected
655 // already. Unbind the old CPU and then bind the ports of the one
656 // we are switching to.
657 getInstPort().takeOverFrom(&oldCPU->getInstPort());
658 getDataPort().takeOverFrom(&oldCPU->getDataPort());
659 }
660
661 void
662 BaseCPU::flushTLBs()
663 {
664 for (ThreadID i = 0; i < threadContexts.size(); ++i) {
665 ThreadContext &tc(*threadContexts[i]);
666 CheckerCPU *checker(tc.getCheckerCpuPtr());
667
668 tc.getITBPtr()->flushAll();
669 tc.getDTBPtr()->flushAll();
670 if (checker) {
671 checker->getITBPtr()->flushAll();
672 checker->getDTBPtr()->flushAll();
673 }
674 }
675 }
676
677 void
678 BaseCPU::processProfileEvent()
679 {
680 ThreadID size = threadContexts.size();
681
682 for (ThreadID i = 0; i < size; ++i)
683 threadContexts[i]->profileSample();
684
685 schedule(profileEvent, curTick() + params()->profile);
686 }
687
688 void
689 BaseCPU::serialize(CheckpointOut &cp) const
690 {
691 SERIALIZE_SCALAR(instCnt);
692
693 if (!_switchedOut) {
694 /* Unlike _pid, _taskId is not serialized, as they are dynamically
695 * assigned unique ids that are only meaningful for the duration of
696 * a specific run. We will need to serialize the entire taskMap in
697 * system. */
698 SERIALIZE_SCALAR(_pid);
699
700 // Serialize the threads, this is done by the CPU implementation.
701 for (ThreadID i = 0; i < numThreads; ++i) {
702 ScopedCheckpointSection sec(cp, csprintf("xc.%i", i));
703 interrupts[i]->serialize(cp);
704 serializeThread(cp, i);
705 }
706 }
707 }
708
709 void
710 BaseCPU::unserialize(CheckpointIn &cp)
711 {
712 UNSERIALIZE_SCALAR(instCnt);
713
714 if (!_switchedOut) {
715 UNSERIALIZE_SCALAR(_pid);
716
717 // Unserialize the threads, this is done by the CPU implementation.
718 for (ThreadID i = 0; i < numThreads; ++i) {
719 ScopedCheckpointSection sec(cp, csprintf("xc.%i", i));
720 interrupts[i]->unserialize(cp);
721 unserializeThread(cp, i);
722 }
723 }
724 }
725
726 void
727 BaseCPU::scheduleInstStop(ThreadID tid, Counter insts, const char *cause)
728 {
729 const Tick now(getCurrentInstCount(tid));
730 Event *event(new LocalSimLoopExitEvent(cause, 0));
731
732 scheduleInstCountEvent(tid, event, now + insts);
733 }
734
735 Tick
736 BaseCPU::getCurrentInstCount(ThreadID tid)
737 {
738 return comInstEventQueue[tid]->getCurTick();
739 }
740
741 AddressMonitor::AddressMonitor() {
742 armed = false;
743 waiting = false;
744 gotWakeup = false;
745 }
746
747 bool AddressMonitor::doMonitor(PacketPtr pkt) {
748 assert(pkt->req->hasPaddr());
749 if (armed && waiting) {
750 if (pAddr == pkt->getAddr()) {
751 DPRINTF(Mwait,"pAddr=0x%lx invalidated: waking up core\n",
752 pkt->getAddr());
753 waiting = false;
754 return true;
755 }
756 }
757 return false;
758 }
759
760
761 void
762 BaseCPU::traceFunctionsInternal(Addr pc)
763 {
764 if (!debugSymbolTable)
765 return;
766
767 // if pc enters different function, print new function symbol and
768 // update saved range. Otherwise do nothing.
769 if (pc < currentFunctionStart || pc >= currentFunctionEnd) {
770 string sym_str;
771 bool found = debugSymbolTable->findNearestSymbol(pc, sym_str,
772 currentFunctionStart,
773 currentFunctionEnd);
774
775 if (!found) {
776 // no symbol found: use addr as label
777 sym_str = csprintf("0x%x", pc);
778 currentFunctionStart = pc;
779 currentFunctionEnd = pc + 1;
780 }
781
782 ccprintf(*functionTraceStream, " (%d)\n%d: %s",
783 curTick() - functionEntryTick, curTick(), sym_str);
784 functionEntryTick = curTick();
785 }
786 }
787
788 bool
789 BaseCPU::waitForRemoteGDB() const
790 {
791 return params()->wait_for_remote_gdb;
792 }