cpu.hh revision 14085
1/*
2 * Copyright (c) 2011-2013, 2016-2019 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) 2004-2005 The Regents of The University of Michigan
16 * Copyright (c) 2011 Regents of the University of California
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Authors: Kevin Lim
43 *          Korey Sewell
44 *          Rick Strong
45 */
46
47#ifndef __CPU_O3_CPU_HH__
48#define __CPU_O3_CPU_HH__
49
50#include <iostream>
51#include <list>
52#include <queue>
53#include <set>
54#include <vector>
55
56#include "arch/generic/types.hh"
57#include "arch/types.hh"
58#include "base/statistics.hh"
59#include "config/the_isa.hh"
60#include "cpu/o3/comm.hh"
61#include "cpu/o3/cpu_policy.hh"
62#include "cpu/o3/scoreboard.hh"
63#include "cpu/o3/thread_state.hh"
64#include "cpu/activity.hh"
65#include "cpu/base.hh"
66#include "cpu/simple_thread.hh"
67#include "cpu/timebuf.hh"
68//#include "cpu/o3/thread_context.hh"
69#include "params/DerivO3CPU.hh"
70#include "sim/process.hh"
71
72template <class>
73class Checker;
74class ThreadContext;
75template <class>
76class O3ThreadContext;
77
78class Checkpoint;
79class Process;
80
81struct BaseCPUParams;
82
83class BaseO3CPU : public BaseCPU
84{
85    //Stuff that's pretty ISA independent will go here.
86  public:
87    BaseO3CPU(BaseCPUParams *params);
88
89    void regStats();
90};
91
92/**
93 * FullO3CPU class, has each of the stages (fetch through commit)
94 * within it, as well as all of the time buffers between stages.  The
95 * tick() function for the CPU is defined here.
96 */
97template <class Impl>
98class FullO3CPU : public BaseO3CPU
99{
100  public:
101    // Typedefs from the Impl here.
102    typedef typename Impl::CPUPol CPUPolicy;
103    typedef typename Impl::DynInstPtr DynInstPtr;
104    typedef typename Impl::O3CPU O3CPU;
105
106    using VecElem =  TheISA::VecElem;
107    using VecRegContainer =  TheISA::VecRegContainer;
108
109    using VecPredRegContainer = TheISA::VecPredRegContainer;
110
111    typedef O3ThreadState<Impl> ImplState;
112    typedef O3ThreadState<Impl> Thread;
113
114    typedef typename std::list<DynInstPtr>::iterator ListIt;
115
116    friend class O3ThreadContext<Impl>;
117
118  public:
119    enum Status {
120        Running,
121        Idle,
122        Halted,
123        Blocked,
124        SwitchedOut
125    };
126
127    BaseTLB *itb;
128    BaseTLB *dtb;
129    using LSQRequest = typename LSQ<Impl>::LSQRequest;
130
131    /** Overall CPU status. */
132    Status _status;
133
134  private:
135
136    /**
137     * IcachePort class for instruction fetch.
138     */
139    class IcachePort : public MasterPort
140    {
141      protected:
142        /** Pointer to fetch. */
143        DefaultFetch<Impl> *fetch;
144
145      public:
146        /** Default constructor. */
147        IcachePort(DefaultFetch<Impl> *_fetch, FullO3CPU<Impl>* _cpu)
148            : MasterPort(_cpu->name() + ".icache_port", _cpu), fetch(_fetch)
149        { }
150
151      protected:
152
153        /** Timing version of receive.  Handles setting fetch to the
154         * proper status to start fetching. */
155        virtual bool recvTimingResp(PacketPtr pkt);
156
157        /** Handles doing a retry of a failed fetch. */
158        virtual void recvReqRetry();
159    };
160
161    /**
162     * DcachePort class for the load/store queue.
163     */
164    class DcachePort : public MasterPort
165    {
166      protected:
167
168        /** Pointer to LSQ. */
169        LSQ<Impl> *lsq;
170        FullO3CPU<Impl> *cpu;
171
172      public:
173        /** Default constructor. */
174        DcachePort(LSQ<Impl> *_lsq, FullO3CPU<Impl>* _cpu)
175            : MasterPort(_cpu->name() + ".dcache_port", _cpu), lsq(_lsq),
176              cpu(_cpu)
177        { }
178
179      protected:
180
181        /** Timing version of receive.  Handles writing back and
182         * completing the load or store that has returned from
183         * memory. */
184        virtual bool recvTimingResp(PacketPtr pkt);
185        virtual void recvTimingSnoopReq(PacketPtr pkt);
186
187        virtual void recvFunctionalSnoop(PacketPtr pkt)
188        {
189            // @todo: Is there a need for potential invalidation here?
190        }
191
192        /** Handles doing a retry of the previous send. */
193        virtual void recvReqRetry();
194
195        /**
196         * As this CPU requires snooping to maintain the load store queue
197         * change the behaviour from the base CPU port.
198         *
199         * @return true since we have to snoop
200         */
201        virtual bool isSnooping() const { return true; }
202    };
203
204    /** The tick event used for scheduling CPU ticks. */
205    EventFunctionWrapper tickEvent;
206
207    /** The exit event used for terminating all ready-to-exit threads */
208    EventFunctionWrapper threadExitEvent;
209
210    /** Schedule tick event, regardless of its current state. */
211    void scheduleTickEvent(Cycles delay)
212    {
213        if (tickEvent.squashed())
214            reschedule(tickEvent, clockEdge(delay));
215        else if (!tickEvent.scheduled())
216            schedule(tickEvent, clockEdge(delay));
217    }
218
219    /** Unschedule tick event, regardless of its current state. */
220    void unscheduleTickEvent()
221    {
222        if (tickEvent.scheduled())
223            tickEvent.squash();
224    }
225
226    /**
227     * Check if the pipeline has drained and signal drain done.
228     *
229     * This method checks if a drain has been requested and if the CPU
230     * has drained successfully (i.e., there are no instructions in
231     * the pipeline). If the CPU has drained, it deschedules the tick
232     * event and signals the drain manager.
233     *
234     * @return False if a drain hasn't been requested or the CPU
235     * hasn't drained, true otherwise.
236     */
237    bool tryDrain();
238
239    /**
240     * Perform sanity checks after a drain.
241     *
242     * This method is called from drain() when it has determined that
243     * the CPU is fully drained when gem5 is compiled with the NDEBUG
244     * macro undefined. The intention of this method is to do more
245     * extensive tests than the isDrained() method to weed out any
246     * draining bugs.
247     */
248    void drainSanityCheck() const;
249
250    /** Check if a system is in a drained state. */
251    bool isCpuDrained() const;
252
253  public:
254    /** Constructs a CPU with the given parameters. */
255    FullO3CPU(DerivO3CPUParams *params);
256    /** Destructor. */
257    ~FullO3CPU();
258
259    /** Registers statistics. */
260    void regStats() override;
261
262    ProbePointArg<PacketPtr> *ppInstAccessComplete;
263    ProbePointArg<std::pair<DynInstPtr, PacketPtr> > *ppDataAccessComplete;
264
265    /** Register probe points. */
266    void regProbePoints() override;
267
268    void demapPage(Addr vaddr, uint64_t asn)
269    {
270        this->itb->demapPage(vaddr, asn);
271        this->dtb->demapPage(vaddr, asn);
272    }
273
274    void demapInstPage(Addr vaddr, uint64_t asn)
275    {
276        this->itb->demapPage(vaddr, asn);
277    }
278
279    void demapDataPage(Addr vaddr, uint64_t asn)
280    {
281        this->dtb->demapPage(vaddr, asn);
282    }
283
284    /** Ticks CPU, calling tick() on each stage, and checking the overall
285     *  activity to see if the CPU should deschedule itself.
286     */
287    void tick();
288
289    /** Initialize the CPU */
290    void init() override;
291
292    void startup() override;
293
294    /** Returns the Number of Active Threads in the CPU */
295    int numActiveThreads()
296    { return activeThreads.size(); }
297
298    /** Add Thread to Active Threads List */
299    void activateThread(ThreadID tid);
300
301    /** Remove Thread from Active Threads List */
302    void deactivateThread(ThreadID tid);
303
304    /** Setup CPU to insert a thread's context */
305    void insertThread(ThreadID tid);
306
307    /** Remove all of a thread's context from CPU */
308    void removeThread(ThreadID tid);
309
310    /** Count the Total Instructions Committed in the CPU. */
311    Counter totalInsts() const override;
312
313    /** Count the Total Ops (including micro ops) committed in the CPU. */
314    Counter totalOps() const override;
315
316    /** Add Thread to Active Threads List. */
317    void activateContext(ThreadID tid) override;
318
319    /** Remove Thread from Active Threads List */
320    void suspendContext(ThreadID tid) override;
321
322    /** Remove Thread from Active Threads List &&
323     *  Remove Thread Context from CPU.
324     */
325    void haltContext(ThreadID tid) override;
326
327    /** Update The Order In Which We Process Threads. */
328    void updateThreadPriority();
329
330    /** Is the CPU draining? */
331    bool isDraining() const { return drainState() == DrainState::Draining; }
332
333    void serializeThread(CheckpointOut &cp, ThreadID tid) const override;
334    void unserializeThread(CheckpointIn &cp, ThreadID tid) override;
335
336    /** Insert tid to the list of threads trying to exit */
337    void addThreadToExitingList(ThreadID tid);
338
339    /** Is the thread trying to exit? */
340    bool isThreadExiting(ThreadID tid) const;
341
342    /**
343     *  If a thread is trying to exit and its corresponding trap event
344     *  has been completed, schedule an event to terminate the thread.
345     */
346    void scheduleThreadExitEvent(ThreadID tid);
347
348    /** Terminate all threads that are ready to exit */
349    void exitThreads();
350
351  public:
352    /** Executes a syscall.
353     * @todo: Determine if this needs to be virtual.
354     */
355    void syscall(int64_t callnum, ThreadID tid, Fault *fault);
356
357    /** Starts draining the CPU's pipeline of all instructions in
358     * order to stop all memory accesses. */
359    DrainState drain() override;
360
361    /** Resumes execution after a drain. */
362    void drainResume() override;
363
364    /**
365     * Commit has reached a safe point to drain a thread.
366     *
367     * Commit calls this method to inform the pipeline that it has
368     * reached a point where it is not executed microcode and is about
369     * to squash uncommitted instructions to fully drain the pipeline.
370     */
371    void commitDrained(ThreadID tid);
372
373    /** Switches out this CPU. */
374    void switchOut() override;
375
376    /** Takes over from another CPU. */
377    void takeOverFrom(BaseCPU *oldCPU) override;
378
379    void verifyMemoryMode() const override;
380
381    /** Get the current instruction sequence number, and increment it. */
382    InstSeqNum getAndIncrementInstSeq()
383    { return globalSeqNum++; }
384
385    /** Traps to handle given fault. */
386    void trap(const Fault &fault, ThreadID tid, const StaticInstPtr &inst);
387
388    /** Check if a change in renaming is needed for vector registers.
389     * The vecMode variable is updated and propagated to rename maps.
390     *
391     * @param tid ThreadID
392     * @param freelist list of free registers
393     */
394    void switchRenameMode(ThreadID tid, UnifiedFreeList* freelist);
395
396    /** Returns the Fault for any valid interrupt. */
397    Fault getInterrupts();
398
399    /** Processes any an interrupt fault. */
400    void processInterrupts(const Fault &interrupt);
401
402    /** Halts the CPU. */
403    void halt() { panic("Halt not implemented!\n"); }
404
405    /** Register accessors.  Index refers to the physical register index. */
406
407    /** Reads a miscellaneous register. */
408    RegVal readMiscRegNoEffect(int misc_reg, ThreadID tid) const;
409
410    /** Reads a misc. register, including any side effects the read
411     * might have as defined by the architecture.
412     */
413    RegVal readMiscReg(int misc_reg, ThreadID tid);
414
415    /** Sets a miscellaneous register. */
416    void setMiscRegNoEffect(int misc_reg, RegVal val, ThreadID tid);
417
418    /** Sets a misc. register, including any side effects the write
419     * might have as defined by the architecture.
420     */
421    void setMiscReg(int misc_reg, RegVal val, ThreadID tid);
422
423    RegVal readIntReg(PhysRegIdPtr phys_reg);
424
425    RegVal readFloatReg(PhysRegIdPtr phys_reg);
426
427    const VecRegContainer& readVecReg(PhysRegIdPtr reg_idx) const;
428
429    /**
430     * Read physical vector register for modification.
431     */
432    VecRegContainer& getWritableVecReg(PhysRegIdPtr reg_idx);
433
434    /** Returns current vector renaming mode */
435    Enums::VecRegRenameMode vecRenameMode() const { return vecMode; }
436
437    /** Sets the current vector renaming mode */
438    void vecRenameMode(Enums::VecRegRenameMode vec_mode)
439    { vecMode = vec_mode; }
440
441    /**
442     * Read physical vector register lane
443     */
444    template<typename VecElem, int LaneIdx>
445    VecLaneT<VecElem, true>
446    readVecLane(PhysRegIdPtr phys_reg) const
447    {
448        vecRegfileReads++;
449        return regFile.readVecLane<VecElem, LaneIdx>(phys_reg);
450    }
451
452    /**
453     * Read physical vector register lane
454     */
455    template<typename VecElem>
456    VecLaneT<VecElem, true>
457    readVecLane(PhysRegIdPtr phys_reg) const
458    {
459        vecRegfileReads++;
460        return regFile.readVecLane<VecElem>(phys_reg);
461    }
462
463    /** Write a lane of the destination vector register. */
464    template<typename LD>
465    void
466    setVecLane(PhysRegIdPtr phys_reg, const LD& val)
467    {
468        vecRegfileWrites++;
469        return regFile.setVecLane(phys_reg, val);
470    }
471
472    const VecElem& readVecElem(PhysRegIdPtr reg_idx) const;
473
474    const VecPredRegContainer& readVecPredReg(PhysRegIdPtr reg_idx) const;
475
476    VecPredRegContainer& getWritableVecPredReg(PhysRegIdPtr reg_idx);
477
478    RegVal readCCReg(PhysRegIdPtr phys_reg);
479
480    void setIntReg(PhysRegIdPtr phys_reg, RegVal val);
481
482    void setFloatReg(PhysRegIdPtr phys_reg, RegVal val);
483
484    void setVecReg(PhysRegIdPtr reg_idx, const VecRegContainer& val);
485
486    void setVecElem(PhysRegIdPtr reg_idx, const VecElem& val);
487
488    void setVecPredReg(PhysRegIdPtr reg_idx, const VecPredRegContainer& val);
489
490    void setCCReg(PhysRegIdPtr phys_reg, RegVal val);
491
492    RegVal readArchIntReg(int reg_idx, ThreadID tid);
493
494    RegVal readArchFloatReg(int reg_idx, ThreadID tid);
495
496    const VecRegContainer& readArchVecReg(int reg_idx, ThreadID tid) const;
497    /** Read architectural vector register for modification. */
498    VecRegContainer& getWritableArchVecReg(int reg_idx, ThreadID tid);
499
500    /** Read architectural vector register lane. */
501    template<typename VecElem>
502    VecLaneT<VecElem, true>
503    readArchVecLane(int reg_idx, int lId, ThreadID tid) const
504    {
505        PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup(
506                    RegId(VecRegClass, reg_idx));
507        return readVecLane<VecElem>(phys_reg);
508    }
509
510
511    /** Write a lane of the destination vector register. */
512    template<typename LD>
513    void
514    setArchVecLane(int reg_idx, int lId, ThreadID tid, const LD& val)
515    {
516        PhysRegIdPtr phys_reg = commitRenameMap[tid].lookup(
517                    RegId(VecRegClass, reg_idx));
518        setVecLane(phys_reg, val);
519    }
520
521    const VecElem& readArchVecElem(const RegIndex& reg_idx,
522                                   const ElemIndex& ldx, ThreadID tid) const;
523
524    const VecPredRegContainer& readArchVecPredReg(int reg_idx,
525                                                  ThreadID tid) const;
526
527    VecPredRegContainer& getWritableArchVecPredReg(int reg_idx, ThreadID tid);
528
529    RegVal readArchCCReg(int reg_idx, ThreadID tid);
530
531    /** Architectural register accessors.  Looks up in the commit
532     * rename table to obtain the true physical index of the
533     * architected register first, then accesses that physical
534     * register.
535     */
536    void setArchIntReg(int reg_idx, RegVal val, ThreadID tid);
537
538    void setArchFloatReg(int reg_idx, RegVal val, ThreadID tid);
539
540    void setArchVecPredReg(int reg_idx, const VecPredRegContainer& val,
541                           ThreadID tid);
542
543    void setArchVecReg(int reg_idx, const VecRegContainer& val, ThreadID tid);
544
545    void setArchVecElem(const RegIndex& reg_idx, const ElemIndex& ldx,
546                        const VecElem& val, ThreadID tid);
547
548    void setArchCCReg(int reg_idx, RegVal val, ThreadID tid);
549
550    /** Sets the commit PC state of a specific thread. */
551    void pcState(const TheISA::PCState &newPCState, ThreadID tid);
552
553    /** Reads the commit PC state of a specific thread. */
554    TheISA::PCState pcState(ThreadID tid);
555
556    /** Reads the commit PC of a specific thread. */
557    Addr instAddr(ThreadID tid);
558
559    /** Reads the commit micro PC of a specific thread. */
560    MicroPC microPC(ThreadID tid);
561
562    /** Reads the next PC of a specific thread. */
563    Addr nextInstAddr(ThreadID tid);
564
565    /** Initiates a squash of all in-flight instructions for a given
566     * thread.  The source of the squash is an external update of
567     * state through the TC.
568     */
569    void squashFromTC(ThreadID tid);
570
571    /** Function to add instruction onto the head of the list of the
572     *  instructions.  Used when new instructions are fetched.
573     */
574    ListIt addInst(const DynInstPtr &inst);
575
576    /** Function to tell the CPU that an instruction has completed. */
577    void instDone(ThreadID tid, const DynInstPtr &inst);
578
579    /** Remove an instruction from the front end of the list.  There's
580     *  no restriction on location of the instruction.
581     */
582    void removeFrontInst(const DynInstPtr &inst);
583
584    /** Remove all instructions that are not currently in the ROB.
585     *  There's also an option to not squash delay slot instructions.*/
586    void removeInstsNotInROB(ThreadID tid);
587
588    /** Remove all instructions younger than the given sequence number. */
589    void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid);
590
591    /** Removes the instruction pointed to by the iterator. */
592    inline void squashInstIt(const ListIt &instIt, ThreadID tid);
593
594    /** Cleans up all instructions on the remove list. */
595    void cleanUpRemovedInsts();
596
597    /** Debug function to print all instructions on the list. */
598    void dumpInsts();
599
600  public:
601#ifndef NDEBUG
602    /** Count of total number of dynamic instructions in flight. */
603    int instcount;
604#endif
605
606    /** List of all the instructions in flight. */
607    std::list<DynInstPtr> instList;
608
609    /** List of all the instructions that will be removed at the end of this
610     *  cycle.
611     */
612    std::queue<ListIt> removeList;
613
614#ifdef DEBUG
615    /** Debug structure to keep track of the sequence numbers still in
616     * flight.
617     */
618    std::set<InstSeqNum> snList;
619#endif
620
621    /** Records if instructions need to be removed this cycle due to
622     *  being retired or squashed.
623     */
624    bool removeInstsThisCycle;
625
626  protected:
627    /** The fetch stage. */
628    typename CPUPolicy::Fetch fetch;
629
630    /** The decode stage. */
631    typename CPUPolicy::Decode decode;
632
633    /** The dispatch stage. */
634    typename CPUPolicy::Rename rename;
635
636    /** The issue/execute/writeback stages. */
637    typename CPUPolicy::IEW iew;
638
639    /** The commit stage. */
640    typename CPUPolicy::Commit commit;
641
642    /** The rename mode of the vector registers */
643    Enums::VecRegRenameMode vecMode;
644
645    /** The register file. */
646    PhysRegFile regFile;
647
648    /** The free list. */
649    typename CPUPolicy::FreeList freeList;
650
651    /** The rename map. */
652    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
653
654    /** The commit rename map. */
655    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
656
657    /** The re-order buffer. */
658    typename CPUPolicy::ROB rob;
659
660    /** Active Threads List */
661    std::list<ThreadID> activeThreads;
662
663    /**
664     *  This is a list of threads that are trying to exit. Each thread id
665     *  is mapped to a boolean value denoting whether the thread is ready
666     *  to exit.
667     */
668    std::unordered_map<ThreadID, bool> exitingThreads;
669
670    /** Integer Register Scoreboard */
671    Scoreboard scoreboard;
672
673    std::vector<TheISA::ISA *> isa;
674
675    /** Instruction port. Note that it has to appear after the fetch stage. */
676    IcachePort icachePort;
677
678    /** Data port. Note that it has to appear after the iew stages */
679    DcachePort dcachePort;
680
681  public:
682    /** Enum to give each stage a specific index, so when calling
683     *  activateStage() or deactivateStage(), they can specify which stage
684     *  is being activated/deactivated.
685     */
686    enum StageIdx {
687        FetchIdx,
688        DecodeIdx,
689        RenameIdx,
690        IEWIdx,
691        CommitIdx,
692        NumStages };
693
694    /** Typedefs from the Impl to get the structs that each of the
695     *  time buffers should use.
696     */
697    typedef typename CPUPolicy::TimeStruct TimeStruct;
698
699    typedef typename CPUPolicy::FetchStruct FetchStruct;
700
701    typedef typename CPUPolicy::DecodeStruct DecodeStruct;
702
703    typedef typename CPUPolicy::RenameStruct RenameStruct;
704
705    typedef typename CPUPolicy::IEWStruct IEWStruct;
706
707    /** The main time buffer to do backwards communication. */
708    TimeBuffer<TimeStruct> timeBuffer;
709
710    /** The fetch stage's instruction queue. */
711    TimeBuffer<FetchStruct> fetchQueue;
712
713    /** The decode stage's instruction queue. */
714    TimeBuffer<DecodeStruct> decodeQueue;
715
716    /** The rename stage's instruction queue. */
717    TimeBuffer<RenameStruct> renameQueue;
718
719    /** The IEW stage's instruction queue. */
720    TimeBuffer<IEWStruct> iewQueue;
721
722  private:
723    /** The activity recorder; used to tell if the CPU has any
724     * activity remaining or if it can go to idle and deschedule
725     * itself.
726     */
727    ActivityRecorder activityRec;
728
729  public:
730    /** Records that there was time buffer activity this cycle. */
731    void activityThisCycle() { activityRec.activity(); }
732
733    /** Changes a stage's status to active within the activity recorder. */
734    void activateStage(const StageIdx idx)
735    { activityRec.activateStage(idx); }
736
737    /** Changes a stage's status to inactive within the activity recorder. */
738    void deactivateStage(const StageIdx idx)
739    { activityRec.deactivateStage(idx); }
740
741    /** Wakes the CPU, rescheduling the CPU if it's not already active. */
742    void wakeCPU();
743
744    virtual void wakeup(ThreadID tid) override;
745
746    /** Gets a free thread id. Use if thread ids change across system. */
747    ThreadID getFreeTid();
748
749  public:
750    /** Returns a pointer to a thread context. */
751    ThreadContext *
752    tcBase(ThreadID tid)
753    {
754        return thread[tid]->getTC();
755    }
756
757    /** The global sequence number counter. */
758    InstSeqNum globalSeqNum;//[Impl::MaxThreads];
759
760    /** Pointer to the checker, which can dynamically verify
761     * instruction results at run time.  This can be set to NULL if it
762     * is not being used.
763     */
764    Checker<Impl> *checker;
765
766    /** Pointer to the system. */
767    System *system;
768
769    /** Pointers to all of the threads in the CPU. */
770    std::vector<Thread *> thread;
771
772    /** Threads Scheduled to Enter CPU */
773    std::list<int> cpuWaitList;
774
775    /** The cycle that the CPU was last running, used for statistics. */
776    Cycles lastRunningCycle;
777
778    /** The cycle that the CPU was last activated by a new thread*/
779    Tick lastActivatedCycle;
780
781    /** Mapping for system thread id to cpu id */
782    std::map<ThreadID, unsigned> threadMap;
783
784    /** Available thread ids in the cpu*/
785    std::vector<ThreadID> tids;
786
787    /** CPU pushRequest function, forwards request to LSQ. */
788    Fault pushRequest(const DynInstPtr& inst, bool isLoad, uint8_t *data,
789                      unsigned int size, Addr addr, Request::Flags flags,
790                      uint64_t *res, AtomicOpFunctor *amo_op = nullptr,
791                      const std::vector<bool>& byteEnable =
792                          std::vector<bool>())
793
794    {
795        return iew.ldstQueue.pushRequest(inst, isLoad, data, size, addr,
796                flags, res, amo_op, byteEnable);
797    }
798
799    /** CPU read function, forwards read to LSQ. */
800    Fault read(LSQRequest* req, int load_idx)
801    {
802        return this->iew.ldstQueue.read(req, load_idx);
803    }
804
805    /** CPU write function, forwards write to LSQ. */
806    Fault write(LSQRequest* req, uint8_t *data, int store_idx)
807    {
808        return this->iew.ldstQueue.write(req, data, store_idx);
809    }
810
811    /** Used by the fetch unit to get a hold of the instruction port. */
812    MasterPort &getInstPort() override { return icachePort; }
813
814    /** Get the dcache port (used to find block size for translations). */
815    MasterPort &getDataPort() override { return dcachePort; }
816
817    /** Stat for total number of times the CPU is descheduled. */
818    Stats::Scalar timesIdled;
819    /** Stat for total number of cycles the CPU spends descheduled. */
820    Stats::Scalar idleCycles;
821    /** Stat for total number of cycles the CPU spends descheduled due to a
822     * quiesce operation or waiting for an interrupt. */
823    Stats::Scalar quiesceCycles;
824    /** Stat for the number of committed instructions per thread. */
825    Stats::Vector committedInsts;
826    /** Stat for the number of committed ops (including micro ops) per thread. */
827    Stats::Vector committedOps;
828    /** Stat for the CPI per thread. */
829    Stats::Formula cpi;
830    /** Stat for the total CPI. */
831    Stats::Formula totalCpi;
832    /** Stat for the IPC per thread. */
833    Stats::Formula ipc;
834    /** Stat for the total IPC. */
835    Stats::Formula totalIpc;
836
837    //number of integer register file accesses
838    Stats::Scalar intRegfileReads;
839    Stats::Scalar intRegfileWrites;
840    //number of float register file accesses
841    Stats::Scalar fpRegfileReads;
842    Stats::Scalar fpRegfileWrites;
843    //number of vector register file accesses
844    mutable Stats::Scalar vecRegfileReads;
845    Stats::Scalar vecRegfileWrites;
846    //number of predicate register file accesses
847    mutable Stats::Scalar vecPredRegfileReads;
848    Stats::Scalar vecPredRegfileWrites;
849    //number of CC register file accesses
850    Stats::Scalar ccRegfileReads;
851    Stats::Scalar ccRegfileWrites;
852    //number of misc
853    Stats::Scalar miscRegfileReads;
854    Stats::Scalar miscRegfileWrites;
855};
856
857#endif // __CPU_O3_CPU_HH__
858