commit.hh revision 2632:1bb2f91485ea
112853Sgabeblack@google.com/*
212853Sgabeblack@google.com * Copyright (c) 2004-2005 The Regents of The University of Michigan
312853Sgabeblack@google.com * All rights reserved.
412853Sgabeblack@google.com *
512853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612853Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112853Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412853Sgabeblack@google.com * this software without specific prior written permission.
1512853Sgabeblack@google.com *
1612853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712853Sgabeblack@google.com */
2812853Sgabeblack@google.com
2912853Sgabeblack@google.com// Todo: Maybe have a special method for handling interrupts/traps.
3012853Sgabeblack@google.com//
3112853Sgabeblack@google.com// Traps:  Have IEW send a signal to commit saying that there's a trap to
3212853Sgabeblack@google.com// be handled.  Have commit send the PC back to the fetch stage, along
3312853Sgabeblack@google.com// with the current commit PC.  Fetch will directly access the IPR and save
3412853Sgabeblack@google.com// off all the proper stuff.  Commit can send out a squash, or something
3512853Sgabeblack@google.com// close to it.
3612853Sgabeblack@google.com// Do the same for hwrei().  However, requires that commit be specifically
3712853Sgabeblack@google.com// built to support that kind of stuff.  Probably not horrible to have
3812853Sgabeblack@google.com// commit support having the CPU tell it to squash the other stages and
3912853Sgabeblack@google.com// restart at a given address.  The IPR register does become an issue.
4012853Sgabeblack@google.com// Probably not a big deal if the IPR stuff isn't cycle accurate.  Can just
4112853Sgabeblack@google.com// have the original function handle writing to the IPR register.
4212853Sgabeblack@google.com
4312853Sgabeblack@google.com#ifndef __CPU_O3_CPU_SIMPLE_COMMIT_HH__
4412853Sgabeblack@google.com#define __CPU_O3_CPU_SIMPLE_COMMIT_HH__
4512853Sgabeblack@google.com
4612853Sgabeblack@google.com#include "base/statistics.hh"
4712853Sgabeblack@google.com#include "base/timebuf.hh"
4812853Sgabeblack@google.com#include "mem/memory_interface.hh"
4912853Sgabeblack@google.com
5012853Sgabeblack@google.comtemplate<class Impl>
5112853Sgabeblack@google.comclass SimpleCommit
5212853Sgabeblack@google.com{
5312853Sgabeblack@google.com  public:
5412853Sgabeblack@google.com    // Typedefs from the Impl.
5512853Sgabeblack@google.com    typedef typename Impl::FullCPU FullCPU;
5612853Sgabeblack@google.com    typedef typename Impl::DynInstPtr DynInstPtr;
5712853Sgabeblack@google.com    typedef typename Impl::Params Params;
5812853Sgabeblack@google.com    typedef typename Impl::CPUPol CPUPol;
5912853Sgabeblack@google.com
6012853Sgabeblack@google.com    typedef typename CPUPol::ROB ROB;
6112853Sgabeblack@google.com
6212853Sgabeblack@google.com    typedef typename CPUPol::TimeStruct TimeStruct;
6312853Sgabeblack@google.com    typedef typename CPUPol::IEWStruct IEWStruct;
6412853Sgabeblack@google.com    typedef typename CPUPol::RenameStruct RenameStruct;
6512853Sgabeblack@google.com
6612853Sgabeblack@google.com  public:
6712853Sgabeblack@google.com    // I don't believe commit can block, so it will only have two
6812853Sgabeblack@google.com    // statuses for now.
6912853Sgabeblack@google.com    // Actually if there's a cache access that needs to block (ie
7012853Sgabeblack@google.com    // uncachable load or just a mem access in commit) then the stage
7112853Sgabeblack@google.com    // may have to wait.
7212853Sgabeblack@google.com    enum Status {
7312853Sgabeblack@google.com        Running,
7412853Sgabeblack@google.com        Idle,
7512853Sgabeblack@google.com        ROBSquashing,
7612853Sgabeblack@google.com        DcacheMissStall,
7712853Sgabeblack@google.com        DcacheMissComplete
7812853Sgabeblack@google.com    };
7912853Sgabeblack@google.com
8012853Sgabeblack@google.com  private:
8112853Sgabeblack@google.com    Status _status;
8212853Sgabeblack@google.com
8312853Sgabeblack@google.com  public:
8412853Sgabeblack@google.com    SimpleCommit(Params &params);
8512853Sgabeblack@google.com
8612853Sgabeblack@google.com    void regStats();
8712853Sgabeblack@google.com
8812853Sgabeblack@google.com    void setCPU(FullCPU *cpu_ptr);
8912853Sgabeblack@google.com
9012853Sgabeblack@google.com    void setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr);
9112853Sgabeblack@google.com
9212853Sgabeblack@google.com    void setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr);
9312853Sgabeblack@google.com
9412853Sgabeblack@google.com    void setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr);
9512853Sgabeblack@google.com
9612853Sgabeblack@google.com    void setROB(ROB *rob_ptr);
9712853Sgabeblack@google.com
9812853Sgabeblack@google.com    void tick();
9912853Sgabeblack@google.com
10012853Sgabeblack@google.com    void commit();
10112853Sgabeblack@google.com
10212853Sgabeblack@google.com  private:
10312853Sgabeblack@google.com
10412853Sgabeblack@google.com    void commitInsts();
10512853Sgabeblack@google.com
10612853Sgabeblack@google.com    bool commitHead(DynInstPtr &head_inst, unsigned inst_num);
10712853Sgabeblack@google.com
10812853Sgabeblack@google.com    void getInsts();
10912853Sgabeblack@google.com
11012853Sgabeblack@google.com    void markCompletedInsts();
11112853Sgabeblack@google.com
11212853Sgabeblack@google.com  public:
11312853Sgabeblack@google.com    uint64_t readCommitPC();
11412853Sgabeblack@google.com
11512853Sgabeblack@google.com    void setSquashing() { _status = ROBSquashing; }
11612853Sgabeblack@google.com
11712853Sgabeblack@google.com  private:
11812853Sgabeblack@google.com    /** Time buffer interface. */
11912853Sgabeblack@google.com    TimeBuffer<TimeStruct> *timeBuffer;
12012853Sgabeblack@google.com
12112853Sgabeblack@google.com    /** Wire to write information heading to previous stages. */
12212853Sgabeblack@google.com    typename TimeBuffer<TimeStruct>::wire toIEW;
12312853Sgabeblack@google.com
12412853Sgabeblack@google.com    /** Wire to read information from IEW (for ROB). */
12512853Sgabeblack@google.com    typename TimeBuffer<TimeStruct>::wire robInfoFromIEW;
12612853Sgabeblack@google.com
12712853Sgabeblack@google.com    /** IEW instruction queue interface. */
12812853Sgabeblack@google.com    TimeBuffer<IEWStruct> *iewQueue;
12912853Sgabeblack@google.com
13012853Sgabeblack@google.com    /** Wire to read information from IEW queue. */
13112853Sgabeblack@google.com    typename TimeBuffer<IEWStruct>::wire fromIEW;
13212853Sgabeblack@google.com
13312853Sgabeblack@google.com    /** Rename instruction queue interface, for ROB. */
13412853Sgabeblack@google.com    TimeBuffer<RenameStruct> *renameQueue;
13512853Sgabeblack@google.com
13612853Sgabeblack@google.com    /** Wire to read information from rename queue. */
13712853Sgabeblack@google.com    typename TimeBuffer<RenameStruct>::wire fromRename;
13812853Sgabeblack@google.com
13912853Sgabeblack@google.com    /** ROB interface. */
14012853Sgabeblack@google.com    ROB *rob;
14112853Sgabeblack@google.com
14212853Sgabeblack@google.com    /** Pointer to FullCPU. */
14312853Sgabeblack@google.com    FullCPU *cpu;
14412853Sgabeblack@google.com
14512853Sgabeblack@google.com    /** Memory interface.  Used for d-cache accesses. */
14612853Sgabeblack@google.com    MemInterface *dcacheInterface;
14712853Sgabeblack@google.com
14812853Sgabeblack@google.com  private:
14912853Sgabeblack@google.com    /** IEW to Commit delay, in ticks. */
15012853Sgabeblack@google.com    unsigned iewToCommitDelay;
15112853Sgabeblack@google.com
15212853Sgabeblack@google.com    /** Rename to ROB delay, in ticks. */
15312853Sgabeblack@google.com    unsigned renameToROBDelay;
15412853Sgabeblack@google.com
15512853Sgabeblack@google.com    /** Rename width, in instructions.  Used so ROB knows how many
15612853Sgabeblack@google.com     *  instructions to get from the rename instruction queue.
15712853Sgabeblack@google.com     */
15812853Sgabeblack@google.com    unsigned renameWidth;
15912853Sgabeblack@google.com
16012853Sgabeblack@google.com    /** IEW width, in instructions.  Used so ROB knows how many
16112853Sgabeblack@google.com     *  instructions to get from the IEW instruction queue.
16212853Sgabeblack@google.com     */
16312853Sgabeblack@google.com    unsigned iewWidth;
16412853Sgabeblack@google.com
16512853Sgabeblack@google.com    /** Commit width, in instructions. */
16612853Sgabeblack@google.com    unsigned commitWidth;
16712853Sgabeblack@google.com
16812853Sgabeblack@google.com    Stats::Scalar<> commitCommittedInsts;
16912853Sgabeblack@google.com    Stats::Scalar<> commitSquashedInsts;
17012853Sgabeblack@google.com    Stats::Scalar<> commitSquashEvents;
17112853Sgabeblack@google.com    Stats::Scalar<> commitNonSpecStalls;
17212853Sgabeblack@google.com    Stats::Scalar<> commitCommittedBranches;
17312853Sgabeblack@google.com    Stats::Scalar<> commitCommittedLoads;
17412853Sgabeblack@google.com    Stats::Scalar<> commitCommittedMemRefs;
17512853Sgabeblack@google.com    Stats::Scalar<> branchMispredicts;
17612853Sgabeblack@google.com
17712853Sgabeblack@google.com    Stats::Distribution<> n_committed_dist;
17812853Sgabeblack@google.com};
17912853Sgabeblack@google.com
18012853Sgabeblack@google.com#endif // __CPU_O3_CPU_SIMPLE_COMMIT_HH__
18112853Sgabeblack@google.com