cpu.hh (5707:da86e00f87a0) cpu.hh (5712:199d31b47f7b)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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: Kevin Lim
29 * Korey Sewell
30 */
31
32#ifndef __CPU_O3_CPU_HH__
33#define __CPU_O3_CPU_HH__
34
35#include <iostream>
36#include <list>
37#include <queue>
38#include <set>
39#include <vector>
40
41#include "arch/types.hh"
42#include "base/statistics.hh"
43#include "base/timebuf.hh"
44#include "config/full_system.hh"
45#include "config/use_checker.hh"
46#include "cpu/activity.hh"
47#include "cpu/base.hh"
48#include "cpu/simple_thread.hh"
49#include "cpu/o3/comm.hh"
50#include "cpu/o3/cpu_policy.hh"
51#include "cpu/o3/scoreboard.hh"
52#include "cpu/o3/thread_state.hh"
53//#include "cpu/o3/thread_context.hh"
54#include "sim/process.hh"
55
56#include "params/DerivO3CPU.hh"
57
58template <class>
59class Checker;
60class ThreadContext;
61template <class>
62class O3ThreadContext;
63
64class Checkpoint;
65class MemObject;
66class Process;
67
68class BaseCPUParams;
69
70class BaseO3CPU : public BaseCPU
71{
72 //Stuff that's pretty ISA independent will go here.
73 public:
74 BaseO3CPU(BaseCPUParams *params);
75
76 void regStats();
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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: Kevin Lim
29 * Korey Sewell
30 */
31
32#ifndef __CPU_O3_CPU_HH__
33#define __CPU_O3_CPU_HH__
34
35#include <iostream>
36#include <list>
37#include <queue>
38#include <set>
39#include <vector>
40
41#include "arch/types.hh"
42#include "base/statistics.hh"
43#include "base/timebuf.hh"
44#include "config/full_system.hh"
45#include "config/use_checker.hh"
46#include "cpu/activity.hh"
47#include "cpu/base.hh"
48#include "cpu/simple_thread.hh"
49#include "cpu/o3/comm.hh"
50#include "cpu/o3/cpu_policy.hh"
51#include "cpu/o3/scoreboard.hh"
52#include "cpu/o3/thread_state.hh"
53//#include "cpu/o3/thread_context.hh"
54#include "sim/process.hh"
55
56#include "params/DerivO3CPU.hh"
57
58template <class>
59class Checker;
60class ThreadContext;
61template <class>
62class O3ThreadContext;
63
64class Checkpoint;
65class MemObject;
66class Process;
67
68class BaseCPUParams;
69
70class BaseO3CPU : public BaseCPU
71{
72 //Stuff that's pretty ISA independent will go here.
73 public:
74 BaseO3CPU(BaseCPUParams *params);
75
76 void regStats();
77
78 /** Sets this CPU's ID. */
79 void setCpuId(int id) { cpuId = id; }
80
81 /** Reads this CPU's ID. */
82 int readCpuId() { return cpuId; }
83
84 protected:
85 int cpuId;
86};
87
88/**
89 * FullO3CPU class, has each of the stages (fetch through commit)
90 * within it, as well as all of the time buffers between stages. The
91 * tick() function for the CPU is defined here.
92 */
93template <class Impl>
94class FullO3CPU : public BaseO3CPU
95{
96 public:
97 // Typedefs from the Impl here.
98 typedef typename Impl::CPUPol CPUPolicy;
99 typedef typename Impl::DynInstPtr DynInstPtr;
100 typedef typename Impl::O3CPU O3CPU;
101
102 typedef O3ThreadState<Impl> ImplState;
103 typedef O3ThreadState<Impl> Thread;
104
105 typedef typename std::list<DynInstPtr>::iterator ListIt;
106
107 friend class O3ThreadContext<Impl>;
108
109 public:
110 enum Status {
111 Running,
112 Idle,
113 Halted,
114 Blocked,
115 SwitchedOut
116 };
117
118 TheISA::ITB * itb;
119 TheISA::DTB * dtb;
120
121 /** Overall CPU status. */
122 Status _status;
123
124 /** Per-thread status in CPU, used for SMT. */
125 Status _threadStatus[Impl::MaxThreads];
126
127 private:
128 class TickEvent : public Event
129 {
130 private:
131 /** Pointer to the CPU. */
132 FullO3CPU<Impl> *cpu;
133
134 public:
135 /** Constructs a tick event. */
136 TickEvent(FullO3CPU<Impl> *c);
137
138 /** Processes a tick event, calling tick() on the CPU. */
139 void process();
140 /** Returns the description of the tick event. */
141 const char *description() const;
142 };
143
144 /** The tick event used for scheduling CPU ticks. */
145 TickEvent tickEvent;
146
147 /** Schedule tick event, regardless of its current state. */
148 void scheduleTickEvent(int delay)
149 {
150 if (tickEvent.squashed())
151 reschedule(tickEvent, nextCycle(curTick + ticks(delay)));
152 else if (!tickEvent.scheduled())
153 schedule(tickEvent, nextCycle(curTick + ticks(delay)));
154 }
155
156 /** Unschedule tick event, regardless of its current state. */
157 void unscheduleTickEvent()
158 {
159 if (tickEvent.scheduled())
160 tickEvent.squash();
161 }
162
163 class ActivateThreadEvent : public Event
164 {
165 private:
166 /** Number of Thread to Activate */
167 int tid;
168
169 /** Pointer to the CPU. */
170 FullO3CPU<Impl> *cpu;
171
172 public:
173 /** Constructs the event. */
174 ActivateThreadEvent();
175
176 /** Initialize Event */
177 void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
178
179 /** Processes the event, calling activateThread() on the CPU. */
180 void process();
181
182 /** Returns the description of the event. */
183 const char *description() const;
184 };
185
186 /** Schedule thread to activate , regardless of its current state. */
187 void scheduleActivateThreadEvent(int tid, int delay)
188 {
189 // Schedule thread to activate, regardless of its current state.
190 if (activateThreadEvent[tid].squashed())
191 reschedule(activateThreadEvent[tid],
192 nextCycle(curTick + ticks(delay)));
193 else if (!activateThreadEvent[tid].scheduled())
194 schedule(activateThreadEvent[tid],
195 nextCycle(curTick + ticks(delay)));
196 }
197
198 /** Unschedule actiavte thread event, regardless of its current state. */
199 void unscheduleActivateThreadEvent(int tid)
200 {
201 if (activateThreadEvent[tid].scheduled())
202 activateThreadEvent[tid].squash();
203 }
204
205#if !FULL_SYSTEM
206 TheISA::IntReg getSyscallArg(int i, int tid);
207
208 /** Used to shift args for indirect syscall. */
209 void setSyscallArg(int i, TheISA::IntReg val, int tid);
210#endif
211
212 /** The tick event used for scheduling CPU ticks. */
213 ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];
214
215 class DeallocateContextEvent : public Event
216 {
217 private:
218 /** Number of Thread to deactivate */
219 int tid;
220
221 /** Should the thread be removed from the CPU? */
222 bool remove;
223
224 /** Pointer to the CPU. */
225 FullO3CPU<Impl> *cpu;
226
227 public:
228 /** Constructs the event. */
229 DeallocateContextEvent();
230
231 /** Initialize Event */
232 void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
233
234 /** Processes the event, calling activateThread() on the CPU. */
235 void process();
236
237 /** Sets whether the thread should also be removed from the CPU. */
238 void setRemove(bool _remove) { remove = _remove; }
239
240 /** Returns the description of the event. */
241 const char *description() const;
242 };
243
244 /** Schedule cpu to deallocate thread context.*/
245 void scheduleDeallocateContextEvent(int tid, bool remove, int delay)
246 {
247 // Schedule thread to activate, regardless of its current state.
248 if (deallocateContextEvent[tid].squashed())
249 reschedule(deallocateContextEvent[tid],
250 nextCycle(curTick + ticks(delay)));
251 else if (!deallocateContextEvent[tid].scheduled())
252 schedule(deallocateContextEvent[tid],
253 nextCycle(curTick + ticks(delay)));
254 }
255
256 /** Unschedule thread deallocation in CPU */
257 void unscheduleDeallocateContextEvent(int tid)
258 {
259 if (deallocateContextEvent[tid].scheduled())
260 deallocateContextEvent[tid].squash();
261 }
262
263 /** The tick event used for scheduling CPU ticks. */
264 DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];
265
266 public:
267 /** Constructs a CPU with the given parameters. */
268 FullO3CPU(DerivO3CPUParams *params);
269 /** Destructor. */
270 ~FullO3CPU();
271
272 /** Registers statistics. */
273 void regStats();
274
275 void demapPage(Addr vaddr, uint64_t asn)
276 {
277 this->itb->demapPage(vaddr, asn);
278 this->dtb->demapPage(vaddr, asn);
279 }
280
281 void demapInstPage(Addr vaddr, uint64_t asn)
282 {
283 this->itb->demapPage(vaddr, asn);
284 }
285
286 void demapDataPage(Addr vaddr, uint64_t asn)
287 {
288 this->dtb->demapPage(vaddr, asn);
289 }
290
291 /** Translates instruction requestion. */
292 Fault translateInstReq(RequestPtr &req, Thread *thread)
293 {
294 return this->itb->translate(req, thread->getTC());
295 }
296
297 /** Translates data read request. */
298 Fault translateDataReadReq(RequestPtr &req, Thread *thread)
299 {
300 return this->dtb->translate(req, thread->getTC(), false);
301 }
302
303 /** Translates data write request. */
304 Fault translateDataWriteReq(RequestPtr &req, Thread *thread)
305 {
306 return this->dtb->translate(req, thread->getTC(), true);
307 }
308
309 /** Returns a specific port. */
310 Port *getPort(const std::string &if_name, int idx);
311
312 /** Ticks CPU, calling tick() on each stage, and checking the overall
313 * activity to see if the CPU should deschedule itself.
314 */
315 void tick();
316
317 /** Initialize the CPU */
318 void init();
319
320 /** Returns the Number of Active Threads in the CPU */
321 int numActiveThreads()
322 { return activeThreads.size(); }
323
324 /** Add Thread to Active Threads List */
325 void activateThread(unsigned tid);
326
327 /** Remove Thread from Active Threads List */
328 void deactivateThread(unsigned tid);
329
330 /** Setup CPU to insert a thread's context */
331 void insertThread(unsigned tid);
332
333 /** Remove all of a thread's context from CPU */
334 void removeThread(unsigned tid);
335
336 /** Count the Total Instructions Committed in the CPU. */
337 virtual Counter totalInstructions() const
338 {
339 Counter total(0);
340
341 for (int i=0; i < thread.size(); i++)
342 total += thread[i]->numInst;
343
344 return total;
345 }
346
347 /** Add Thread to Active Threads List. */
348 void activateContext(int tid, int delay);
349
350 /** Remove Thread from Active Threads List */
351 void suspendContext(int tid);
352
353 /** Remove Thread from Active Threads List &&
354 * Possibly Remove Thread Context from CPU.
355 */
356 bool deallocateContext(int tid, bool remove, int delay = 1);
357
358 /** Remove Thread from Active Threads List &&
359 * Remove Thread Context from CPU.
360 */
361 void haltContext(int tid);
362
363 /** Activate a Thread When CPU Resources are Available. */
364 void activateWhenReady(int tid);
365
366 /** Add or Remove a Thread Context in the CPU. */
367 void doContextSwitch();
368
369 /** Update The Order In Which We Process Threads. */
370 void updateThreadPriority();
371
372 /** Serialize state. */
373 virtual void serialize(std::ostream &os);
374
375 /** Unserialize from a checkpoint. */
376 virtual void unserialize(Checkpoint *cp, const std::string &section);
377
378 public:
379#if !FULL_SYSTEM
380 /** Executes a syscall.
381 * @todo: Determine if this needs to be virtual.
382 */
383 void syscall(int64_t callnum, int tid);
384
385 /** Sets the return value of a syscall. */
386 void setSyscallReturn(SyscallReturn return_value, int tid);
387
388#endif
389
390 /** Starts draining the CPU's pipeline of all instructions in
391 * order to stop all memory accesses. */
392 virtual unsigned int drain(Event *drain_event);
393
394 /** Resumes execution after a drain. */
395 virtual void resume();
396
397 /** Signals to this CPU that a stage has completed switching out. */
398 void signalDrained();
399
400 /** Switches out this CPU. */
401 virtual void switchOut();
402
403 /** Takes over from another CPU. */
404 virtual void takeOverFrom(BaseCPU *oldCPU);
405
406 /** Get the current instruction sequence number, and increment it. */
407 InstSeqNum getAndIncrementInstSeq()
408 { return globalSeqNum++; }
409
410 /** Traps to handle given fault. */
411 void trap(Fault fault, unsigned tid);
412
413#if FULL_SYSTEM
414 /** Posts an interrupt. */
415 void postInterrupt(int int_num, int index);
416
417 /** HW return from error interrupt. */
418 Fault hwrei(unsigned tid);
419
420 bool simPalCheck(int palFunc, unsigned tid);
421
422 /** Returns the Fault for any valid interrupt. */
423 Fault getInterrupts();
424
425 /** Processes any an interrupt fault. */
426 void processInterrupts(Fault interrupt);
427
428 /** Halts the CPU. */
429 void halt() { panic("Halt not implemented!\n"); }
430
431 /** Update the Virt and Phys ports of all ThreadContexts to
432 * reflect change in memory connections. */
433 void updateMemPorts();
434
435 /** Check if this address is a valid instruction address. */
436 bool validInstAddr(Addr addr) { return true; }
437
438 /** Check if this address is a valid data address. */
439 bool validDataAddr(Addr addr) { return true; }
440
441 /** Get instruction asid. */
442 int getInstAsid(unsigned tid)
443 { return regFile.miscRegs[tid].getInstAsid(); }
444
445 /** Get data asid. */
446 int getDataAsid(unsigned tid)
447 { return regFile.miscRegs[tid].getDataAsid(); }
448#else
449 /** Get instruction asid. */
450 int getInstAsid(unsigned tid)
451 { return thread[tid]->getInstAsid(); }
452
453 /** Get data asid. */
454 int getDataAsid(unsigned tid)
455 { return thread[tid]->getDataAsid(); }
456
457#endif
458
459 /** Register accessors. Index refers to the physical register index. */
460
461 /** Reads a miscellaneous register. */
462 TheISA::MiscReg readMiscRegNoEffect(int misc_reg, unsigned tid);
463
464 /** Reads a misc. register, including any side effects the read
465 * might have as defined by the architecture.
466 */
467 TheISA::MiscReg readMiscReg(int misc_reg, unsigned tid);
468
469 /** Sets a miscellaneous register. */
470 void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val, unsigned tid);
471
472 /** Sets a misc. register, including any side effects the write
473 * might have as defined by the architecture.
474 */
475 void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
476 unsigned tid);
477
478 uint64_t readIntReg(int reg_idx);
479
480 TheISA::FloatReg readFloatReg(int reg_idx);
481
482 TheISA::FloatReg readFloatReg(int reg_idx, int width);
483
484 TheISA::FloatRegBits readFloatRegBits(int reg_idx);
485
486 TheISA::FloatRegBits readFloatRegBits(int reg_idx, int width);
487
488 void setIntReg(int reg_idx, uint64_t val);
489
490 void setFloatReg(int reg_idx, TheISA::FloatReg val);
491
492 void setFloatReg(int reg_idx, TheISA::FloatReg val, int width);
493
494 void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
495
496 void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val, int width);
497
498 uint64_t readArchIntReg(int reg_idx, unsigned tid);
499
500 float readArchFloatRegSingle(int reg_idx, unsigned tid);
501
502 double readArchFloatRegDouble(int reg_idx, unsigned tid);
503
504 uint64_t readArchFloatRegInt(int reg_idx, unsigned tid);
505
506 /** Architectural register accessors. Looks up in the commit
507 * rename table to obtain the true physical index of the
508 * architected register first, then accesses that physical
509 * register.
510 */
511 void setArchIntReg(int reg_idx, uint64_t val, unsigned tid);
512
513 void setArchFloatRegSingle(int reg_idx, float val, unsigned tid);
514
515 void setArchFloatRegDouble(int reg_idx, double val, unsigned tid);
516
517 void setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid);
518
519 /** Reads the commit PC of a specific thread. */
520 Addr readPC(unsigned tid);
521
522 /** Sets the commit PC of a specific thread. */
523 void setPC(Addr new_PC, unsigned tid);
524
525 /** Reads the commit micro PC of a specific thread. */
526 Addr readMicroPC(unsigned tid);
527
528 /** Sets the commmit micro PC of a specific thread. */
529 void setMicroPC(Addr new_microPC, unsigned tid);
530
531 /** Reads the next PC of a specific thread. */
532 Addr readNextPC(unsigned tid);
533
534 /** Sets the next PC of a specific thread. */
535 void setNextPC(Addr val, unsigned tid);
536
537 /** Reads the next NPC of a specific thread. */
538 Addr readNextNPC(unsigned tid);
539
540 /** Sets the next NPC of a specific thread. */
541 void setNextNPC(Addr val, unsigned tid);
542
543 /** Reads the commit next micro PC of a specific thread. */
544 Addr readNextMicroPC(unsigned tid);
545
546 /** Sets the commit next micro PC of a specific thread. */
547 void setNextMicroPC(Addr val, unsigned tid);
548
549 /** Initiates a squash of all in-flight instructions for a given
550 * thread. The source of the squash is an external update of
551 * state through the TC.
552 */
553 void squashFromTC(unsigned tid);
554
555 /** Function to add instruction onto the head of the list of the
556 * instructions. Used when new instructions are fetched.
557 */
558 ListIt addInst(DynInstPtr &inst);
559
560 /** Function to tell the CPU that an instruction has completed. */
561 void instDone(unsigned tid);
562
563 /** Add Instructions to the CPU Remove List*/
564 void addToRemoveList(DynInstPtr &inst);
565
566 /** Remove an instruction from the front end of the list. There's
567 * no restriction on location of the instruction.
568 */
569 void removeFrontInst(DynInstPtr &inst);
570
571 /** Remove all instructions that are not currently in the ROB.
572 * There's also an option to not squash delay slot instructions.*/
573 void removeInstsNotInROB(unsigned tid);
574
575 /** Remove all instructions younger than the given sequence number. */
576 void removeInstsUntil(const InstSeqNum &seq_num,unsigned tid);
577
578 /** Removes the instruction pointed to by the iterator. */
579 inline void squashInstIt(const ListIt &instIt, const unsigned &tid);
580
581 /** Cleans up all instructions on the remove list. */
582 void cleanUpRemovedInsts();
583
584 /** Debug function to print all instructions on the list. */
585 void dumpInsts();
586
587 public:
588 /** List of all the instructions in flight. */
589 std::list<DynInstPtr> instList;
590
591 /** List of all the instructions that will be removed at the end of this
592 * cycle.
593 */
594 std::queue<ListIt> removeList;
595
596#ifdef DEBUG
597 /** Debug structure to keep track of the sequence numbers still in
598 * flight.
599 */
600 std::set<InstSeqNum> snList;
601#endif
602
603 /** Records if instructions need to be removed this cycle due to
604 * being retired or squashed.
605 */
606 bool removeInstsThisCycle;
607
608 protected:
609 /** The fetch stage. */
610 typename CPUPolicy::Fetch fetch;
611
612 /** The decode stage. */
613 typename CPUPolicy::Decode decode;
614
615 /** The dispatch stage. */
616 typename CPUPolicy::Rename rename;
617
618 /** The issue/execute/writeback stages. */
619 typename CPUPolicy::IEW iew;
620
621 /** The commit stage. */
622 typename CPUPolicy::Commit commit;
623
624 /** The register file. */
625 typename CPUPolicy::RegFile regFile;
626
627 /** The free list. */
628 typename CPUPolicy::FreeList freeList;
629
630 /** The rename map. */
631 typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
632
633 /** The commit rename map. */
634 typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
635
636 /** The re-order buffer. */
637 typename CPUPolicy::ROB rob;
638
639 /** Active Threads List */
640 std::list<unsigned> activeThreads;
641
642 /** Integer Register Scoreboard */
643 Scoreboard scoreboard;
644
645 public:
646 /** Enum to give each stage a specific index, so when calling
647 * activateStage() or deactivateStage(), they can specify which stage
648 * is being activated/deactivated.
649 */
650 enum StageIdx {
651 FetchIdx,
652 DecodeIdx,
653 RenameIdx,
654 IEWIdx,
655 CommitIdx,
656 NumStages };
657
658 /** Typedefs from the Impl to get the structs that each of the
659 * time buffers should use.
660 */
661 typedef typename CPUPolicy::TimeStruct TimeStruct;
662
663 typedef typename CPUPolicy::FetchStruct FetchStruct;
664
665 typedef typename CPUPolicy::DecodeStruct DecodeStruct;
666
667 typedef typename CPUPolicy::RenameStruct RenameStruct;
668
669 typedef typename CPUPolicy::IEWStruct IEWStruct;
670
671 /** The main time buffer to do backwards communication. */
672 TimeBuffer<TimeStruct> timeBuffer;
673
674 /** The fetch stage's instruction queue. */
675 TimeBuffer<FetchStruct> fetchQueue;
676
677 /** The decode stage's instruction queue. */
678 TimeBuffer<DecodeStruct> decodeQueue;
679
680 /** The rename stage's instruction queue. */
681 TimeBuffer<RenameStruct> renameQueue;
682
683 /** The IEW stage's instruction queue. */
684 TimeBuffer<IEWStruct> iewQueue;
685
686 private:
687 /** The activity recorder; used to tell if the CPU has any
688 * activity remaining or if it can go to idle and deschedule
689 * itself.
690 */
691 ActivityRecorder activityRec;
692
693 public:
694 /** Records that there was time buffer activity this cycle. */
695 void activityThisCycle() { activityRec.activity(); }
696
697 /** Changes a stage's status to active within the activity recorder. */
698 void activateStage(const StageIdx idx)
699 { activityRec.activateStage(idx); }
700
701 /** Changes a stage's status to inactive within the activity recorder. */
702 void deactivateStage(const StageIdx idx)
703 { activityRec.deactivateStage(idx); }
704
705 /** Wakes the CPU, rescheduling the CPU if it's not already active. */
706 void wakeCPU();
707
708 /** Gets a free thread id. Use if thread ids change across system. */
709 int getFreeTid();
710
711 public:
712 /** Returns a pointer to a thread context. */
713 ThreadContext *tcBase(unsigned tid)
714 {
715 return thread[tid]->getTC();
716 }
717
718 /** The global sequence number counter. */
719 InstSeqNum globalSeqNum;//[Impl::MaxThreads];
720
721#if USE_CHECKER
722 /** Pointer to the checker, which can dynamically verify
723 * instruction results at run time. This can be set to NULL if it
724 * is not being used.
725 */
726 Checker<DynInstPtr> *checker;
727#endif
728
729#if FULL_SYSTEM
730 /** Pointer to the system. */
731 System *system;
732
733 /** Pointer to physical memory. */
734 PhysicalMemory *physmem;
735#endif
736
737 /** Event to call process() on once draining has completed. */
738 Event *drainEvent;
739
740 /** Counter of how many stages have completed draining. */
741 int drainCount;
742
743 /** Pointers to all of the threads in the CPU. */
744 std::vector<Thread *> thread;
745
746 /** Whether or not the CPU should defer its registration. */
747 bool deferRegistration;
748
749 /** Is there a context switch pending? */
750 bool contextSwitch;
751
752 /** Threads Scheduled to Enter CPU */
753 std::list<int> cpuWaitList;
754
755 /** The cycle that the CPU was last running, used for statistics. */
756 Tick lastRunningCycle;
757
758 /** The cycle that the CPU was last activated by a new thread*/
759 Tick lastActivatedCycle;
760
761 /** Number of Threads CPU can process */
762 unsigned numThreads;
763
764 /** Mapping for system thread id to cpu id */
765 std::map<unsigned,unsigned> threadMap;
766
767 /** Available thread ids in the cpu*/
768 std::vector<unsigned> tids;
769
770 /** CPU read function, forwards read to LSQ. */
771 template <class T>
772 Fault read(RequestPtr &req, T &data, int load_idx)
773 {
774 return this->iew.ldstQueue.read(req, data, load_idx);
775 }
776
777 /** CPU write function, forwards write to LSQ. */
778 template <class T>
779 Fault write(RequestPtr &req, T &data, int store_idx)
780 {
781 return this->iew.ldstQueue.write(req, data, store_idx);
782 }
783
784 Addr lockAddr;
785
786 /** Temporary fix for the lock flag, works in the UP case. */
787 bool lockFlag;
788
789 /** Stat for total number of times the CPU is descheduled. */
790 Stats::Scalar<> timesIdled;
791 /** Stat for total number of cycles the CPU spends descheduled. */
792 Stats::Scalar<> idleCycles;
793 /** Stat for the number of committed instructions per thread. */
794 Stats::Vector<> committedInsts;
795 /** Stat for the total number of committed instructions. */
796 Stats::Scalar<> totalCommittedInsts;
797 /** Stat for the CPI per thread. */
798 Stats::Formula cpi;
799 /** Stat for the total CPI. */
800 Stats::Formula totalCpi;
801 /** Stat for the IPC per thread. */
802 Stats::Formula ipc;
803 /** Stat for the total IPC. */
804 Stats::Formula totalIpc;
805};
806
807#endif // __CPU_O3_CPU_HH__
77};
78
79/**
80 * FullO3CPU class, has each of the stages (fetch through commit)
81 * within it, as well as all of the time buffers between stages. The
82 * tick() function for the CPU is defined here.
83 */
84template <class Impl>
85class FullO3CPU : public BaseO3CPU
86{
87 public:
88 // Typedefs from the Impl here.
89 typedef typename Impl::CPUPol CPUPolicy;
90 typedef typename Impl::DynInstPtr DynInstPtr;
91 typedef typename Impl::O3CPU O3CPU;
92
93 typedef O3ThreadState<Impl> ImplState;
94 typedef O3ThreadState<Impl> Thread;
95
96 typedef typename std::list<DynInstPtr>::iterator ListIt;
97
98 friend class O3ThreadContext<Impl>;
99
100 public:
101 enum Status {
102 Running,
103 Idle,
104 Halted,
105 Blocked,
106 SwitchedOut
107 };
108
109 TheISA::ITB * itb;
110 TheISA::DTB * dtb;
111
112 /** Overall CPU status. */
113 Status _status;
114
115 /** Per-thread status in CPU, used for SMT. */
116 Status _threadStatus[Impl::MaxThreads];
117
118 private:
119 class TickEvent : public Event
120 {
121 private:
122 /** Pointer to the CPU. */
123 FullO3CPU<Impl> *cpu;
124
125 public:
126 /** Constructs a tick event. */
127 TickEvent(FullO3CPU<Impl> *c);
128
129 /** Processes a tick event, calling tick() on the CPU. */
130 void process();
131 /** Returns the description of the tick event. */
132 const char *description() const;
133 };
134
135 /** The tick event used for scheduling CPU ticks. */
136 TickEvent tickEvent;
137
138 /** Schedule tick event, regardless of its current state. */
139 void scheduleTickEvent(int delay)
140 {
141 if (tickEvent.squashed())
142 reschedule(tickEvent, nextCycle(curTick + ticks(delay)));
143 else if (!tickEvent.scheduled())
144 schedule(tickEvent, nextCycle(curTick + ticks(delay)));
145 }
146
147 /** Unschedule tick event, regardless of its current state. */
148 void unscheduleTickEvent()
149 {
150 if (tickEvent.scheduled())
151 tickEvent.squash();
152 }
153
154 class ActivateThreadEvent : public Event
155 {
156 private:
157 /** Number of Thread to Activate */
158 int tid;
159
160 /** Pointer to the CPU. */
161 FullO3CPU<Impl> *cpu;
162
163 public:
164 /** Constructs the event. */
165 ActivateThreadEvent();
166
167 /** Initialize Event */
168 void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
169
170 /** Processes the event, calling activateThread() on the CPU. */
171 void process();
172
173 /** Returns the description of the event. */
174 const char *description() const;
175 };
176
177 /** Schedule thread to activate , regardless of its current state. */
178 void scheduleActivateThreadEvent(int tid, int delay)
179 {
180 // Schedule thread to activate, regardless of its current state.
181 if (activateThreadEvent[tid].squashed())
182 reschedule(activateThreadEvent[tid],
183 nextCycle(curTick + ticks(delay)));
184 else if (!activateThreadEvent[tid].scheduled())
185 schedule(activateThreadEvent[tid],
186 nextCycle(curTick + ticks(delay)));
187 }
188
189 /** Unschedule actiavte thread event, regardless of its current state. */
190 void unscheduleActivateThreadEvent(int tid)
191 {
192 if (activateThreadEvent[tid].scheduled())
193 activateThreadEvent[tid].squash();
194 }
195
196#if !FULL_SYSTEM
197 TheISA::IntReg getSyscallArg(int i, int tid);
198
199 /** Used to shift args for indirect syscall. */
200 void setSyscallArg(int i, TheISA::IntReg val, int tid);
201#endif
202
203 /** The tick event used for scheduling CPU ticks. */
204 ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];
205
206 class DeallocateContextEvent : public Event
207 {
208 private:
209 /** Number of Thread to deactivate */
210 int tid;
211
212 /** Should the thread be removed from the CPU? */
213 bool remove;
214
215 /** Pointer to the CPU. */
216 FullO3CPU<Impl> *cpu;
217
218 public:
219 /** Constructs the event. */
220 DeallocateContextEvent();
221
222 /** Initialize Event */
223 void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
224
225 /** Processes the event, calling activateThread() on the CPU. */
226 void process();
227
228 /** Sets whether the thread should also be removed from the CPU. */
229 void setRemove(bool _remove) { remove = _remove; }
230
231 /** Returns the description of the event. */
232 const char *description() const;
233 };
234
235 /** Schedule cpu to deallocate thread context.*/
236 void scheduleDeallocateContextEvent(int tid, bool remove, int delay)
237 {
238 // Schedule thread to activate, regardless of its current state.
239 if (deallocateContextEvent[tid].squashed())
240 reschedule(deallocateContextEvent[tid],
241 nextCycle(curTick + ticks(delay)));
242 else if (!deallocateContextEvent[tid].scheduled())
243 schedule(deallocateContextEvent[tid],
244 nextCycle(curTick + ticks(delay)));
245 }
246
247 /** Unschedule thread deallocation in CPU */
248 void unscheduleDeallocateContextEvent(int tid)
249 {
250 if (deallocateContextEvent[tid].scheduled())
251 deallocateContextEvent[tid].squash();
252 }
253
254 /** The tick event used for scheduling CPU ticks. */
255 DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];
256
257 public:
258 /** Constructs a CPU with the given parameters. */
259 FullO3CPU(DerivO3CPUParams *params);
260 /** Destructor. */
261 ~FullO3CPU();
262
263 /** Registers statistics. */
264 void regStats();
265
266 void demapPage(Addr vaddr, uint64_t asn)
267 {
268 this->itb->demapPage(vaddr, asn);
269 this->dtb->demapPage(vaddr, asn);
270 }
271
272 void demapInstPage(Addr vaddr, uint64_t asn)
273 {
274 this->itb->demapPage(vaddr, asn);
275 }
276
277 void demapDataPage(Addr vaddr, uint64_t asn)
278 {
279 this->dtb->demapPage(vaddr, asn);
280 }
281
282 /** Translates instruction requestion. */
283 Fault translateInstReq(RequestPtr &req, Thread *thread)
284 {
285 return this->itb->translate(req, thread->getTC());
286 }
287
288 /** Translates data read request. */
289 Fault translateDataReadReq(RequestPtr &req, Thread *thread)
290 {
291 return this->dtb->translate(req, thread->getTC(), false);
292 }
293
294 /** Translates data write request. */
295 Fault translateDataWriteReq(RequestPtr &req, Thread *thread)
296 {
297 return this->dtb->translate(req, thread->getTC(), true);
298 }
299
300 /** Returns a specific port. */
301 Port *getPort(const std::string &if_name, int idx);
302
303 /** Ticks CPU, calling tick() on each stage, and checking the overall
304 * activity to see if the CPU should deschedule itself.
305 */
306 void tick();
307
308 /** Initialize the CPU */
309 void init();
310
311 /** Returns the Number of Active Threads in the CPU */
312 int numActiveThreads()
313 { return activeThreads.size(); }
314
315 /** Add Thread to Active Threads List */
316 void activateThread(unsigned tid);
317
318 /** Remove Thread from Active Threads List */
319 void deactivateThread(unsigned tid);
320
321 /** Setup CPU to insert a thread's context */
322 void insertThread(unsigned tid);
323
324 /** Remove all of a thread's context from CPU */
325 void removeThread(unsigned tid);
326
327 /** Count the Total Instructions Committed in the CPU. */
328 virtual Counter totalInstructions() const
329 {
330 Counter total(0);
331
332 for (int i=0; i < thread.size(); i++)
333 total += thread[i]->numInst;
334
335 return total;
336 }
337
338 /** Add Thread to Active Threads List. */
339 void activateContext(int tid, int delay);
340
341 /** Remove Thread from Active Threads List */
342 void suspendContext(int tid);
343
344 /** Remove Thread from Active Threads List &&
345 * Possibly Remove Thread Context from CPU.
346 */
347 bool deallocateContext(int tid, bool remove, int delay = 1);
348
349 /** Remove Thread from Active Threads List &&
350 * Remove Thread Context from CPU.
351 */
352 void haltContext(int tid);
353
354 /** Activate a Thread When CPU Resources are Available. */
355 void activateWhenReady(int tid);
356
357 /** Add or Remove a Thread Context in the CPU. */
358 void doContextSwitch();
359
360 /** Update The Order In Which We Process Threads. */
361 void updateThreadPriority();
362
363 /** Serialize state. */
364 virtual void serialize(std::ostream &os);
365
366 /** Unserialize from a checkpoint. */
367 virtual void unserialize(Checkpoint *cp, const std::string &section);
368
369 public:
370#if !FULL_SYSTEM
371 /** Executes a syscall.
372 * @todo: Determine if this needs to be virtual.
373 */
374 void syscall(int64_t callnum, int tid);
375
376 /** Sets the return value of a syscall. */
377 void setSyscallReturn(SyscallReturn return_value, int tid);
378
379#endif
380
381 /** Starts draining the CPU's pipeline of all instructions in
382 * order to stop all memory accesses. */
383 virtual unsigned int drain(Event *drain_event);
384
385 /** Resumes execution after a drain. */
386 virtual void resume();
387
388 /** Signals to this CPU that a stage has completed switching out. */
389 void signalDrained();
390
391 /** Switches out this CPU. */
392 virtual void switchOut();
393
394 /** Takes over from another CPU. */
395 virtual void takeOverFrom(BaseCPU *oldCPU);
396
397 /** Get the current instruction sequence number, and increment it. */
398 InstSeqNum getAndIncrementInstSeq()
399 { return globalSeqNum++; }
400
401 /** Traps to handle given fault. */
402 void trap(Fault fault, unsigned tid);
403
404#if FULL_SYSTEM
405 /** Posts an interrupt. */
406 void postInterrupt(int int_num, int index);
407
408 /** HW return from error interrupt. */
409 Fault hwrei(unsigned tid);
410
411 bool simPalCheck(int palFunc, unsigned tid);
412
413 /** Returns the Fault for any valid interrupt. */
414 Fault getInterrupts();
415
416 /** Processes any an interrupt fault. */
417 void processInterrupts(Fault interrupt);
418
419 /** Halts the CPU. */
420 void halt() { panic("Halt not implemented!\n"); }
421
422 /** Update the Virt and Phys ports of all ThreadContexts to
423 * reflect change in memory connections. */
424 void updateMemPorts();
425
426 /** Check if this address is a valid instruction address. */
427 bool validInstAddr(Addr addr) { return true; }
428
429 /** Check if this address is a valid data address. */
430 bool validDataAddr(Addr addr) { return true; }
431
432 /** Get instruction asid. */
433 int getInstAsid(unsigned tid)
434 { return regFile.miscRegs[tid].getInstAsid(); }
435
436 /** Get data asid. */
437 int getDataAsid(unsigned tid)
438 { return regFile.miscRegs[tid].getDataAsid(); }
439#else
440 /** Get instruction asid. */
441 int getInstAsid(unsigned tid)
442 { return thread[tid]->getInstAsid(); }
443
444 /** Get data asid. */
445 int getDataAsid(unsigned tid)
446 { return thread[tid]->getDataAsid(); }
447
448#endif
449
450 /** Register accessors. Index refers to the physical register index. */
451
452 /** Reads a miscellaneous register. */
453 TheISA::MiscReg readMiscRegNoEffect(int misc_reg, unsigned tid);
454
455 /** Reads a misc. register, including any side effects the read
456 * might have as defined by the architecture.
457 */
458 TheISA::MiscReg readMiscReg(int misc_reg, unsigned tid);
459
460 /** Sets a miscellaneous register. */
461 void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val, unsigned tid);
462
463 /** Sets a misc. register, including any side effects the write
464 * might have as defined by the architecture.
465 */
466 void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
467 unsigned tid);
468
469 uint64_t readIntReg(int reg_idx);
470
471 TheISA::FloatReg readFloatReg(int reg_idx);
472
473 TheISA::FloatReg readFloatReg(int reg_idx, int width);
474
475 TheISA::FloatRegBits readFloatRegBits(int reg_idx);
476
477 TheISA::FloatRegBits readFloatRegBits(int reg_idx, int width);
478
479 void setIntReg(int reg_idx, uint64_t val);
480
481 void setFloatReg(int reg_idx, TheISA::FloatReg val);
482
483 void setFloatReg(int reg_idx, TheISA::FloatReg val, int width);
484
485 void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
486
487 void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val, int width);
488
489 uint64_t readArchIntReg(int reg_idx, unsigned tid);
490
491 float readArchFloatRegSingle(int reg_idx, unsigned tid);
492
493 double readArchFloatRegDouble(int reg_idx, unsigned tid);
494
495 uint64_t readArchFloatRegInt(int reg_idx, unsigned tid);
496
497 /** Architectural register accessors. Looks up in the commit
498 * rename table to obtain the true physical index of the
499 * architected register first, then accesses that physical
500 * register.
501 */
502 void setArchIntReg(int reg_idx, uint64_t val, unsigned tid);
503
504 void setArchFloatRegSingle(int reg_idx, float val, unsigned tid);
505
506 void setArchFloatRegDouble(int reg_idx, double val, unsigned tid);
507
508 void setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid);
509
510 /** Reads the commit PC of a specific thread. */
511 Addr readPC(unsigned tid);
512
513 /** Sets the commit PC of a specific thread. */
514 void setPC(Addr new_PC, unsigned tid);
515
516 /** Reads the commit micro PC of a specific thread. */
517 Addr readMicroPC(unsigned tid);
518
519 /** Sets the commmit micro PC of a specific thread. */
520 void setMicroPC(Addr new_microPC, unsigned tid);
521
522 /** Reads the next PC of a specific thread. */
523 Addr readNextPC(unsigned tid);
524
525 /** Sets the next PC of a specific thread. */
526 void setNextPC(Addr val, unsigned tid);
527
528 /** Reads the next NPC of a specific thread. */
529 Addr readNextNPC(unsigned tid);
530
531 /** Sets the next NPC of a specific thread. */
532 void setNextNPC(Addr val, unsigned tid);
533
534 /** Reads the commit next micro PC of a specific thread. */
535 Addr readNextMicroPC(unsigned tid);
536
537 /** Sets the commit next micro PC of a specific thread. */
538 void setNextMicroPC(Addr val, unsigned tid);
539
540 /** Initiates a squash of all in-flight instructions for a given
541 * thread. The source of the squash is an external update of
542 * state through the TC.
543 */
544 void squashFromTC(unsigned tid);
545
546 /** Function to add instruction onto the head of the list of the
547 * instructions. Used when new instructions are fetched.
548 */
549 ListIt addInst(DynInstPtr &inst);
550
551 /** Function to tell the CPU that an instruction has completed. */
552 void instDone(unsigned tid);
553
554 /** Add Instructions to the CPU Remove List*/
555 void addToRemoveList(DynInstPtr &inst);
556
557 /** Remove an instruction from the front end of the list. There's
558 * no restriction on location of the instruction.
559 */
560 void removeFrontInst(DynInstPtr &inst);
561
562 /** Remove all instructions that are not currently in the ROB.
563 * There's also an option to not squash delay slot instructions.*/
564 void removeInstsNotInROB(unsigned tid);
565
566 /** Remove all instructions younger than the given sequence number. */
567 void removeInstsUntil(const InstSeqNum &seq_num,unsigned tid);
568
569 /** Removes the instruction pointed to by the iterator. */
570 inline void squashInstIt(const ListIt &instIt, const unsigned &tid);
571
572 /** Cleans up all instructions on the remove list. */
573 void cleanUpRemovedInsts();
574
575 /** Debug function to print all instructions on the list. */
576 void dumpInsts();
577
578 public:
579 /** List of all the instructions in flight. */
580 std::list<DynInstPtr> instList;
581
582 /** List of all the instructions that will be removed at the end of this
583 * cycle.
584 */
585 std::queue<ListIt> removeList;
586
587#ifdef DEBUG
588 /** Debug structure to keep track of the sequence numbers still in
589 * flight.
590 */
591 std::set<InstSeqNum> snList;
592#endif
593
594 /** Records if instructions need to be removed this cycle due to
595 * being retired or squashed.
596 */
597 bool removeInstsThisCycle;
598
599 protected:
600 /** The fetch stage. */
601 typename CPUPolicy::Fetch fetch;
602
603 /** The decode stage. */
604 typename CPUPolicy::Decode decode;
605
606 /** The dispatch stage. */
607 typename CPUPolicy::Rename rename;
608
609 /** The issue/execute/writeback stages. */
610 typename CPUPolicy::IEW iew;
611
612 /** The commit stage. */
613 typename CPUPolicy::Commit commit;
614
615 /** The register file. */
616 typename CPUPolicy::RegFile regFile;
617
618 /** The free list. */
619 typename CPUPolicy::FreeList freeList;
620
621 /** The rename map. */
622 typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
623
624 /** The commit rename map. */
625 typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
626
627 /** The re-order buffer. */
628 typename CPUPolicy::ROB rob;
629
630 /** Active Threads List */
631 std::list<unsigned> activeThreads;
632
633 /** Integer Register Scoreboard */
634 Scoreboard scoreboard;
635
636 public:
637 /** Enum to give each stage a specific index, so when calling
638 * activateStage() or deactivateStage(), they can specify which stage
639 * is being activated/deactivated.
640 */
641 enum StageIdx {
642 FetchIdx,
643 DecodeIdx,
644 RenameIdx,
645 IEWIdx,
646 CommitIdx,
647 NumStages };
648
649 /** Typedefs from the Impl to get the structs that each of the
650 * time buffers should use.
651 */
652 typedef typename CPUPolicy::TimeStruct TimeStruct;
653
654 typedef typename CPUPolicy::FetchStruct FetchStruct;
655
656 typedef typename CPUPolicy::DecodeStruct DecodeStruct;
657
658 typedef typename CPUPolicy::RenameStruct RenameStruct;
659
660 typedef typename CPUPolicy::IEWStruct IEWStruct;
661
662 /** The main time buffer to do backwards communication. */
663 TimeBuffer<TimeStruct> timeBuffer;
664
665 /** The fetch stage's instruction queue. */
666 TimeBuffer<FetchStruct> fetchQueue;
667
668 /** The decode stage's instruction queue. */
669 TimeBuffer<DecodeStruct> decodeQueue;
670
671 /** The rename stage's instruction queue. */
672 TimeBuffer<RenameStruct> renameQueue;
673
674 /** The IEW stage's instruction queue. */
675 TimeBuffer<IEWStruct> iewQueue;
676
677 private:
678 /** The activity recorder; used to tell if the CPU has any
679 * activity remaining or if it can go to idle and deschedule
680 * itself.
681 */
682 ActivityRecorder activityRec;
683
684 public:
685 /** Records that there was time buffer activity this cycle. */
686 void activityThisCycle() { activityRec.activity(); }
687
688 /** Changes a stage's status to active within the activity recorder. */
689 void activateStage(const StageIdx idx)
690 { activityRec.activateStage(idx); }
691
692 /** Changes a stage's status to inactive within the activity recorder. */
693 void deactivateStage(const StageIdx idx)
694 { activityRec.deactivateStage(idx); }
695
696 /** Wakes the CPU, rescheduling the CPU if it's not already active. */
697 void wakeCPU();
698
699 /** Gets a free thread id. Use if thread ids change across system. */
700 int getFreeTid();
701
702 public:
703 /** Returns a pointer to a thread context. */
704 ThreadContext *tcBase(unsigned tid)
705 {
706 return thread[tid]->getTC();
707 }
708
709 /** The global sequence number counter. */
710 InstSeqNum globalSeqNum;//[Impl::MaxThreads];
711
712#if USE_CHECKER
713 /** Pointer to the checker, which can dynamically verify
714 * instruction results at run time. This can be set to NULL if it
715 * is not being used.
716 */
717 Checker<DynInstPtr> *checker;
718#endif
719
720#if FULL_SYSTEM
721 /** Pointer to the system. */
722 System *system;
723
724 /** Pointer to physical memory. */
725 PhysicalMemory *physmem;
726#endif
727
728 /** Event to call process() on once draining has completed. */
729 Event *drainEvent;
730
731 /** Counter of how many stages have completed draining. */
732 int drainCount;
733
734 /** Pointers to all of the threads in the CPU. */
735 std::vector<Thread *> thread;
736
737 /** Whether or not the CPU should defer its registration. */
738 bool deferRegistration;
739
740 /** Is there a context switch pending? */
741 bool contextSwitch;
742
743 /** Threads Scheduled to Enter CPU */
744 std::list<int> cpuWaitList;
745
746 /** The cycle that the CPU was last running, used for statistics. */
747 Tick lastRunningCycle;
748
749 /** The cycle that the CPU was last activated by a new thread*/
750 Tick lastActivatedCycle;
751
752 /** Number of Threads CPU can process */
753 unsigned numThreads;
754
755 /** Mapping for system thread id to cpu id */
756 std::map<unsigned,unsigned> threadMap;
757
758 /** Available thread ids in the cpu*/
759 std::vector<unsigned> tids;
760
761 /** CPU read function, forwards read to LSQ. */
762 template <class T>
763 Fault read(RequestPtr &req, T &data, int load_idx)
764 {
765 return this->iew.ldstQueue.read(req, data, load_idx);
766 }
767
768 /** CPU write function, forwards write to LSQ. */
769 template <class T>
770 Fault write(RequestPtr &req, T &data, int store_idx)
771 {
772 return this->iew.ldstQueue.write(req, data, store_idx);
773 }
774
775 Addr lockAddr;
776
777 /** Temporary fix for the lock flag, works in the UP case. */
778 bool lockFlag;
779
780 /** Stat for total number of times the CPU is descheduled. */
781 Stats::Scalar<> timesIdled;
782 /** Stat for total number of cycles the CPU spends descheduled. */
783 Stats::Scalar<> idleCycles;
784 /** Stat for the number of committed instructions per thread. */
785 Stats::Vector<> committedInsts;
786 /** Stat for the total number of committed instructions. */
787 Stats::Scalar<> totalCommittedInsts;
788 /** Stat for the CPI per thread. */
789 Stats::Formula cpi;
790 /** Stat for the total CPI. */
791 Stats::Formula totalCpi;
792 /** Stat for the IPC per thread. */
793 Stats::Formula ipc;
794 /** Stat for the total IPC. */
795 Stats::Formula totalIpc;
796};
797
798#endif // __CPU_O3_CPU_HH__