Merge with head, hopefully the last time for this batch.
[gem5.git] / src / cpu / inorder / cpu.hh
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 #ifndef __CPU_INORDER_CPU_HH__
33 #define __CPU_INORDER_CPU_HH__
34
35 #include <iostream>
36 #include <list>
37 #include <queue>
38 #include <set>
39 #include <vector>
40
41 #include "arch/isa_traits.hh"
42 #include "arch/registers.hh"
43 #include "arch/types.hh"
44 #include "base/statistics.hh"
45 #include "base/types.hh"
46 #include "config/the_isa.hh"
47 #include "cpu/inorder/inorder_dyn_inst.hh"
48 #include "cpu/inorder/pipeline_stage.hh"
49 #include "cpu/inorder/pipeline_traits.hh"
50 #include "cpu/inorder/reg_dep_map.hh"
51 #include "cpu/inorder/thread_state.hh"
52 #include "cpu/o3/dep_graph.hh"
53 #include "cpu/o3/rename_map.hh"
54 #include "cpu/activity.hh"
55 #include "cpu/base.hh"
56 #include "cpu/simple_thread.hh"
57 #include "cpu/timebuf.hh"
58 #include "mem/packet.hh"
59 #include "mem/port.hh"
60 #include "mem/request.hh"
61 #include "sim/eventq.hh"
62 #include "sim/process.hh"
63
64 class ThreadContext;
65 class MemInterface;
66 class MemObject;
67 class Process;
68 class ResourcePool;
69
70 class InOrderCPU : public BaseCPU
71 {
72
73 protected:
74 typedef ThePipeline::Params Params;
75 typedef InOrderThreadState Thread;
76
77 //ISA TypeDefs
78 typedef TheISA::IntReg IntReg;
79 typedef TheISA::FloatReg FloatReg;
80 typedef TheISA::FloatRegBits FloatRegBits;
81 typedef TheISA::MiscReg MiscReg;
82 typedef TheISA::RegIndex RegIndex;
83
84 //DynInstPtr TypeDefs
85 typedef ThePipeline::DynInstPtr DynInstPtr;
86 typedef std::list<DynInstPtr>::iterator ListIt;
87
88 //TimeBuffer TypeDefs
89 typedef TimeBuffer<InterStageStruct> StageQueue;
90
91 friend class Resource;
92
93 public:
94 /** Constructs a CPU with the given parameters. */
95 InOrderCPU(Params *params);
96 /* Destructor */
97 ~InOrderCPU();
98
99 /** CPU ID */
100 int cpu_id;
101
102 // SE Mode ASIDs
103 ThreadID asid[ThePipeline::MaxThreads];
104
105 /** Type of core that this is */
106 std::string coreType;
107
108 // Only need for SE MODE
109 enum ThreadModel {
110 Single,
111 SMT,
112 SwitchOnCacheMiss
113 };
114
115 ThreadModel threadModel;
116
117 int readCpuId() { return cpu_id; }
118
119 void setCpuId(int val) { cpu_id = val; }
120
121 Params *cpu_params;
122
123 public:
124 enum Status {
125 Running,
126 Idle,
127 Halted,
128 Blocked,
129 SwitchedOut
130 };
131
132 /** Overall CPU status. */
133 Status _status;
134 private:
135 /** Define TickEvent for the CPU */
136 class TickEvent : public Event
137 {
138 private:
139 /** Pointer to the CPU. */
140 InOrderCPU *cpu;
141
142 public:
143 /** Constructs a tick event. */
144 TickEvent(InOrderCPU *c);
145
146 /** Processes a tick event, calling tick() on the CPU. */
147 void process();
148
149 /** Returns the description of the tick event. */
150 const char *description() const;
151 };
152
153 /** The tick event used for scheduling CPU ticks. */
154 TickEvent tickEvent;
155
156 /** Schedule tick event, regardless of its current state. */
157 void scheduleTickEvent(int delay)
158 {
159 assert(!tickEvent.scheduled() || tickEvent.squashed());
160 reschedule(&tickEvent, nextCycle(curTick() + ticks(delay)), true);
161 }
162
163 /** Unschedule tick event, regardless of its current state. */
164 void unscheduleTickEvent()
165 {
166 if (tickEvent.scheduled())
167 tickEvent.squash();
168 }
169
170 public:
171 // List of Events That can be scheduled from
172 // within the CPU.
173 // NOTE(1): The Resource Pool also uses this event list
174 // to schedule events broadcast to all resources interfaces
175 // NOTE(2): CPU Events usually need to schedule a corresponding resource
176 // pool event.
177 enum CPUEventType {
178 ActivateThread,
179 ActivateNextReadyThread,
180 DeactivateThread,
181 HaltThread,
182 SuspendThread,
183 Trap,
184 Syscall,
185 SquashFromMemStall,
186 UpdatePCs,
187 NumCPUEvents
188 };
189
190 static std::string eventNames[NumCPUEvents];
191
192 enum CPUEventPri {
193 InOrderCPU_Pri = Event::CPU_Tick_Pri,
194 Syscall_Pri = Event::CPU_Tick_Pri + 9,
195 ActivateNextReadyThread_Pri = Event::CPU_Tick_Pri + 10
196 };
197
198 /** Define CPU Event */
199 class CPUEvent : public Event
200 {
201 protected:
202 InOrderCPU *cpu;
203
204 public:
205 CPUEventType cpuEventType;
206 ThreadID tid;
207 DynInstPtr inst;
208 Fault fault;
209 unsigned vpe;
210 short syscall_num;
211
212 public:
213 /** Constructs a CPU event. */
214 CPUEvent(InOrderCPU *_cpu, CPUEventType e_type, Fault fault,
215 ThreadID _tid, DynInstPtr inst, CPUEventPri event_pri);
216
217 /** Set Type of Event To Be Scheduled */
218 void setEvent(CPUEventType e_type, Fault _fault, ThreadID _tid,
219 DynInstPtr _inst)
220 {
221 fault = _fault;
222 cpuEventType = e_type;
223 tid = _tid;
224 inst = _inst;
225 vpe = 0;
226 }
227
228 /** Processes a CPU event. */
229 void process();
230
231 /** Returns the description of the CPU event. */
232 const char *description() const;
233
234 /** Schedule Event */
235 void scheduleEvent(int delay);
236
237 /** Unschedule This Event */
238 void unscheduleEvent();
239 };
240
241 /** Schedule a CPU Event */
242 void scheduleCpuEvent(CPUEventType cpu_event, Fault fault, ThreadID tid,
243 DynInstPtr inst, unsigned delay = 0,
244 CPUEventPri event_pri = InOrderCPU_Pri);
245
246 public:
247 /** Interface between the CPU and CPU resources. */
248 ResourcePool *resPool;
249
250 /** Instruction used to signify that there is no *real* instruction in
251 buffer slot */
252 DynInstPtr dummyInst[ThePipeline::MaxThreads];
253 DynInstPtr dummyBufferInst;
254 DynInstPtr dummyReqInst;
255 DynInstPtr dummyTrapInst[ThePipeline::MaxThreads];
256
257 /** Used by resources to signify a denied access to a resource. */
258 ResourceRequest *dummyReq[ThePipeline::MaxThreads];
259
260 /** Identifies the resource id that identifies a fetch
261 * access unit.
262 */
263 unsigned fetchPortIdx;
264
265 /** Identifies the resource id that identifies a data
266 * access unit.
267 */
268 unsigned dataPortIdx;
269
270 /** The Pipeline Stages for the CPU */
271 PipelineStage *pipelineStage[ThePipeline::NumStages];
272
273 /** Width (processing bandwidth) of each stage */
274 int stageWidth;
275
276 /** Program Counters */
277 TheISA::PCState pc[ThePipeline::MaxThreads];
278
279 /** Last Committed PC */
280 TheISA::PCState lastCommittedPC[ThePipeline::MaxThreads];
281
282 /** The Register File for the CPU */
283 union {
284 FloatReg f[ThePipeline::MaxThreads][TheISA::NumFloatRegs];
285 FloatRegBits i[ThePipeline::MaxThreads][TheISA::NumFloatRegs];
286 } floatRegs;
287 TheISA::IntReg intRegs[ThePipeline::MaxThreads][TheISA::NumIntRegs];
288
289 /** ISA state */
290 TheISA::ISA isa[ThePipeline::MaxThreads];
291
292 /** Dependency Tracker for Integer & Floating Point Regs */
293 RegDepMap archRegDepMap[ThePipeline::MaxThreads];
294
295 /** Register Types Used in Dependency Tracking */
296 enum RegType { IntType, FloatType, MiscType, NumRegTypes};
297
298 /** Global communication structure */
299 TimeBuffer<TimeStruct> timeBuffer;
300
301 /** Communication structure that sits in between pipeline stages */
302 StageQueue *stageQueue[ThePipeline::NumStages-1];
303
304 TheISA::TLB *getITBPtr();
305 TheISA::TLB *getDTBPtr();
306
307 Decoder *getDecoderPtr();
308
309 /** Accessor Type for the SkedCache */
310 typedef uint32_t SkedID;
311
312 /** Cache of Instruction Schedule using the instruction's name as a key */
313 static m5::hash_map<SkedID, ThePipeline::RSkedPtr> skedCache;
314
315 typedef m5::hash_map<SkedID, ThePipeline::RSkedPtr>::iterator SkedCacheIt;
316
317 /** Initialized to last iterator in map, signifying a invalid entry
318 on map searches
319 */
320 SkedCacheIt endOfSkedIt;
321
322 ThePipeline::RSkedPtr frontEndSked;
323 ThePipeline::RSkedPtr faultSked;
324
325 /** Add a new instruction schedule to the schedule cache */
326 void addToSkedCache(DynInstPtr inst, ThePipeline::RSkedPtr inst_sked)
327 {
328 SkedID sked_id = genSkedID(inst);
329 assert(skedCache.find(sked_id) == skedCache.end());
330 skedCache[sked_id] = inst_sked;
331 }
332
333
334 /** Find a instruction schedule */
335 ThePipeline::RSkedPtr lookupSked(DynInstPtr inst)
336 {
337 SkedID sked_id = genSkedID(inst);
338 SkedCacheIt lookup_it = skedCache.find(sked_id);
339
340 if (lookup_it != endOfSkedIt) {
341 return (*lookup_it).second;
342 } else {
343 return NULL;
344 }
345 }
346
347 static const uint8_t INST_OPCLASS = 26;
348 static const uint8_t INST_LOAD = 25;
349 static const uint8_t INST_STORE = 24;
350 static const uint8_t INST_CONTROL = 23;
351 static const uint8_t INST_NONSPEC = 22;
352 static const uint8_t INST_DEST_REGS = 18;
353 static const uint8_t INST_SRC_REGS = 14;
354 static const uint8_t INST_SPLIT_DATA = 13;
355
356 inline SkedID genSkedID(DynInstPtr inst)
357 {
358 SkedID id = 0;
359 id = (inst->opClass() << INST_OPCLASS) |
360 (inst->isLoad() << INST_LOAD) |
361 (inst->isStore() << INST_STORE) |
362 (inst->isControl() << INST_CONTROL) |
363 (inst->isNonSpeculative() << INST_NONSPEC) |
364 (inst->numDestRegs() << INST_DEST_REGS) |
365 (inst->numSrcRegs() << INST_SRC_REGS) |
366 (inst->splitInst << INST_SPLIT_DATA);
367 return id;
368 }
369
370 ThePipeline::RSkedPtr createFrontEndSked();
371 ThePipeline::RSkedPtr createFaultSked();
372 ThePipeline::RSkedPtr createBackEndSked(DynInstPtr inst);
373
374 class StageScheduler {
375 private:
376 ThePipeline::RSkedPtr rsked;
377 int stageNum;
378 int nextTaskPriority;
379
380 public:
381 StageScheduler(ThePipeline::RSkedPtr _rsked, int stage_num)
382 : rsked(_rsked), stageNum(stage_num),
383 nextTaskPriority(0)
384 { }
385
386 void needs(int unit, int request) {
387 rsked->push(new ScheduleEntry(
388 stageNum, nextTaskPriority++, unit, request
389 ));
390 }
391
392 void needs(int unit, int request, int param) {
393 rsked->push(new ScheduleEntry(
394 stageNum, nextTaskPriority++, unit, request, param
395 ));
396 }
397 };
398
399 public:
400
401 /** Registers statistics. */
402 void regStats();
403
404 /** Ticks CPU, calling tick() on each stage, and checking the overall
405 * activity to see if the CPU should deschedule itself.
406 */
407 void tick();
408
409 /** Initialize the CPU */
410 void init();
411
412 /** Get a Memory Port */
413 Port* getPort(const std::string &if_name, int idx = 0);
414
415 /** HW return from error interrupt. */
416 Fault hwrei(ThreadID tid);
417
418 bool simPalCheck(int palFunc, ThreadID tid);
419
420 void checkForInterrupts();
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 /** Check if this address is a valid instruction address. */
432 bool validInstAddr(Addr addr) { return true; }
433
434 /** Check if this address is a valid data address. */
435 bool validDataAddr(Addr addr) { return true; }
436
437 /** Schedule a syscall on the CPU */
438 void syscallContext(Fault fault, ThreadID tid, DynInstPtr inst,
439 int delay = 0);
440
441 /** Executes a syscall.*/
442 void syscall(int64_t callnum, ThreadID tid);
443
444 /** Schedule a trap on the CPU */
445 void trapContext(Fault fault, ThreadID tid, DynInstPtr inst, int delay = 0);
446
447 /** Perform trap to Handle Given Fault */
448 void trap(Fault fault, ThreadID tid, DynInstPtr inst);
449
450 /** Schedule thread activation on the CPU */
451 void activateContext(ThreadID tid, int delay = 0);
452
453 /** Add Thread to Active Threads List. */
454 void activateThread(ThreadID tid);
455
456 /** Activate Thread In Each Pipeline Stage */
457 void activateThreadInPipeline(ThreadID tid);
458
459 /** Schedule Thread Activation from Ready List */
460 void activateNextReadyContext(int delay = 0);
461
462 /** Add Thread From Ready List to Active Threads List. */
463 void activateNextReadyThread();
464
465 /** Schedule a thread deactivation on the CPU */
466 void deactivateContext(ThreadID tid, int delay = 0);
467
468 /** Remove from Active Thread List */
469 void deactivateThread(ThreadID tid);
470
471 /** Schedule a thread suspension on the CPU */
472 void suspendContext(ThreadID tid);
473
474 /** Suspend Thread, Remove from Active Threads List, Add to Suspend List */
475 void suspendThread(ThreadID tid);
476
477 /** Schedule a thread halt on the CPU */
478 void haltContext(ThreadID tid);
479
480 /** Halt Thread, Remove from Active Thread List, Place Thread on Halted
481 * Threads List
482 */
483 void haltThread(ThreadID tid);
484
485 /** squashFromMemStall() - sets up a squash event
486 * squashDueToMemStall() - squashes pipeline
487 * @note: maybe squashContext/squashThread would be better?
488 */
489 void squashFromMemStall(DynInstPtr inst, ThreadID tid, int delay = 0);
490 void squashDueToMemStall(int stage_num, InstSeqNum seq_num, ThreadID tid);
491
492 void removePipelineStalls(ThreadID tid);
493 void squashThreadInPipeline(ThreadID tid);
494 void squashBehindMemStall(int stage_num, InstSeqNum seq_num, ThreadID tid);
495
496 PipelineStage* getPipeStage(int stage_num);
497
498 int
499 contextId()
500 {
501 hack_once("return a bogus context id");
502 return 0;
503 }
504
505 /** Update The Order In Which We Process Threads. */
506 void updateThreadPriority();
507
508 /** Switches a Pipeline Stage to Active. (Unused currently) */
509 void switchToActive(int stage_idx)
510 { /*pipelineStage[stage_idx]->switchToActive();*/ }
511
512 /** Get the current instruction sequence number, and increment it. */
513 InstSeqNum getAndIncrementInstSeq(ThreadID tid)
514 { return globalSeqNum[tid]++; }
515
516 /** Get the current instruction sequence number, and increment it. */
517 InstSeqNum nextInstSeqNum(ThreadID tid)
518 { return globalSeqNum[tid]; }
519
520 /** Increment Instruction Sequence Number */
521 void incrInstSeqNum(ThreadID tid)
522 { globalSeqNum[tid]++; }
523
524 /** Set Instruction Sequence Number */
525 void setInstSeqNum(ThreadID tid, InstSeqNum seq_num)
526 {
527 globalSeqNum[tid] = seq_num;
528 }
529
530 /** Get & Update Next Event Number */
531 InstSeqNum getNextEventNum()
532 {
533 #ifdef DEBUG
534 return cpuEventNum++;
535 #else
536 return 0;
537 #endif
538 }
539
540 /** Register file accessors */
541 uint64_t readIntReg(RegIndex reg_idx, ThreadID tid);
542
543 FloatReg readFloatReg(RegIndex reg_idx, ThreadID tid);
544
545 FloatRegBits readFloatRegBits(RegIndex reg_idx, ThreadID tid);
546
547 void setIntReg(RegIndex reg_idx, uint64_t val, ThreadID tid);
548
549 void setFloatReg(RegIndex reg_idx, FloatReg val, ThreadID tid);
550
551 void setFloatRegBits(RegIndex reg_idx, FloatRegBits val, ThreadID tid);
552
553 RegType inline getRegType(RegIndex reg_idx)
554 {
555 if (reg_idx < TheISA::FP_Base_DepTag)
556 return IntType;
557 else if (reg_idx < TheISA::Ctrl_Base_DepTag)
558 return FloatType;
559 else
560 return MiscType;
561 }
562
563 RegIndex flattenRegIdx(RegIndex reg_idx, RegType &reg_type, ThreadID tid);
564
565 /** Reads a miscellaneous register. */
566 MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid = 0);
567
568 /** Reads a misc. register, including any side effects the read
569 * might have as defined by the architecture.
570 */
571 MiscReg readMiscReg(int misc_reg, ThreadID tid = 0);
572
573 /** Sets a miscellaneous register. */
574 void setMiscRegNoEffect(int misc_reg, const MiscReg &val,
575 ThreadID tid = 0);
576
577 /** Sets a misc. register, including any side effects the write
578 * might have as defined by the architecture.
579 */
580 void setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0);
581
582 /** Reads a int/fp/misc reg. from another thread depending on ISA-defined
583 * target thread
584 */
585 uint64_t readRegOtherThread(unsigned misc_reg,
586 ThreadID tid = InvalidThreadID);
587
588 /** Sets a int/fp/misc reg. from another thread depending on an ISA-defined
589 * target thread
590 */
591 void setRegOtherThread(unsigned misc_reg, const MiscReg &val,
592 ThreadID tid);
593
594 /** Reads the commit PC of a specific thread. */
595 TheISA::PCState
596 pcState(ThreadID tid)
597 {
598 return pc[tid];
599 }
600
601 /** Sets the commit PC of a specific thread. */
602 void
603 pcState(const TheISA::PCState &newPC, ThreadID tid)
604 {
605 pc[tid] = newPC;
606 }
607
608 Addr instAddr(ThreadID tid) { return pc[tid].instAddr(); }
609 Addr nextInstAddr(ThreadID tid) { return pc[tid].nextInstAddr(); }
610 MicroPC microPC(ThreadID tid) { return pc[tid].microPC(); }
611
612 /** Function to add instruction onto the head of the list of the
613 * instructions. Used when new instructions are fetched.
614 */
615 ListIt addInst(DynInstPtr inst);
616
617 /** Find instruction on instruction list */
618 ListIt findInst(InstSeqNum seq_num, ThreadID tid);
619
620 /** Function to tell the CPU that an instruction has completed. */
621 void instDone(DynInstPtr inst, ThreadID tid);
622
623 /** Add Instructions to the CPU Remove List*/
624 void addToRemoveList(DynInstPtr inst);
625
626 /** Remove an instruction from CPU */
627 void removeInst(DynInstPtr inst);
628
629 /** Remove all instructions younger than the given sequence number. */
630 void removeInstsUntil(const InstSeqNum &seq_num,ThreadID tid);
631
632 /** Removes the instruction pointed to by the iterator. */
633 inline void squashInstIt(const ListIt inst_it, ThreadID tid);
634
635 /** Cleans up all instructions on the instruction remove list. */
636 void cleanUpRemovedInsts();
637
638 /** Cleans up all events on the CPU event remove list. */
639 void cleanUpRemovedEvents();
640
641 /** Debug function to print all instructions on the list. */
642 void dumpInsts();
643
644 /** Forwards an instruction read to the appropriate data
645 * resource (indexes into Resource Pool thru "dataPortIdx")
646 */
647 Fault read(DynInstPtr inst, Addr addr,
648 uint8_t *data, unsigned size, unsigned flags);
649
650 /** Forwards an instruction write. to the appropriate data
651 * resource (indexes into Resource Pool thru "dataPortIdx")
652 */
653 Fault write(DynInstPtr inst, uint8_t *data, unsigned size,
654 Addr addr, unsigned flags, uint64_t *write_res = NULL);
655
656 public:
657 /** Per-Thread List of all the instructions in flight. */
658 std::list<DynInstPtr> instList[ThePipeline::MaxThreads];
659
660 /** List of all the instructions that will be removed at the end of this
661 * cycle.
662 */
663 std::queue<ListIt> removeList;
664
665 bool trapPending[ThePipeline::MaxThreads];
666
667 /** List of all the cpu event requests that will be removed at the end of
668 * the current cycle.
669 */
670 std::queue<Event*> cpuEventRemoveList;
671
672 /** Records if instructions need to be removed this cycle due to
673 * being retired or squashed.
674 */
675 bool removeInstsThisCycle;
676
677 /** True if there is non-speculative Inst Active In Pipeline. Lets any
678 * execution unit know, NOT to execute while the instruction is active.
679 */
680 bool nonSpecInstActive[ThePipeline::MaxThreads];
681
682 /** Instruction Seq. Num of current non-speculative instruction. */
683 InstSeqNum nonSpecSeqNum[ThePipeline::MaxThreads];
684
685 /** Instruction Seq. Num of last instruction squashed in pipeline */
686 InstSeqNum squashSeqNum[ThePipeline::MaxThreads];
687
688 /** Last Cycle that the CPU squashed instruction end. */
689 Tick lastSquashCycle[ThePipeline::MaxThreads];
690
691 std::list<ThreadID> fetchPriorityList;
692
693 protected:
694 /** Active Threads List */
695 std::list<ThreadID> activeThreads;
696
697 /** Ready Threads List */
698 std::list<ThreadID> readyThreads;
699
700 /** Suspended Threads List */
701 std::list<ThreadID> suspendedThreads;
702
703 /** Halted Threads List */
704 std::list<ThreadID> haltedThreads;
705
706 /** Thread Status Functions */
707 bool isThreadActive(ThreadID tid);
708 bool isThreadReady(ThreadID tid);
709 bool isThreadSuspended(ThreadID tid);
710
711 private:
712 /** The activity recorder; used to tell if the CPU has any
713 * activity remaining or if it can go to idle and deschedule
714 * itself.
715 */
716 ActivityRecorder activityRec;
717
718 public:
719 /** Number of Active Threads in the CPU */
720 ThreadID numActiveThreads() { return activeThreads.size(); }
721
722 /** Thread id of active thread
723 * Only used for SwitchOnCacheMiss model.
724 * Assumes only 1 thread active
725 */
726 ThreadID activeThreadId()
727 {
728 if (numActiveThreads() > 0)
729 return activeThreads.front();
730 else
731 return InvalidThreadID;
732 }
733
734
735 /** Records that there was time buffer activity this cycle. */
736 void activityThisCycle() { activityRec.activity(); }
737
738 /** Changes a stage's status to active within the activity recorder. */
739 void activateStage(const int idx)
740 { activityRec.activateStage(idx); }
741
742 /** Changes a stage's status to inactive within the activity recorder. */
743 void deactivateStage(const int idx)
744 { activityRec.deactivateStage(idx); }
745
746 /** Wakes the CPU, rescheduling the CPU if it's not already active. */
747 void wakeCPU();
748
749 virtual void wakeup();
750
751 /* LL/SC debug functionality
752 unsigned stCondFails;
753
754 unsigned readStCondFailures()
755 { return stCondFails; }
756
757 unsigned setStCondFailures(unsigned st_fails)
758 { return stCondFails = st_fails; }
759 */
760
761 /** Returns a pointer to a thread context. */
762 ThreadContext *tcBase(ThreadID tid = 0)
763 {
764 return thread[tid]->getTC();
765 }
766
767 /** Count the Total Instructions Committed in the CPU. */
768 virtual Counter totalInstructions() const
769 {
770 Counter total(0);
771
772 for (ThreadID tid = 0; tid < (ThreadID)thread.size(); tid++)
773 total += thread[tid]->numInst;
774
775 return total;
776 }
777
778 /** Pointer to the system. */
779 System *system;
780
781 /** The global sequence number counter. */
782 InstSeqNum globalSeqNum[ThePipeline::MaxThreads];
783
784 #ifdef DEBUG
785 /** The global event number counter. */
786 InstSeqNum cpuEventNum;
787
788 /** Number of resource requests active in CPU **/
789 unsigned resReqCount;
790 #endif
791
792 Addr lockAddr;
793
794 /** Temporary fix for the lock flag, works in the UP case. */
795 bool lockFlag;
796
797 /** Counter of how many stages have completed draining */
798 int drainCount;
799
800 /** Pointers to all of the threads in the CPU. */
801 std::vector<Thread *> thread;
802
803 /** Pointer to the icache interface. */
804 MemInterface *icacheInterface;
805
806 /** Pointer to the dcache interface. */
807 MemInterface *dcacheInterface;
808
809 /** Whether or not the CPU should defer its registration. */
810 bool deferRegistration;
811
812 /** Per-Stage Instruction Tracing */
813 bool stageTracing;
814
815 /** The cycle that the CPU was last running, used for statistics. */
816 Tick lastRunningCycle;
817
818 void updateContextSwitchStats();
819 unsigned instsPerSwitch;
820 Stats::Average instsPerCtxtSwitch;
821 Stats::Scalar numCtxtSwitches;
822
823 /** Update Thread , used for statistic purposes*/
824 inline void tickThreadStats();
825
826 /** Per-Thread Tick */
827 Stats::Vector threadCycles;
828
829 /** Tick for SMT */
830 Stats::Scalar smtCycles;
831
832 /** Stat for total number of times the CPU is descheduled. */
833 Stats::Scalar timesIdled;
834
835 /** Stat for total number of cycles the CPU spends descheduled or no
836 * stages active.
837 */
838 Stats::Scalar idleCycles;
839
840 /** Stat for total number of cycles the CPU is active. */
841 Stats::Scalar runCycles;
842
843 /** Percentage of cycles a stage was active */
844 Stats::Formula activity;
845
846 /** Instruction Mix Stats */
847 Stats::Scalar comLoads;
848 Stats::Scalar comStores;
849 Stats::Scalar comBranches;
850 Stats::Scalar comNops;
851 Stats::Scalar comNonSpec;
852 Stats::Scalar comInts;
853 Stats::Scalar comFloats;
854
855 /** Stat for the number of committed instructions per thread. */
856 Stats::Vector committedInsts;
857
858 /** Stat for the number of committed instructions per thread. */
859 Stats::Vector smtCommittedInsts;
860
861 /** Stat for the total number of committed instructions. */
862 Stats::Scalar totalCommittedInsts;
863
864 /** Stat for the CPI per thread. */
865 Stats::Formula cpi;
866
867 /** Stat for the SMT-CPI per thread. */
868 Stats::Formula smtCpi;
869
870 /** Stat for the total CPI. */
871 Stats::Formula totalCpi;
872
873 /** Stat for the IPC per thread. */
874 Stats::Formula ipc;
875
876 /** Stat for the total IPC. */
877 Stats::Formula smtIpc;
878
879 /** Stat for the total IPC. */
880 Stats::Formula totalIpc;
881 };
882
883 #endif // __CPU_O3_CPU_HH__