cpu.hh revision 9342
1/*
2 * Copyright (c) 2011 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2004-2005 The Regents of The University of Michigan
15 * Copyright (c) 2011 Regents of the University of California
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: Kevin Lim
42 *          Korey Sewell
43 *          Rick Strong
44 */
45
46#ifndef __CPU_O3_CPU_HH__
47#define __CPU_O3_CPU_HH__
48
49#include <iostream>
50#include <list>
51#include <queue>
52#include <set>
53#include <vector>
54
55#include "arch/types.hh"
56#include "base/statistics.hh"
57#include "config/the_isa.hh"
58#include "cpu/o3/comm.hh"
59#include "cpu/o3/cpu_policy.hh"
60#include "cpu/o3/scoreboard.hh"
61#include "cpu/o3/thread_state.hh"
62#include "cpu/activity.hh"
63#include "cpu/base.hh"
64#include "cpu/simple_thread.hh"
65#include "cpu/timebuf.hh"
66//#include "cpu/o3/thread_context.hh"
67#include "params/DerivO3CPU.hh"
68#include "sim/process.hh"
69
70template <class>
71class Checker;
72class ThreadContext;
73template <class>
74class O3ThreadContext;
75
76class Checkpoint;
77class MemObject;
78class Process;
79
80struct BaseCPUParams;
81
82class BaseO3CPU : public BaseCPU
83{
84    //Stuff that's pretty ISA independent will go here.
85  public:
86    BaseO3CPU(BaseCPUParams *params);
87
88    void regStats();
89};
90
91/**
92 * FullO3CPU class, has each of the stages (fetch through commit)
93 * within it, as well as all of the time buffers between stages.  The
94 * tick() function for the CPU is defined here.
95 */
96template <class Impl>
97class FullO3CPU : public BaseO3CPU
98{
99  public:
100    // Typedefs from the Impl here.
101    typedef typename Impl::CPUPol CPUPolicy;
102    typedef typename Impl::DynInstPtr DynInstPtr;
103    typedef typename Impl::O3CPU O3CPU;
104
105    typedef O3ThreadState<Impl> ImplState;
106    typedef O3ThreadState<Impl> Thread;
107
108    typedef typename std::list<DynInstPtr>::iterator ListIt;
109
110    friend class O3ThreadContext<Impl>;
111
112  public:
113    enum Status {
114        Running,
115        Idle,
116        Halted,
117        Blocked,
118        SwitchedOut
119    };
120
121    TheISA::TLB * itb;
122    TheISA::TLB * dtb;
123
124    /** Overall CPU status. */
125    Status _status;
126
127    /** Per-thread status in CPU, used for SMT.  */
128    Status _threadStatus[Impl::MaxThreads];
129
130  private:
131
132    /**
133     * IcachePort class for instruction fetch.
134     */
135    class IcachePort : public CpuPort
136    {
137      protected:
138        /** Pointer to fetch. */
139        DefaultFetch<Impl> *fetch;
140
141      public:
142        /** Default constructor. */
143        IcachePort(DefaultFetch<Impl> *_fetch, FullO3CPU<Impl>* _cpu)
144            : CpuPort(_cpu->name() + ".icache_port", _cpu), fetch(_fetch)
145        { }
146
147      protected:
148
149        /** Timing version of receive.  Handles setting fetch to the
150         * proper status to start fetching. */
151        virtual bool recvTimingResp(PacketPtr pkt);
152        virtual void recvTimingSnoopReq(PacketPtr pkt) { }
153
154        /** Handles doing a retry of a failed fetch. */
155        virtual void recvRetry();
156    };
157
158    /**
159     * DcachePort class for the load/store queue.
160     */
161    class DcachePort : public CpuPort
162    {
163      protected:
164
165        /** Pointer to LSQ. */
166        LSQ<Impl> *lsq;
167
168      public:
169        /** Default constructor. */
170        DcachePort(LSQ<Impl> *_lsq, FullO3CPU<Impl>* _cpu)
171            : CpuPort(_cpu->name() + ".dcache_port", _cpu), lsq(_lsq)
172        { }
173
174      protected:
175
176        /** Timing version of receive.  Handles writing back and
177         * completing the load or store that has returned from
178         * memory. */
179        virtual bool recvTimingResp(PacketPtr pkt);
180        virtual void recvTimingSnoopReq(PacketPtr pkt);
181
182        /** Handles doing a retry of the previous send. */
183        virtual void recvRetry();
184
185        /**
186         * As this CPU requires snooping to maintain the load store queue
187         * change the behaviour from the base CPU port.
188         *
189         * @return true since we have to snoop
190         */
191        virtual bool isSnooping() const { return true; }
192    };
193
194    class TickEvent : public Event
195    {
196      private:
197        /** Pointer to the CPU. */
198        FullO3CPU<Impl> *cpu;
199
200      public:
201        /** Constructs a tick event. */
202        TickEvent(FullO3CPU<Impl> *c);
203
204        /** Processes a tick event, calling tick() on the CPU. */
205        void process();
206        /** Returns the description of the tick event. */
207        const char *description() const;
208    };
209
210    /** The tick event used for scheduling CPU ticks. */
211    TickEvent tickEvent;
212
213    /** Schedule tick event, regardless of its current state. */
214    void scheduleTickEvent(Cycles delay)
215    {
216        if (tickEvent.squashed())
217            reschedule(tickEvent, clockEdge(delay));
218        else if (!tickEvent.scheduled())
219            schedule(tickEvent, clockEdge(delay));
220    }
221
222    /** Unschedule tick event, regardless of its current state. */
223    void unscheduleTickEvent()
224    {
225        if (tickEvent.scheduled())
226            tickEvent.squash();
227    }
228
229    class ActivateThreadEvent : public Event
230    {
231      private:
232        /** Number of Thread to Activate */
233        ThreadID tid;
234
235        /** Pointer to the CPU. */
236        FullO3CPU<Impl> *cpu;
237
238      public:
239        /** Constructs the event. */
240        ActivateThreadEvent();
241
242        /** Initialize Event */
243        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
244
245        /** Processes the event, calling activateThread() on the CPU. */
246        void process();
247
248        /** Returns the description of the event. */
249        const char *description() const;
250    };
251
252    /** Schedule thread to activate , regardless of its current state. */
253    void
254    scheduleActivateThreadEvent(ThreadID tid, Cycles delay)
255    {
256        // Schedule thread to activate, regardless of its current state.
257        if (activateThreadEvent[tid].squashed())
258            reschedule(activateThreadEvent[tid],
259                       clockEdge(delay));
260        else if (!activateThreadEvent[tid].scheduled()) {
261            Tick when = clockEdge(delay);
262
263            // Check if the deallocateEvent is also scheduled, and make
264            // sure they do not happen at same time causing a sleep that
265            // is never woken from.
266            if (deallocateContextEvent[tid].scheduled() &&
267                deallocateContextEvent[tid].when() == when) {
268                when++;
269            }
270
271            schedule(activateThreadEvent[tid], when);
272        }
273    }
274
275    /** Unschedule actiavte thread event, regardless of its current state. */
276    void
277    unscheduleActivateThreadEvent(ThreadID tid)
278    {
279        if (activateThreadEvent[tid].scheduled())
280            activateThreadEvent[tid].squash();
281    }
282
283    /** The tick event used for scheduling CPU ticks. */
284    ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];
285
286    class DeallocateContextEvent : public Event
287    {
288      private:
289        /** Number of Thread to deactivate */
290        ThreadID tid;
291
292        /** Should the thread be removed from the CPU? */
293        bool remove;
294
295        /** Pointer to the CPU. */
296        FullO3CPU<Impl> *cpu;
297
298      public:
299        /** Constructs the event. */
300        DeallocateContextEvent();
301
302        /** Initialize Event */
303        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
304
305        /** Processes the event, calling activateThread() on the CPU. */
306        void process();
307
308        /** Sets whether the thread should also be removed from the CPU. */
309        void setRemove(bool _remove) { remove = _remove; }
310
311        /** Returns the description of the event. */
312        const char *description() const;
313    };
314
315    /** Schedule cpu to deallocate thread context.*/
316    void
317    scheduleDeallocateContextEvent(ThreadID tid, bool remove, Cycles delay)
318    {
319        // Schedule thread to activate, regardless of its current state.
320        if (deallocateContextEvent[tid].squashed())
321            reschedule(deallocateContextEvent[tid],
322                       clockEdge(delay));
323        else if (!deallocateContextEvent[tid].scheduled())
324            schedule(deallocateContextEvent[tid],
325                     clockEdge(delay));
326    }
327
328    /** Unschedule thread deallocation in CPU */
329    void
330    unscheduleDeallocateContextEvent(ThreadID tid)
331    {
332        if (deallocateContextEvent[tid].scheduled())
333            deallocateContextEvent[tid].squash();
334    }
335
336    /** The tick event used for scheduling CPU ticks. */
337    DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];
338
339  public:
340    /** Constructs a CPU with the given parameters. */
341    FullO3CPU(DerivO3CPUParams *params);
342    /** Destructor. */
343    ~FullO3CPU();
344
345    /** Registers statistics. */
346    void regStats();
347
348    void demapPage(Addr vaddr, uint64_t asn)
349    {
350        this->itb->demapPage(vaddr, asn);
351        this->dtb->demapPage(vaddr, asn);
352    }
353
354    void demapInstPage(Addr vaddr, uint64_t asn)
355    {
356        this->itb->demapPage(vaddr, asn);
357    }
358
359    void demapDataPage(Addr vaddr, uint64_t asn)
360    {
361        this->dtb->demapPage(vaddr, asn);
362    }
363
364    /** Ticks CPU, calling tick() on each stage, and checking the overall
365     *  activity to see if the CPU should deschedule itself.
366     */
367    void tick();
368
369    /** Initialize the CPU */
370    void init();
371
372    /** Returns the Number of Active Threads in the CPU */
373    int numActiveThreads()
374    { return activeThreads.size(); }
375
376    /** Add Thread to Active Threads List */
377    void activateThread(ThreadID tid);
378
379    /** Remove Thread from Active Threads List */
380    void deactivateThread(ThreadID tid);
381
382    /** Setup CPU to insert a thread's context */
383    void insertThread(ThreadID tid);
384
385    /** Remove all of a thread's context from CPU */
386    void removeThread(ThreadID tid);
387
388    /** Count the Total Instructions Committed in the CPU. */
389    virtual Counter totalInsts() const;
390
391    /** Count the Total Ops (including micro ops) committed in the CPU. */
392    virtual Counter totalOps() const;
393
394    /** Add Thread to Active Threads List. */
395    void activateContext(ThreadID tid, Cycles delay);
396
397    /** Remove Thread from Active Threads List */
398    void suspendContext(ThreadID tid);
399
400    /** Remove Thread from Active Threads List &&
401     *  Possibly Remove Thread Context from CPU.
402     */
403    bool scheduleDeallocateContext(ThreadID tid, bool remove,
404                                   Cycles delay = Cycles(1));
405
406    /** Remove Thread from Active Threads List &&
407     *  Remove Thread Context from CPU.
408     */
409    void haltContext(ThreadID tid);
410
411    /** Activate a Thread When CPU Resources are Available. */
412    void activateWhenReady(ThreadID tid);
413
414    /** Add or Remove a Thread Context in the CPU. */
415    void doContextSwitch();
416
417    /** Update The Order In Which We Process Threads. */
418    void updateThreadPriority();
419
420    /** Serialize state. */
421    virtual void serialize(std::ostream &os);
422
423    /** Unserialize from a checkpoint. */
424    virtual void unserialize(Checkpoint *cp, const std::string &section);
425
426  public:
427    /** Executes a syscall.
428     * @todo: Determine if this needs to be virtual.
429     */
430    void syscall(int64_t callnum, ThreadID tid);
431
432    /** Starts draining the CPU's pipeline of all instructions in
433     * order to stop all memory accesses. */
434    unsigned int drain(DrainManager *drain_manager);
435
436    /** Resumes execution after a drain. */
437    void drainResume();
438
439    /** Signals to this CPU that a stage has completed switching out. */
440    void signalDrained();
441
442    /** Switches out this CPU. */
443    virtual void switchOut();
444
445    /** Takes over from another CPU. */
446    virtual void takeOverFrom(BaseCPU *oldCPU);
447
448    /** Get the current instruction sequence number, and increment it. */
449    InstSeqNum getAndIncrementInstSeq()
450    { return globalSeqNum++; }
451
452    /** Traps to handle given fault. */
453    void trap(Fault fault, ThreadID tid, StaticInstPtr inst);
454
455    /** HW return from error interrupt. */
456    Fault hwrei(ThreadID tid);
457
458    bool simPalCheck(int palFunc, ThreadID tid);
459
460    /** Returns the Fault for any valid interrupt. */
461    Fault getInterrupts();
462
463    /** Processes any an interrupt fault. */
464    void processInterrupts(Fault interrupt);
465
466    /** Halts the CPU. */
467    void halt() { panic("Halt not implemented!\n"); }
468
469    /** Check if this address is a valid instruction address. */
470    bool validInstAddr(Addr addr) { return true; }
471
472    /** Check if this address is a valid data address. */
473    bool validDataAddr(Addr addr) { return true; }
474
475    /** Register accessors.  Index refers to the physical register index. */
476
477    /** Reads a miscellaneous register. */
478    TheISA::MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid);
479
480    /** Reads a misc. register, including any side effects the read
481     * might have as defined by the architecture.
482     */
483    TheISA::MiscReg readMiscReg(int misc_reg, ThreadID tid);
484
485    /** Sets a miscellaneous register. */
486    void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val,
487            ThreadID tid);
488
489    /** Sets a misc. register, including any side effects the write
490     * might have as defined by the architecture.
491     */
492    void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
493            ThreadID tid);
494
495    uint64_t readIntReg(int reg_idx);
496
497    TheISA::FloatReg readFloatReg(int reg_idx);
498
499    TheISA::FloatRegBits readFloatRegBits(int reg_idx);
500
501    void setIntReg(int reg_idx, uint64_t val);
502
503    void setFloatReg(int reg_idx, TheISA::FloatReg val);
504
505    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
506
507    uint64_t readArchIntReg(int reg_idx, ThreadID tid);
508
509    float readArchFloatReg(int reg_idx, ThreadID tid);
510
511    uint64_t readArchFloatRegInt(int reg_idx, ThreadID tid);
512
513    /** Architectural register accessors.  Looks up in the commit
514     * rename table to obtain the true physical index of the
515     * architected register first, then accesses that physical
516     * register.
517     */
518    void setArchIntReg(int reg_idx, uint64_t val, ThreadID tid);
519
520    void setArchFloatReg(int reg_idx, float val, ThreadID tid);
521
522    void setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid);
523
524    /** Sets the commit PC state of a specific thread. */
525    void pcState(const TheISA::PCState &newPCState, ThreadID tid);
526
527    /** Reads the commit PC state of a specific thread. */
528    TheISA::PCState pcState(ThreadID tid);
529
530    /** Reads the commit PC of a specific thread. */
531    Addr instAddr(ThreadID tid);
532
533    /** Reads the commit micro PC of a specific thread. */
534    MicroPC microPC(ThreadID tid);
535
536    /** Reads the next PC of a specific thread. */
537    Addr nextInstAddr(ThreadID tid);
538
539    /** Initiates a squash of all in-flight instructions for a given
540     * thread.  The source of the squash is an external update of
541     * state through the TC.
542     */
543    void squashFromTC(ThreadID tid);
544
545    /** Function to add instruction onto the head of the list of the
546     *  instructions.  Used when new instructions are fetched.
547     */
548    ListIt addInst(DynInstPtr &inst);
549
550    /** Function to tell the CPU that an instruction has completed. */
551    void instDone(ThreadID tid, DynInstPtr &inst);
552
553    /** Remove an instruction from the front end of the list.  There's
554     *  no restriction on location of the instruction.
555     */
556    void removeFrontInst(DynInstPtr &inst);
557
558    /** Remove all instructions that are not currently in the ROB.
559     *  There's also an option to not squash delay slot instructions.*/
560    void removeInstsNotInROB(ThreadID tid);
561
562    /** Remove all instructions younger than the given sequence number. */
563    void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid);
564
565    /** Removes the instruction pointed to by the iterator. */
566    inline void squashInstIt(const ListIt &instIt, ThreadID tid);
567
568    /** Cleans up all instructions on the remove list. */
569    void cleanUpRemovedInsts();
570
571    /** Debug function to print all instructions on the list. */
572    void dumpInsts();
573
574  public:
575#ifndef NDEBUG
576    /** Count of total number of dynamic instructions in flight. */
577    int instcount;
578#endif
579
580    /** List of all the instructions in flight. */
581    std::list<DynInstPtr> instList;
582
583    /** List of all the instructions that will be removed at the end of this
584     *  cycle.
585     */
586    std::queue<ListIt> removeList;
587
588#ifdef DEBUG
589    /** Debug structure to keep track of the sequence numbers still in
590     * flight.
591     */
592    std::set<InstSeqNum> snList;
593#endif
594
595    /** Records if instructions need to be removed this cycle due to
596     *  being retired or squashed.
597     */
598    bool removeInstsThisCycle;
599
600  protected:
601    /** The fetch stage. */
602    typename CPUPolicy::Fetch fetch;
603
604    /** The decode stage. */
605    typename CPUPolicy::Decode decode;
606
607    /** The dispatch stage. */
608    typename CPUPolicy::Rename rename;
609
610    /** The issue/execute/writeback stages. */
611    typename CPUPolicy::IEW iew;
612
613    /** The commit stage. */
614    typename CPUPolicy::Commit commit;
615
616    /** The register file. */
617    typename CPUPolicy::RegFile regFile;
618
619    /** The free list. */
620    typename CPUPolicy::FreeList freeList;
621
622    /** The rename map. */
623    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
624
625    /** The commit rename map. */
626    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
627
628    /** The re-order buffer. */
629    typename CPUPolicy::ROB rob;
630
631    /** Active Threads List */
632    std::list<ThreadID> activeThreads;
633
634    /** Integer Register Scoreboard */
635    Scoreboard scoreboard;
636
637    TheISA::ISA isa[Impl::MaxThreads];
638
639    /** Instruction port. Note that it has to appear after the fetch stage. */
640    IcachePort icachePort;
641
642    /** Data port. Note that it has to appear after the iew stages */
643    DcachePort dcachePort;
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    virtual void wakeup();
709
710    /** Gets a free thread id. Use if thread ids change across system. */
711    ThreadID getFreeTid();
712
713  public:
714    /** Returns a pointer to a thread context. */
715    ThreadContext *
716    tcBase(ThreadID tid)
717    {
718        return thread[tid]->getTC();
719    }
720
721    /** The global sequence number counter. */
722    InstSeqNum globalSeqNum;//[Impl::MaxThreads];
723
724    /** Pointer to the checker, which can dynamically verify
725     * instruction results at run time.  This can be set to NULL if it
726     * is not being used.
727     */
728    Checker<Impl> *checker;
729
730    /** Pointer to the system. */
731    System *system;
732
733    /** DrainManager to notify when draining has completed. */
734    DrainManager *drainManager;
735
736    /** Counter of how many stages have completed draining. */
737    int drainCount;
738
739    /** Pointers to all of the threads in the CPU. */
740    std::vector<Thread *> thread;
741
742    /** Whether or not the CPU should defer its registration. */
743    bool deferRegistration;
744
745    /** Is there a context switch pending? */
746    bool contextSwitch;
747
748    /** Threads Scheduled to Enter CPU */
749    std::list<int> cpuWaitList;
750
751    /** The cycle that the CPU was last running, used for statistics. */
752    Cycles lastRunningCycle;
753
754    /** The cycle that the CPU was last activated by a new thread*/
755    Tick lastActivatedCycle;
756
757    /** Mapping for system thread id to cpu id */
758    std::map<ThreadID, unsigned> threadMap;
759
760    /** Available thread ids in the cpu*/
761    std::vector<ThreadID> tids;
762
763    /** CPU read function, forwards read to LSQ. */
764    Fault read(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
765               uint8_t *data, int load_idx)
766    {
767        return this->iew.ldstQueue.read(req, sreqLow, sreqHigh,
768                                        data, load_idx);
769    }
770
771    /** CPU write function, forwards write to LSQ. */
772    Fault write(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
773                uint8_t *data, int store_idx)
774    {
775        return this->iew.ldstQueue.write(req, sreqLow, sreqHigh,
776                                         data, store_idx);
777    }
778
779    /** Used by the fetch unit to get a hold of the instruction port. */
780    virtual CpuPort &getInstPort() { return icachePort; }
781
782    /** Get the dcache port (used to find block size for translations). */
783    virtual CpuPort &getDataPort() { return dcachePort; }
784
785    Addr lockAddr;
786
787    /** Temporary fix for the lock flag, works in the UP case. */
788    bool lockFlag;
789
790    /** Stat for total number of times the CPU is descheduled. */
791    Stats::Scalar timesIdled;
792    /** Stat for total number of cycles the CPU spends descheduled. */
793    Stats::Scalar idleCycles;
794    /** Stat for total number of cycles the CPU spends descheduled due to a
795     * quiesce operation or waiting for an interrupt. */
796    Stats::Scalar quiesceCycles;
797    /** Stat for the number of committed instructions per thread. */
798    Stats::Vector committedInsts;
799    /** Stat for the number of committed ops (including micro ops) per thread. */
800    Stats::Vector committedOps;
801    /** Stat for the total number of committed instructions. */
802    Stats::Scalar totalCommittedInsts;
803    /** Stat for the CPI per thread. */
804    Stats::Formula cpi;
805    /** Stat for the total CPI. */
806    Stats::Formula totalCpi;
807    /** Stat for the IPC per thread. */
808    Stats::Formula ipc;
809    /** Stat for the total IPC. */
810    Stats::Formula totalIpc;
811
812    //number of integer register file accesses
813    Stats::Scalar intRegfileReads;
814    Stats::Scalar intRegfileWrites;
815    //number of float register file accesses
816    Stats::Scalar fpRegfileReads;
817    Stats::Scalar fpRegfileWrites;
818    //number of misc
819    Stats::Scalar miscRegfileReads;
820    Stats::Scalar miscRegfileWrites;
821};
822
823#endif // __CPU_O3_CPU_HH__
824