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