2 * Copyright (c) 2012 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2007 MIPS Technologies, Inc.
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Authors: Korey Sewell
46 #include "arch/utility.hh"
47 #include "base/bigint.hh"
48 #include "config/the_isa.hh"
49 #include "cpu/inorder/resources/cache_unit.hh"
50 #include "cpu/inorder/resources/resource_list.hh"
51 #include "cpu/inorder/cpu.hh"
52 #include "cpu/inorder/first_stage.hh"
53 #include "cpu/inorder/inorder_dyn_inst.hh"
54 #include "cpu/inorder/pipeline_traits.hh"
55 #include "cpu/inorder/resource_pool.hh"
56 #include "cpu/inorder/thread_context.hh"
57 #include "cpu/inorder/thread_state.hh"
58 #include "cpu/activity.hh"
59 #include "cpu/base.hh"
60 #include "cpu/exetrace.hh"
61 #include "cpu/quiesce_event.hh"
62 #include "cpu/simple_thread.hh"
63 #include "cpu/thread_context.hh"
64 #include "debug/Activity.hh"
65 #include "debug/InOrderCPU.hh"
66 #include "debug/InOrderCachePort.hh"
67 #include "debug/Interrupt.hh"
68 #include "debug/Quiesce.hh"
69 #include "debug/RefCount.hh"
70 #include "debug/SkedCache.hh"
71 #include "params/InOrderCPU.hh"
72 #include "sim/full_system.hh"
73 #include "sim/process.hh"
74 #include "sim/stat_control.hh"
75 #include "sim/system.hh"
77 #if THE_ISA == ALPHA_ISA
78 #include "arch/alpha/osfpal.hh"
82 using namespace TheISA
;
83 using namespace ThePipeline
;
85 InOrderCPU::CachePort::CachePort(CacheUnit
*_cacheUnit
) :
86 CpuPort(_cacheUnit
->name() + "-cache-port", _cacheUnit
->cpu
),
91 InOrderCPU::CachePort::recvTiming(Packet
*pkt
)
94 DPRINTF(InOrderCachePort
, "Got error packet back for address: %x\n",
96 else if (pkt
->isResponse())
97 cacheUnit
->processCacheCompletion(pkt
);
99 //@note: depending on consistency model, update here
100 DPRINTF(InOrderCachePort
, "Received snoop pkt %x,Ignoring\n",
108 InOrderCPU::CachePort::recvRetry()
110 cacheUnit
->recvRetry();
113 InOrderCPU::TickEvent::TickEvent(InOrderCPU
*c
)
114 : Event(CPU_Tick_Pri
), cpu(c
)
119 InOrderCPU::TickEvent::process()
126 InOrderCPU::TickEvent::description() const
128 return "InOrderCPU tick event";
131 InOrderCPU::CPUEvent::CPUEvent(InOrderCPU
*_cpu
, CPUEventType e_type
,
132 Fault fault
, ThreadID _tid
, DynInstPtr inst
,
133 CPUEventPri event_pri
)
134 : Event(event_pri
), cpu(_cpu
)
136 setEvent(e_type
, fault
, _tid
, inst
);
140 std::string
InOrderCPU::eventNames
[NumCPUEvents
] =
143 "ActivateNextReadyThread",
149 "SquashFromMemStall",
154 InOrderCPU::CPUEvent::process()
156 switch (cpuEventType
)
159 cpu
->activateThread(tid
);
160 cpu
->resPool
->activateThread(tid
);
163 case ActivateNextReadyThread
:
164 cpu
->activateNextReadyThread();
167 case DeactivateThread
:
168 cpu
->deactivateThread(tid
);
169 cpu
->resPool
->deactivateThread(tid
);
173 cpu
->haltThread(tid
);
174 cpu
->resPool
->deactivateThread(tid
);
178 cpu
->suspendThread(tid
);
179 cpu
->resPool
->suspendThread(tid
);
182 case SquashFromMemStall
:
183 cpu
->squashDueToMemStall(inst
->squashingStage
, inst
->seqNum
, tid
);
184 cpu
->resPool
->squashDueToMemStall(inst
, inst
->squashingStage
,
189 DPRINTF(InOrderCPU
, "Trapping CPU\n");
190 cpu
->trap(fault
, tid
, inst
);
191 cpu
->resPool
->trap(fault
, tid
, inst
);
192 cpu
->trapPending
[tid
] = false;
196 cpu
->syscall(inst
->syscallNum
, tid
);
197 cpu
->resPool
->trap(fault
, tid
, inst
);
201 fatal("Unrecognized Event Type %s", eventNames
[cpuEventType
]);
204 cpu
->cpuEventRemoveList
.push(this);
210 InOrderCPU::CPUEvent::description() const
212 return "InOrderCPU event";
216 InOrderCPU::CPUEvent::scheduleEvent(int delay
)
218 assert(!scheduled() || squashed());
219 cpu
->reschedule(this, cpu
->nextCycle(curTick() + cpu
->ticks(delay
)), true);
223 InOrderCPU::CPUEvent::unscheduleEvent()
229 InOrderCPU::InOrderCPU(Params
*params
)
231 cpu_id(params
->cpu_id
),
235 stageWidth(params
->stageWidth
),
236 resPool(new ResourcePool(this, params
)),
238 dataPort(resPool
->getDataUnit()),
239 instPort(resPool
->getInstUnit()),
240 removeInstsThisCycle(false),
241 activityRec(params
->name
, NumStages
, 10, params
->activity
),
242 system(params
->system
),
248 deferRegistration(false/*params->deferRegistration*/),
249 stageTracing(params
->stageTracing
),
255 // Resize for Multithreading CPUs
256 thread
.resize(numThreads
);
258 ThreadID active_threads
= params
->workload
.size();
262 active_threads
= params
->workload
.size();
264 if (active_threads
> MaxThreads
) {
265 panic("Workload Size too large. Increase the 'MaxThreads'"
266 "in your InOrder implementation or "
267 "edit your workload size.");
271 if (active_threads
> 1) {
272 threadModel
= (InOrderCPU::ThreadModel
) params
->threadModel
;
274 if (threadModel
== SMT
) {
275 DPRINTF(InOrderCPU
, "Setting Thread Model to SMT.\n");
276 } else if (threadModel
== SwitchOnCacheMiss
) {
277 DPRINTF(InOrderCPU
, "Setting Thread Model to "
278 "Switch On Cache Miss\n");
282 threadModel
= Single
;
286 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
) {
288 lastCommittedPC
[tid
].set(0);
291 // SMT is not supported in FS mode yet.
292 assert(numThreads
== 1);
293 thread
[tid
] = new Thread(this, 0, NULL
);
295 if (tid
< (ThreadID
)params
->workload
.size()) {
296 DPRINTF(InOrderCPU
, "Workload[%i] process is %#x\n",
297 tid
, params
->workload
[tid
]->prog_fname
);
299 new Thread(this, tid
, params
->workload
[tid
]);
301 //Allocate Empty thread so M5 can use later
302 //when scheduling threads to CPU
303 Process
* dummy_proc
= params
->workload
[0];
304 thread
[tid
] = new Thread(this, tid
, dummy_proc
);
307 // Eventually set this with parameters...
311 // Setup the TC that will serve as the interface to the threads/CPU.
312 InOrderThreadContext
*tc
= new InOrderThreadContext
;
314 tc
->thread
= thread
[tid
];
316 // Setup quiesce event.
317 this->thread
[tid
]->quiesceEvent
= new EndQuiesceEvent(tc
);
319 // Give the thread the TC.
320 thread
[tid
]->tc
= tc
;
321 thread
[tid
]->setFuncExeInst(0);
322 globalSeqNum
[tid
] = 1;
324 // Add the TC to the CPU's list of TC's.
325 this->threadContexts
.push_back(tc
);
328 // Initialize TimeBuffer Stage Queues
329 for (int stNum
=0; stNum
< NumStages
- 1; stNum
++) {
330 stageQueue
[stNum
] = new StageQueue(NumStages
, NumStages
);
331 stageQueue
[stNum
]->id(stNum
);
335 // Set Up Pipeline Stages
336 for (int stNum
=0; stNum
< NumStages
; stNum
++) {
338 pipelineStage
[stNum
] = new FirstStage(params
, stNum
);
340 pipelineStage
[stNum
] = new PipelineStage(params
, stNum
);
342 pipelineStage
[stNum
]->setCPU(this);
343 pipelineStage
[stNum
]->setActiveThreads(&activeThreads
);
344 pipelineStage
[stNum
]->setTimeBuffer(&timeBuffer
);
346 // Take Care of 1st/Nth stages
348 pipelineStage
[stNum
]->setPrevStageQueue(stageQueue
[stNum
- 1]);
349 if (stNum
< NumStages
- 1)
350 pipelineStage
[stNum
]->setNextStageQueue(stageQueue
[stNum
]);
353 // Initialize thread specific variables
354 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
355 archRegDepMap
[tid
].setCPU(this);
357 nonSpecInstActive
[tid
] = false;
358 nonSpecSeqNum
[tid
] = 0;
360 squashSeqNum
[tid
] = MaxAddr
;
361 lastSquashCycle
[tid
] = 0;
363 memset(intRegs
[tid
], 0, sizeof(intRegs
[tid
]));
364 memset(floatRegs
.i
[tid
], 0, sizeof(floatRegs
.i
[tid
]));
367 // Define dummy instructions and resource requests to be used.
368 dummyInst
[tid
] = new InOrderDynInst(this,
374 dummyReq
[tid
] = new ResourceRequest(resPool
->getResource(0));
378 // Use this dummy inst to force squashing behind every instruction
380 dummyTrapInst
[tid
] = new InOrderDynInst(this, NULL
, 0, 0, 0);
381 dummyTrapInst
[tid
]->seqNum
= 0;
382 dummyTrapInst
[tid
]->squashSeqNum
= 0;
383 dummyTrapInst
[tid
]->setTid(tid
);
386 trapPending
[tid
] = false;
390 // InOrderCPU always requires an interrupt controller.
391 if (!params
->defer_registration
&& !interrupts
) {
392 fatal("InOrderCPU %s has no interrupt controller.\n"
393 "Ensure createInterruptController() is called.\n", name());
396 dummyReqInst
= new InOrderDynInst(this, NULL
, 0, 0, 0);
397 dummyReqInst
->setSquashed();
398 dummyReqInst
->resetInstCount();
400 dummyBufferInst
= new InOrderDynInst(this, NULL
, 0, 0, 0);
401 dummyBufferInst
->setSquashed();
402 dummyBufferInst
->resetInstCount();
404 endOfSkedIt
= skedCache
.end();
405 frontEndSked
= createFrontEndSked();
406 faultSked
= createFaultSked();
408 lastRunningCycle
= curTick();
413 // Schedule First Tick Event, CPU will reschedule itself from here on out.
414 scheduleTickEvent(0);
417 InOrderCPU::~InOrderCPU()
421 SkedCacheIt sked_it
= skedCache
.begin();
422 SkedCacheIt sked_end
= skedCache
.end();
424 while (sked_it
!= sked_end
) {
425 delete (*sked_it
).second
;
431 m5::hash_map
<InOrderCPU::SkedID
, ThePipeline::RSkedPtr
> InOrderCPU::skedCache
;
434 InOrderCPU::createFrontEndSked()
436 RSkedPtr res_sked
= new ResourceSked();
438 StageScheduler
F(res_sked
, stage_num
++);
439 StageScheduler
D(res_sked
, stage_num
++);
442 F
.needs(FetchSeq
, FetchSeqUnit::AssignNextPC
);
443 F
.needs(ICache
, FetchUnit::InitiateFetch
);
446 D
.needs(ICache
, FetchUnit::CompleteFetch
);
447 D
.needs(Decode
, DecodeUnit::DecodeInst
);
448 D
.needs(BPred
, BranchPredictor::PredictBranch
);
449 D
.needs(FetchSeq
, FetchSeqUnit::UpdateTargetPC
);
452 DPRINTF(SkedCache
, "Resource Sked created for instruction Front End\n");
458 InOrderCPU::createFaultSked()
460 RSkedPtr res_sked
= new ResourceSked();
461 StageScheduler
W(res_sked
, NumStages
- 1);
462 W
.needs(Grad
, GraduationUnit::CheckFault
);
463 DPRINTF(SkedCache
, "Resource Sked created for instruction Faults\n");
468 InOrderCPU::createBackEndSked(DynInstPtr inst
)
470 RSkedPtr res_sked
= lookupSked(inst
);
471 if (res_sked
!= NULL
) {
472 DPRINTF(SkedCache
, "Found %s in sked cache.\n",
476 res_sked
= new ResourceSked();
479 int stage_num
= ThePipeline::BackEndStartStage
;
480 StageScheduler
X(res_sked
, stage_num
++);
481 StageScheduler
M(res_sked
, stage_num
++);
482 StageScheduler
W(res_sked
, stage_num
++);
484 if (!inst
->staticInst
) {
485 warn_once("Static Instruction Object Not Set. Can't Create"
486 " Back End Schedule");
491 X
.needs(RegManager
, UseDefUnit::MarkDestRegs
);
492 for (int idx
=0; idx
< inst
->numSrcRegs(); idx
++) {
493 if (!idx
|| !inst
->isStore()) {
494 X
.needs(RegManager
, UseDefUnit::ReadSrcReg
, idx
);
498 //@todo: schedule non-spec insts to operate on this cycle
499 // as long as all previous insts are done
500 if ( inst
->isNonSpeculative() ) {
501 // skip execution of non speculative insts until later
502 } else if ( inst
->isMemRef() ) {
503 if ( inst
->isLoad() ) {
504 X
.needs(AGEN
, AGENUnit::GenerateAddr
);
506 } else if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
507 X
.needs(MDU
, MultDivUnit::StartMultDiv
);
509 X
.needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
513 if (!inst
->isNonSpeculative()) {
514 if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
515 M
.needs(MDU
, MultDivUnit::EndMultDiv
);
518 if ( inst
->isLoad() ) {
519 M
.needs(DCache
, CacheUnit::InitiateReadData
);
521 M
.needs(DCache
, CacheUnit::InitSecondSplitRead
);
522 } else if ( inst
->isStore() ) {
523 for (int i
= 1; i
< inst
->numSrcRegs(); i
++ ) {
524 M
.needs(RegManager
, UseDefUnit::ReadSrcReg
, i
);
526 M
.needs(AGEN
, AGENUnit::GenerateAddr
);
527 M
.needs(DCache
, CacheUnit::InitiateWriteData
);
529 M
.needs(DCache
, CacheUnit::InitSecondSplitWrite
);
534 if (!inst
->isNonSpeculative()) {
535 if ( inst
->isLoad() ) {
536 W
.needs(DCache
, CacheUnit::CompleteReadData
);
538 W
.needs(DCache
, CacheUnit::CompleteSecondSplitRead
);
539 } else if ( inst
->isStore() ) {
540 W
.needs(DCache
, CacheUnit::CompleteWriteData
);
542 W
.needs(DCache
, CacheUnit::CompleteSecondSplitWrite
);
545 // Finally, Execute Speculative Data
546 if (inst
->isMemRef()) {
547 if (inst
->isLoad()) {
548 W
.needs(AGEN
, AGENUnit::GenerateAddr
);
549 W
.needs(DCache
, CacheUnit::InitiateReadData
);
551 W
.needs(DCache
, CacheUnit::InitSecondSplitRead
);
552 W
.needs(DCache
, CacheUnit::CompleteReadData
);
554 W
.needs(DCache
, CacheUnit::CompleteSecondSplitRead
);
555 } else if (inst
->isStore()) {
556 if ( inst
->numSrcRegs() >= 2 ) {
557 W
.needs(RegManager
, UseDefUnit::ReadSrcReg
, 1);
559 W
.needs(AGEN
, AGENUnit::GenerateAddr
);
560 W
.needs(DCache
, CacheUnit::InitiateWriteData
);
562 W
.needs(DCache
, CacheUnit::InitSecondSplitWrite
);
563 W
.needs(DCache
, CacheUnit::CompleteWriteData
);
565 W
.needs(DCache
, CacheUnit::CompleteSecondSplitWrite
);
568 W
.needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
572 W
.needs(Grad
, GraduationUnit::CheckFault
);
574 for (int idx
=0; idx
< inst
->numDestRegs(); idx
++) {
575 W
.needs(RegManager
, UseDefUnit::WriteDestReg
, idx
);
578 if (inst
->isControl())
579 W
.needs(BPred
, BranchPredictor::UpdatePredictor
);
581 W
.needs(Grad
, GraduationUnit::GraduateInst
);
583 // Insert Back Schedule into our cache of
584 // resource schedules
585 addToSkedCache(inst
, res_sked
);
587 DPRINTF(SkedCache
, "Back End Sked Created for instruction: %s (%08p)\n",
588 inst
->instName(), inst
->getMachInst());
595 InOrderCPU::regStats()
597 /* Register the Resource Pool's stats here.*/
600 /* Register for each Pipeline Stage */
601 for (int stage_num
=0; stage_num
< ThePipeline::NumStages
; stage_num
++) {
602 pipelineStage
[stage_num
]->regStats();
605 /* Register any of the InOrderCPU's stats here.*/
607 .name(name() + ".instsPerContextSwitch")
608 .desc("Instructions Committed Per Context Switch")
609 .prereq(instsPerCtxtSwitch
);
612 .name(name() + ".contextSwitches")
613 .desc("Number of context switches");
616 .name(name() + ".comLoads")
617 .desc("Number of Load instructions committed");
620 .name(name() + ".comStores")
621 .desc("Number of Store instructions committed");
624 .name(name() + ".comBranches")
625 .desc("Number of Branches instructions committed");
628 .name(name() + ".comNops")
629 .desc("Number of Nop instructions committed");
632 .name(name() + ".comNonSpec")
633 .desc("Number of Non-Speculative instructions committed");
636 .name(name() + ".comInts")
637 .desc("Number of Integer instructions committed");
640 .name(name() + ".comFloats")
641 .desc("Number of Floating Point instructions committed");
644 .name(name() + ".timesIdled")
645 .desc("Number of times that the entire CPU went into an idle state and"
646 " unscheduled itself")
650 .name(name() + ".idleCycles")
651 .desc("Number of cycles cpu's stages were not processed");
654 .name(name() + ".runCycles")
655 .desc("Number of cycles cpu stages are processed.");
658 .name(name() + ".activity")
659 .desc("Percentage of cycles cpu is active")
661 activity
= (runCycles
/ numCycles
) * 100;
665 .name(name() + ".threadCycles")
666 .desc("Total Number of Cycles A Thread Was Active in CPU (Per-Thread)");
669 .name(name() + ".smtCycles")
670 .desc("Total number of cycles that the CPU was in SMT-mode");
674 .name(name() + ".committedInsts")
675 .desc("Number of Instructions committed (Per-Thread)");
679 .name(name() + ".committedOps")
680 .desc("Number of Ops committed (Per-Thread)");
684 .name(name() + ".smtCommittedInsts")
685 .desc("Number of SMT Instructions committed (Per-Thread)");
688 .name(name() + ".committedInsts_total")
689 .desc("Number of Instructions committed (Total)");
692 .name(name() + ".cpi")
693 .desc("CPI: Cycles Per Instruction (Per-Thread)")
695 cpi
= numCycles
/ committedInsts
;
698 .name(name() + ".smt_cpi")
699 .desc("CPI: Total SMT-CPI")
701 smtCpi
= smtCycles
/ smtCommittedInsts
;
704 .name(name() + ".cpi_total")
705 .desc("CPI: Total CPI of All Threads")
707 totalCpi
= numCycles
/ totalCommittedInsts
;
710 .name(name() + ".ipc")
711 .desc("IPC: Instructions Per Cycle (Per-Thread)")
713 ipc
= committedInsts
/ numCycles
;
716 .name(name() + ".smt_ipc")
717 .desc("IPC: Total SMT-IPC")
719 smtIpc
= smtCommittedInsts
/ smtCycles
;
722 .name(name() + ".ipc_total")
723 .desc("IPC: Total IPC of All Threads")
725 totalIpc
= totalCommittedInsts
/ numCycles
;
734 DPRINTF(InOrderCPU
, "\n\nInOrderCPU: Ticking main, InOrderCPU.\n");
738 checkForInterrupts();
740 bool pipes_idle
= true;
741 //Tick each of the stages
742 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
743 pipelineStage
[stNum
]->tick();
745 pipes_idle
= pipes_idle
&& pipelineStage
[stNum
]->idle
;
753 // Now advance the time buffers one tick
754 timeBuffer
.advance();
755 for (int sqNum
=0; sqNum
< NumStages
- 1; sqNum
++) {
756 stageQueue
[sqNum
]->advance();
758 activityRec
.advance();
760 // Any squashed events, or insts then remove them now
761 cleanUpRemovedEvents();
762 cleanUpRemovedInsts();
764 // Re-schedule CPU for this cycle
765 if (!tickEvent
.scheduled()) {
766 if (_status
== SwitchedOut
) {
768 lastRunningCycle
= curTick();
769 } else if (!activityRec
.active()) {
770 DPRINTF(InOrderCPU
, "sleeping CPU.\n");
771 lastRunningCycle
= curTick();
774 //Tick next_tick = curTick() + cycles(1);
775 //tickEvent.schedule(next_tick);
776 schedule(&tickEvent
, nextCycle(curTick() + 1));
777 DPRINTF(InOrderCPU
, "Scheduled CPU for next tick @ %i.\n",
778 nextCycle(curTick() + 1));
783 updateThreadPriority();
790 if (!deferRegistration
) {
791 registerThreadContexts();
794 // Set inSyscall so that the CPU doesn't squash when initially
795 // setting up registers.
796 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
)
797 thread
[tid
]->inSyscall
= true;
800 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
801 ThreadContext
*src_tc
= threadContexts
[tid
];
802 TheISA::initCPU(src_tc
, src_tc
->contextId());
803 // Initialise the ThreadContext's memory proxies
804 thread
[tid
]->initMemProxies(thread
[tid
]->getTC());
809 for (ThreadID tid
= 0; tid
< numThreads
; ++tid
)
810 thread
[tid
]->inSyscall
= false;
812 // Call Initializiation Routine for Resource Pool
817 InOrderCPU::hwrei(ThreadID tid
)
819 #if THE_ISA == ALPHA_ISA
820 // Need to clear the lock flag upon returning from an interrupt.
821 setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG
, false, tid
);
823 thread
[tid
]->kernelStats
->hwrei();
824 // FIXME: XXX check for interrupts? XXX
832 InOrderCPU::simPalCheck(int palFunc
, ThreadID tid
)
834 #if THE_ISA == ALPHA_ISA
835 if (this->thread
[tid
]->kernelStats
)
836 this->thread
[tid
]->kernelStats
->callpal(palFunc
,
837 this->threadContexts
[tid
]);
842 if (--System::numSystemsRunning
== 0)
843 exitSimLoop("all cpus halted");
848 if (this->system
->breakpoint())
857 InOrderCPU::checkForInterrupts()
859 for (int i
= 0; i
< threadContexts
.size(); i
++) {
860 ThreadContext
*tc
= threadContexts
[i
];
862 if (interrupts
->checkInterrupts(tc
)) {
863 Fault interrupt
= interrupts
->getInterrupt(tc
);
865 if (interrupt
!= NoFault
) {
866 DPRINTF(Interrupt
, "Processing Intterupt for [tid:%i].\n",
869 ThreadID tid
= tc
->threadId();
870 interrupts
->updateIntrInfo(tc
);
872 // Squash from Last Stage in Pipeline
873 unsigned last_stage
= NumStages
- 1;
874 dummyTrapInst
[tid
]->squashingStage
= last_stage
;
875 pipelineStage
[last_stage
]->setupSquash(dummyTrapInst
[tid
],
878 // By default, setupSquash will always squash from stage + 1
879 pipelineStage
[BackEndStartStage
- 1]->setupSquash(dummyTrapInst
[tid
],
882 // Schedule Squash Through-out Resource Pool
883 resPool
->scheduleEvent(
884 (InOrderCPU::CPUEventType
)ResourcePool::SquashAll
,
885 dummyTrapInst
[tid
], 0);
887 // Finally, Setup Trap to happen at end of cycle
888 trapContext(interrupt
, tid
, dummyTrapInst
[tid
]);
895 InOrderCPU::getInterrupts()
897 // Check if there are any outstanding interrupts
898 return interrupts
->getInterrupt(threadContexts
[0]);
902 InOrderCPU::processInterrupts(Fault interrupt
)
904 // Check for interrupts here. For now can copy the code that
905 // exists within isa_fullsys_traits.hh. Also assume that thread 0
906 // is the one that handles the interrupts.
907 // @todo: Possibly consolidate the interrupt checking code.
908 // @todo: Allow other threads to handle interrupts.
910 assert(interrupt
!= NoFault
);
911 interrupts
->updateIntrInfo(threadContexts
[0]);
913 DPRINTF(InOrderCPU
, "Interrupt %s being handled\n", interrupt
->name());
915 // Note: Context ID ok here? Impl. of FS mode needs to revisit this
916 trap(interrupt
, threadContexts
[0]->contextId(), dummyBufferInst
);
920 InOrderCPU::trapContext(Fault fault
, ThreadID tid
, DynInstPtr inst
, int delay
)
922 scheduleCpuEvent(Trap
, fault
, tid
, inst
, delay
);
923 trapPending
[tid
] = true;
927 InOrderCPU::trap(Fault fault
, ThreadID tid
, DynInstPtr inst
)
929 fault
->invoke(tcBase(tid
), inst
->staticInst
);
930 removePipelineStalls(tid
);
934 InOrderCPU::squashFromMemStall(DynInstPtr inst
, ThreadID tid
, int delay
)
936 scheduleCpuEvent(SquashFromMemStall
, NoFault
, tid
, inst
, delay
);
941 InOrderCPU::squashDueToMemStall(int stage_num
, InstSeqNum seq_num
,
944 DPRINTF(InOrderCPU
, "Squashing Pipeline Stages Due to Memory Stall...\n");
946 // Squash all instructions in each stage including
947 // instruction that caused the squash (seq_num - 1)
948 // NOTE: The stage bandwidth needs to be cleared so thats why
949 // the stalling instruction is squashed as well. The stalled
950 // instruction is previously placed in another intermediate buffer
951 // while it's stall is being handled.
952 InstSeqNum squash_seq_num
= seq_num
- 1;
954 for (int stNum
=stage_num
; stNum
>= 0 ; stNum
--) {
955 pipelineStage
[stNum
]->squashDueToMemStall(squash_seq_num
, tid
);
960 InOrderCPU::scheduleCpuEvent(CPUEventType c_event
, Fault fault
,
961 ThreadID tid
, DynInstPtr inst
,
962 unsigned delay
, CPUEventPri event_pri
)
964 CPUEvent
*cpu_event
= new CPUEvent(this, c_event
, fault
, tid
, inst
,
967 Tick sked_tick
= nextCycle(curTick() + ticks(delay
));
969 DPRINTF(InOrderCPU
, "Scheduling CPU Event (%s) for cycle %i, [tid:%i].\n",
970 eventNames
[c_event
], curTick() + delay
, tid
);
971 schedule(cpu_event
, sked_tick
);
973 cpu_event
->process();
974 cpuEventRemoveList
.push(cpu_event
);
977 // Broadcast event to the Resource Pool
978 // Need to reset tid just in case this is a dummy instruction
980 resPool
->scheduleEvent(c_event
, inst
, 0, 0, tid
);
984 InOrderCPU::isThreadActive(ThreadID tid
)
986 list
<ThreadID
>::iterator isActive
=
987 std::find(activeThreads
.begin(), activeThreads
.end(), tid
);
989 return (isActive
!= activeThreads
.end());
993 InOrderCPU::isThreadReady(ThreadID tid
)
995 list
<ThreadID
>::iterator isReady
=
996 std::find(readyThreads
.begin(), readyThreads
.end(), tid
);
998 return (isReady
!= readyThreads
.end());
1002 InOrderCPU::isThreadSuspended(ThreadID tid
)
1004 list
<ThreadID
>::iterator isSuspended
=
1005 std::find(suspendedThreads
.begin(), suspendedThreads
.end(), tid
);
1007 return (isSuspended
!= suspendedThreads
.end());
1011 InOrderCPU::activateNextReadyThread()
1013 if (readyThreads
.size() >= 1) {
1014 ThreadID ready_tid
= readyThreads
.front();
1016 // Activate in Pipeline
1017 activateThread(ready_tid
);
1019 // Activate in Resource Pool
1020 resPool
->activateThread(ready_tid
);
1022 list
<ThreadID
>::iterator ready_it
=
1023 std::find(readyThreads
.begin(), readyThreads
.end(), ready_tid
);
1024 readyThreads
.erase(ready_it
);
1027 "Attempting to activate new thread, but No Ready Threads to"
1030 "Unable to switch to next active thread.\n");
1035 InOrderCPU::activateThread(ThreadID tid
)
1037 if (isThreadSuspended(tid
)) {
1039 "Removing [tid:%i] from suspended threads list.\n", tid
);
1041 list
<ThreadID
>::iterator susp_it
=
1042 std::find(suspendedThreads
.begin(), suspendedThreads
.end(),
1044 suspendedThreads
.erase(susp_it
);
1047 if (threadModel
== SwitchOnCacheMiss
&&
1048 numActiveThreads() == 1) {
1050 "Ignoring activation of [tid:%i], since [tid:%i] is "
1051 "already running.\n", tid
, activeThreadId());
1053 DPRINTF(InOrderCPU
,"Placing [tid:%i] on ready threads list\n",
1056 readyThreads
.push_back(tid
);
1058 } else if (!isThreadActive(tid
)) {
1060 "Adding [tid:%i] to active threads list.\n", tid
);
1061 activeThreads
.push_back(tid
);
1063 activateThreadInPipeline(tid
);
1065 thread
[tid
]->lastActivate
= curTick();
1067 tcBase(tid
)->setStatus(ThreadContext::Active
);
1076 InOrderCPU::activateThreadInPipeline(ThreadID tid
)
1078 for (int stNum
=0; stNum
< NumStages
; stNum
++) {
1079 pipelineStage
[stNum
]->activateThread(tid
);
1084 InOrderCPU::deactivateContext(ThreadID tid
, int delay
)
1086 DPRINTF(InOrderCPU
,"[tid:%i]: Deactivating ...\n", tid
);
1088 scheduleCpuEvent(DeactivateThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1090 // Be sure to signal that there's some activity so the CPU doesn't
1091 // deschedule itself.
1092 activityRec
.activity();
1098 InOrderCPU::deactivateThread(ThreadID tid
)
1100 DPRINTF(InOrderCPU
, "[tid:%i]: Calling deactivate thread.\n", tid
);
1102 if (isThreadActive(tid
)) {
1103 DPRINTF(InOrderCPU
,"[tid:%i]: Removing from active threads list\n",
1105 list
<ThreadID
>::iterator thread_it
=
1106 std::find(activeThreads
.begin(), activeThreads
.end(), tid
);
1108 removePipelineStalls(*thread_it
);
1110 activeThreads
.erase(thread_it
);
1112 // Ideally, this should be triggered from the
1113 // suspendContext/Thread functions
1114 tcBase(tid
)->setStatus(ThreadContext::Suspended
);
1117 assert(!isThreadActive(tid
));
1121 InOrderCPU::removePipelineStalls(ThreadID tid
)
1123 DPRINTF(InOrderCPU
,"[tid:%i]: Removing all pipeline stalls\n",
1126 for (int stNum
= 0; stNum
< NumStages
; stNum
++) {
1127 pipelineStage
[stNum
]->removeStalls(tid
);
1133 InOrderCPU::updateThreadPriority()
1135 if (activeThreads
.size() > 1)
1137 //DEFAULT TO ROUND ROBIN SCHEME
1138 //e.g. Move highest priority to end of thread list
1139 list
<ThreadID
>::iterator list_begin
= activeThreads
.begin();
1141 unsigned high_thread
= *list_begin
;
1143 activeThreads
.erase(list_begin
);
1145 activeThreads
.push_back(high_thread
);
1150 InOrderCPU::tickThreadStats()
1152 /** Keep track of cycles that each thread is active */
1153 list
<ThreadID
>::iterator thread_it
= activeThreads
.begin();
1154 while (thread_it
!= activeThreads
.end()) {
1155 threadCycles
[*thread_it
]++;
1159 // Keep track of cycles where SMT is active
1160 if (activeThreads
.size() > 1) {
1166 InOrderCPU::activateContext(ThreadID tid
, int delay
)
1168 DPRINTF(InOrderCPU
,"[tid:%i]: Activating ...\n", tid
);
1171 scheduleCpuEvent(ActivateThread
, NoFault
, tid
, dummyInst
[tid
], delay
);
1173 // Be sure to signal that there's some activity so the CPU doesn't
1174 // deschedule itself.
1175 activityRec
.activity();
1181 InOrderCPU::activateNextReadyContext(int delay
)
1183 DPRINTF(InOrderCPU
,"Activating next ready thread\n");
1185 scheduleCpuEvent(ActivateNextReadyThread
, NoFault
, 0/*tid*/, dummyInst
[0],
1186 delay
, ActivateNextReadyThread_Pri
);
1188 // Be sure to signal that there's some activity so the CPU doesn't
1189 // deschedule itself.
1190 activityRec
.activity();
1196 InOrderCPU::haltContext(ThreadID tid
)
1198 DPRINTF(InOrderCPU
, "[tid:%i]: Calling Halt Context...\n", tid
);
1200 scheduleCpuEvent(HaltThread
, NoFault
, tid
, dummyInst
[tid
]);
1202 activityRec
.activity();
1206 InOrderCPU::haltThread(ThreadID tid
)
1208 DPRINTF(InOrderCPU
, "[tid:%i]: Placing on Halted Threads List...\n", tid
);
1209 deactivateThread(tid
);
1210 squashThreadInPipeline(tid
);
1211 haltedThreads
.push_back(tid
);
1213 tcBase(tid
)->setStatus(ThreadContext::Halted
);
1215 if (threadModel
== SwitchOnCacheMiss
) {
1216 activateNextReadyContext();
1221 InOrderCPU::suspendContext(ThreadID tid
)
1223 scheduleCpuEvent(SuspendThread
, NoFault
, tid
, dummyInst
[tid
]);
1227 InOrderCPU::suspendThread(ThreadID tid
)
1229 DPRINTF(InOrderCPU
, "[tid:%i]: Placing on Suspended Threads List...\n",
1231 deactivateThread(tid
);
1232 suspendedThreads
.push_back(tid
);
1233 thread
[tid
]->lastSuspend
= curTick();
1235 tcBase(tid
)->setStatus(ThreadContext::Suspended
);
1239 InOrderCPU::squashThreadInPipeline(ThreadID tid
)
1241 //Squash all instructions in each stage
1242 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
1243 pipelineStage
[stNum
]->squash(0 /*seq_num*/, tid
);
1248 InOrderCPU::getPipeStage(int stage_num
)
1250 return pipelineStage
[stage_num
];
1255 InOrderCPU::flattenRegIdx(RegIndex reg_idx
, RegType
®_type
, ThreadID tid
)
1257 if (reg_idx
< FP_Base_DepTag
) {
1259 return isa
[tid
].flattenIntIndex(reg_idx
);
1260 } else if (reg_idx
< Ctrl_Base_DepTag
) {
1261 reg_type
= FloatType
;
1262 reg_idx
-= FP_Base_DepTag
;
1263 return isa
[tid
].flattenFloatIndex(reg_idx
);
1265 reg_type
= MiscType
;
1266 return reg_idx
- TheISA::Ctrl_Base_DepTag
;
1271 InOrderCPU::readIntReg(RegIndex reg_idx
, ThreadID tid
)
1273 DPRINTF(IntRegs
, "[tid:%i]: Reading Int. Reg %i as %x\n",
1274 tid
, reg_idx
, intRegs
[tid
][reg_idx
]);
1276 return intRegs
[tid
][reg_idx
];
1280 InOrderCPU::readFloatReg(RegIndex reg_idx
, ThreadID tid
)
1282 DPRINTF(FloatRegs
, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
1283 tid
, reg_idx
, floatRegs
.i
[tid
][reg_idx
], floatRegs
.f
[tid
][reg_idx
]);
1285 return floatRegs
.f
[tid
][reg_idx
];
1289 InOrderCPU::readFloatRegBits(RegIndex reg_idx
, ThreadID tid
)
1291 DPRINTF(FloatRegs
, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
1292 tid
, reg_idx
, floatRegs
.i
[tid
][reg_idx
], floatRegs
.f
[tid
][reg_idx
]);
1294 return floatRegs
.i
[tid
][reg_idx
];
1298 InOrderCPU::setIntReg(RegIndex reg_idx
, uint64_t val
, ThreadID tid
)
1300 if (reg_idx
== TheISA::ZeroReg
) {
1301 DPRINTF(IntRegs
, "[tid:%i]: Ignoring Setting of ISA-ZeroReg "
1302 "(Int. Reg %i) to %x\n", tid
, reg_idx
, val
);
1305 DPRINTF(IntRegs
, "[tid:%i]: Setting Int. Reg %i to %x\n",
1308 intRegs
[tid
][reg_idx
] = val
;
1314 InOrderCPU::setFloatReg(RegIndex reg_idx
, FloatReg val
, ThreadID tid
)
1316 floatRegs
.f
[tid
][reg_idx
] = val
;
1317 DPRINTF(FloatRegs
, "[tid:%i]: Setting Float. Reg %i bits to "
1320 floatRegs
.i
[tid
][reg_idx
],
1321 floatRegs
.f
[tid
][reg_idx
]);
1326 InOrderCPU::setFloatRegBits(RegIndex reg_idx
, FloatRegBits val
, ThreadID tid
)
1328 floatRegs
.i
[tid
][reg_idx
] = val
;
1329 DPRINTF(FloatRegs
, "[tid:%i]: Setting Float. Reg %i bits to "
1332 floatRegs
.i
[tid
][reg_idx
],
1333 floatRegs
.f
[tid
][reg_idx
]);
1337 InOrderCPU::readRegOtherThread(unsigned reg_idx
, ThreadID tid
)
1339 // If Default value is set, then retrieve target thread
1340 if (tid
== InvalidThreadID
) {
1341 tid
= TheISA::getTargetThread(tcBase(tid
));
1344 if (reg_idx
< FP_Base_DepTag
) {
1345 // Integer Register File
1346 return readIntReg(reg_idx
, tid
);
1347 } else if (reg_idx
< Ctrl_Base_DepTag
) {
1348 // Float Register File
1349 reg_idx
-= FP_Base_DepTag
;
1350 return readFloatRegBits(reg_idx
, tid
);
1352 reg_idx
-= Ctrl_Base_DepTag
;
1353 return readMiscReg(reg_idx
, tid
); // Misc. Register File
1357 InOrderCPU::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
,
1360 // If Default value is set, then retrieve target thread
1361 if (tid
== InvalidThreadID
) {
1362 tid
= TheISA::getTargetThread(tcBase(tid
));
1365 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
1366 setIntReg(reg_idx
, val
, tid
);
1367 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
1368 reg_idx
-= FP_Base_DepTag
;
1369 setFloatRegBits(reg_idx
, val
, tid
);
1371 reg_idx
-= Ctrl_Base_DepTag
;
1372 setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
1377 InOrderCPU::readMiscRegNoEffect(int misc_reg
, ThreadID tid
)
1379 return isa
[tid
].readMiscRegNoEffect(misc_reg
);
1383 InOrderCPU::readMiscReg(int misc_reg
, ThreadID tid
)
1385 return isa
[tid
].readMiscReg(misc_reg
, tcBase(tid
));
1389 InOrderCPU::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
, ThreadID tid
)
1391 isa
[tid
].setMiscRegNoEffect(misc_reg
, val
);
1395 InOrderCPU::setMiscReg(int misc_reg
, const MiscReg
&val
, ThreadID tid
)
1397 isa
[tid
].setMiscReg(misc_reg
, val
, tcBase(tid
));
1402 InOrderCPU::addInst(DynInstPtr inst
)
1404 ThreadID tid
= inst
->readTid();
1406 instList
[tid
].push_back(inst
);
1408 return --(instList
[tid
].end());
1412 InOrderCPU::findInst(InstSeqNum seq_num
, ThreadID tid
)
1414 ListIt it
= instList
[tid
].begin();
1415 ListIt end
= instList
[tid
].end();
1418 if ((*it
)->seqNum
== seq_num
)
1420 else if ((*it
)->seqNum
> seq_num
)
1426 return instList
[tid
].end();
1430 InOrderCPU::updateContextSwitchStats()
1432 // Set Average Stat Here, then reset to 0
1433 instsPerCtxtSwitch
= instsPerSwitch
;
1439 InOrderCPU::instDone(DynInstPtr inst
, ThreadID tid
)
1441 // Set the nextPC to be fetched if this is the last instruction
1444 // This contributes to the precise state of the CPU
1445 // which can be used when restoring a thread to the CPU after after any
1446 // type of context switching activity (fork, exception, etc.)
1447 TheISA::PCState comm_pc
= inst
->pcState();
1448 lastCommittedPC
[tid
] = comm_pc
;
1449 TheISA::advancePC(comm_pc
, inst
->staticInst
);
1450 pcState(comm_pc
, tid
);
1452 //@todo: may be unnecessary with new-ISA-specific branch handling code
1453 if (inst
->isControl()) {
1454 thread
[tid
]->lastGradIsBranch
= true;
1455 thread
[tid
]->lastBranchPC
= inst
->pcState();
1456 TheISA::advancePC(thread
[tid
]->lastBranchPC
, inst
->staticInst
);
1458 thread
[tid
]->lastGradIsBranch
= false;
1462 // Finalize Trace Data For Instruction
1463 if (inst
->traceData
) {
1464 //inst->traceData->setCycle(curTick());
1465 inst
->traceData
->setFetchSeq(inst
->seqNum
);
1466 //inst->traceData->setCPSeq(cpu->tcBase(tid)->numInst);
1467 inst
->traceData
->dump();
1468 delete inst
->traceData
;
1469 inst
->traceData
= NULL
;
1472 // Increment active thread's instruction count
1475 // Increment thread-state's instruction count
1476 thread
[tid
]->numInst
++;
1477 thread
[tid
]->numOp
++;
1479 // Increment thread-state's instruction stats
1480 thread
[tid
]->numInsts
++;
1481 thread
[tid
]->numOps
++;
1483 // Count committed insts per thread stats
1484 if (!inst
->isMicroop() || inst
->isLastMicroop()) {
1485 committedInsts
[tid
]++;
1487 // Count total insts committed stat
1488 totalCommittedInsts
++;
1491 committedOps
[tid
]++;
1493 // Count SMT-committed insts per thread stat
1494 if (numActiveThreads() > 1) {
1495 if (!inst
->isMicroop() || inst
->isLastMicroop())
1496 smtCommittedInsts
[tid
]++;
1499 // Instruction-Mix Stats
1500 if (inst
->isLoad()) {
1502 } else if (inst
->isStore()) {
1504 } else if (inst
->isControl()) {
1506 } else if (inst
->isNop()) {
1508 } else if (inst
->isNonSpeculative()) {
1510 } else if (inst
->isInteger()) {
1512 } else if (inst
->isFloating()) {
1516 // Check for instruction-count-based events.
1517 comInstEventQueue
[tid
]->serviceEvents(thread
[tid
]->numOp
);
1519 // Finally, remove instruction from CPU
1523 // currently unused function, but substitute repetitive code w/this function
1526 InOrderCPU::addToRemoveList(DynInstPtr inst
)
1528 removeInstsThisCycle
= true;
1529 if (!inst
->isRemoveList()) {
1530 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1531 "[sn:%lli] to remove list\n",
1532 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1533 inst
->setRemoveList();
1534 removeList
.push(inst
->getInstListIt());
1536 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i] PC %s "
1537 "[sn:%lli], already remove list\n",
1538 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1544 InOrderCPU::removeInst(DynInstPtr inst
)
1546 DPRINTF(InOrderCPU
, "Removing graduated instruction [tid:%i] PC %s "
1548 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1550 removeInstsThisCycle
= true;
1552 // Remove the instruction.
1553 if (!inst
->isRemoveList()) {
1554 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1555 "[sn:%lli] to remove list\n",
1556 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1557 inst
->setRemoveList();
1558 removeList
.push(inst
->getInstListIt());
1560 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i] PC %s "
1561 "[sn:%lli], already on remove list\n",
1562 inst
->threadNumber
, inst
->pcState(), inst
->seqNum
);
1568 InOrderCPU::removeInstsUntil(const InstSeqNum
&seq_num
, ThreadID tid
)
1570 //assert(!instList[tid].empty());
1572 removeInstsThisCycle
= true;
1574 ListIt inst_iter
= instList
[tid
].end();
1578 DPRINTF(InOrderCPU
, "Squashing instructions from CPU instruction "
1579 "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
1580 tid
, seq_num
, (*inst_iter
)->seqNum
);
1582 while ((*inst_iter
)->seqNum
> seq_num
) {
1584 bool break_loop
= (inst_iter
== instList
[tid
].begin());
1586 squashInstIt(inst_iter
, tid
);
1597 InOrderCPU::squashInstIt(const ListIt inst_it
, ThreadID tid
)
1599 DynInstPtr inst
= (*inst_it
);
1600 if (inst
->threadNumber
== tid
) {
1601 DPRINTF(InOrderCPU
, "Squashing instruction, "
1602 "[tid:%i] [sn:%lli] PC %s\n",
1607 inst
->setSquashed();
1608 archRegDepMap
[tid
].remove(inst
);
1610 if (!inst
->isRemoveList()) {
1611 DPRINTF(InOrderCPU
, "Pushing instruction [tid:%i] PC %s "
1612 "[sn:%lli] to remove list\n",
1613 inst
->threadNumber
, inst
->pcState(),
1615 inst
->setRemoveList();
1616 removeList
.push(inst_it
);
1618 DPRINTF(InOrderCPU
, "Ignoring instruction removal for [tid:%i]"
1619 " PC %s [sn:%lli], already on remove list\n",
1620 inst
->threadNumber
, inst
->pcState(),
1630 InOrderCPU::cleanUpRemovedInsts()
1632 while (!removeList
.empty()) {
1633 DPRINTF(InOrderCPU
, "Removing instruction, "
1634 "[tid:%i] [sn:%lli] PC %s\n",
1635 (*removeList
.front())->threadNumber
,
1636 (*removeList
.front())->seqNum
,
1637 (*removeList
.front())->pcState());
1639 DynInstPtr inst
= *removeList
.front();
1640 ThreadID tid
= inst
->threadNumber
;
1642 // Remove From Register Dependency Map, If Necessary
1643 // archRegDepMap[tid].remove(inst);
1645 // Clear if Non-Speculative
1646 if (inst
->staticInst
&&
1647 inst
->seqNum
== nonSpecSeqNum
[tid
] &&
1648 nonSpecInstActive
[tid
] == true) {
1649 nonSpecInstActive
[tid
] = false;
1652 inst
->onInstList
= false;
1654 instList
[tid
].erase(removeList
.front());
1659 removeInstsThisCycle
= false;
1663 InOrderCPU::cleanUpRemovedEvents()
1665 while (!cpuEventRemoveList
.empty()) {
1666 Event
*cpu_event
= cpuEventRemoveList
.front();
1667 cpuEventRemoveList
.pop();
1674 InOrderCPU::dumpInsts()
1678 ListIt inst_list_it
= instList
[0].begin();
1680 cprintf("Dumping Instruction List\n");
1682 while (inst_list_it
!= instList
[0].end()) {
1683 cprintf("Instruction:%i\nPC:%s\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
1685 num
, (*inst_list_it
)->pcState(),
1686 (*inst_list_it
)->threadNumber
,
1687 (*inst_list_it
)->seqNum
, (*inst_list_it
)->isIssued(),
1688 (*inst_list_it
)->isSquashed());
1695 InOrderCPU::wakeCPU()
1697 if (/*activityRec.active() || */tickEvent
.scheduled()) {
1698 DPRINTF(Activity
, "CPU already running.\n");
1702 DPRINTF(Activity
, "Waking up CPU\n");
1704 Tick extra_cycles
= tickToCycles((curTick() - 1) - lastRunningCycle
);
1706 idleCycles
+= extra_cycles
;
1707 for (int stage_num
= 0; stage_num
< NumStages
; stage_num
++) {
1708 pipelineStage
[stage_num
]->idleCycles
+= extra_cycles
;
1711 numCycles
+= extra_cycles
;
1713 schedule(&tickEvent
, nextCycle(curTick()));
1716 // Lots of copied full system code...place into BaseCPU class?
1718 InOrderCPU::wakeup()
1720 if (thread
[0]->status() != ThreadContext::Suspended
)
1725 DPRINTF(Quiesce
, "Suspended Processor woken\n");
1726 threadContexts
[0]->activate();
1730 InOrderCPU::syscallContext(Fault fault
, ThreadID tid
, DynInstPtr inst
, int delay
)
1732 // Syscall must be non-speculative, so squash from last stage
1733 unsigned squash_stage
= NumStages
- 1;
1734 inst
->setSquashInfo(squash_stage
);
1736 // Squash In Pipeline Stage
1737 pipelineStage
[squash_stage
]->setupSquash(inst
, tid
);
1739 // Schedule Squash Through-out Resource Pool
1740 resPool
->scheduleEvent(
1741 (InOrderCPU::CPUEventType
)ResourcePool::SquashAll
, inst
, 0);
1742 scheduleCpuEvent(Syscall
, fault
, tid
, inst
, delay
, Syscall_Pri
);
1746 InOrderCPU::syscall(int64_t callnum
, ThreadID tid
)
1748 DPRINTF(InOrderCPU
, "[tid:%i] Executing syscall().\n\n", tid
);
1750 DPRINTF(Activity
,"Activity: syscall() called.\n");
1752 // Temporarily increase this by one to account for the syscall
1754 ++(this->thread
[tid
]->funcExeInst
);
1756 // Execute the actual syscall.
1757 this->thread
[tid
]->syscall(callnum
);
1759 // Decrease funcExeInst by one as the normal commit will handle
1761 --(this->thread
[tid
]->funcExeInst
);
1763 // Clear Non-Speculative Block Variable
1764 nonSpecInstActive
[tid
] = false;
1768 InOrderCPU::getITBPtr()
1770 CacheUnit
*itb_res
= resPool
->getInstUnit();
1771 return itb_res
->tlb();
1776 InOrderCPU::getDTBPtr()
1778 return resPool
->getDataUnit()->tlb();
1782 InOrderCPU::getDecoderPtr()
1784 return &resPool
->getInstUnit()->decoder
;
1788 InOrderCPU::read(DynInstPtr inst
, Addr addr
,
1789 uint8_t *data
, unsigned size
, unsigned flags
)
1791 return resPool
->getDataUnit()->read(inst
, addr
, data
, size
, flags
);
1795 InOrderCPU::write(DynInstPtr inst
, uint8_t *data
, unsigned size
,
1796 Addr addr
, unsigned flags
, uint64_t *write_res
)
1798 return resPool
->getDataUnit()->write(inst
, data
, size
, addr
, flags
,