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