2 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
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.
28 * Authors: Korey Sewell
34 #include "arch/utility.hh"
35 #include "base/bigint.hh"
36 #include "config/full_system.hh"
37 #include "config/the_isa.hh"
38 #include "cpu/inorder/resources/resource_list.hh"
39 #include "cpu/inorder/cpu.hh"
40 #include "cpu/inorder/first_stage.hh"
41 #include "cpu/inorder/inorder_dyn_inst.hh"
42 #include "cpu/inorder/pipeline_traits.hh"
43 #include "cpu/inorder/resource_pool.hh"
44 #include "cpu/inorder/thread_context.hh"
45 #include "cpu/inorder/thread_state.hh"
46 #include "cpu/activity.hh"
47 #include "cpu/base.hh"
48 #include "cpu/exetrace.hh"
49 #include "cpu/simple_thread.hh"
50 #include "cpu/thread_context.hh"
51 #include "debug/Activity.hh"
52 #include "debug/InOrderCPU.hh"
53 #include "debug/RefCount.hh"
54 #include "debug/SkedCache.hh"
55 #include "mem/translating_port.hh"
56 #include "params/InOrderCPU.hh"
57 #include "sim/process.hh"
58 #include "sim/stat_control.hh"
61 #include "cpu/quiesce_event.hh"
62 #include "sim/system.hh"
65 #if THE_ISA == ALPHA_ISA
66 #include "arch/alpha/osfpal.hh"
70 using namespace TheISA
;
71 using namespace ThePipeline
;
73 InOrderCPU::TickEvent::TickEvent(InOrderCPU
*c
)
74 : Event(CPU_Tick_Pri
), cpu(c
)
79 InOrderCPU::TickEvent::process()
86 InOrderCPU::TickEvent::description()
88 return "InOrderCPU tick event";
91 InOrderCPU::CPUEvent::CPUEvent(InOrderCPU
*_cpu
, CPUEventType e_type
,
92 Fault fault
, ThreadID _tid
, DynInstPtr inst
,
93 CPUEventPri event_pri
)
94 : Event(event_pri
), cpu(_cpu
)
96 setEvent(e_type
, fault
, _tid
, inst
);
100 std::string
InOrderCPU::eventNames
[NumCPUEvents
] =
103 "ActivateNextReadyThread",
109 "SquashFromMemStall",
114 InOrderCPU::CPUEvent::process()
116 switch (cpuEventType
)
119 cpu
->activateThread(tid
);
120 cpu
->resPool
->activateThread(tid
);
123 case ActivateNextReadyThread
:
124 cpu
->activateNextReadyThread();
127 case DeactivateThread
:
128 cpu
->deactivateThread(tid
);
129 cpu
->resPool
->deactivateThread(tid
);
133 cpu
->haltThread(tid
);
134 cpu
->resPool
->deactivateThread(tid
);
138 cpu
->suspendThread(tid
);
139 cpu
->resPool
->suspendThread(tid
);
142 case SquashFromMemStall
:
143 cpu
->squashDueToMemStall(inst
->squashingStage
, inst
->seqNum
, tid
);
144 cpu
->resPool
->squashDueToMemStall(inst
, inst
->squashingStage
,
149 DPRINTF(InOrderCPU
, "Trapping CPU\n");
150 cpu
->trap(fault
, tid
, inst
);
151 cpu
->resPool
->trap(fault
, tid
, inst
);
156 cpu
->syscall(inst
->syscallNum
, tid
);
157 cpu
->resPool
->trap(fault
, tid
, inst
);
161 fatal("Unrecognized Event Type %s", eventNames
[cpuEventType
]);
164 cpu
->cpuEventRemoveList
.push(this);
170 InOrderCPU::CPUEvent::description()
172 return "InOrderCPU event";
176 InOrderCPU::CPUEvent::scheduleEvent(int delay
)
178 assert(!scheduled() || squashed());
179 cpu
->reschedule(this, cpu
->nextCycle(curTick() + cpu
->ticks(delay
)), true);
183 InOrderCPU::CPUEvent::unscheduleEvent()
189 InOrderCPU::InOrderCPU(Params
*params
)
191 cpu_id(params
->cpu_id
),
195 stageWidth(params
->stageWidth
),
197 removeInstsThisCycle(false),
198 activityRec(params
->name
, NumStages
, 10, params
->activity
),
201 system(params
->system
),
202 #endif // FULL_SYSTEM
208 deferRegistration(false/*params->deferRegistration*/),
209 stageTracing(params
->stageTracing
),
213 ThreadID active_threads
;
216 resPool
= new ResourcePool(this, params
);
218 // Resize for Multithreading CPUs
219 thread
.resize(numThreads
);
224 active_threads
= params
->workload
.size();
226 if (active_threads
> MaxThreads
) {
227 panic("Workload Size too large. Increase the 'MaxThreads'"
228 "in your InOrder implementation or "
229 "edit your workload size.");
233 if (active_threads
> 1) {
234 threadModel
= (InOrderCPU::ThreadModel
) params
->threadModel
;
236 if (threadModel
== SMT
) {
237 DPRINTF(InOrderCPU
, "Setting Thread Model to SMT.\n");
238 } else if (threadModel
== SwitchOnCacheMiss
) {
239 DPRINTF(InOrderCPU
, "Setting Thread Model to "
240 "Switch On Cache Miss\n");
244 threadModel
= Single
;
251 // Bind the fetch & data ports from the resource pool.
252 fetchPortIdx
= resPool
->getPortIdx(params
->fetchMemPort
);
253 if (fetchPortIdx
== 0) {
254 fatal("Unable to find port to fetch instructions from.\n");
257 dataPortIdx
= resPool
->getPortIdx(params
->dataMemPort
);
258 if (dataPortIdx
== 0) {
259 fatal("Unable to find port for data.\n");
262 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
) {
264 lastCommittedPC
[tid
].set(0);
267 // SMT is not supported in FS mode yet.
268 assert(numThreads
== 1);
269 thread
[tid
] = new Thread(this, 0);
271 if (tid
< (ThreadID
)params
->workload
.size()) {
272 DPRINTF(InOrderCPU
, "Workload[%i] process is %#x\n",
273 tid
, params
->workload
[tid
]->prog_fname
);
275 new Thread(this, tid
, params
->workload
[tid
]);
277 //Allocate Empty thread so M5 can use later
278 //when scheduling threads to CPU
279 Process
* dummy_proc
= params
->workload
[0];
280 thread
[tid
] = new Thread(this, tid
, dummy_proc
);
283 // Eventually set this with parameters...
287 // Setup the TC that will serve as the interface to the threads/CPU.
288 InOrderThreadContext
*tc
= new InOrderThreadContext
;
290 tc
->thread
= thread
[tid
];
293 // Setup quiesce event.
294 this->thread
[tid
]->quiesceEvent
= new EndQuiesceEvent(tc
);
297 // Give the thread the TC.
298 thread
[tid
]->tc
= tc
;
299 thread
[tid
]->setFuncExeInst(0);
300 globalSeqNum
[tid
] = 1;
302 // Add the TC to the CPU's list of TC's.
303 this->threadContexts
.push_back(tc
);
306 // Initialize TimeBuffer Stage Queues
307 for (int stNum
=0; stNum
< NumStages
- 1; stNum
++) {
308 stageQueue
[stNum
] = new StageQueue(NumStages
, NumStages
);
309 stageQueue
[stNum
]->id(stNum
);
313 // Set Up Pipeline Stages
314 for (int stNum
=0; stNum
< NumStages
; stNum
++) {
316 pipelineStage
[stNum
] = new FirstStage(params
, stNum
);
318 pipelineStage
[stNum
] = new PipelineStage(params
, stNum
);
320 pipelineStage
[stNum
]->setCPU(this);
321 pipelineStage
[stNum
]->setActiveThreads(&activeThreads
);
322 pipelineStage
[stNum
]->setTimeBuffer(&timeBuffer
);
324 // Take Care of 1st/Nth stages
326 pipelineStage
[stNum
]->setPrevStageQueue(stageQueue
[stNum
- 1]);
327 if (stNum
< NumStages
- 1)
328 pipelineStage
[stNum
]->setNextStageQueue(stageQueue
[stNum
]);
331 // Initialize thread specific variables
332 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
333 archRegDepMap
[tid
].setCPU(this);
335 nonSpecInstActive
[tid
] = false;
336 nonSpecSeqNum
[tid
] = 0;
338 squashSeqNum
[tid
] = MaxAddr
;
339 lastSquashCycle
[tid
] = 0;
341 memset(intRegs
[tid
], 0, sizeof(intRegs
[tid
]));
342 memset(floatRegs
.i
[tid
], 0, sizeof(floatRegs
.i
[tid
]));
345 // Define dummy instructions and resource requests to be used.
346 dummyInst
[tid
] = new InOrderDynInst(this,
352 dummyReq
[tid
] = new ResourceRequest(resPool
->getResource(0));
355 dummyReqInst
= new InOrderDynInst(this, NULL
, 0, 0, 0);
356 dummyReqInst
->setSquashed();
357 dummyReqInst
->resetInstCount();
359 dummyBufferInst
= new InOrderDynInst(this, NULL
, 0, 0, 0);
360 dummyBufferInst
->setSquashed();
361 dummyBufferInst
->resetInstCount();
363 endOfSkedIt
= skedCache
.end();
364 frontEndSked
= createFrontEndSked();
366 lastRunningCycle
= curTick();
371 // Schedule First Tick Event, CPU will reschedule itself from here on out.
372 scheduleTickEvent(0);
375 InOrderCPU::~InOrderCPU()
379 SkedCacheIt sked_it
= skedCache
.begin();
380 SkedCacheIt sked_end
= skedCache
.end();
382 while (sked_it
!= sked_end
) {
383 delete (*sked_it
).second
;
389 m5::hash_map
<InOrderCPU::SkedID
, ThePipeline::RSkedPtr
> InOrderCPU::skedCache
;
392 InOrderCPU::createFrontEndSked()
394 RSkedPtr res_sked
= new ResourceSked();
396 StageScheduler
F(res_sked
, stage_num
++);
397 StageScheduler
D(res_sked
, stage_num
++);
400 F
.needs(FetchSeq
, FetchSeqUnit::AssignNextPC
);
401 F
.needs(ICache
, FetchUnit::InitiateFetch
);
404 D
.needs(ICache
, FetchUnit::CompleteFetch
);
405 D
.needs(Decode
, DecodeUnit::DecodeInst
);
406 D
.needs(BPred
, BranchPredictor::PredictBranch
);
407 D
.needs(FetchSeq
, FetchSeqUnit::UpdateTargetPC
);
410 DPRINTF(SkedCache
, "Resource Sked created for instruction \"front_end\"\n");
416 InOrderCPU::createBackEndSked(DynInstPtr inst
)
418 RSkedPtr res_sked
= lookupSked(inst
);
419 if (res_sked
!= NULL
) {
420 DPRINTF(SkedCache
, "Found %s in sked cache.\n",
424 res_sked
= new ResourceSked();
427 int stage_num
= ThePipeline::BackEndStartStage
;
428 StageScheduler
X(res_sked
, stage_num
++);
429 StageScheduler
M(res_sked
, stage_num
++);
430 StageScheduler
W(res_sked
, stage_num
++);
432 if (!inst
->staticInst
) {
433 warn_once("Static Instruction Object Not Set. Can't Create"
434 " Back End Schedule");
439 X
.needs(RegManager
, UseDefUnit::MarkDestRegs
);
440 for (int idx
=0; idx
< inst
->numSrcRegs(); idx
++) {
441 if (!idx
|| !inst
->isStore()) {
442 X
.needs(RegManager
, UseDefUnit::ReadSrcReg
, idx
);
446 //@todo: schedule non-spec insts to operate on this cycle
447 // as long as all previous insts are done
448 if ( inst
->isNonSpeculative() ) {
449 // skip execution of non speculative insts until later
450 } else if ( inst
->isMemRef() ) {
451 if ( inst
->isLoad() ) {
452 X
.needs(AGEN
, AGENUnit::GenerateAddr
);
454 } else if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
455 X
.needs(MDU
, MultDivUnit::StartMultDiv
);
457 X
.needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
461 if (!inst
->isNonSpeculative()) {
462 if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
463 M
.needs(MDU
, MultDivUnit::EndMultDiv
);
466 if ( inst
->isLoad() ) {
467 M
.needs(DCache
, CacheUnit::InitiateReadData
);
469 M
.needs(DCache
, CacheUnit::InitSecondSplitRead
);
470 } else if ( inst
->isStore() ) {
471 for (int i
= 1; i
< inst
->numSrcRegs(); i
++ ) {
472 M
.needs(RegManager
, UseDefUnit::ReadSrcReg
, i
);
474 M
.needs(AGEN
, AGENUnit::GenerateAddr
);
475 M
.needs(DCache
, CacheUnit::InitiateWriteData
);
477 M
.needs(DCache
, CacheUnit::InitSecondSplitWrite
);
482 if (!inst
->isNonSpeculative()) {
483 if ( inst
->isLoad() ) {
484 W
.needs(DCache
, CacheUnit::CompleteReadData
);
486 W
.needs(DCache
, CacheUnit::CompleteSecondSplitRead
);
487 } else if ( inst
->isStore() ) {
488 W
.needs(DCache
, CacheUnit::CompleteWriteData
);
490 W
.needs(DCache
, CacheUnit::CompleteSecondSplitWrite
);
493 // Finally, Execute Speculative Data
494 if (inst
->isMemRef()) {
495 if (inst
->isLoad()) {
496 W
.needs(AGEN
, AGENUnit::GenerateAddr
);
497 W
.needs(DCache
, CacheUnit::InitiateReadData
);
499 W
.needs(DCache
, CacheUnit::InitSecondSplitRead
);
500 W
.needs(DCache
, CacheUnit::CompleteReadData
);
502 W
.needs(DCache
, CacheUnit::CompleteSecondSplitRead
);
503 } else if (inst
->isStore()) {
504 if ( inst
->numSrcRegs() >= 2 ) {
505 W
.needs(RegManager
, UseDefUnit::ReadSrcReg
, 1);
507 W
.needs(AGEN
, AGENUnit::GenerateAddr
);
508 W
.needs(DCache
, CacheUnit::InitiateWriteData
);
510 W
.needs(DCache
, CacheUnit::InitSecondSplitWrite
);
511 W
.needs(DCache
, CacheUnit::CompleteWriteData
);
513 W
.needs(DCache
, CacheUnit::CompleteSecondSplitWrite
);
516 W
.needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
520 W
.needs(Grad
, GraduationUnit::GraduateInst
);
522 for (int idx
=0; idx
< inst
->numDestRegs(); idx
++) {
523 W
.needs(RegManager
, UseDefUnit::WriteDestReg
, idx
);
526 if (inst
->isControl())
527 W
.needs(BPred
, BranchPredictor::UpdatePredictor
);
529 // Insert Back Schedule into our cache of
530 // resource schedules
531 addToSkedCache(inst
, res_sked
);
533 DPRINTF(SkedCache
, "Back End Sked Created for instruction: %s (%08p)\n",
534 inst
->instName(), inst
->getMachInst());
541 InOrderCPU::regStats()
543 /* Register the Resource Pool's stats here.*/
546 /* Register for each Pipeline Stage */
547 for (int stage_num
=0; stage_num
< ThePipeline::NumStages
; stage_num
++) {
548 pipelineStage
[stage_num
]->regStats();
551 /* Register any of the InOrderCPU's stats here.*/
553 .name(name() + ".instsPerContextSwitch")
554 .desc("Instructions Committed Per Context Switch")
555 .prereq(instsPerCtxtSwitch
);
558 .name(name() + ".contextSwitches")
559 .desc("Number of context switches");
562 .name(name() + ".comLoads")
563 .desc("Number of Load instructions committed");
566 .name(name() + ".comStores")
567 .desc("Number of Store instructions committed");
570 .name(name() + ".comBranches")
571 .desc("Number of Branches instructions committed");
574 .name(name() + ".comNops")
575 .desc("Number of Nop instructions committed");
578 .name(name() + ".comNonSpec")
579 .desc("Number of Non-Speculative instructions committed");
582 .name(name() + ".comInts")
583 .desc("Number of Integer instructions committed");
586 .name(name() + ".comFloats")
587 .desc("Number of Floating Point instructions committed");
590 .name(name() + ".timesIdled")
591 .desc("Number of times that the entire CPU went into an idle state and"
592 " unscheduled itself")
596 .name(name() + ".idleCycles")
597 .desc("Number of cycles cpu's stages were not processed");
600 .name(name() + ".runCycles")
601 .desc("Number of cycles cpu stages are processed.");
604 .name(name() + ".activity")
605 .desc("Percentage of cycles cpu is active")
607 activity
= (runCycles
/ numCycles
) * 100;
611 .name(name() + ".threadCycles")
612 .desc("Total Number of Cycles A Thread Was Active in CPU (Per-Thread)");
615 .name(name() + ".smtCycles")
616 .desc("Total number of cycles that the CPU was in SMT-mode");
620 .name(name() + ".committedInsts")
621 .desc("Number of Instructions Simulated (Per-Thread)");
625 .name(name() + ".smtCommittedInsts")
626 .desc("Number of SMT Instructions Simulated (Per-Thread)");
629 .name(name() + ".committedInsts_total")
630 .desc("Number of Instructions Simulated (Total)");
633 .name(name() + ".cpi")
634 .desc("CPI: Cycles Per Instruction (Per-Thread)")
636 cpi
= numCycles
/ committedInsts
;
639 .name(name() + ".smt_cpi")
640 .desc("CPI: Total SMT-CPI")
642 smtCpi
= smtCycles
/ smtCommittedInsts
;
645 .name(name() + ".cpi_total")
646 .desc("CPI: Total CPI of All Threads")
648 totalCpi
= numCycles
/ totalCommittedInsts
;
651 .name(name() + ".ipc")
652 .desc("IPC: Instructions Per Cycle (Per-Thread)")
654 ipc
= committedInsts
/ numCycles
;
657 .name(name() + ".smt_ipc")
658 .desc("IPC: Total SMT-IPC")
660 smtIpc
= smtCommittedInsts
/ smtCycles
;
663 .name(name() + ".ipc_total")
664 .desc("IPC: Total IPC of All Threads")
666 totalIpc
= totalCommittedInsts
/ numCycles
;
675 DPRINTF(InOrderCPU
, "\n\nInOrderCPU: Ticking main, InOrderCPU.\n");
679 bool pipes_idle
= true;
681 //Tick each of the stages
682 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
683 pipelineStage
[stNum
]->tick();
685 pipes_idle
= pipes_idle
&& pipelineStage
[stNum
]->idle
;
693 // Now advance the time buffers one tick
694 timeBuffer
.advance();
695 for (int sqNum
=0; sqNum
< NumStages
- 1; sqNum
++) {
696 stageQueue
[sqNum
]->advance();
698 activityRec
.advance();
700 // Any squashed events, or insts then remove them now
701 cleanUpRemovedEvents();
702 cleanUpRemovedInsts();
704 // Re-schedule CPU for this cycle
705 if (!tickEvent
.scheduled()) {
706 if (_status
== SwitchedOut
) {
708 lastRunningCycle
= curTick();
709 } else if (!activityRec
.active()) {
710 DPRINTF(InOrderCPU
, "sleeping CPU.\n");
711 lastRunningCycle
= curTick();
714 //Tick next_tick = curTick() + cycles(1);
715 //tickEvent.schedule(next_tick);
716 schedule(&tickEvent
, nextCycle(curTick() + 1));
717 DPRINTF(InOrderCPU
, "Scheduled CPU for next tick @ %i.\n",
718 nextCycle(curTick() + 1));
723 updateThreadPriority();
730 if (!deferRegistration
) {
731 registerThreadContexts();
734 // Set inSyscall so that the CPU doesn't squash when initially
735 // setting up registers.
736 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
)
737 thread
[tid
]->inSyscall
= true;
740 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
741 ThreadContext
*src_tc
= threadContexts
[tid
];
742 TheISA::initCPU(src_tc
, src_tc
->contextId());
747 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
)
748 thread
[tid
]->inSyscall
= false;
750 // Call Initializiation Routine for Resource Pool
755 InOrderCPU::getPort(const std::string
&if_name
, int idx
)
757 return resPool
->getPort(if_name
, idx
);
762 InOrderCPU::hwrei(ThreadID tid
)
764 #if THE_ISA == ALPHA_ISA
765 // Need to clear the lock flag upon returning from an interrupt.
766 setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG
, false, tid
);
768 thread
[tid
]->kernelStats
->hwrei();
769 // FIXME: XXX check for interrupts? XXX
777 InOrderCPU::simPalCheck(int palFunc
, ThreadID tid
)
779 #if THE_ISA == ALPHA_ISA
780 if (this->thread
[tid
]->kernelStats
)
781 this->thread
[tid
]->kernelStats
->callpal(palFunc
,
782 this->threadContexts
[tid
]);
787 if (--System::numSystemsRunning
== 0)
788 exitSimLoop("all cpus halted");
793 if (this->system
->breakpoint())
803 InOrderCPU::getInterrupts()
805 // Check if there are any outstanding interrupts
806 return interrupts
->getInterrupt(threadContexts
[0]);
811 InOrderCPU::processInterrupts(Fault interrupt
)
813 // Check for interrupts here. For now can copy the code that
814 // exists within isa_fullsys_traits.hh. Also assume that thread 0
815 // is the one that handles the interrupts.
816 // @todo: Possibly consolidate the interrupt checking code.
817 // @todo: Allow other threads to handle interrupts.
819 assert(interrupt
!= NoFault
);
820 interrupts
->updateIntrInfo(threadContexts
[0]);
822 DPRINTF(InOrderCPU
, "Interrupt %s being handled\n", interrupt
->name());
824 // Note: Context ID ok here? Impl. of FS mode needs to revisit this
825 trap(interrupt
, threadContexts
[0]->contextId(), dummyBufferInst
);
830 InOrderCPU::updateMemPorts()
832 // Update all ThreadContext's memory ports (Functional/Virtual
834 ThreadID size
= thread
.size();
835 for (ThreadID i
= 0; i
< size
; ++i
)
836 thread
[i
]->connectMemPorts(thread
[i
]->getTC());
841 InOrderCPU::trapContext(Fault fault
, ThreadID tid
, DynInstPtr inst
, int delay
)
843 scheduleCpuEvent(Trap
, fault
, tid
, inst
, delay
);
847 InOrderCPU::trap(Fault fault
, ThreadID tid
, DynInstPtr inst
)
849 fault
->invoke(tcBase(tid
), inst
->staticInst
);
853 InOrderCPU::squashFromMemStall(DynInstPtr inst
, ThreadID tid
, int delay
)
855 scheduleCpuEvent(SquashFromMemStall
, NoFault
, tid
, inst
, delay
);
860 InOrderCPU::squashDueToMemStall(int stage_num
, InstSeqNum seq_num
,
863 DPRINTF(InOrderCPU
, "Squashing Pipeline Stages Due to Memory Stall...\n");
865 // Squash all instructions in each stage including
866 // instruction that caused the squash (seq_num - 1)
867 // NOTE: The stage bandwidth needs to be cleared so thats why
868 // the stalling instruction is squashed as well. The stalled
869 // instruction is previously placed in another intermediate buffer
870 // while it's stall is being handled.
871 InstSeqNum squash_seq_num
= seq_num
- 1;
873 for (int stNum
=stage_num
; stNum
>= 0 ; stNum
--) {
874 pipelineStage
[stNum
]->squashDueToMemStall(squash_seq_num
, tid
);
879 InOrderCPU::scheduleCpuEvent(CPUEventType c_event
, Fault fault
,
880 ThreadID tid
, DynInstPtr inst
,
881 unsigned delay
, CPUEventPri event_pri
)
883 CPUEvent
*cpu_event
= new CPUEvent(this, c_event
, fault
, tid
, inst
,
886 Tick sked_tick
= nextCycle(curTick() + ticks(delay
));
888 DPRINTF(InOrderCPU
, "Scheduling CPU Event (%s) for cycle %i, [tid:%i].\n",
889 eventNames
[c_event
], curTick() + delay
, tid
);
890 schedule(cpu_event
, sked_tick
);
892 cpu_event
->process();
893 cpuEventRemoveList
.push(cpu_event
);
896 // Broadcast event to the Resource Pool
897 // Need to reset tid just in case this is a dummy instruction
899 resPool
->scheduleEvent(c_event
, inst
, 0, 0, tid
);
903 InOrderCPU::isThreadActive(ThreadID tid
)
905 list
<ThreadID
>::iterator isActive
=
906 std::find(activeThreads
.begin(), activeThreads
.end(), tid
);
908 return (isActive
!= activeThreads
.end());
912 InOrderCPU::isThreadReady(ThreadID tid
)
914 list
<ThreadID
>::iterator isReady
=
915 std::find(readyThreads
.begin(), readyThreads
.end(), tid
);
917 return (isReady
!= readyThreads
.end());
921 InOrderCPU::isThreadSuspended(ThreadID tid
)
923 list
<ThreadID
>::iterator isSuspended
=
924 std::find(suspendedThreads
.begin(), suspendedThreads
.end(), tid
);
926 return (isSuspended
!= suspendedThreads
.end());
930 InOrderCPU::activateNextReadyThread()
932 if (readyThreads
.size() >= 1) {
933 ThreadID ready_tid
= readyThreads
.front();
935 // Activate in Pipeline
936 activateThread(ready_tid
);
938 // Activate in Resource Pool
939 resPool
->activateThread(ready_tid
);
941 list
<ThreadID
>::iterator ready_it
=
942 std::find(readyThreads
.begin(), readyThreads
.end(), ready_tid
);
943 readyThreads
.erase(ready_it
);
946 "Attempting to activate new thread, but No Ready Threads to"
949 "Unable to switch to next active thread.\n");
954 InOrderCPU::activateThread(ThreadID tid
)
956 if (isThreadSuspended(tid
)) {
958 "Removing [tid:%i] from suspended threads list.\n", tid
);
960 list
<ThreadID
>::iterator susp_it
=
961 std::find(suspendedThreads
.begin(), suspendedThreads
.end(),
963 suspendedThreads
.erase(susp_it
);
966 if (threadModel
== SwitchOnCacheMiss
&&
967 numActiveThreads() == 1) {
969 "Ignoring activation of [tid:%i], since [tid:%i] is "
970 "already running.\n", tid
, activeThreadId());
972 DPRINTF(InOrderCPU
,"Placing [tid:%i] on ready threads list\n",
975 readyThreads
.push_back(tid
);
977 } else if (!isThreadActive(tid
)) {
979 "Adding [tid:%i] to active threads list.\n", tid
);
980 activeThreads
.push_back(tid
);
982 activateThreadInPipeline(tid
);
984 thread
[tid
]->lastActivate
= curTick();
986 tcBase(tid
)->setStatus(ThreadContext::Active
);
995 InOrderCPU::activateThreadInPipeline(ThreadID tid
)
997 for (int stNum
=0; stNum
< NumStages
; stNum
++) {
998 pipelineStage
[stNum
]->activateThread(tid
);
1003 InOrderCPU::deactivateContext(ThreadID tid
, int delay
)
1005 DPRINTF(InOrderCPU
,"[tid:%i]: Deactivating ...\n", tid
);
1007 scheduleCpuEvent(DeactivateThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1009 // Be sure to signal that there's some activity so the CPU doesn't
1010 // deschedule itself.
1011 activityRec
.activity();
1017 InOrderCPU::deactivateThread(ThreadID tid
)
1019 DPRINTF(InOrderCPU
, "[tid:%i]: Calling deactivate thread.\n", tid
);
1021 if (isThreadActive(tid
)) {
1022 DPRINTF(InOrderCPU
,"[tid:%i]: Removing from active threads list\n",
1024 list
<ThreadID
>::iterator thread_it
=
1025 std::find(activeThreads
.begin(), activeThreads
.end(), tid
);
1027 removePipelineStalls(*thread_it
);
1029 activeThreads
.erase(thread_it
);
1031 // Ideally, this should be triggered from the
1032 // suspendContext/Thread functions
1033 tcBase(tid
)->setStatus(ThreadContext::Suspended
);
1036 assert(!isThreadActive(tid
));
1040 InOrderCPU::removePipelineStalls(ThreadID tid
)
1042 DPRINTF(InOrderCPU
,"[tid:%i]: Removing all pipeline stalls\n",
1045 for (int stNum
= 0; stNum
< NumStages
; stNum
++) {
1046 pipelineStage
[stNum
]->removeStalls(tid
);
1052 InOrderCPU::updateThreadPriority()
1054 if (activeThreads
.size() > 1)
1056 //DEFAULT TO ROUND ROBIN SCHEME
1057 //e.g. Move highest priority to end of thread list
1058 list
<ThreadID
>::iterator list_begin
= activeThreads
.begin();
1059 list
<ThreadID
>::iterator list_end
= activeThreads
.end();
1061 unsigned high_thread
= *list_begin
;
1063 activeThreads
.erase(list_begin
);
1065 activeThreads
.push_back(high_thread
);
1070 InOrderCPU::tickThreadStats()
1072 /** Keep track of cycles that each thread is active */
1073 list
<ThreadID
>::iterator thread_it
= activeThreads
.begin();
1074 while (thread_it
!= activeThreads
.end()) {
1075 threadCycles
[*thread_it
]++;
1079 // Keep track of cycles where SMT is active
1080 if (activeThreads
.size() > 1) {
1086 InOrderCPU::activateContext(ThreadID tid
, int delay
)
1088 DPRINTF(InOrderCPU
,"[tid:%i]: Activating ...\n", tid
);
1091 scheduleCpuEvent(ActivateThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1093 // Be sure to signal that there's some activity so the CPU doesn't
1094 // deschedule itself.
1095 activityRec
.activity();
1101 InOrderCPU::activateNextReadyContext(int delay
)
1103 DPRINTF(InOrderCPU
,"Activating next ready thread\n");
1105 scheduleCpuEvent(ActivateNextReadyThread
, NoFault
, 0/*tid*/, dummyInst
[0],
1106 delay
, ActivateNextReadyThread_Pri
);
1108 // Be sure to signal that there's some activity so the CPU doesn't
1109 // deschedule itself.
1110 activityRec
.activity();
1116 InOrderCPU::haltContext(ThreadID tid
, int delay
)
1118 DPRINTF(InOrderCPU
, "[tid:%i]: Calling Halt Context...\n", tid
);
1120 scheduleCpuEvent(HaltThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1122 activityRec
.activity();
1126 InOrderCPU::haltThread(ThreadID tid
)
1128 DPRINTF(InOrderCPU
, "[tid:%i]: Placing on Halted Threads List...\n", tid
);
1129 deactivateThread(tid
);
1130 squashThreadInPipeline(tid
);
1131 haltedThreads
.push_back(tid
);
1133 tcBase(tid
)->setStatus(ThreadContext::Halted
);
1135 if (threadModel
== SwitchOnCacheMiss
) {
1136 activateNextReadyContext();
1141 InOrderCPU::suspendContext(ThreadID tid
, int delay
)
1143 scheduleCpuEvent(SuspendThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1147 InOrderCPU::suspendThread(ThreadID tid
)
1149 DPRINTF(InOrderCPU
, "[tid:%i]: Placing on Suspended Threads List...\n",
1151 deactivateThread(tid
);
1152 suspendedThreads
.push_back(tid
);
1153 thread
[tid
]->lastSuspend
= curTick();
1155 tcBase(tid
)->setStatus(ThreadContext::Suspended
);
1159 InOrderCPU::squashThreadInPipeline(ThreadID tid
)
1161 //Squash all instructions in each stage
1162 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
1163 pipelineStage
[stNum
]->squash(0 /*seq_num*/, tid
);
1168 InOrderCPU::getPipeStage(int stage_num
)
1170 return pipelineStage
[stage_num
];
1175 InOrderCPU::flattenRegIdx(RegIndex reg_idx
, RegType
®_type
, ThreadID tid
)
1177 if (reg_idx
< FP_Base_DepTag
) {
1179 return isa
[tid
].flattenIntIndex(reg_idx
);
1180 } else if (reg_idx
< Ctrl_Base_DepTag
) {
1181 reg_type
= FloatType
;
1182 reg_idx
-= FP_Base_DepTag
;
1183 return isa
[tid
].flattenFloatIndex(reg_idx
);
1185 reg_type
= MiscType
;
1186 return reg_idx
- TheISA::Ctrl_Base_DepTag
;
1191 InOrderCPU::readIntReg(RegIndex reg_idx
, ThreadID tid
)
1193 DPRINTF(IntRegs
, "[tid:%i]: Reading Int. Reg %i as %x\n",
1194 tid
, reg_idx
, intRegs
[tid
][reg_idx
]);
1196 return intRegs
[tid
][reg_idx
];
1200 InOrderCPU::readFloatReg(RegIndex reg_idx
, ThreadID tid
)
1202 DPRINTF(FloatRegs
, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
1203 tid
, reg_idx
, floatRegs
.i
[tid
][reg_idx
], floatRegs
.f
[tid
][reg_idx
]);
1205 return floatRegs
.f
[tid
][reg_idx
];
1209 InOrderCPU::readFloatRegBits(RegIndex reg_idx
, ThreadID tid
)
1211 DPRINTF(FloatRegs
, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
1212 tid
, reg_idx
, floatRegs
.i
[tid
][reg_idx
], floatRegs
.f
[tid
][reg_idx
]);
1214 return floatRegs
.i
[tid
][reg_idx
];
1218 InOrderCPU::setIntReg(RegIndex reg_idx
, uint64_t val
, ThreadID tid
)
1220 if (reg_idx
== TheISA::ZeroReg
) {
1221 DPRINTF(IntRegs
, "[tid:%i]: Ignoring Setting of ISA-ZeroReg "
1222 "(Int. Reg %i) to %x\n", tid
, reg_idx
, val
);
1225 DPRINTF(IntRegs
, "[tid:%i]: Setting Int. Reg %i to %x\n",
1228 intRegs
[tid
][reg_idx
] = val
;
1234 InOrderCPU::setFloatReg(RegIndex reg_idx
, FloatReg val
, ThreadID tid
)
1236 floatRegs
.f
[tid
][reg_idx
] = val
;
1237 DPRINTF(FloatRegs
, "[tid:%i]: Setting Float. Reg %i bits to "
1240 floatRegs
.i
[tid
][reg_idx
],
1241 floatRegs
.f
[tid
][reg_idx
]);
1246 InOrderCPU::setFloatRegBits(RegIndex reg_idx
, FloatRegBits val
, ThreadID tid
)
1248 floatRegs
.i
[tid
][reg_idx
] = val
;
1249 DPRINTF(FloatRegs
, "[tid:%i]: Setting Float. Reg %i bits to "
1252 floatRegs
.i
[tid
][reg_idx
],
1253 floatRegs
.f
[tid
][reg_idx
]);
1257 InOrderCPU::readRegOtherThread(unsigned reg_idx
, ThreadID tid
)
1259 // If Default value is set, then retrieve target thread
1260 if (tid
== InvalidThreadID
) {
1261 tid
= TheISA::getTargetThread(tcBase(tid
));
1264 if (reg_idx
< FP_Base_DepTag
) {
1265 // Integer Register File
1266 return readIntReg(reg_idx
, tid
);
1267 } else if (reg_idx
< Ctrl_Base_DepTag
) {
1268 // Float Register File
1269 reg_idx
-= FP_Base_DepTag
;
1270 return readFloatRegBits(reg_idx
, tid
);
1272 reg_idx
-= Ctrl_Base_DepTag
;
1273 return readMiscReg(reg_idx
, tid
); // Misc. Register File
1277 InOrderCPU::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
,
1280 // If Default value is set, then retrieve target thread
1281 if (tid
== InvalidThreadID
) {
1282 tid
= TheISA::getTargetThread(tcBase(tid
));
1285 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
1286 setIntReg(reg_idx
, val
, tid
);
1287 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
1288 reg_idx
-= FP_Base_DepTag
;
1289 setFloatRegBits(reg_idx
, val
, tid
);
1291 reg_idx
-= Ctrl_Base_DepTag
;
1292 setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
1297 InOrderCPU::readMiscRegNoEffect(int misc_reg
, ThreadID tid
)
1299 return isa
[tid
].readMiscRegNoEffect(misc_reg
);
1303 InOrderCPU::readMiscReg(int misc_reg
, ThreadID tid
)
1305 DPRINTF(InOrderCPU
, "MiscReg: %i\n", misc_reg
);
1306 DPRINTF(InOrderCPU
, "tid: %i\n", tid
);
1307 DPRINTF(InOrderCPU
, "tcBase: %x\n", tcBase(tid
));
1308 DPRINTF(InOrderCPU
, "isa-tid: %x\n", &isa
[tid
]);
1310 return isa
[tid
].readMiscReg(misc_reg
, tcBase(tid
));
1314 InOrderCPU::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
, ThreadID tid
)
1316 isa
[tid
].setMiscRegNoEffect(misc_reg
, val
);
1320 InOrderCPU::setMiscReg(int misc_reg
, const MiscReg
&val
, ThreadID tid
)
1322 isa
[tid
].setMiscReg(misc_reg
, val
, tcBase(tid
));
1327 InOrderCPU::addInst(DynInstPtr inst
)
1329 ThreadID tid
= inst
->readTid();
1331 instList
[tid
].push_back(inst
);
1333 return --(instList
[tid
].end());
1337 InOrderCPU::findInst(InstSeqNum seq_num
, ThreadID tid
)
1339 ListIt it
= instList
[tid
].begin();
1340 ListIt end
= instList
[tid
].end();
1343 if ((*it
)->seqNum
== seq_num
)
1345 else if ((*it
)->seqNum
> seq_num
)
1351 return instList
[tid
].end();
1355 InOrderCPU::updateContextSwitchStats()
1357 // Set Average Stat Here, then reset to 0
1358 instsPerCtxtSwitch
= instsPerSwitch
;
1364 InOrderCPU::instDone(DynInstPtr inst
, ThreadID tid
)
1366 // Set the nextPC to be fetched if this is the last instruction
1369 // This contributes to the precise state of the CPU
1370 // which can be used when restoring a thread to the CPU after after any
1371 // type of context switching activity (fork, exception, etc.)
1372 TheISA::PCState comm_pc
= inst
->pcState();
1373 lastCommittedPC
[tid
] = comm_pc
;
1374 TheISA::advancePC(comm_pc
, inst
->staticInst
);
1375 pcState(comm_pc
, tid
);
1377 //@todo: may be unnecessary with new-ISA-specific branch handling code
1378 if (inst
->isControl()) {
1379 thread
[tid
]->lastGradIsBranch
= true;
1380 thread
[tid
]->lastBranchPC
= inst
->pcState();
1381 TheISA::advancePC(thread
[tid
]->lastBranchPC
, inst
->staticInst
);
1383 thread
[tid
]->lastGradIsBranch
= false;
1387 // Finalize Trace Data For Instruction
1388 if (inst
->traceData
) {
1389 //inst->traceData->setCycle(curTick());
1390 inst
->traceData
->setFetchSeq(inst
->seqNum
);
1391 //inst->traceData->setCPSeq(cpu->tcBase(tid)->numInst);
1392 inst
->traceData
->dump();
1393 delete inst
->traceData
;
1394 inst
->traceData
= NULL
;
1397 // Increment active thread's instruction count
1400 // Increment thread-state's instruction count
1401 thread
[tid
]->numInst
++;
1403 // Increment thread-state's instruction stats
1404 thread
[tid
]->numInsts
++;
1406 // Count committed insts per thread stats
1407 committedInsts
[tid
]++;
1409 // Count total insts committed stat
1410 totalCommittedInsts
++;
1412 // Count SMT-committed insts per thread stat
1413 if (numActiveThreads() > 1) {
1414 smtCommittedInsts
[tid
]++;
1417 // Instruction-Mix Stats
1418 if (inst
->isLoad()) {
1420 } else if (inst
->isStore()) {
1422 } else if (inst
->isControl()) {
1424 } else if (inst
->isNop()) {
1426 } else if (inst
->isNonSpeculative()) {
1428 } else if (inst
->isInteger()) {
1430 } else if (inst
->isFloating()) {
1434 // Check for instruction-count-based events.
1435 comInstEventQueue
[tid
]->serviceEvents(thread
[tid
]->numInst
);
1437 // Finally, remove instruction from CPU
1441 // currently unused function, but substitute repetitive code w/this function
1444 InOrderCPU::addToRemoveList(DynInstPtr inst
)
1446 removeInstsThisCycle
= true;
1447 if (!inst
->isRemoveList()) {
1448 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1449 "[sn:%lli] to remove list\n",
1450 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1451 inst
->setRemoveList();
1452 removeList
.push(inst
->getInstListIt());
1454 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i] PC %s "
1455 "[sn:%lli], already remove list\n",
1456 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1462 InOrderCPU::removeInst(DynInstPtr inst
)
1464 DPRINTF(InOrderCPU
, "Removing graduated instruction [tid:%i] PC %s "
1466 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1468 removeInstsThisCycle
= true;
1470 // Remove the instruction.
1471 if (!inst
->isRemoveList()) {
1472 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1473 "[sn:%lli] to remove list\n",
1474 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1475 inst
->setRemoveList();
1476 removeList
.push(inst
->getInstListIt());
1478 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i] PC %s "
1479 "[sn:%lli], already on remove list\n",
1480 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1486 InOrderCPU::removeInstsUntil(const InstSeqNum
&seq_num
, ThreadID tid
)
1488 //assert(!instList[tid].empty());
1490 removeInstsThisCycle
= true;
1492 ListIt inst_iter
= instList
[tid
].end();
1496 DPRINTF(InOrderCPU
, "Squashing instructions from CPU instruction "
1497 "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
1498 tid
, seq_num
, (*inst_iter
)->seqNum
);
1500 while ((*inst_iter
)->seqNum
> seq_num
) {
1502 bool break_loop
= (inst_iter
== instList
[tid
].begin());
1504 squashInstIt(inst_iter
, tid
);
1515 InOrderCPU::squashInstIt(const ListIt inst_it
, ThreadID tid
)
1517 DynInstPtr inst
= (*inst_it
);
1518 if (inst
->threadNumber
== tid
) {
1519 DPRINTF(InOrderCPU
, "Squashing instruction, "
1520 "[tid:%i] [sn:%lli] PC %s\n",
1525 inst
->setSquashed();
1526 archRegDepMap
[tid
].remove(inst
);
1528 if (!inst
->isRemoveList()) {
1529 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1530 "[sn:%lli] to remove list\n",
1531 inst
->threadNumber
, inst
->pcState(),
1533 inst
->setRemoveList();
1534 removeList
.push(inst_it
);
1536 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i]"
1537 " PC %s [sn:%lli], already on remove list\n",
1538 inst
->threadNumber
, inst
->pcState(),
1548 InOrderCPU::cleanUpRemovedInsts()
1550 while (!removeList
.empty()) {
1551 DPRINTF(InOrderCPU
, "Removing instruction, "
1552 "[tid:%i] [sn:%lli] PC %s\n",
1553 (*removeList
.front())->threadNumber
,
1554 (*removeList
.front())->seqNum
,
1555 (*removeList
.front())->pcState());
1557 DynInstPtr inst
= *removeList
.front();
1558 ThreadID tid
= inst
->threadNumber
;
1560 // Remove From Register Dependency Map, If Necessary
1561 // archRegDepMap[tid].remove(inst);
1563 // Clear if Non-Speculative
1564 if (inst
->staticInst
&&
1565 inst
->seqNum
== nonSpecSeqNum
[tid
] &&
1566 nonSpecInstActive
[tid
] == true) {
1567 nonSpecInstActive
[tid
] = false;
1570 inst
->onInstList
= false;
1572 instList
[tid
].erase(removeList
.front());
1577 removeInstsThisCycle
= false;
1581 InOrderCPU::cleanUpRemovedEvents()
1583 while (!cpuEventRemoveList
.empty()) {
1584 Event
*cpu_event
= cpuEventRemoveList
.front();
1585 cpuEventRemoveList
.pop();
1592 InOrderCPU::dumpInsts()
1596 ListIt inst_list_it
= instList
[0].begin();
1598 cprintf("Dumping Instruction List\n");
1600 while (inst_list_it
!= instList
[0].end()) {
1601 cprintf("Instruction:%i\nPC:%s\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
1603 num
, (*inst_list_it
)->pcState(),
1604 (*inst_list_it
)->threadNumber
,
1605 (*inst_list_it
)->seqNum
, (*inst_list_it
)->isIssued(),
1606 (*inst_list_it
)->isSquashed());
1613 InOrderCPU::wakeCPU()
1615 if (/*activityRec.active() || */tickEvent
.scheduled()) {
1616 DPRINTF(Activity
, "CPU already running.\n");
1620 DPRINTF(Activity
, "Waking up CPU\n");
1622 Tick extra_cycles
= tickToCycles((curTick() - 1) - lastRunningCycle
);
1624 idleCycles
+= extra_cycles
;
1625 for (int stage_num
= 0; stage_num
< NumStages
; stage_num
++) {
1626 pipelineStage
[stage_num
]->idleCycles
+= extra_cycles
;
1629 numCycles
+= extra_cycles
;
1631 schedule(&tickEvent
, nextCycle(curTick()));
1635 // Lots of copied full system code...place into BaseCPU class?
1637 InOrderCPU::wakeup()
1639 if (thread
[0]->status() != ThreadContext::Suspended
)
1644 DPRINTF(Quiesce
, "Suspended Processor woken\n");
1645 threadContexts
[0]->activate();
1651 InOrderCPU::syscallContext(Fault fault
, ThreadID tid
, DynInstPtr inst
, int delay
)
1653 scheduleCpuEvent(Syscall
, fault
, tid
, inst
, delay
, Syscall_Pri
);
1657 InOrderCPU::syscall(int64_t callnum
, ThreadID tid
)
1659 DPRINTF(InOrderCPU
, "[tid:%i] Executing syscall().\n\n", tid
);
1661 DPRINTF(Activity
,"Activity: syscall() called.\n");
1663 // Temporarily increase this by one to account for the syscall
1665 ++(this->thread
[tid
]->funcExeInst
);
1667 // Execute the actual syscall.
1668 this->thread
[tid
]->syscall(callnum
);
1670 // Decrease funcExeInst by one as the normal commit will handle
1672 --(this->thread
[tid
]->funcExeInst
);
1674 // Clear Non-Speculative Block Variable
1675 nonSpecInstActive
[tid
] = false;
1680 InOrderCPU::getITBPtr()
1682 CacheUnit
*itb_res
=
1683 dynamic_cast<CacheUnit
*>(resPool
->getResource(fetchPortIdx
));
1684 return itb_res
->tlb();
1689 InOrderCPU::getDTBPtr()
1691 CacheUnit
*dtb_res
=
1692 dynamic_cast<CacheUnit
*>(resPool
->getResource(dataPortIdx
));
1693 return dtb_res
->tlb();
1697 InOrderCPU::read(DynInstPtr inst
, Addr addr
,
1698 uint8_t *data
, unsigned size
, unsigned flags
)
1700 //@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
1701 // you want to run w/out caches?
1702 CacheUnit
*cache_res
=
1703 dynamic_cast<CacheUnit
*>(resPool
->getResource(dataPortIdx
));
1705 return cache_res
->read(inst
, addr
, data
, size
, flags
);
1709 InOrderCPU::write(DynInstPtr inst
, uint8_t *data
, unsigned size
,
1710 Addr addr
, unsigned flags
, uint64_t *write_res
)
1712 //@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
1713 // you want to run w/out caches?
1714 CacheUnit
*cache_res
=
1715 dynamic_cast<CacheUnit
*>(resPool
->getResource(dataPortIdx
));
1716 return cache_res
->write(inst
, data
, size
, addr
, flags
, write_res
);