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
32 #include "config/full_system.hh"
34 #include "arch/utility.hh"
35 #include "cpu/exetrace.hh"
36 #include "cpu/activity.hh"
37 #include "cpu/simple_thread.hh"
38 #include "cpu/thread_context.hh"
39 #include "cpu/base.hh"
40 #include "cpu/inorder/inorder_dyn_inst.hh"
41 #include "cpu/inorder/thread_context.hh"
42 #include "cpu/inorder/thread_state.hh"
43 #include "cpu/inorder/cpu.hh"
44 #include "params/InOrderCPU.hh"
45 #include "cpu/inorder/pipeline_traits.hh"
46 #include "cpu/inorder/first_stage.hh"
47 #include "cpu/inorder/resources/resource_list.hh"
48 #include "cpu/inorder/resource_pool.hh"
49 #include "mem/translating_port.hh"
50 #include "sim/process.hh"
51 #include "sim/stat_control.hh"
55 using namespace TheISA
;
56 using namespace ThePipeline
;
58 InOrderCPU::TickEvent::TickEvent(InOrderCPU
*c
)
59 : Event(CPU_Tick_Pri
), cpu(c
)
64 InOrderCPU::TickEvent::process()
71 InOrderCPU::TickEvent::description()
73 return "InOrderCPU tick event";
76 InOrderCPU::CPUEvent::CPUEvent(InOrderCPU
*_cpu
, CPUEventType e_type
,
77 Fault fault
, unsigned _tid
, unsigned _vpe
)
78 : Event(CPU_Tick_Pri
), cpu(_cpu
)
80 setEvent(e_type
, fault
, _tid
, _vpe
);
84 InOrderCPU::CPUEvent::process()
89 cpu
->activateThread(tid
);
92 //@TODO: Consider Implementing "Suspend Thread" as Separate from Deallocate
93 case SuspendThread
: // Suspend & Deallocate are same for now.
94 //cpu->suspendThread(tid);
96 case DeallocateThread
:
97 cpu
->deallocateThread(tid
);
101 cpu
->enableVPEs(vpe
);
105 cpu
->disableVPEs(tid
, vpe
);
109 cpu
->enableThreads(vpe
);
113 cpu
->disableThreads(tid
, vpe
);
117 cpu
->trapCPU(fault
, tid
);
121 fatal("Unrecognized Event Type %d", cpuEventType
);
124 cpu
->cpuEventRemoveList
.push(this);
128 InOrderCPU::CPUEvent::description()
130 return "InOrderCPU event";
134 InOrderCPU::CPUEvent::scheduleEvent(int delay
)
137 mainEventQueue
.reschedule(this,curTick
+ cpu
->ticks(delay
));
138 else if (!scheduled())
139 mainEventQueue
.schedule(this,curTick
+ cpu
->ticks(delay
));
143 InOrderCPU::CPUEvent::unscheduleEvent()
149 InOrderCPU::InOrderCPU(Params
*params
)
151 cpu_id(params
->cpu_id
),
157 removeInstsThisCycle(false),
158 activityRec(params
->name
, NumStages
, 10, params
->activity
),
160 deferRegistration(false/*params->deferRegistration*/),
161 stageTracing(params
->stageTracing
),
162 numThreads(params
->numThreads
),
167 resPool
= new ResourcePool(this, params
);
169 // Resize for Multithreading CPUs
170 thread
.resize(numThreads
);
172 int active_threads
= params
->workload
.size();
174 if (active_threads
> MaxThreads
) {
175 panic("Workload Size too large. Increase the 'MaxThreads'"
176 "in your InOrder implementation or "
177 "edit your workload size.");
180 // Bind the fetch & data ports from the resource pool.
181 fetchPortIdx
= resPool
->getPortIdx(params
->fetchMemPort
);
182 if (fetchPortIdx
== 0) {
183 fatal("Unable to find port to fetch instructions from.\n");
186 dataPortIdx
= resPool
->getPortIdx(params
->dataMemPort
);
187 if (dataPortIdx
== 0) {
188 fatal("Unable to find port for data.\n");
192 // Hard-Code Bindings to ITB & DTB
193 itbIdx
= resPool
->getResIdx(name() + "." + "I-TLB");
195 fatal("Unable to find ITB resource.\n");
198 dtbIdx
= resPool
->getResIdx(name() + "." + "D-TLB");
200 fatal("Unable to find DTB resource.\n");
203 for (int i
= 0; i
< numThreads
; ++i
) {
204 if (i
< params
->workload
.size()) {
205 DPRINTF(InOrderCPU
, "Workload[%i] process is %#x\n",
207 this->thread
[i
] = new Thread(this, i
, params
->workload
[i
],
210 //Allocate Empty thread so M5 can use later
211 //when scheduling threads to CPU
212 Process
* dummy_proc
= params
->workload
[0];
213 this->thread
[i
] = new Thread(this, i
, dummy_proc
, i
);
216 // Setup the TC that will serve as the interface to the threads/CPU.
217 InOrderThreadContext
*tc
= new InOrderThreadContext
;
219 tc
->thread
= this->thread
[i
];
221 // Give the thread the TC.
223 thread
[i
]->setFuncExeInst(0);
226 // Add the TC to the CPU's list of TC's.
227 this->threadContexts
.push_back(tc
);
230 // Initialize TimeBuffer Stage Queues
231 for (int stNum
=0; stNum
< NumStages
- 1; stNum
++) {
232 stageQueue
[stNum
] = new StageQueue(NumStages
, NumStages
);
233 stageQueue
[stNum
]->id(stNum
);
237 // Set Up Pipeline Stages
238 for (int stNum
=0; stNum
< NumStages
; stNum
++) {
240 pipelineStage
[stNum
] = new FirstStage(params
, stNum
);
242 pipelineStage
[stNum
] = new PipelineStage(params
, stNum
);
244 pipelineStage
[stNum
]->setCPU(this);
245 pipelineStage
[stNum
]->setActiveThreads(&activeThreads
);
246 pipelineStage
[stNum
]->setTimeBuffer(&timeBuffer
);
248 // Take Care of 1st/Nth stages
250 pipelineStage
[stNum
]->setPrevStageQueue(stageQueue
[stNum
- 1]);
251 if (stNum
< NumStages
- 1)
252 pipelineStage
[stNum
]->setNextStageQueue(stageQueue
[stNum
]);
255 // Initialize thread specific variables
256 for (int tid
=0; tid
< numThreads
; tid
++) {
257 archRegDepMap
[tid
].setCPU(this);
259 nonSpecInstActive
[tid
] = false;
260 nonSpecSeqNum
[tid
] = 0;
262 squashSeqNum
[tid
] = MaxAddr
;
263 lastSquashCycle
[tid
] = 0;
265 intRegFile
[tid
].clear();
266 floatRegFile
[tid
].clear();
269 // Update miscRegFile if necessary
270 if (numThreads
> 1) {
271 miscRegFile
.expandForMultithreading(numThreads
, numVirtProcs
);
276 lastRunningCycle
= curTick
;
277 contextSwitch
= false;
279 // Define dummy instructions and resource requests to be used.
280 DynInstPtr dummyBufferInst
= new InOrderDynInst(this, NULL
, 0, 0);
281 dummyReq
= new ResourceRequest(NULL
, NULL
, 0, 0, 0, 0);
283 // Reset CPU to reset state.
285 Fault resetFault
= new ResetFault();
286 resetFault
->invoke(tcBase());
291 // Schedule First Tick Event, CPU will reschedule itself from here on out.
292 scheduleTickEvent(0);
297 InOrderCPU::regStats()
299 /* Register the Resource Pool's stats here.*/
302 /* Register any of the InOrderCPU's stats here.*/
304 .name(name() + ".timesIdled")
305 .desc("Number of times that the entire CPU went into an idle state and"
306 " unscheduled itself")
310 .name(name() + ".idleCycles")
311 .desc("Total number of cycles that the CPU has spent unscheduled due "
317 .name(name() + ".threadCycles")
318 .desc("Total Number of Cycles A Thread Was Active in CPU (Per-Thread)");
321 .name(name() + ".smtCycles")
322 .desc("Total number of cycles that the CPU was simultaneous multithreading.(SMT)");
326 .name(name() + ".committedInsts")
327 .desc("Number of Instructions Simulated (Per-Thread)");
331 .name(name() + ".smtCommittedInsts")
332 .desc("Number of SMT Instructions Simulated (Per-Thread)");
335 .name(name() + ".committedInsts_total")
336 .desc("Number of Instructions Simulated (Total)");
339 .name(name() + ".cpi")
340 .desc("CPI: Cycles Per Instruction (Per-Thread)")
342 cpi
= threadCycles
/ committedInsts
;
345 .name(name() + ".smt_cpi")
346 .desc("CPI: Total SMT-CPI")
348 smtCpi
= smtCycles
/ smtCommittedInsts
;
351 .name(name() + ".cpi_total")
352 .desc("CPI: Total CPI of All Threads")
354 totalCpi
= numCycles
/ totalCommittedInsts
;
357 .name(name() + ".ipc")
358 .desc("IPC: Instructions Per Cycle (Per-Thread)")
360 ipc
= committedInsts
/ threadCycles
;
363 .name(name() + ".smt_ipc")
364 .desc("IPC: Total SMT-IPC")
366 smtIpc
= smtCommittedInsts
/ smtCycles
;
369 .name(name() + ".ipc_total")
370 .desc("IPC: Total IPC of All Threads")
372 totalIpc
= totalCommittedInsts
/ numCycles
;
381 DPRINTF(InOrderCPU
, "\n\nInOrderCPU: Ticking main, InOrderCPU.\n");
385 //Tick each of the stages
386 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
387 pipelineStage
[stNum
]->tick();
390 // Now advance the time buffers one tick
391 timeBuffer
.advance();
392 for (int sqNum
=0; sqNum
< NumStages
- 1; sqNum
++) {
393 stageQueue
[sqNum
]->advance();
395 activityRec
.advance();
397 // Any squashed requests, events, or insts then remove them now
398 cleanUpRemovedReqs();
399 cleanUpRemovedEvents();
400 cleanUpRemovedInsts();
402 // Re-schedule CPU for this cycle
403 if (!tickEvent
.scheduled()) {
404 if (_status
== SwitchedOut
) {
406 lastRunningCycle
= curTick
;
407 } else if (!activityRec
.active()) {
408 DPRINTF(InOrderCPU
, "sleeping CPU.\n");
409 lastRunningCycle
= curTick
;
412 //Tick next_tick = curTick + cycles(1);
413 //tickEvent.schedule(next_tick);
414 mainEventQueue
.schedule(&tickEvent
, nextCycle(curTick
+ 1));
415 DPRINTF(InOrderCPU
, "Scheduled CPU for next tick @ %i.\n", nextCycle() + curTick
);
420 updateThreadPriority();
427 if (!deferRegistration
) {
428 registerThreadContexts();
431 // Set inSyscall so that the CPU doesn't squash when initially
432 // setting up registers.
433 for (int i
= 0; i
< number_of_threads
; ++i
)
434 thread
[i
]->inSyscall
= true;
437 for (int tid
=0; tid
< number_of_threads
; tid
++) {
438 ThreadContext
*src_tc
= threadContexts
[tid
];
439 TheISA::initCPU(src_tc
, src_tc
->contextId());
444 for (int i
= 0; i
< number_of_threads
; ++i
)
445 thread
[i
]->inSyscall
= false;
447 // Call Initializiation Routine for Resource Pool
452 InOrderCPU::readFunctional(Addr addr
, uint32_t &buffer
)
454 tcBase()->getMemPort()->readBlob(addr
, (uint8_t*)&buffer
, sizeof(uint32_t));
455 buffer
= gtoh(buffer
);
461 miscRegFile
.reset(coreType
, numThreads
, numVirtProcs
, dynamic_cast<BaseCPU
*>(this));
465 InOrderCPU::getPort(const std::string
&if_name
, int idx
)
467 return resPool
->getPort(if_name
, idx
);
471 InOrderCPU::trap(Fault fault
, unsigned tid
, int delay
)
473 scheduleCpuEvent(Trap
, fault
, tid
, 0/*vpe*/, delay
);
477 InOrderCPU::trapCPU(Fault fault
, unsigned tid
)
479 fault
->invoke(tcBase(tid
));
483 InOrderCPU::scheduleCpuEvent(CPUEventType c_event
, Fault fault
,
484 unsigned tid
, unsigned vpe
, unsigned delay
)
486 CPUEvent
*cpu_event
= new CPUEvent(this, c_event
, fault
, tid
, vpe
);
489 DPRINTF(InOrderCPU
, "Scheduling CPU Event Type #%i for cycle %i.\n",
490 c_event
, curTick
+ delay
);
491 mainEventQueue
.schedule(cpu_event
,curTick
+ delay
);
493 cpu_event
->process();
494 cpuEventRemoveList
.push(cpu_event
);
497 // Broadcast event to the Resource Pool
498 DynInstPtr dummy_inst
= new InOrderDynInst(this, NULL
, getNextEventNum(), tid
);
499 resPool
->scheduleEvent(c_event
, dummy_inst
, 0, 0, tid
);
503 InOrderCPU::isThreadActive(unsigned tid
)
505 list
<unsigned>::iterator isActive
= std::find(
506 activeThreads
.begin(), activeThreads
.end(), tid
);
508 return (isActive
!= activeThreads
.end());
513 InOrderCPU::activateThread(unsigned tid
)
515 if (!isThreadActive(tid
)) {
516 DPRINTF(InOrderCPU
, "Adding Thread %i to active threads list in CPU.\n",
518 activeThreads
.push_back(tid
);
525 InOrderCPU::deactivateThread(unsigned tid
)
527 DPRINTF(InOrderCPU
, "[tid:%i]: Calling deactivate thread.\n", tid
);
529 if (isThreadActive(tid
)) {
530 DPRINTF(InOrderCPU
,"[tid:%i]: Removing from active threads list\n",
532 list
<unsigned>::iterator thread_it
= std::find(activeThreads
.begin(),
533 activeThreads
.end(), tid
);
535 removePipelineStalls(*thread_it
);
537 //@TODO: change stage status' to Idle?
539 activeThreads
.erase(thread_it
);
544 InOrderCPU::removePipelineStalls(unsigned tid
)
546 DPRINTF(InOrderCPU
,"[tid:%i]: Removing all pipeline stalls\n",
549 for (int stNum
= 0; stNum
< NumStages
; stNum
++) {
550 pipelineStage
[stNum
]->removeStalls(tid
);
555 InOrderCPU::isThreadInCPU(unsigned tid
)
557 list
<unsigned>::iterator isCurrent
= std::find(
558 currentThreads
.begin(), currentThreads
.end(), tid
);
560 return (isCurrent
!= currentThreads
.end());
564 InOrderCPU::addToCurrentThreads(unsigned tid
)
566 if (!isThreadInCPU(tid
)) {
567 DPRINTF(InOrderCPU
, "Adding Thread %i to current threads list in CPU.\n",
569 currentThreads
.push_back(tid
);
574 InOrderCPU::removeFromCurrentThreads(unsigned tid
)
576 if (isThreadInCPU(tid
)) {
577 DPRINTF(InOrderCPU
, "Adding Thread %i to current threads list in CPU.\n",
579 list
<unsigned>::iterator isCurrent
= std::find(
580 currentThreads
.begin(), currentThreads
.end(), tid
);
581 currentThreads
.erase(isCurrent
);
586 InOrderCPU::isThreadSuspended(unsigned tid
)
588 list
<unsigned>::iterator isSuspended
= std::find(
589 suspendedThreads
.begin(), suspendedThreads
.end(), tid
);
591 return (isSuspended
!= suspendedThreads
.end());
595 InOrderCPU::enableVirtProcElement(unsigned vpe
)
597 DPRINTF(InOrderCPU
, "[vpe:%i]: Scheduling "
598 "Enabling of concurrent virtual processor execution",
601 scheduleCpuEvent(EnableVPEs
, NoFault
, 0/*tid*/, vpe
);
605 InOrderCPU::enableVPEs(unsigned vpe
)
607 DPRINTF(InOrderCPU
, "[vpe:%i]: Enabling Concurrent Execution "
608 "virtual processors %i", vpe
);
610 list
<unsigned>::iterator thread_it
= currentThreads
.begin();
612 while (thread_it
!= currentThreads
.end()) {
613 if (!isThreadSuspended(*thread_it
)) {
614 activateThread(*thread_it
);
621 InOrderCPU::disableVirtProcElement(unsigned tid
, unsigned vpe
)
623 DPRINTF(InOrderCPU
, "[vpe:%i]: Scheduling "
624 "Disabling of concurrent virtual processor execution",
627 scheduleCpuEvent(DisableVPEs
, NoFault
, 0/*tid*/, vpe
);
631 InOrderCPU::disableVPEs(unsigned tid
, unsigned vpe
)
633 DPRINTF(InOrderCPU
, "[vpe:%i]: Disabling Concurrent Execution of "
634 "virtual processors %i", vpe
);
636 unsigned base_vpe
= TheISA::getVirtProcNum(tcBase(tid
));
638 list
<unsigned>::iterator thread_it
= activeThreads
.begin();
640 std::vector
<list
<unsigned>::iterator
> removeList
;
642 while (thread_it
!= activeThreads
.end()) {
643 if (base_vpe
!= vpe
) {
644 removeList
.push_back(thread_it
);
649 for (int i
= 0; i
< removeList
.size(); i
++) {
650 activeThreads
.erase(removeList
[i
]);
655 InOrderCPU::enableMultiThreading(unsigned vpe
)
657 // Schedule event to take place at end of cycle
658 DPRINTF(InOrderCPU
, "[vpe:%i]: Scheduling Enable Multithreading on "
659 "virtual processor %i", vpe
);
661 scheduleCpuEvent(EnableThreads
, NoFault
, 0/*tid*/, vpe
);
665 InOrderCPU::enableThreads(unsigned vpe
)
667 DPRINTF(InOrderCPU
, "[vpe:%i]: Enabling Multithreading on "
668 "virtual processor %i", vpe
);
670 list
<unsigned>::iterator thread_it
= currentThreads
.begin();
672 while (thread_it
!= currentThreads
.end()) {
673 if (TheISA::getVirtProcNum(tcBase(*thread_it
)) == vpe
) {
674 if (!isThreadSuspended(*thread_it
)) {
675 activateThread(*thread_it
);
682 InOrderCPU::disableMultiThreading(unsigned tid
, unsigned vpe
)
684 // Schedule event to take place at end of cycle
685 DPRINTF(InOrderCPU
, "[tid:%i]: Scheduling Disable Multithreading on "
686 "virtual processor %i", tid
, vpe
);
688 scheduleCpuEvent(DisableThreads
, NoFault
, tid
, vpe
);
692 InOrderCPU::disableThreads(unsigned tid
, unsigned vpe
)
694 DPRINTF(InOrderCPU
, "[tid:%i]: Disabling Multithreading on "
695 "virtual processor %i", tid
, vpe
);
697 list
<unsigned>::iterator thread_it
= activeThreads
.begin();
699 std::vector
<list
<unsigned>::iterator
> removeList
;
701 while (thread_it
!= activeThreads
.end()) {
702 if (TheISA::getVirtProcNum(tcBase(*thread_it
)) == vpe
) {
703 removeList
.push_back(thread_it
);
708 for (int i
= 0; i
< removeList
.size(); i
++) {
709 activeThreads
.erase(removeList
[i
]);
714 InOrderCPU::updateThreadPriority()
716 if (activeThreads
.size() > 1)
718 //DEFAULT TO ROUND ROBIN SCHEME
719 //e.g. Move highest priority to end of thread list
720 list
<unsigned>::iterator list_begin
= activeThreads
.begin();
721 list
<unsigned>::iterator list_end
= activeThreads
.end();
723 unsigned high_thread
= *list_begin
;
725 activeThreads
.erase(list_begin
);
727 activeThreads
.push_back(high_thread
);
732 InOrderCPU::tickThreadStats()
734 /** Keep track of cycles that each thread is active */
735 list
<unsigned>::iterator thread_it
= activeThreads
.begin();
736 while (thread_it
!= activeThreads
.end()) {
737 threadCycles
[*thread_it
]++;
741 // Keep track of cycles where SMT is active
742 if (activeThreads
.size() > 1) {
748 InOrderCPU::activateContext(unsigned tid
, int delay
)
750 DPRINTF(InOrderCPU
,"[tid:%i]: Activating ...\n", tid
);
752 scheduleCpuEvent(ActivateThread
, NoFault
, tid
, 0/*vpe*/, delay
);
754 // Be sure to signal that there's some activity so the CPU doesn't
755 // deschedule itself.
756 activityRec
.activity();
763 InOrderCPU::suspendContext(unsigned tid
, int delay
)
765 scheduleCpuEvent(SuspendThread
, NoFault
, tid
, 0/*vpe*/, delay
);
770 InOrderCPU::suspendThread(unsigned tid
)
772 DPRINTF(InOrderCPU
,"[tid: %i]: Suspended ...\n", tid
);
773 deactivateThread(tid
);
777 InOrderCPU::deallocateContext(unsigned tid
, int delay
)
779 scheduleCpuEvent(DeallocateThread
, NoFault
, tid
, 0/*vpe*/, delay
);
783 InOrderCPU::deallocateThread(unsigned tid
)
785 DPRINTF(InOrderCPU
,"[tid:%i]: Deallocating ...", tid
);
787 removeFromCurrentThreads(tid
);
789 deactivateThread(tid
);
791 squashThreadInPipeline(tid
);
795 InOrderCPU::squashThreadInPipeline(unsigned tid
)
797 //Squash all instructions in each stage
798 for (int stNum
=NumStages
- 1; stNum
>= 0 ; stNum
--) {
799 pipelineStage
[stNum
]->squash(0 /*seq_num*/, tid
);
804 InOrderCPU::haltContext(unsigned tid
, int delay
)
806 DPRINTF(InOrderCPU
, "[tid:%i]: Halt context called.\n", tid
);
808 // Halt is same thing as deallocate for now
809 // @TODO: Differentiate between halt & deallocate in the CPU
811 deallocateContext(tid
, delay
);
815 InOrderCPU::insertThread(unsigned tid
)
817 panic("Unimplemented Function\n.");
821 InOrderCPU::removeThread(unsigned tid
)
823 DPRINTF(InOrderCPU
, "Removing Thread %i from CPU.\n", tid
);
825 /** Broadcast to CPU resources*/
829 InOrderCPU::getPipeStage(int stage_num
)
831 return pipelineStage
[stage_num
];
836 InOrderCPU::activateWhenReady(int tid
)
838 panic("Unimplemented Function\n.");
843 InOrderCPU::readPC(unsigned tid
)
850 InOrderCPU::setPC(Addr new_PC
, unsigned tid
)
857 InOrderCPU::readNextPC(unsigned tid
)
864 InOrderCPU::setNextPC(uint64_t new_NPC
, unsigned tid
)
866 nextPC
[tid
] = new_NPC
;
871 InOrderCPU::readNextNPC(unsigned tid
)
878 InOrderCPU::setNextNPC(uint64_t new_NNPC
, unsigned tid
)
880 nextNPC
[tid
] = new_NNPC
;
884 InOrderCPU::readIntReg(int reg_idx
, unsigned tid
)
886 return intRegFile
[tid
].readReg(reg_idx
);
890 InOrderCPU::readFloatReg(int reg_idx
, unsigned tid
, int width
)
893 return floatRegFile
[tid
].readReg(reg_idx
, width
);
897 InOrderCPU::readFloatRegBits(int reg_idx
, unsigned tid
, int width
)
899 return floatRegFile
[tid
].readRegBits(reg_idx
, width
);
903 InOrderCPU::setIntReg(int reg_idx
, uint64_t val
, unsigned tid
)
905 intRegFile
[tid
].setReg(reg_idx
, val
);
910 InOrderCPU::setFloatReg(int reg_idx
, FloatReg val
, unsigned tid
, int width
)
912 floatRegFile
[tid
].setReg(reg_idx
, val
, width
);
917 InOrderCPU::setFloatRegBits(int reg_idx
, FloatRegBits val
, unsigned tid
, int width
)
919 floatRegFile
[tid
].setRegBits(reg_idx
, val
, width
);
923 InOrderCPU::readRegOtherThread(unsigned reg_idx
, unsigned tid
)
925 // If Default value is set, then retrieve target thread
927 tid
= TheISA::getTargetThread(tcBase(tid
));
930 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
931 return readIntReg(reg_idx
, tid
);
932 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
933 reg_idx
-= FP_Base_DepTag
;
934 return readFloatRegBits(reg_idx
, tid
);
936 reg_idx
-= Ctrl_Base_DepTag
;
937 return readMiscReg(reg_idx
, tid
); // Misc. Register File
941 InOrderCPU::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
, unsigned tid
)
943 // If Default value is set, then retrieve target thread
945 tid
= TheISA::getTargetThread(tcBase(tid
));
948 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
949 setIntReg(reg_idx
, val
, tid
);
950 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
951 reg_idx
-= FP_Base_DepTag
;
952 setFloatRegBits(reg_idx
, val
, tid
);
954 reg_idx
-= Ctrl_Base_DepTag
;
955 setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
960 InOrderCPU::readMiscRegNoEffect(int misc_reg
, unsigned tid
)
962 return miscRegFile
.readRegNoEffect(misc_reg
, tid
);
966 InOrderCPU::readMiscReg(int misc_reg
, unsigned tid
)
968 return miscRegFile
.readReg(misc_reg
, tcBase(tid
), tid
);
972 InOrderCPU::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
, unsigned tid
)
974 miscRegFile
.setRegNoEffect(misc_reg
, val
, tid
);
978 InOrderCPU::setMiscReg(int misc_reg
, const MiscReg
&val
, unsigned tid
)
980 miscRegFile
.setReg(misc_reg
, val
, tcBase(tid
), tid
);
985 InOrderCPU::addInst(DynInstPtr
&inst
)
987 int tid
= inst
->readTid();
989 instList
[tid
].push_back(inst
);
991 return --(instList
[tid
].end());
995 InOrderCPU::instDone(DynInstPtr inst
, unsigned tid
)
997 // Set the CPU's PCs - This contributes to the precise state of the CPU which can be used
998 // when restoring a thread to the CPU after a fork or after an exception
999 // @TODO: Set-Up Grad-Info/Committed-Info to let ThreadState know if it's a branch or not
1000 setPC(inst
->readPC(), tid
);
1001 setNextPC(inst
->readNextPC(), tid
);
1002 setNextNPC(inst
->readNextNPC(), tid
);
1004 // Finalize Trace Data For Instruction
1005 if (inst
->traceData
) {
1006 //inst->traceData->setCycle(curTick);
1007 inst
->traceData
->setFetchSeq(inst
->seqNum
);
1008 //inst->traceData->setCPSeq(cpu->tcBase(tid)->numInst);
1009 inst
->traceData
->dump();
1010 delete inst
->traceData
;
1011 inst
->traceData
= NULL
;
1014 // Set Last Graduated Instruction In Thread State
1015 //thread[tid]->lastGradInst = inst;
1017 // Increment thread-state's instruction count
1018 thread
[tid
]->numInst
++;
1020 // Increment thread-state's instruction stats
1021 thread
[tid
]->numInsts
++;
1023 // Count committed insts per thread stats
1024 committedInsts
[tid
]++;
1026 // Count total insts committed stat
1027 totalCommittedInsts
++;
1029 // Count SMT-committed insts per thread stat
1030 if (numActiveThreads() > 1) {
1031 smtCommittedInsts
[tid
]++;
1034 // Check for instruction-count-based events.
1035 comInstEventQueue
[tid
]->serviceEvents(thread
[tid
]->numInst
);
1037 // Broadcast to other resources an instruction
1038 // has been completed
1039 resPool
->scheduleEvent((CPUEventType
)ResourcePool::InstGraduated
, inst
, tid
);
1041 // Finally, remove instruction from CPU
1046 InOrderCPU::addToRemoveList(DynInstPtr
&inst
)
1048 removeInstsThisCycle
= true;
1050 removeList
.push(inst
->getInstListIt());
1054 InOrderCPU::removeInst(DynInstPtr
&inst
)
1056 DPRINTF(InOrderCPU
, "Removing graduated instruction [tid:%i] PC %#x "
1058 inst
->threadNumber
, inst
->readPC(), inst
->seqNum
);
1060 removeInstsThisCycle
= true;
1062 // Remove the instruction.
1063 removeList
.push(inst
->getInstListIt());
1067 InOrderCPU::removeInstsUntil(const InstSeqNum
&seq_num
,
1070 //assert(!instList[tid].empty());
1072 removeInstsThisCycle
= true;
1074 ListIt inst_iter
= instList
[tid
].end();
1078 DPRINTF(InOrderCPU
, "Deleting instructions from CPU instruction "
1079 "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
1080 tid
, seq_num
, (*inst_iter
)->seqNum
);
1082 while ((*inst_iter
)->seqNum
> seq_num
) {
1084 bool break_loop
= (inst_iter
== instList
[tid
].begin());
1086 squashInstIt(inst_iter
, tid
);
1097 InOrderCPU::squashInstIt(const ListIt
&instIt
, const unsigned &tid
)
1099 if ((*instIt
)->threadNumber
== tid
) {
1100 DPRINTF(InOrderCPU
, "Squashing instruction, "
1101 "[tid:%i] [sn:%lli] PC %#x\n",
1102 (*instIt
)->threadNumber
,
1104 (*instIt
)->readPC());
1106 (*instIt
)->setSquashed();
1108 removeList
.push(instIt
);
1114 InOrderCPU::cleanUpRemovedInsts()
1116 while (!removeList
.empty()) {
1117 DPRINTF(InOrderCPU
, "Removing instruction, "
1118 "[tid:%i] [sn:%lli] PC %#x\n",
1119 (*removeList
.front())->threadNumber
,
1120 (*removeList
.front())->seqNum
,
1121 (*removeList
.front())->readPC());
1123 DynInstPtr inst
= *removeList
.front();
1124 int tid
= inst
->threadNumber
;
1126 // Make Sure Resource Schedule Is Emptied Out
1127 ThePipeline::ResSchedule
*inst_sched
= &inst
->resSched
;
1128 while (!inst_sched
->empty()) {
1129 ThePipeline::ScheduleEntry
* sch_entry
= inst_sched
->top();
1134 // Remove From Register Dependency Map, If Necessary
1135 archRegDepMap
[(*removeList
.front())->threadNumber
].
1136 remove((*removeList
.front()));
1139 // Clear if Non-Speculative
1140 if (inst
->staticInst
&&
1141 inst
->seqNum
== nonSpecSeqNum
[tid
] &&
1142 nonSpecInstActive
[tid
] == true) {
1143 nonSpecInstActive
[tid
] = false;
1146 instList
[tid
].erase(removeList
.front());
1150 DPRINTF(RefCount
, "pop from remove list: [sn:%i]: Refcount = %i.\n",
1152 0/*inst->curCount()*/);
1156 removeInstsThisCycle
= false;
1160 InOrderCPU::cleanUpRemovedReqs()
1162 while (!reqRemoveList
.empty()) {
1163 ResourceRequest
*res_req
= reqRemoveList
.front();
1165 DPRINTF(RefCount
, "[tid:%i]: Removing Request, "
1166 "[sn:%lli] [slot:%i] [stage_num:%i] [res:%s] [refcount:%i].\n",
1167 res_req
->inst
->threadNumber
,
1168 res_req
->inst
->seqNum
,
1170 res_req
->getStageNum(),
1171 res_req
->res
->name(),
1172 0/*res_req->inst->curCount()*/);
1174 reqRemoveList
.pop();
1178 DPRINTF(RefCount
, "after remove request: [sn:%i]: Refcount = %i.\n",
1179 res_req
->inst
->seqNum
,
1180 0/*res_req->inst->curCount()*/);
1185 InOrderCPU::cleanUpRemovedEvents()
1187 while (!cpuEventRemoveList
.empty()) {
1188 Event
*cpu_event
= cpuEventRemoveList
.front();
1189 cpuEventRemoveList
.pop();
1196 InOrderCPU::dumpInsts()
1200 ListIt inst_list_it
= instList
[0].begin();
1202 cprintf("Dumping Instruction List\n");
1204 while (inst_list_it
!= instList
[0].end()) {
1205 cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
1207 num
, (*inst_list_it
)->readPC(), (*inst_list_it
)->threadNumber
,
1208 (*inst_list_it
)->seqNum
, (*inst_list_it
)->isIssued(),
1209 (*inst_list_it
)->isSquashed());
1216 InOrderCPU::wakeCPU()
1218 if (/*activityRec.active() || */tickEvent
.scheduled()) {
1219 DPRINTF(Activity
, "CPU already running.\n");
1223 DPRINTF(Activity
, "Waking up CPU\n");
1225 //@todo: figure out how to count idleCycles correctly
1226 //idleCycles += (curTick - 1) - lastRunningCycle;
1228 mainEventQueue
.schedule(&tickEvent
, curTick
);
1232 InOrderCPU::syscall(int64_t callnum
, int tid
)
1234 DPRINTF(InOrderCPU
, "[tid:%i] Executing syscall().\n\n", tid
);
1236 DPRINTF(Activity
,"Activity: syscall() called.\n");
1238 // Temporarily increase this by one to account for the syscall
1240 ++(this->thread
[tid
]->funcExeInst
);
1242 // Execute the actual syscall.
1243 this->thread
[tid
]->syscall(callnum
);
1245 // Decrease funcExeInst by one as the normal commit will handle
1247 --(this->thread
[tid
]->funcExeInst
);
1249 // Clear Non-Speculative Block Variable
1250 nonSpecInstActive
[tid
] = false;
1254 InOrderCPU::read(DynInstPtr inst
)
1256 Resource
*mem_res
= resPool
->getResource(dataPortIdx
);
1257 return mem_res
->doDataAccess(inst
);
1261 InOrderCPU::write(DynInstPtr inst
)
1263 Resource
*mem_res
= resPool
->getResource(dataPortIdx
);
1264 return mem_res
->doDataAccess(inst
);
1268 InOrderCPU::prefetch(DynInstPtr inst
)
1270 Resource
*mem_res
= resPool
->getResource(dataPortIdx
);
1271 return mem_res
->prefetch(inst
);
1275 InOrderCPU::writeHint(DynInstPtr inst
)
1277 Resource
*mem_res
= resPool
->getResource(dataPortIdx
);
1278 return mem_res
->writeHint(inst
);
1283 InOrderCPU::getITBPtr()
1285 TLBUnit
*itb_res
= dynamic_cast<TLBUnit
*>(resPool
->getResource(itbIdx
));
1286 return itb_res
->tlb();
1291 InOrderCPU::getDTBPtr()
1293 TLBUnit
*dtb_res
= dynamic_cast<TLBUnit
*>(resPool
->getResource(dtbIdx
));
1294 return dtb_res
->tlb();