0591b05102c1eefcfa90fd7ba774790bdfffd604
[gem5.git] / src / cpu / inorder / cpu.cc
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Korey Sewell
29 *
30 */
31
32 #include <algorithm>
33
34 #include "arch/utility.hh"
35 #include "config/full_system.hh"
36 #include "config/the_isa.hh"
37 #include "cpu/activity.hh"
38 #include "cpu/base.hh"
39 #include "cpu/exetrace.hh"
40 #include "cpu/inorder/cpu.hh"
41 #include "cpu/inorder/first_stage.hh"
42 #include "cpu/inorder/inorder_dyn_inst.hh"
43 #include "cpu/inorder/pipeline_traits.hh"
44 #include "cpu/inorder/resource_pool.hh"
45 #include "cpu/inorder/resources/resource_list.hh"
46 #include "cpu/inorder/thread_context.hh"
47 #include "cpu/inorder/thread_state.hh"
48 #include "cpu/simple_thread.hh"
49 #include "cpu/thread_context.hh"
50 #include "mem/translating_port.hh"
51 #include "params/InOrderCPU.hh"
52 #include "sim/process.hh"
53 #include "sim/stat_control.hh"
54
55 #if FULL_SYSTEM
56 #include "cpu/quiesce_event.hh"
57 #include "sim/system.hh"
58 #endif
59
60 #if THE_ISA == ALPHA_ISA
61 #include "arch/alpha/osfpal.hh"
62 #endif
63
64 using namespace std;
65 using namespace TheISA;
66 using namespace ThePipeline;
67
68 InOrderCPU::TickEvent::TickEvent(InOrderCPU *c)
69 : Event(CPU_Tick_Pri), cpu(c)
70 { }
71
72
73 void
74 InOrderCPU::TickEvent::process()
75 {
76 cpu->tick();
77 }
78
79
80 const char *
81 InOrderCPU::TickEvent::description()
82 {
83 return "InOrderCPU tick event";
84 }
85
86 InOrderCPU::CPUEvent::CPUEvent(InOrderCPU *_cpu, CPUEventType e_type,
87 Fault fault, ThreadID _tid, DynInstPtr inst,
88 unsigned event_pri_offset)
89 : Event(Event::Priority((unsigned int)CPU_Tick_Pri + event_pri_offset)),
90 cpu(_cpu)
91 {
92 setEvent(e_type, fault, _tid, inst);
93 }
94
95
96 std::string InOrderCPU::eventNames[NumCPUEvents] =
97 {
98 "ActivateThread",
99 "ActivateNextReadyThread",
100 "DeactivateThread",
101 "HaltThread",
102 "SuspendThread",
103 "Trap",
104 "InstGraduated",
105 "SquashFromMemStall",
106 "UpdatePCs"
107 };
108
109 void
110 InOrderCPU::CPUEvent::process()
111 {
112 switch (cpuEventType)
113 {
114 case ActivateThread:
115 cpu->activateThread(tid);
116 break;
117
118 case ActivateNextReadyThread:
119 cpu->activateNextReadyThread();
120 break;
121
122 case DeactivateThread:
123 cpu->deactivateThread(tid);
124 break;
125
126 case HaltThread:
127 cpu->haltThread(tid);
128 break;
129
130 case SuspendThread:
131 cpu->suspendThread(tid);
132 break;
133
134 case SquashFromMemStall:
135 cpu->squashDueToMemStall(inst->squashingStage, inst->seqNum, tid);
136 break;
137
138 case Trap:
139 cpu->trapCPU(fault, tid, inst);
140 break;
141
142 default:
143 fatal("Unrecognized Event Type %s", eventNames[cpuEventType]);
144 }
145
146 cpu->cpuEventRemoveList.push(this);
147 }
148
149
150
151 const char *
152 InOrderCPU::CPUEvent::description()
153 {
154 return "InOrderCPU event";
155 }
156
157 void
158 InOrderCPU::CPUEvent::scheduleEvent(int delay)
159 {
160 assert(!scheduled() || squashed());
161 cpu->reschedule(this, cpu->nextCycle(curTick() + cpu->ticks(delay)), true);
162 }
163
164 void
165 InOrderCPU::CPUEvent::unscheduleEvent()
166 {
167 if (scheduled())
168 squash();
169 }
170
171 InOrderCPU::InOrderCPU(Params *params)
172 : BaseCPU(params),
173 cpu_id(params->cpu_id),
174 coreType("default"),
175 _status(Idle),
176 tickEvent(this),
177 stageWidth(params->stageWidth),
178 timeBuffer(2 , 2),
179 removeInstsThisCycle(false),
180 activityRec(params->name, NumStages, 10, params->activity),
181 #if FULL_SYSTEM
182 system(params->system),
183 physmem(system->physmem),
184 #endif // FULL_SYSTEM
185 #ifdef DEBUG
186 cpuEventNum(0),
187 resReqCount(0),
188 #endif // DEBUG
189 switchCount(0),
190 deferRegistration(false/*params->deferRegistration*/),
191 stageTracing(params->stageTracing),
192 instsPerSwitch(0)
193 {
194 ThreadID active_threads;
195 cpu_params = params;
196
197 resPool = new ResourcePool(this, params);
198
199 // Resize for Multithreading CPUs
200 thread.resize(numThreads);
201
202 #if FULL_SYSTEM
203 active_threads = 1;
204 #else
205 active_threads = params->workload.size();
206
207 if (active_threads > MaxThreads) {
208 panic("Workload Size too large. Increase the 'MaxThreads'"
209 "in your InOrder implementation or "
210 "edit your workload size.");
211 }
212
213
214 if (active_threads > 1) {
215 threadModel = (InOrderCPU::ThreadModel) params->threadModel;
216
217 if (threadModel == SMT) {
218 DPRINTF(InOrderCPU, "Setting Thread Model to SMT.\n");
219 } else if (threadModel == SwitchOnCacheMiss) {
220 DPRINTF(InOrderCPU, "Setting Thread Model to "
221 "Switch On Cache Miss\n");
222 }
223
224 } else {
225 threadModel = Single;
226 }
227
228
229
230 #endif
231
232 // Bind the fetch & data ports from the resource pool.
233 fetchPortIdx = resPool->getPortIdx(params->fetchMemPort);
234 if (fetchPortIdx == 0) {
235 fatal("Unable to find port to fetch instructions from.\n");
236 }
237
238 dataPortIdx = resPool->getPortIdx(params->dataMemPort);
239 if (dataPortIdx == 0) {
240 fatal("Unable to find port for data.\n");
241 }
242
243 for (ThreadID tid = 0; tid < numThreads; ++tid) {
244 #if FULL_SYSTEM
245 // SMT is not supported in FS mode yet.
246 assert(numThreads == 1);
247 thread[tid] = new Thread(this, 0);
248 #else
249 if (tid < (ThreadID)params->workload.size()) {
250 DPRINTF(InOrderCPU, "Workload[%i] process is %#x\n",
251 tid, params->workload[tid]->prog_fname);
252 thread[tid] =
253 new Thread(this, tid, params->workload[tid]);
254 } else {
255 //Allocate Empty thread so M5 can use later
256 //when scheduling threads to CPU
257 Process* dummy_proc = params->workload[0];
258 thread[tid] = new Thread(this, tid, dummy_proc);
259 }
260
261 // Eventually set this with parameters...
262 asid[tid] = tid;
263 #endif
264
265 // Setup the TC that will serve as the interface to the threads/CPU.
266 InOrderThreadContext *tc = new InOrderThreadContext;
267 tc->cpu = this;
268 tc->thread = thread[tid];
269
270 // Give the thread the TC.
271 thread[tid]->tc = tc;
272 thread[tid]->setFuncExeInst(0);
273 globalSeqNum[tid] = 1;
274
275 // Add the TC to the CPU's list of TC's.
276 this->threadContexts.push_back(tc);
277 }
278
279 // Initialize TimeBuffer Stage Queues
280 for (int stNum=0; stNum < NumStages - 1; stNum++) {
281 stageQueue[stNum] = new StageQueue(NumStages, NumStages);
282 stageQueue[stNum]->id(stNum);
283 }
284
285
286 // Set Up Pipeline Stages
287 for (int stNum=0; stNum < NumStages; stNum++) {
288 if (stNum == 0)
289 pipelineStage[stNum] = new FirstStage(params, stNum);
290 else
291 pipelineStage[stNum] = new PipelineStage(params, stNum);
292
293 pipelineStage[stNum]->setCPU(this);
294 pipelineStage[stNum]->setActiveThreads(&activeThreads);
295 pipelineStage[stNum]->setTimeBuffer(&timeBuffer);
296
297 // Take Care of 1st/Nth stages
298 if (stNum > 0)
299 pipelineStage[stNum]->setPrevStageQueue(stageQueue[stNum - 1]);
300 if (stNum < NumStages - 1)
301 pipelineStage[stNum]->setNextStageQueue(stageQueue[stNum]);
302 }
303
304 // Initialize thread specific variables
305 for (ThreadID tid = 0; tid < numThreads; tid++) {
306 archRegDepMap[tid].setCPU(this);
307
308 nonSpecInstActive[tid] = false;
309 nonSpecSeqNum[tid] = 0;
310
311 squashSeqNum[tid] = MaxAddr;
312 lastSquashCycle[tid] = 0;
313
314 memset(intRegs[tid], 0, sizeof(intRegs[tid]));
315 memset(floatRegs.i[tid], 0, sizeof(floatRegs.i[tid]));
316 isa[tid].clear();
317
318 isa[tid].expandForMultithreading(numThreads, 1/*numVirtProcs*/);
319
320 // Define dummy instructions and resource requests to be used.
321 dummyInst[tid] = new InOrderDynInst(this,
322 thread[tid],
323 0,
324 tid,
325 asid[tid]);
326
327 dummyReq[tid] = new ResourceRequest(resPool->getResource(0),
328 dummyInst[tid],
329 0,
330 0,
331 0,
332 0);
333 }
334
335 dummyReqInst = new InOrderDynInst(this, NULL, 0, 0, 0);
336 dummyReqInst->setSquashed();
337 dummyReqInst->resetInstCount();
338
339 dummyBufferInst = new InOrderDynInst(this, NULL, 0, 0, 0);
340 dummyBufferInst->setSquashed();
341 dummyBufferInst->resetInstCount();
342
343 endOfSkedIt = skedCache.end();
344 frontEndSked = createFrontEndSked();
345
346 lastRunningCycle = curTick();
347
348 // Reset CPU to reset state.
349 #if FULL_SYSTEM
350 Fault resetFault = new ResetFault();
351 resetFault->invoke(tcBase());
352 #else
353 reset();
354 #endif
355
356
357 // Schedule First Tick Event, CPU will reschedule itself from here on out.
358 scheduleTickEvent(0);
359 }
360
361 InOrderCPU::~InOrderCPU()
362 {
363 delete resPool;
364 }
365
366 std::map<InOrderCPU::SkedID, ThePipeline::RSkedPtr> InOrderCPU::skedCache;
367
368 RSkedPtr
369 InOrderCPU::createFrontEndSked()
370 {
371 RSkedPtr res_sked = NULL;
372 int stage_num = 0;
373 StageScheduler F(res_sked, stage_num++);
374 StageScheduler D(res_sked, stage_num++);
375
376 // FETCH
377 F.needs(FetchSeq, FetchSeqUnit::AssignNextPC);
378 F.needs(ICache, FetchUnit::InitiateFetch);
379
380 // DECODE
381 D.needs(ICache, FetchUnit::CompleteFetch);
382 D.needs(Decode, DecodeUnit::DecodeInst);
383 D.needs(BPred, BranchPredictor::PredictBranch);
384 D.needs(FetchSeq, FetchSeqUnit::UpdateTargetPC);
385
386 return res_sked;
387 }
388
389 RSkedPtr
390 InOrderCPU::createBackEndSked(DynInstPtr inst)
391 {
392 RSkedPtr res_sked = lookupSked(inst);
393 if (res_sked != NULL) {
394 return res_sked;
395 }
396
397 int stage_num = ThePipeline::BackEndStartStage;
398 StageScheduler X(res_sked, stage_num++);
399 StageScheduler M(res_sked, stage_num++);
400 StageScheduler W(res_sked, stage_num++);
401
402 if (!inst->staticInst) {
403 warn_once("Static Instruction Object Not Set. Can't Create"
404 " Back End Schedule");
405 return false;
406 }
407
408 // EXECUTE
409 for (int idx=0; idx < inst->numSrcRegs(); idx++) {
410 if (!idx || !inst->isStore()) {
411 X.needs(RegManager, UseDefUnit::ReadSrcReg, idx);
412 }
413 }
414
415 if ( inst->isNonSpeculative() ) {
416 // skip execution of non speculative insts until later
417 } else if ( inst->isMemRef() ) {
418 if ( inst->isLoad() ) {
419 X.needs(AGEN, AGENUnit::GenerateAddr);
420 }
421 } else if (inst->opClass() == IntMultOp || inst->opClass() == IntDivOp) {
422 X.needs(MDU, MultDivUnit::StartMultDiv);
423 } else {
424 X.needs(ExecUnit, ExecutionUnit::ExecuteInst);
425 }
426
427 if (inst->opClass() == IntMultOp || inst->opClass() == IntDivOp) {
428 X.needs(MDU, MultDivUnit::EndMultDiv);
429 }
430
431 // MEMORY
432 if ( inst->isLoad() ) {
433 M.needs(DCache, CacheUnit::InitiateReadData);
434 } else if ( inst->isStore() ) {
435 if ( inst->numSrcRegs() >= 2 ) {
436 M.needs(RegManager, UseDefUnit::ReadSrcReg, 1);
437 }
438 M.needs(AGEN, AGENUnit::GenerateAddr);
439 M.needs(DCache, CacheUnit::InitiateWriteData);
440 }
441
442
443 // WRITEBACK
444 if ( inst->isLoad() ) {
445 W.needs(DCache, CacheUnit::CompleteReadData);
446 } else if ( inst->isStore() ) {
447 W.needs(DCache, CacheUnit::CompleteWriteData);
448 }
449
450 if ( inst->isNonSpeculative() ) {
451 if ( inst->isMemRef() ) fatal("Non-Speculative Memory Instruction");
452 W.needs(ExecUnit, ExecutionUnit::ExecuteInst);
453 }
454
455 for (int idx=0; idx < inst->numDestRegs(); idx++) {
456 W.needs(RegManager, UseDefUnit::WriteDestReg, idx);
457 }
458
459 W.needs(Grad, GraduationUnit::GraduateInst);
460
461 return res_sked;
462 }
463
464 void
465 InOrderCPU::regStats()
466 {
467 /* Register the Resource Pool's stats here.*/
468 resPool->regStats();
469
470 /* Register for each Pipeline Stage */
471 for (int stage_num=0; stage_num < ThePipeline::NumStages; stage_num++) {
472 pipelineStage[stage_num]->regStats();
473 }
474
475 /* Register any of the InOrderCPU's stats here.*/
476 instsPerCtxtSwitch
477 .name(name() + ".instsPerContextSwitch")
478 .desc("Instructions Committed Per Context Switch")
479 .prereq(instsPerCtxtSwitch);
480
481 numCtxtSwitches
482 .name(name() + ".contextSwitches")
483 .desc("Number of context switches");
484
485 comLoads
486 .name(name() + ".comLoads")
487 .desc("Number of Load instructions committed");
488
489 comStores
490 .name(name() + ".comStores")
491 .desc("Number of Store instructions committed");
492
493 comBranches
494 .name(name() + ".comBranches")
495 .desc("Number of Branches instructions committed");
496
497 comNops
498 .name(name() + ".comNops")
499 .desc("Number of Nop instructions committed");
500
501 comNonSpec
502 .name(name() + ".comNonSpec")
503 .desc("Number of Non-Speculative instructions committed");
504
505 comInts
506 .name(name() + ".comInts")
507 .desc("Number of Integer instructions committed");
508
509 comFloats
510 .name(name() + ".comFloats")
511 .desc("Number of Floating Point instructions committed");
512
513 timesIdled
514 .name(name() + ".timesIdled")
515 .desc("Number of times that the entire CPU went into an idle state and"
516 " unscheduled itself")
517 .prereq(timesIdled);
518
519 idleCycles
520 .name(name() + ".idleCycles")
521 .desc("Number of cycles cpu's stages were not processed");
522
523 runCycles
524 .name(name() + ".runCycles")
525 .desc("Number of cycles cpu stages are processed.");
526
527 activity
528 .name(name() + ".activity")
529 .desc("Percentage of cycles cpu is active")
530 .precision(6);
531 activity = (runCycles / numCycles) * 100;
532
533 threadCycles
534 .init(numThreads)
535 .name(name() + ".threadCycles")
536 .desc("Total Number of Cycles A Thread Was Active in CPU (Per-Thread)");
537
538 smtCycles
539 .name(name() + ".smtCycles")
540 .desc("Total number of cycles that the CPU was in SMT-mode");
541
542 committedInsts
543 .init(numThreads)
544 .name(name() + ".committedInsts")
545 .desc("Number of Instructions Simulated (Per-Thread)");
546
547 smtCommittedInsts
548 .init(numThreads)
549 .name(name() + ".smtCommittedInsts")
550 .desc("Number of SMT Instructions Simulated (Per-Thread)");
551
552 totalCommittedInsts
553 .name(name() + ".committedInsts_total")
554 .desc("Number of Instructions Simulated (Total)");
555
556 cpi
557 .name(name() + ".cpi")
558 .desc("CPI: Cycles Per Instruction (Per-Thread)")
559 .precision(6);
560 cpi = numCycles / committedInsts;
561
562 smtCpi
563 .name(name() + ".smt_cpi")
564 .desc("CPI: Total SMT-CPI")
565 .precision(6);
566 smtCpi = smtCycles / smtCommittedInsts;
567
568 totalCpi
569 .name(name() + ".cpi_total")
570 .desc("CPI: Total CPI of All Threads")
571 .precision(6);
572 totalCpi = numCycles / totalCommittedInsts;
573
574 ipc
575 .name(name() + ".ipc")
576 .desc("IPC: Instructions Per Cycle (Per-Thread)")
577 .precision(6);
578 ipc = committedInsts / numCycles;
579
580 smtIpc
581 .name(name() + ".smt_ipc")
582 .desc("IPC: Total SMT-IPC")
583 .precision(6);
584 smtIpc = smtCommittedInsts / smtCycles;
585
586 totalIpc
587 .name(name() + ".ipc_total")
588 .desc("IPC: Total IPC of All Threads")
589 .precision(6);
590 totalIpc = totalCommittedInsts / numCycles;
591
592 BaseCPU::regStats();
593 }
594
595
596 void
597 InOrderCPU::tick()
598 {
599 DPRINTF(InOrderCPU, "\n\nInOrderCPU: Ticking main, InOrderCPU.\n");
600
601 ++numCycles;
602
603 bool pipes_idle = true;
604
605 //Tick each of the stages
606 for (int stNum=NumStages - 1; stNum >= 0 ; stNum--) {
607 pipelineStage[stNum]->tick();
608
609 pipes_idle = pipes_idle && pipelineStage[stNum]->idle;
610 }
611
612 if (pipes_idle)
613 idleCycles++;
614 else
615 runCycles++;
616
617 // Now advance the time buffers one tick
618 timeBuffer.advance();
619 for (int sqNum=0; sqNum < NumStages - 1; sqNum++) {
620 stageQueue[sqNum]->advance();
621 }
622 activityRec.advance();
623
624 // Any squashed requests, events, or insts then remove them now
625 cleanUpRemovedReqs();
626 cleanUpRemovedEvents();
627 cleanUpRemovedInsts();
628
629 // Re-schedule CPU for this cycle
630 if (!tickEvent.scheduled()) {
631 if (_status == SwitchedOut) {
632 // increment stat
633 lastRunningCycle = curTick();
634 } else if (!activityRec.active()) {
635 DPRINTF(InOrderCPU, "sleeping CPU.\n");
636 lastRunningCycle = curTick();
637 timesIdled++;
638 } else {
639 //Tick next_tick = curTick() + cycles(1);
640 //tickEvent.schedule(next_tick);
641 schedule(&tickEvent, nextCycle(curTick() + 1));
642 DPRINTF(InOrderCPU, "Scheduled CPU for next tick @ %i.\n",
643 nextCycle(curTick() + 1));
644 }
645 }
646
647 tickThreadStats();
648 updateThreadPriority();
649 }
650
651
652 void
653 InOrderCPU::init()
654 {
655 if (!deferRegistration) {
656 registerThreadContexts();
657 }
658
659 // Set inSyscall so that the CPU doesn't squash when initially
660 // setting up registers.
661 for (ThreadID tid = 0; tid < numThreads; ++tid)
662 thread[tid]->inSyscall = true;
663
664 #if FULL_SYSTEM
665 for (ThreadID tid = 0; tid < numThreads; tid++) {
666 ThreadContext *src_tc = threadContexts[tid];
667 TheISA::initCPU(src_tc, src_tc->contextId());
668 }
669 #endif
670
671 // Clear inSyscall.
672 for (ThreadID tid = 0; tid < numThreads; ++tid)
673 thread[tid]->inSyscall = false;
674
675 // Call Initializiation Routine for Resource Pool
676 resPool->init();
677 }
678
679 void
680 InOrderCPU::reset()
681 {
682 for (int i = 0; i < numThreads; i++) {
683 isa[i].reset(coreType, numThreads,
684 1/*numVirtProcs*/, dynamic_cast<BaseCPU*>(this));
685 }
686 }
687
688 Port*
689 InOrderCPU::getPort(const std::string &if_name, int idx)
690 {
691 return resPool->getPort(if_name, idx);
692 }
693
694 #if FULL_SYSTEM
695 Fault
696 InOrderCPU::hwrei(ThreadID tid)
697 {
698 panic("hwrei: Unimplemented");
699
700 return NoFault;
701 }
702
703
704 bool
705 InOrderCPU::simPalCheck(int palFunc, ThreadID tid)
706 {
707 panic("simPalCheck: Unimplemented");
708
709 return true;
710 }
711
712
713 Fault
714 InOrderCPU::getInterrupts()
715 {
716 // Check if there are any outstanding interrupts
717 return interrupts->getInterrupt(threadContexts[0]);
718 }
719
720
721 void
722 InOrderCPU::processInterrupts(Fault interrupt)
723 {
724 // Check for interrupts here. For now can copy the code that
725 // exists within isa_fullsys_traits.hh. Also assume that thread 0
726 // is the one that handles the interrupts.
727 // @todo: Possibly consolidate the interrupt checking code.
728 // @todo: Allow other threads to handle interrupts.
729
730 assert(interrupt != NoFault);
731 interrupts->updateIntrInfo(threadContexts[0]);
732
733 DPRINTF(InOrderCPU, "Interrupt %s being handled\n", interrupt->name());
734
735 // Note: Context ID ok here? Impl. of FS mode needs to revisit this
736 trap(interrupt, threadContexts[0]->contextId(), dummyBufferInst);
737 }
738
739
740 void
741 InOrderCPU::updateMemPorts()
742 {
743 // Update all ThreadContext's memory ports (Functional/Virtual
744 // Ports)
745 ThreadID size = thread.size();
746 for (ThreadID i = 0; i < size; ++i)
747 thread[i]->connectMemPorts(thread[i]->getTC());
748 }
749 #endif
750
751 void
752 InOrderCPU::trap(Fault fault, ThreadID tid, DynInstPtr inst, int delay)
753 {
754 //@ Squash Pipeline during TRAP
755 scheduleCpuEvent(Trap, fault, tid, inst, delay);
756 }
757
758 void
759 InOrderCPU::trapCPU(Fault fault, ThreadID tid, DynInstPtr inst)
760 {
761 fault->invoke(tcBase(tid), inst->staticInst);
762 }
763
764 void
765 InOrderCPU::squashFromMemStall(DynInstPtr inst, ThreadID tid, int delay)
766 {
767 scheduleCpuEvent(SquashFromMemStall, NoFault, tid, inst, delay);
768 }
769
770
771 void
772 InOrderCPU::squashDueToMemStall(int stage_num, InstSeqNum seq_num,
773 ThreadID tid)
774 {
775 DPRINTF(InOrderCPU, "Squashing Pipeline Stages Due to Memory Stall...\n");
776
777 // Squash all instructions in each stage including
778 // instruction that caused the squash (seq_num - 1)
779 // NOTE: The stage bandwidth needs to be cleared so thats why
780 // the stalling instruction is squashed as well. The stalled
781 // instruction is previously placed in another intermediate buffer
782 // while it's stall is being handled.
783 InstSeqNum squash_seq_num = seq_num - 1;
784
785 for (int stNum=stage_num; stNum >= 0 ; stNum--) {
786 pipelineStage[stNum]->squashDueToMemStall(squash_seq_num, tid);
787 }
788 }
789
790 void
791 InOrderCPU::scheduleCpuEvent(CPUEventType c_event, Fault fault,
792 ThreadID tid, DynInstPtr inst,
793 unsigned delay, unsigned event_pri_offset)
794 {
795 CPUEvent *cpu_event = new CPUEvent(this, c_event, fault, tid, inst,
796 event_pri_offset);
797
798 Tick sked_tick = nextCycle(curTick() + ticks(delay));
799 if (delay >= 0) {
800 DPRINTF(InOrderCPU, "Scheduling CPU Event (%s) for cycle %i, [tid:%i].\n",
801 eventNames[c_event], curTick() + delay, tid);
802 schedule(cpu_event, sked_tick);
803 } else {
804 cpu_event->process();
805 cpuEventRemoveList.push(cpu_event);
806 }
807
808 // Broadcast event to the Resource Pool
809 // Need to reset tid just in case this is a dummy instruction
810 inst->setTid(tid);
811 resPool->scheduleEvent(c_event, inst, 0, 0, tid);
812 }
813
814 bool
815 InOrderCPU::isThreadActive(ThreadID tid)
816 {
817 list<ThreadID>::iterator isActive =
818 std::find(activeThreads.begin(), activeThreads.end(), tid);
819
820 return (isActive != activeThreads.end());
821 }
822
823 bool
824 InOrderCPU::isThreadReady(ThreadID tid)
825 {
826 list<ThreadID>::iterator isReady =
827 std::find(readyThreads.begin(), readyThreads.end(), tid);
828
829 return (isReady != readyThreads.end());
830 }
831
832 bool
833 InOrderCPU::isThreadSuspended(ThreadID tid)
834 {
835 list<ThreadID>::iterator isSuspended =
836 std::find(suspendedThreads.begin(), suspendedThreads.end(), tid);
837
838 return (isSuspended != suspendedThreads.end());
839 }
840
841 void
842 InOrderCPU::activateNextReadyThread()
843 {
844 if (readyThreads.size() >= 1) {
845 ThreadID ready_tid = readyThreads.front();
846
847 // Activate in Pipeline
848 activateThread(ready_tid);
849
850 // Activate in Resource Pool
851 resPool->activateAll(ready_tid);
852
853 list<ThreadID>::iterator ready_it =
854 std::find(readyThreads.begin(), readyThreads.end(), ready_tid);
855 readyThreads.erase(ready_it);
856 } else {
857 DPRINTF(InOrderCPU,
858 "Attempting to activate new thread, but No Ready Threads to"
859 "activate.\n");
860 DPRINTF(InOrderCPU,
861 "Unable to switch to next active thread.\n");
862 }
863 }
864
865 void
866 InOrderCPU::activateThread(ThreadID tid)
867 {
868 if (isThreadSuspended(tid)) {
869 DPRINTF(InOrderCPU,
870 "Removing [tid:%i] from suspended threads list.\n", tid);
871
872 list<ThreadID>::iterator susp_it =
873 std::find(suspendedThreads.begin(), suspendedThreads.end(),
874 tid);
875 suspendedThreads.erase(susp_it);
876 }
877
878 if (threadModel == SwitchOnCacheMiss &&
879 numActiveThreads() == 1) {
880 DPRINTF(InOrderCPU,
881 "Ignoring activation of [tid:%i], since [tid:%i] is "
882 "already running.\n", tid, activeThreadId());
883
884 DPRINTF(InOrderCPU,"Placing [tid:%i] on ready threads list\n",
885 tid);
886
887 readyThreads.push_back(tid);
888
889 } else if (!isThreadActive(tid)) {
890 DPRINTF(InOrderCPU,
891 "Adding [tid:%i] to active threads list.\n", tid);
892 activeThreads.push_back(tid);
893
894 activateThreadInPipeline(tid);
895
896 thread[tid]->lastActivate = curTick();
897
898 tcBase(tid)->setStatus(ThreadContext::Active);
899
900 wakeCPU();
901
902 numCtxtSwitches++;
903 }
904 }
905
906 void
907 InOrderCPU::activateThreadInPipeline(ThreadID tid)
908 {
909 for (int stNum=0; stNum < NumStages; stNum++) {
910 pipelineStage[stNum]->activateThread(tid);
911 }
912 }
913
914 void
915 InOrderCPU::deactivateContext(ThreadID tid, int delay)
916 {
917 DPRINTF(InOrderCPU,"[tid:%i]: Deactivating ...\n", tid);
918
919 scheduleCpuEvent(DeactivateThread, NoFault, tid, dummyInst[tid], delay);
920
921 // Be sure to signal that there's some activity so the CPU doesn't
922 // deschedule itself.
923 activityRec.activity();
924
925 _status = Running;
926 }
927
928 void
929 InOrderCPU::deactivateThread(ThreadID tid)
930 {
931 DPRINTF(InOrderCPU, "[tid:%i]: Calling deactivate thread.\n", tid);
932
933 if (isThreadActive(tid)) {
934 DPRINTF(InOrderCPU,"[tid:%i]: Removing from active threads list\n",
935 tid);
936 list<ThreadID>::iterator thread_it =
937 std::find(activeThreads.begin(), activeThreads.end(), tid);
938
939 removePipelineStalls(*thread_it);
940
941 activeThreads.erase(thread_it);
942
943 // Ideally, this should be triggered from the
944 // suspendContext/Thread functions
945 tcBase(tid)->setStatus(ThreadContext::Suspended);
946 }
947
948 assert(!isThreadActive(tid));
949 }
950
951 void
952 InOrderCPU::removePipelineStalls(ThreadID tid)
953 {
954 DPRINTF(InOrderCPU,"[tid:%i]: Removing all pipeline stalls\n",
955 tid);
956
957 for (int stNum = 0; stNum < NumStages ; stNum++) {
958 pipelineStage[stNum]->removeStalls(tid);
959 }
960
961 }
962
963 void
964 InOrderCPU::updateThreadPriority()
965 {
966 if (activeThreads.size() > 1)
967 {
968 //DEFAULT TO ROUND ROBIN SCHEME
969 //e.g. Move highest priority to end of thread list
970 list<ThreadID>::iterator list_begin = activeThreads.begin();
971 list<ThreadID>::iterator list_end = activeThreads.end();
972
973 unsigned high_thread = *list_begin;
974
975 activeThreads.erase(list_begin);
976
977 activeThreads.push_back(high_thread);
978 }
979 }
980
981 inline void
982 InOrderCPU::tickThreadStats()
983 {
984 /** Keep track of cycles that each thread is active */
985 list<ThreadID>::iterator thread_it = activeThreads.begin();
986 while (thread_it != activeThreads.end()) {
987 threadCycles[*thread_it]++;
988 thread_it++;
989 }
990
991 // Keep track of cycles where SMT is active
992 if (activeThreads.size() > 1) {
993 smtCycles++;
994 }
995 }
996
997 void
998 InOrderCPU::activateContext(ThreadID tid, int delay)
999 {
1000 DPRINTF(InOrderCPU,"[tid:%i]: Activating ...\n", tid);
1001
1002
1003 scheduleCpuEvent(ActivateThread, NoFault, tid, dummyInst[tid], delay);
1004
1005 // Be sure to signal that there's some activity so the CPU doesn't
1006 // deschedule itself.
1007 activityRec.activity();
1008
1009 _status = Running;
1010 }
1011
1012 void
1013 InOrderCPU::activateNextReadyContext(int delay)
1014 {
1015 DPRINTF(InOrderCPU,"Activating next ready thread\n");
1016
1017 // NOTE: Add 5 to the event priority so that we always activate
1018 // threads after we've finished deactivating, squashing,etc.
1019 // other threads
1020 scheduleCpuEvent(ActivateNextReadyThread, NoFault, 0/*tid*/, dummyInst[0],
1021 delay, 5);
1022
1023 // Be sure to signal that there's some activity so the CPU doesn't
1024 // deschedule itself.
1025 activityRec.activity();
1026
1027 _status = Running;
1028 }
1029
1030 void
1031 InOrderCPU::haltContext(ThreadID tid, int delay)
1032 {
1033 DPRINTF(InOrderCPU, "[tid:%i]: Calling Halt Context...\n", tid);
1034
1035 scheduleCpuEvent(HaltThread, NoFault, tid, dummyInst[tid], delay);
1036
1037 activityRec.activity();
1038 }
1039
1040 void
1041 InOrderCPU::haltThread(ThreadID tid)
1042 {
1043 DPRINTF(InOrderCPU, "[tid:%i]: Placing on Halted Threads List...\n", tid);
1044 deactivateThread(tid);
1045 squashThreadInPipeline(tid);
1046 haltedThreads.push_back(tid);
1047
1048 tcBase(tid)->setStatus(ThreadContext::Halted);
1049
1050 if (threadModel == SwitchOnCacheMiss) {
1051 activateNextReadyContext();
1052 }
1053 }
1054
1055 void
1056 InOrderCPU::suspendContext(ThreadID tid, int delay)
1057 {
1058 scheduleCpuEvent(SuspendThread, NoFault, tid, dummyInst[tid], delay);
1059 }
1060
1061 void
1062 InOrderCPU::suspendThread(ThreadID tid)
1063 {
1064 DPRINTF(InOrderCPU, "[tid:%i]: Placing on Suspended Threads List...\n",
1065 tid);
1066 deactivateThread(tid);
1067 suspendedThreads.push_back(tid);
1068 thread[tid]->lastSuspend = curTick();
1069
1070 tcBase(tid)->setStatus(ThreadContext::Suspended);
1071 }
1072
1073 void
1074 InOrderCPU::squashThreadInPipeline(ThreadID tid)
1075 {
1076 //Squash all instructions in each stage
1077 for (int stNum=NumStages - 1; stNum >= 0 ; stNum--) {
1078 pipelineStage[stNum]->squash(0 /*seq_num*/, tid);
1079 }
1080 }
1081
1082 PipelineStage*
1083 InOrderCPU::getPipeStage(int stage_num)
1084 {
1085 return pipelineStage[stage_num];
1086 }
1087
1088 uint64_t
1089 InOrderCPU::readIntReg(int reg_idx, ThreadID tid)
1090 {
1091 return intRegs[tid][reg_idx];
1092 }
1093
1094 FloatReg
1095 InOrderCPU::readFloatReg(int reg_idx, ThreadID tid)
1096 {
1097 return floatRegs.f[tid][reg_idx];
1098 }
1099
1100 FloatRegBits
1101 InOrderCPU::readFloatRegBits(int reg_idx, ThreadID tid)
1102 {;
1103 return floatRegs.i[tid][reg_idx];
1104 }
1105
1106 void
1107 InOrderCPU::setIntReg(int reg_idx, uint64_t val, ThreadID tid)
1108 {
1109 intRegs[tid][reg_idx] = val;
1110 }
1111
1112
1113 void
1114 InOrderCPU::setFloatReg(int reg_idx, FloatReg val, ThreadID tid)
1115 {
1116 floatRegs.f[tid][reg_idx] = val;
1117 }
1118
1119
1120 void
1121 InOrderCPU::setFloatRegBits(int reg_idx, FloatRegBits val, ThreadID tid)
1122 {
1123 floatRegs.i[tid][reg_idx] = val;
1124 }
1125
1126 uint64_t
1127 InOrderCPU::readRegOtherThread(unsigned reg_idx, ThreadID tid)
1128 {
1129 // If Default value is set, then retrieve target thread
1130 if (tid == InvalidThreadID) {
1131 tid = TheISA::getTargetThread(tcBase(tid));
1132 }
1133
1134 if (reg_idx < FP_Base_DepTag) {
1135 // Integer Register File
1136 return readIntReg(reg_idx, tid);
1137 } else if (reg_idx < Ctrl_Base_DepTag) {
1138 // Float Register File
1139 reg_idx -= FP_Base_DepTag;
1140 return readFloatRegBits(reg_idx, tid);
1141 } else {
1142 reg_idx -= Ctrl_Base_DepTag;
1143 return readMiscReg(reg_idx, tid); // Misc. Register File
1144 }
1145 }
1146 void
1147 InOrderCPU::setRegOtherThread(unsigned reg_idx, const MiscReg &val,
1148 ThreadID tid)
1149 {
1150 // If Default value is set, then retrieve target thread
1151 if (tid == InvalidThreadID) {
1152 tid = TheISA::getTargetThread(tcBase(tid));
1153 }
1154
1155 if (reg_idx < FP_Base_DepTag) { // Integer Register File
1156 setIntReg(reg_idx, val, tid);
1157 } else if (reg_idx < Ctrl_Base_DepTag) { // Float Register File
1158 reg_idx -= FP_Base_DepTag;
1159 setFloatRegBits(reg_idx, val, tid);
1160 } else {
1161 reg_idx -= Ctrl_Base_DepTag;
1162 setMiscReg(reg_idx, val, tid); // Misc. Register File
1163 }
1164 }
1165
1166 MiscReg
1167 InOrderCPU::readMiscRegNoEffect(int misc_reg, ThreadID tid)
1168 {
1169 return isa[tid].readMiscRegNoEffect(misc_reg);
1170 }
1171
1172 MiscReg
1173 InOrderCPU::readMiscReg(int misc_reg, ThreadID tid)
1174 {
1175 return isa[tid].readMiscReg(misc_reg, tcBase(tid));
1176 }
1177
1178 void
1179 InOrderCPU::setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid)
1180 {
1181 isa[tid].setMiscRegNoEffect(misc_reg, val);
1182 }
1183
1184 void
1185 InOrderCPU::setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid)
1186 {
1187 isa[tid].setMiscReg(misc_reg, val, tcBase(tid));
1188 }
1189
1190
1191 InOrderCPU::ListIt
1192 InOrderCPU::addInst(DynInstPtr &inst)
1193 {
1194 ThreadID tid = inst->readTid();
1195
1196 instList[tid].push_back(inst);
1197
1198 return --(instList[tid].end());
1199 }
1200
1201 void
1202 InOrderCPU::updateContextSwitchStats()
1203 {
1204 // Set Average Stat Here, then reset to 0
1205 instsPerCtxtSwitch = instsPerSwitch;
1206 instsPerSwitch = 0;
1207 }
1208
1209
1210 void
1211 InOrderCPU::instDone(DynInstPtr inst, ThreadID tid)
1212 {
1213 // Set the CPU's PCs - This contributes to the precise state of the CPU
1214 // which can be used when restoring a thread to the CPU after after any
1215 // type of context switching activity (fork, exception, etc.)
1216 pcState(inst->pcState(), tid);
1217
1218 if (inst->isControl()) {
1219 thread[tid]->lastGradIsBranch = true;
1220 thread[tid]->lastBranchPC = inst->pcState();
1221 TheISA::advancePC(thread[tid]->lastBranchPC, inst->staticInst);
1222 } else {
1223 thread[tid]->lastGradIsBranch = false;
1224 }
1225
1226
1227 // Finalize Trace Data For Instruction
1228 if (inst->traceData) {
1229 //inst->traceData->setCycle(curTick());
1230 inst->traceData->setFetchSeq(inst->seqNum);
1231 //inst->traceData->setCPSeq(cpu->tcBase(tid)->numInst);
1232 inst->traceData->dump();
1233 delete inst->traceData;
1234 inst->traceData = NULL;
1235 }
1236
1237 // Increment active thread's instruction count
1238 instsPerSwitch++;
1239
1240 // Increment thread-state's instruction count
1241 thread[tid]->numInst++;
1242
1243 // Increment thread-state's instruction stats
1244 thread[tid]->numInsts++;
1245
1246 // Count committed insts per thread stats
1247 committedInsts[tid]++;
1248
1249 // Count total insts committed stat
1250 totalCommittedInsts++;
1251
1252 // Count SMT-committed insts per thread stat
1253 if (numActiveThreads() > 1) {
1254 smtCommittedInsts[tid]++;
1255 }
1256
1257 // Instruction-Mix Stats
1258 if (inst->isLoad()) {
1259 comLoads++;
1260 } else if (inst->isStore()) {
1261 comStores++;
1262 } else if (inst->isControl()) {
1263 comBranches++;
1264 } else if (inst->isNop()) {
1265 comNops++;
1266 } else if (inst->isNonSpeculative()) {
1267 comNonSpec++;
1268 } else if (inst->isInteger()) {
1269 comInts++;
1270 } else if (inst->isFloating()) {
1271 comFloats++;
1272 }
1273
1274 // Check for instruction-count-based events.
1275 comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);
1276
1277 // Broadcast to other resources an instruction
1278 // has been completed
1279 resPool->scheduleEvent((CPUEventType)ResourcePool::InstGraduated, inst,
1280 0, 0, tid);
1281
1282 // Finally, remove instruction from CPU
1283 removeInst(inst);
1284 }
1285
1286 // currently unused function, but substitute repetitive code w/this function
1287 // call
1288 void
1289 InOrderCPU::addToRemoveList(DynInstPtr &inst)
1290 {
1291 removeInstsThisCycle = true;
1292 if (!inst->isRemoveList()) {
1293 DPRINTF(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
1294 "[sn:%lli] to remove list\n",
1295 inst->threadNumber, inst->pcState(), inst->seqNum);
1296 inst->setRemoveList();
1297 removeList.push(inst->getInstListIt());
1298 } else {
1299 DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i] PC %s "
1300 "[sn:%lli], already remove list\n",
1301 inst->threadNumber, inst->pcState(), inst->seqNum);
1302 }
1303
1304 }
1305
1306 void
1307 InOrderCPU::removeInst(DynInstPtr &inst)
1308 {
1309 DPRINTF(InOrderCPU, "Removing graduated instruction [tid:%i] PC %s "
1310 "[sn:%lli]\n",
1311 inst->threadNumber, inst->pcState(), inst->seqNum);
1312
1313 removeInstsThisCycle = true;
1314
1315 // Remove the instruction.
1316 if (!inst->isRemoveList()) {
1317 DPRINTF(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
1318 "[sn:%lli] to remove list\n",
1319 inst->threadNumber, inst->pcState(), inst->seqNum);
1320 inst->setRemoveList();
1321 removeList.push(inst->getInstListIt());
1322 } else {
1323 DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i] PC %s "
1324 "[sn:%lli], already on remove list\n",
1325 inst->threadNumber, inst->pcState(), inst->seqNum);
1326 }
1327
1328 }
1329
1330 void
1331 InOrderCPU::removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid)
1332 {
1333 //assert(!instList[tid].empty());
1334
1335 removeInstsThisCycle = true;
1336
1337 ListIt inst_iter = instList[tid].end();
1338
1339 inst_iter--;
1340
1341 DPRINTF(InOrderCPU, "Squashing instructions from CPU instruction "
1342 "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
1343 tid, seq_num, (*inst_iter)->seqNum);
1344
1345 while ((*inst_iter)->seqNum > seq_num) {
1346
1347 bool break_loop = (inst_iter == instList[tid].begin());
1348
1349 squashInstIt(inst_iter, tid);
1350
1351 inst_iter--;
1352
1353 if (break_loop)
1354 break;
1355 }
1356 }
1357
1358
1359 inline void
1360 InOrderCPU::squashInstIt(const ListIt &instIt, ThreadID tid)
1361 {
1362 if ((*instIt)->threadNumber == tid) {
1363 DPRINTF(InOrderCPU, "Squashing instruction, "
1364 "[tid:%i] [sn:%lli] PC %s\n",
1365 (*instIt)->threadNumber,
1366 (*instIt)->seqNum,
1367 (*instIt)->pcState());
1368
1369 (*instIt)->setSquashed();
1370
1371 if (!(*instIt)->isRemoveList()) {
1372 DPRINTF(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
1373 "[sn:%lli] to remove list\n",
1374 (*instIt)->threadNumber, (*instIt)->pcState(),
1375 (*instIt)->seqNum);
1376 (*instIt)->setRemoveList();
1377 removeList.push(instIt);
1378 } else {
1379 DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i]"
1380 " PC %s [sn:%lli], already on remove list\n",
1381 (*instIt)->threadNumber, (*instIt)->pcState(),
1382 (*instIt)->seqNum);
1383 }
1384
1385 }
1386
1387 }
1388
1389
1390 void
1391 InOrderCPU::cleanUpRemovedInsts()
1392 {
1393 while (!removeList.empty()) {
1394 DPRINTF(InOrderCPU, "Removing instruction, "
1395 "[tid:%i] [sn:%lli] PC %s\n",
1396 (*removeList.front())->threadNumber,
1397 (*removeList.front())->seqNum,
1398 (*removeList.front())->pcState());
1399
1400 DynInstPtr inst = *removeList.front();
1401 ThreadID tid = inst->threadNumber;
1402
1403 // Make Sure Resource Schedule Is Emptied Out
1404 ThePipeline::ResSchedule *inst_sched = &inst->resSched;
1405 while (!inst_sched->empty()) {
1406 ScheduleEntry* sch_entry = inst_sched->top();
1407 inst_sched->pop();
1408 delete sch_entry;
1409 }
1410
1411 // Remove From Register Dependency Map, If Necessary
1412 archRegDepMap[(*removeList.front())->threadNumber].
1413 remove((*removeList.front()));
1414
1415
1416 // Clear if Non-Speculative
1417 if (inst->staticInst &&
1418 inst->seqNum == nonSpecSeqNum[tid] &&
1419 nonSpecInstActive[tid] == true) {
1420 nonSpecInstActive[tid] = false;
1421 }
1422
1423 instList[tid].erase(removeList.front());
1424
1425 removeList.pop();
1426 }
1427
1428 removeInstsThisCycle = false;
1429 }
1430
1431 void
1432 InOrderCPU::cleanUpRemovedReqs()
1433 {
1434 while (!reqRemoveList.empty()) {
1435 ResourceRequest *res_req = reqRemoveList.front();
1436
1437 DPRINTF(RefCount, "[tid:%i] [sn:%lli]: Removing Request "
1438 "[stage_num:%i] [res:%s] [slot:%i] [completed:%i].\n",
1439 res_req->inst->threadNumber,
1440 res_req->inst->seqNum,
1441 res_req->getStageNum(),
1442 res_req->res->name(),
1443 (res_req->isCompleted()) ?
1444 res_req->getComplSlot() : res_req->getSlot(),
1445 res_req->isCompleted());
1446
1447 reqRemoveList.pop();
1448
1449 delete res_req;
1450 }
1451 }
1452
1453 void
1454 InOrderCPU::cleanUpRemovedEvents()
1455 {
1456 while (!cpuEventRemoveList.empty()) {
1457 Event *cpu_event = cpuEventRemoveList.front();
1458 cpuEventRemoveList.pop();
1459 delete cpu_event;
1460 }
1461 }
1462
1463
1464 void
1465 InOrderCPU::dumpInsts()
1466 {
1467 int num = 0;
1468
1469 ListIt inst_list_it = instList[0].begin();
1470
1471 cprintf("Dumping Instruction List\n");
1472
1473 while (inst_list_it != instList[0].end()) {
1474 cprintf("Instruction:%i\nPC:%s\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
1475 "Squashed:%i\n\n",
1476 num, (*inst_list_it)->pcState(),
1477 (*inst_list_it)->threadNumber,
1478 (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(),
1479 (*inst_list_it)->isSquashed());
1480 inst_list_it++;
1481 ++num;
1482 }
1483 }
1484
1485 void
1486 InOrderCPU::wakeCPU()
1487 {
1488 if (/*activityRec.active() || */tickEvent.scheduled()) {
1489 DPRINTF(Activity, "CPU already running.\n");
1490 return;
1491 }
1492
1493 DPRINTF(Activity, "Waking up CPU\n");
1494
1495 Tick extra_cycles = tickToCycles((curTick() - 1) - lastRunningCycle);
1496
1497 idleCycles += extra_cycles;
1498 for (int stage_num = 0; stage_num < NumStages; stage_num++) {
1499 pipelineStage[stage_num]->idleCycles += extra_cycles;
1500 }
1501
1502 numCycles += extra_cycles;
1503
1504 schedule(&tickEvent, nextCycle(curTick()));
1505 }
1506
1507 #if FULL_SYSTEM
1508
1509 void
1510 InOrderCPU::wakeup()
1511 {
1512 if (thread[0]->status() != ThreadContext::Suspended)
1513 return;
1514
1515 wakeCPU();
1516
1517 DPRINTF(Quiesce, "Suspended Processor woken\n");
1518 threadContexts[0]->activate();
1519 }
1520 #endif
1521
1522 #if !FULL_SYSTEM
1523 void
1524 InOrderCPU::syscall(int64_t callnum, ThreadID tid)
1525 {
1526 DPRINTF(InOrderCPU, "[tid:%i] Executing syscall().\n\n", tid);
1527
1528 DPRINTF(Activity,"Activity: syscall() called.\n");
1529
1530 // Temporarily increase this by one to account for the syscall
1531 // instruction.
1532 ++(this->thread[tid]->funcExeInst);
1533
1534 // Execute the actual syscall.
1535 this->thread[tid]->syscall(callnum);
1536
1537 // Decrease funcExeInst by one as the normal commit will handle
1538 // incrementing it.
1539 --(this->thread[tid]->funcExeInst);
1540
1541 // Clear Non-Speculative Block Variable
1542 nonSpecInstActive[tid] = false;
1543 }
1544 #endif
1545
1546 TheISA::TLB*
1547 InOrderCPU::getITBPtr()
1548 {
1549 CacheUnit *itb_res =
1550 dynamic_cast<CacheUnit*>(resPool->getResource(fetchPortIdx));
1551 return itb_res->tlb();
1552 }
1553
1554
1555 TheISA::TLB*
1556 InOrderCPU::getDTBPtr()
1557 {
1558 CacheUnit *dtb_res =
1559 dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
1560 return dtb_res->tlb();
1561 }
1562
1563 Fault
1564 InOrderCPU::read(DynInstPtr inst, Addr addr,
1565 uint8_t *data, unsigned size, unsigned flags)
1566 {
1567 //@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
1568 // you want to run w/out caches?
1569 CacheUnit *cache_res =
1570 dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
1571
1572 return cache_res->read(inst, addr, data, size, flags);
1573 }
1574
1575 Fault
1576 InOrderCPU::write(DynInstPtr inst, uint8_t *data, unsigned size,
1577 Addr addr, unsigned flags, uint64_t *write_res)
1578 {
1579 //@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
1580 // you want to run w/out caches?
1581 CacheUnit *cache_res =
1582 dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
1583 return cache_res->write(inst, data, size, addr, flags, write_res);
1584 }