commit_impl.hh revision 2790
11689SN/A/*
22316SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
31689SN/A * All rights reserved.
41689SN/A *
51689SN/A * Redistribution and use in source and binary forms, with or without
61689SN/A * modification, are permitted provided that the following conditions are
71689SN/A * met: redistributions of source code must retain the above copyright
81689SN/A * notice, this list of conditions and the following disclaimer;
91689SN/A * redistributions in binary form must reproduce the above copyright
101689SN/A * notice, this list of conditions and the following disclaimer in the
111689SN/A * documentation and/or other materials provided with the distribution;
121689SN/A * neither the name of the copyright holders nor the names of its
131689SN/A * contributors may be used to endorse or promote products derived from
141689SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
291689SN/A */
301689SN/A
312733Sktlim@umich.edu#include "config/full_system.hh"
322733Sktlim@umich.edu#include "config/use_checker.hh"
332733Sktlim@umich.edu
342292SN/A#include <algorithm>
352329SN/A#include <string>
362292SN/A
372292SN/A#include "base/loader/symtab.hh"
381060SN/A#include "base/timebuf.hh"
392292SN/A#include "cpu/exetrace.hh"
401717SN/A#include "cpu/o3/commit.hh"
412292SN/A#include "cpu/o3/thread_state.hh"
422292SN/A
432790Sktlim@umich.edu#if USE_CHECKER
442790Sktlim@umich.edu#include "cpu/checker/cpu.hh"
452790Sktlim@umich.edu#endif
462790Sktlim@umich.edu
472292SN/Ausing namespace std;
481060SN/A
491061SN/Atemplate <class Impl>
502292SN/ADefaultCommit<Impl>::TrapEvent::TrapEvent(DefaultCommit<Impl> *_commit,
512292SN/A                                          unsigned _tid)
522292SN/A    : Event(&mainEventQueue, CPU_Tick_Pri), commit(_commit), tid(_tid)
531060SN/A{
542292SN/A    this->setFlags(Event::AutoDelete);
551060SN/A}
561060SN/A
571061SN/Atemplate <class Impl>
581060SN/Avoid
592292SN/ADefaultCommit<Impl>::TrapEvent::process()
601062SN/A{
612316SN/A    // This will get reset by commit if it was switched out at the
622316SN/A    // time of this event processing.
632292SN/A    commit->trapSquash[tid] = true;
642292SN/A}
652292SN/A
662292SN/Atemplate <class Impl>
672292SN/Aconst char *
682292SN/ADefaultCommit<Impl>::TrapEvent::description()
692292SN/A{
702292SN/A    return "Trap event";
712292SN/A}
722292SN/A
732292SN/Atemplate <class Impl>
742292SN/ADefaultCommit<Impl>::DefaultCommit(Params *params)
752669Sktlim@umich.edu    : squashCounter(0),
762292SN/A      iewToCommitDelay(params->iewToCommitDelay),
772292SN/A      commitToIEWDelay(params->commitToIEWDelay),
782292SN/A      renameToROBDelay(params->renameToROBDelay),
792292SN/A      fetchToCommitDelay(params->commitToFetchDelay),
802292SN/A      renameWidth(params->renameWidth),
812292SN/A      commitWidth(params->commitWidth),
822307SN/A      numThreads(params->numberOfThreads),
832678Sktlim@umich.edu      switchPending(false),
842316SN/A      switchedOut(false),
852316SN/A      trapLatency(params->trapLatency),
862316SN/A      fetchTrapLatency(params->fetchTrapLatency)
872292SN/A{
882292SN/A    _status = Active;
892292SN/A    _nextStatus = Inactive;
902292SN/A    string policy = params->smtCommitPolicy;
912292SN/A
922292SN/A    //Convert string to lowercase
932292SN/A    std::transform(policy.begin(), policy.end(), policy.begin(),
942292SN/A                   (int(*)(int)) tolower);
952292SN/A
962292SN/A    //Assign commit policy
972292SN/A    if (policy == "aggressive"){
982292SN/A        commitPolicy = Aggressive;
992292SN/A
1002292SN/A        DPRINTF(Commit,"Commit Policy set to Aggressive.");
1012292SN/A    } else if (policy == "roundrobin"){
1022292SN/A        commitPolicy = RoundRobin;
1032292SN/A
1042292SN/A        //Set-Up Priority List
1052292SN/A        for (int tid=0; tid < numThreads; tid++) {
1062292SN/A            priority_list.push_back(tid);
1072292SN/A        }
1082292SN/A
1092292SN/A        DPRINTF(Commit,"Commit Policy set to Round Robin.");
1102292SN/A    } else if (policy == "oldestready"){
1112292SN/A        commitPolicy = OldestReady;
1122292SN/A
1132292SN/A        DPRINTF(Commit,"Commit Policy set to Oldest Ready.");
1142292SN/A    } else {
1152292SN/A        assert(0 && "Invalid SMT Commit Policy. Options Are: {Aggressive,"
1162292SN/A               "RoundRobin,OldestReady}");
1172292SN/A    }
1182292SN/A
1192292SN/A    for (int i=0; i < numThreads; i++) {
1202292SN/A        commitStatus[i] = Idle;
1212292SN/A        changedROBNumEntries[i] = false;
1222292SN/A        trapSquash[i] = false;
1232680Sktlim@umich.edu        tcSquash[i] = false;
1242678Sktlim@umich.edu        PC[i] = nextPC[i] = 0;
1252292SN/A    }
1262292SN/A
1272292SN/A    fetchFaultTick = 0;
1282292SN/A    fetchTrapWait = 0;
1292292SN/A}
1302292SN/A
1312292SN/Atemplate <class Impl>
1322292SN/Astd::string
1332292SN/ADefaultCommit<Impl>::name() const
1342292SN/A{
1352292SN/A    return cpu->name() + ".commit";
1362292SN/A}
1372292SN/A
1382292SN/Atemplate <class Impl>
1392292SN/Avoid
1402292SN/ADefaultCommit<Impl>::regStats()
1412132SN/A{
1422301SN/A    using namespace Stats;
1431062SN/A    commitCommittedInsts
1441062SN/A        .name(name() + ".commitCommittedInsts")
1451062SN/A        .desc("The number of committed instructions")
1461062SN/A        .prereq(commitCommittedInsts);
1471062SN/A    commitSquashedInsts
1481062SN/A        .name(name() + ".commitSquashedInsts")
1491062SN/A        .desc("The number of squashed insts skipped by commit")
1501062SN/A        .prereq(commitSquashedInsts);
1511062SN/A    commitSquashEvents
1521062SN/A        .name(name() + ".commitSquashEvents")
1531062SN/A        .desc("The number of times commit is told to squash")
1541062SN/A        .prereq(commitSquashEvents);
1551062SN/A    commitNonSpecStalls
1561062SN/A        .name(name() + ".commitNonSpecStalls")
1571062SN/A        .desc("The number of times commit has been forced to stall to "
1581062SN/A              "communicate backwards")
1591062SN/A        .prereq(commitNonSpecStalls);
1601062SN/A    branchMispredicts
1611062SN/A        .name(name() + ".branchMispredicts")
1621062SN/A        .desc("The number of times a branch was mispredicted")
1631062SN/A        .prereq(branchMispredicts);
1642292SN/A    numCommittedDist
1651062SN/A        .init(0,commitWidth,1)
1661062SN/A        .name(name() + ".COM:committed_per_cycle")
1671062SN/A        .desc("Number of insts commited each cycle")
1681062SN/A        .flags(Stats::pdf)
1691062SN/A        ;
1702301SN/A
1712316SN/A    statComInst
1722301SN/A        .init(cpu->number_of_threads)
1732301SN/A        .name(name() + ".COM:count")
1742301SN/A        .desc("Number of instructions committed")
1752301SN/A        .flags(total)
1762301SN/A        ;
1772301SN/A
1782316SN/A    statComSwp
1792301SN/A        .init(cpu->number_of_threads)
1802301SN/A        .name(name() + ".COM:swp_count")
1812301SN/A        .desc("Number of s/w prefetches committed")
1822301SN/A        .flags(total)
1832301SN/A        ;
1842301SN/A
1852316SN/A    statComRefs
1862301SN/A        .init(cpu->number_of_threads)
1872301SN/A        .name(name() +  ".COM:refs")
1882301SN/A        .desc("Number of memory references committed")
1892301SN/A        .flags(total)
1902301SN/A        ;
1912301SN/A
1922316SN/A    statComLoads
1932301SN/A        .init(cpu->number_of_threads)
1942301SN/A        .name(name() +  ".COM:loads")
1952301SN/A        .desc("Number of loads committed")
1962301SN/A        .flags(total)
1972301SN/A        ;
1982301SN/A
1992316SN/A    statComMembars
2002301SN/A        .init(cpu->number_of_threads)
2012301SN/A        .name(name() +  ".COM:membars")
2022301SN/A        .desc("Number of memory barriers committed")
2032301SN/A        .flags(total)
2042301SN/A        ;
2052301SN/A
2062316SN/A    statComBranches
2072301SN/A        .init(cpu->number_of_threads)
2082301SN/A        .name(name() + ".COM:branches")
2092301SN/A        .desc("Number of branches committed")
2102301SN/A        .flags(total)
2112301SN/A        ;
2122301SN/A
2132316SN/A    commitEligible
2142301SN/A        .init(cpu->number_of_threads)
2152301SN/A        .name(name() + ".COM:bw_limited")
2162301SN/A        .desc("number of insts not committed due to BW limits")
2172301SN/A        .flags(total)
2182301SN/A        ;
2192301SN/A
2202316SN/A    commitEligibleSamples
2212301SN/A        .name(name() + ".COM:bw_lim_events")
2222301SN/A        .desc("number cycles where commit BW limit reached")
2232301SN/A        ;
2241062SN/A}
2251062SN/A
2261062SN/Atemplate <class Impl>
2271062SN/Avoid
2282733Sktlim@umich.eduDefaultCommit<Impl>::setCPU(O3CPU *cpu_ptr)
2291060SN/A{
2301060SN/A    DPRINTF(Commit, "Commit: Setting CPU pointer.\n");
2311060SN/A    cpu = cpu_ptr;
2322292SN/A
2332292SN/A    // Commit must broadcast the number of free entries it has at the start of
2342292SN/A    // the simulation, so it starts as active.
2352733Sktlim@umich.edu    cpu->activateStage(O3CPU::CommitIdx);
2362307SN/A
2372316SN/A    trapLatency = cpu->cycles(trapLatency);
2382316SN/A    fetchTrapLatency = cpu->cycles(fetchTrapLatency);
2391060SN/A}
2401060SN/A
2411061SN/Atemplate <class Impl>
2421060SN/Avoid
2432292SN/ADefaultCommit<Impl>::setThreads(vector<Thread *> &threads)
2442292SN/A{
2452292SN/A    thread = threads;
2462292SN/A}
2472292SN/A
2482292SN/Atemplate <class Impl>
2492292SN/Avoid
2502292SN/ADefaultCommit<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
2511060SN/A{
2521060SN/A    DPRINTF(Commit, "Commit: Setting time buffer pointer.\n");
2531060SN/A    timeBuffer = tb_ptr;
2541060SN/A
2551060SN/A    // Setup wire to send information back to IEW.
2561060SN/A    toIEW = timeBuffer->getWire(0);
2571060SN/A
2581060SN/A    // Setup wire to read data from IEW (for the ROB).
2591060SN/A    robInfoFromIEW = timeBuffer->getWire(-iewToCommitDelay);
2601060SN/A}
2611060SN/A
2621061SN/Atemplate <class Impl>
2631060SN/Avoid
2642292SN/ADefaultCommit<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr)
2652292SN/A{
2662292SN/A    DPRINTF(Commit, "Commit: Setting fetch queue pointer.\n");
2672292SN/A    fetchQueue = fq_ptr;
2682292SN/A
2692292SN/A    // Setup wire to get instructions from rename (for the ROB).
2702292SN/A    fromFetch = fetchQueue->getWire(-fetchToCommitDelay);
2712292SN/A}
2722292SN/A
2732292SN/Atemplate <class Impl>
2742292SN/Avoid
2752292SN/ADefaultCommit<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
2761060SN/A{
2771060SN/A    DPRINTF(Commit, "Commit: Setting rename queue pointer.\n");
2781060SN/A    renameQueue = rq_ptr;
2791060SN/A
2801060SN/A    // Setup wire to get instructions from rename (for the ROB).
2811060SN/A    fromRename = renameQueue->getWire(-renameToROBDelay);
2821060SN/A}
2831060SN/A
2841061SN/Atemplate <class Impl>
2851060SN/Avoid
2862292SN/ADefaultCommit<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr)
2871060SN/A{
2881060SN/A    DPRINTF(Commit, "Commit: Setting IEW queue pointer.\n");
2891060SN/A    iewQueue = iq_ptr;
2901060SN/A
2911060SN/A    // Setup wire to get instructions from IEW.
2921060SN/A    fromIEW = iewQueue->getWire(-iewToCommitDelay);
2931060SN/A}
2941060SN/A
2951061SN/Atemplate <class Impl>
2961060SN/Avoid
2972316SN/ADefaultCommit<Impl>::setFetchStage(Fetch *fetch_stage)
2982316SN/A{
2992316SN/A    fetchStage = fetch_stage;
3002316SN/A}
3012316SN/A
3022316SN/Atemplate <class Impl>
3032316SN/Avoid
3042292SN/ADefaultCommit<Impl>::setIEWStage(IEW *iew_stage)
3052292SN/A{
3062292SN/A    iewStage = iew_stage;
3072292SN/A}
3082292SN/A
3092292SN/Atemplate<class Impl>
3102292SN/Avoid
3112292SN/ADefaultCommit<Impl>::setActiveThreads(list<unsigned> *at_ptr)
3122292SN/A{
3132292SN/A    DPRINTF(Commit, "Commit: Setting active threads list pointer.\n");
3142292SN/A    activeThreads = at_ptr;
3152292SN/A}
3162292SN/A
3172292SN/Atemplate <class Impl>
3182292SN/Avoid
3192292SN/ADefaultCommit<Impl>::setRenameMap(RenameMap rm_ptr[])
3202292SN/A{
3212292SN/A    DPRINTF(Commit, "Setting rename map pointers.\n");
3222292SN/A
3232292SN/A    for (int i=0; i < numThreads; i++) {
3242292SN/A        renameMap[i] = &rm_ptr[i];
3252292SN/A    }
3262292SN/A}
3272292SN/A
3282292SN/Atemplate <class Impl>
3292292SN/Avoid
3302292SN/ADefaultCommit<Impl>::setROB(ROB *rob_ptr)
3311060SN/A{
3321060SN/A    DPRINTF(Commit, "Commit: Setting ROB pointer.\n");
3331060SN/A    rob = rob_ptr;
3341060SN/A}
3351060SN/A
3361061SN/Atemplate <class Impl>
3371060SN/Avoid
3382292SN/ADefaultCommit<Impl>::initStage()
3391060SN/A{
3402292SN/A    rob->setActiveThreads(activeThreads);
3412292SN/A    rob->resetEntries();
3421060SN/A
3432292SN/A    // Broadcast the number of free entries.
3442292SN/A    for (int i=0; i < numThreads; i++) {
3452292SN/A        toIEW->commitInfo[i].usedROB = true;
3462292SN/A        toIEW->commitInfo[i].freeROBEntries = rob->numFreeEntries(i);
3471060SN/A    }
3481060SN/A
3492292SN/A    cpu->activityThisCycle();
3501060SN/A}
3511060SN/A
3521061SN/Atemplate <class Impl>
3531060SN/Avoid
3542307SN/ADefaultCommit<Impl>::switchOut()
3551060SN/A{
3562316SN/A    switchPending = true;
3572316SN/A}
3582316SN/A
3592316SN/Atemplate <class Impl>
3602316SN/Avoid
3612316SN/ADefaultCommit<Impl>::doSwitchOut()
3622316SN/A{
3632316SN/A    switchedOut = true;
3642316SN/A    switchPending = false;
3652307SN/A    rob->switchOut();
3662307SN/A}
3672307SN/A
3682307SN/Atemplate <class Impl>
3692307SN/Avoid
3702307SN/ADefaultCommit<Impl>::takeOverFrom()
3712307SN/A{
3722316SN/A    switchedOut = false;
3732307SN/A    _status = Active;
3742307SN/A    _nextStatus = Inactive;
3752307SN/A    for (int i=0; i < numThreads; i++) {
3762307SN/A        commitStatus[i] = Idle;
3772307SN/A        changedROBNumEntries[i] = false;
3782307SN/A        trapSquash[i] = false;
3792680Sktlim@umich.edu        tcSquash[i] = false;
3802307SN/A    }
3812307SN/A    squashCounter = 0;
3822307SN/A    rob->takeOverFrom();
3832307SN/A}
3842307SN/A
3852307SN/Atemplate <class Impl>
3862307SN/Avoid
3872292SN/ADefaultCommit<Impl>::updateStatus()
3882132SN/A{
3892316SN/A    // reset ROB changed variable
3902316SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
3912316SN/A    while (threads != (*activeThreads).end()) {
3922316SN/A        unsigned tid = *threads++;
3932316SN/A        changedROBNumEntries[tid] = false;
3942316SN/A
3952316SN/A        // Also check if any of the threads has a trap pending
3962316SN/A        if (commitStatus[tid] == TrapPending ||
3972316SN/A            commitStatus[tid] == FetchTrapPending) {
3982316SN/A            _nextStatus = Active;
3992316SN/A        }
4002292SN/A    }
4012292SN/A
4022292SN/A    if (_nextStatus == Inactive && _status == Active) {
4032292SN/A        DPRINTF(Activity, "Deactivating stage.\n");
4042733Sktlim@umich.edu        cpu->deactivateStage(O3CPU::CommitIdx);
4052292SN/A    } else if (_nextStatus == Active && _status == Inactive) {
4062292SN/A        DPRINTF(Activity, "Activating stage.\n");
4072733Sktlim@umich.edu        cpu->activateStage(O3CPU::CommitIdx);
4082292SN/A    }
4092292SN/A
4102292SN/A    _status = _nextStatus;
4112292SN/A}
4122292SN/A
4132292SN/Atemplate <class Impl>
4142292SN/Avoid
4152292SN/ADefaultCommit<Impl>::setNextStatus()
4162292SN/A{
4172292SN/A    int squashes = 0;
4182292SN/A
4192292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
4202292SN/A
4212292SN/A    while (threads != (*activeThreads).end()) {
4222292SN/A        unsigned tid = *threads++;
4232292SN/A
4242292SN/A        if (commitStatus[tid] == ROBSquashing) {
4252292SN/A            squashes++;
4262292SN/A        }
4272292SN/A    }
4282292SN/A
4292702Sktlim@umich.edu    squashCounter = squashes;
4302292SN/A
4312292SN/A    // If commit is currently squashing, then it will have activity for the
4322292SN/A    // next cycle. Set its next status as active.
4332292SN/A    if (squashCounter) {
4342292SN/A        _nextStatus = Active;
4352292SN/A    }
4362292SN/A}
4372292SN/A
4382292SN/Atemplate <class Impl>
4392292SN/Abool
4402292SN/ADefaultCommit<Impl>::changedROBEntries()
4412292SN/A{
4422292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
4432292SN/A
4442292SN/A    while (threads != (*activeThreads).end()) {
4452292SN/A        unsigned tid = *threads++;
4462292SN/A
4472292SN/A        if (changedROBNumEntries[tid]) {
4482292SN/A            return true;
4492292SN/A        }
4502292SN/A    }
4512292SN/A
4522292SN/A    return false;
4532292SN/A}
4542292SN/A
4552292SN/Atemplate <class Impl>
4562292SN/Aunsigned
4572292SN/ADefaultCommit<Impl>::numROBFreeEntries(unsigned tid)
4582292SN/A{
4592292SN/A    return rob->numFreeEntries(tid);
4602292SN/A}
4612292SN/A
4622292SN/Atemplate <class Impl>
4632292SN/Avoid
4642292SN/ADefaultCommit<Impl>::generateTrapEvent(unsigned tid)
4652292SN/A{
4662292SN/A    DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid);
4672292SN/A
4682292SN/A    TrapEvent *trap = new TrapEvent(this, tid);
4692292SN/A
4702292SN/A    trap->schedule(curTick + trapLatency);
4712292SN/A
4722292SN/A    thread[tid]->trapPending = true;
4732292SN/A}
4742292SN/A
4752292SN/Atemplate <class Impl>
4762292SN/Avoid
4772680Sktlim@umich.eduDefaultCommit<Impl>::generateTCEvent(unsigned tid)
4782292SN/A{
4792680Sktlim@umich.edu    DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid);
4802292SN/A
4812680Sktlim@umich.edu    tcSquash[tid] = true;
4822292SN/A}
4832292SN/A
4842292SN/Atemplate <class Impl>
4852292SN/Avoid
4862316SN/ADefaultCommit<Impl>::squashAll(unsigned tid)
4872292SN/A{
4882292SN/A    // If we want to include the squashing instruction in the squash,
4892292SN/A    // then use one older sequence number.
4902292SN/A    // Hopefully this doesn't mess things up.  Basically I want to squash
4912292SN/A    // all instructions of this thread.
4922292SN/A    InstSeqNum squashed_inst = rob->isEmpty() ?
4932292SN/A        0 : rob->readHeadInst(tid)->seqNum - 1;;
4942292SN/A
4952292SN/A    // All younger instructions will be squashed. Set the sequence
4962292SN/A    // number as the youngest instruction in the ROB (0 in this case.
4972292SN/A    // Hopefully nothing breaks.)
4982292SN/A    youngestSeqNum[tid] = 0;
4992292SN/A
5002292SN/A    rob->squash(squashed_inst, tid);
5012292SN/A    changedROBNumEntries[tid] = true;
5022292SN/A
5032292SN/A    // Send back the sequence number of the squashed instruction.
5042292SN/A    toIEW->commitInfo[tid].doneSeqNum = squashed_inst;
5052292SN/A
5062292SN/A    // Send back the squash signal to tell stages that they should
5072292SN/A    // squash.
5082292SN/A    toIEW->commitInfo[tid].squash = true;
5092292SN/A
5102292SN/A    // Send back the rob squashing signal so other stages know that
5112292SN/A    // the ROB is in the process of squashing.
5122292SN/A    toIEW->commitInfo[tid].robSquashing = true;
5132292SN/A
5142292SN/A    toIEW->commitInfo[tid].branchMispredict = false;
5152292SN/A
5162316SN/A    toIEW->commitInfo[tid].nextPC = PC[tid];
5172316SN/A}
5182292SN/A
5192316SN/Atemplate <class Impl>
5202316SN/Avoid
5212316SN/ADefaultCommit<Impl>::squashFromTrap(unsigned tid)
5222316SN/A{
5232316SN/A    squashAll(tid);
5242316SN/A
5252316SN/A    DPRINTF(Commit, "Squashing from trap, restarting at PC %#x\n", PC[tid]);
5262316SN/A
5272316SN/A    thread[tid]->trapPending = false;
5282316SN/A    thread[tid]->inSyscall = false;
5292316SN/A
5302316SN/A    trapSquash[tid] = false;
5312316SN/A
5322316SN/A    commitStatus[tid] = ROBSquashing;
5332316SN/A    cpu->activityThisCycle();
5342316SN/A}
5352316SN/A
5362316SN/Atemplate <class Impl>
5372316SN/Avoid
5382680Sktlim@umich.eduDefaultCommit<Impl>::squashFromTC(unsigned tid)
5392316SN/A{
5402316SN/A    squashAll(tid);
5412292SN/A
5422680Sktlim@umich.edu    DPRINTF(Commit, "Squashing from TC, restarting at PC %#x\n", PC[tid]);
5432292SN/A
5442292SN/A    thread[tid]->inSyscall = false;
5452292SN/A    assert(!thread[tid]->trapPending);
5462316SN/A
5472292SN/A    commitStatus[tid] = ROBSquashing;
5482292SN/A    cpu->activityThisCycle();
5492292SN/A
5502680Sktlim@umich.edu    tcSquash[tid] = false;
5512292SN/A}
5522292SN/A
5532292SN/Atemplate <class Impl>
5542292SN/Avoid
5552292SN/ADefaultCommit<Impl>::tick()
5562292SN/A{
5572292SN/A    wroteToTimeBuffer = false;
5582292SN/A    _nextStatus = Inactive;
5592292SN/A
5602316SN/A    if (switchPending && rob->isEmpty() && !iewStage->hasStoresToWB()) {
5612316SN/A        cpu->signalSwitched();
5622316SN/A        return;
5632316SN/A    }
5642316SN/A
5652292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
5662292SN/A
5672316SN/A    // Check if any of the threads are done squashing.  Change the
5682316SN/A    // status if they are done.
5692292SN/A    while (threads != (*activeThreads).end()) {
5702292SN/A        unsigned tid = *threads++;
5712292SN/A
5722292SN/A        if (commitStatus[tid] == ROBSquashing) {
5732292SN/A
5742292SN/A            if (rob->isDoneSquashing(tid)) {
5752292SN/A                commitStatus[tid] = Running;
5762292SN/A            } else {
5772292SN/A                DPRINTF(Commit,"[tid:%u]: Still Squashing, cannot commit any"
5782292SN/A                        "insts this cycle.\n", tid);
5792702Sktlim@umich.edu                rob->doSquash(tid);
5802702Sktlim@umich.edu                toIEW->commitInfo[tid].robSquashing = true;
5812702Sktlim@umich.edu                wroteToTimeBuffer = true;
5822292SN/A            }
5832292SN/A        }
5842292SN/A    }
5852292SN/A
5862292SN/A    commit();
5872292SN/A
5882292SN/A    markCompletedInsts();
5892292SN/A
5902292SN/A    threads = (*activeThreads).begin();
5912292SN/A
5922292SN/A    while (threads != (*activeThreads).end()) {
5932292SN/A        unsigned tid = *threads++;
5942292SN/A
5952292SN/A        if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) {
5962292SN/A            // The ROB has more instructions it can commit. Its next status
5972292SN/A            // will be active.
5982292SN/A            _nextStatus = Active;
5992292SN/A
6002292SN/A            DynInstPtr inst = rob->readHeadInst(tid);
6012292SN/A
6022292SN/A            DPRINTF(Commit,"[tid:%i]: Instruction [sn:%lli] PC %#x is head of"
6032292SN/A                    " ROB and ready to commit\n",
6042292SN/A                    tid, inst->seqNum, inst->readPC());
6052292SN/A
6062292SN/A        } else if (!rob->isEmpty(tid)) {
6072292SN/A            DynInstPtr inst = rob->readHeadInst(tid);
6082292SN/A
6092292SN/A            DPRINTF(Commit,"[tid:%i]: Can't commit, Instruction [sn:%lli] PC "
6102292SN/A                    "%#x is head of ROB and not ready\n",
6112292SN/A                    tid, inst->seqNum, inst->readPC());
6122292SN/A        }
6132292SN/A
6142292SN/A        DPRINTF(Commit, "[tid:%i]: ROB has %d insts & %d free entries.\n",
6152292SN/A                tid, rob->countInsts(tid), rob->numFreeEntries(tid));
6162292SN/A    }
6172292SN/A
6182292SN/A
6192292SN/A    if (wroteToTimeBuffer) {
6202316SN/A        DPRINTF(Activity, "Activity This Cycle.\n");
6212292SN/A        cpu->activityThisCycle();
6222292SN/A    }
6232292SN/A
6242292SN/A    updateStatus();
6252292SN/A}
6262292SN/A
6272292SN/Atemplate <class Impl>
6282292SN/Avoid
6292292SN/ADefaultCommit<Impl>::commit()
6302292SN/A{
6312292SN/A
6321060SN/A    //////////////////////////////////////
6331060SN/A    // Check for interrupts
6341060SN/A    //////////////////////////////////////
6351060SN/A
6361858SN/A#if FULL_SYSTEM
6372316SN/A    // Process interrupts if interrupts are enabled, not in PAL mode,
6382316SN/A    // and no other traps or external squashes are currently pending.
6392316SN/A    // @todo: Allow other threads to handle interrupts.
6402292SN/A    if (cpu->checkInterrupts &&
6411060SN/A        cpu->check_interrupts() &&
6422292SN/A        !cpu->inPalMode(readPC()) &&
6432292SN/A        !trapSquash[0] &&
6442680Sktlim@umich.edu        !tcSquash[0]) {
6452316SN/A        // Tell fetch that there is an interrupt pending.  This will
6462316SN/A        // make fetch wait until it sees a non PAL-mode PC, at which
6472316SN/A        // point it stops fetching instructions.
6482292SN/A        toIEW->commitInfo[0].interruptPending = true;
6491060SN/A
6502316SN/A        // Wait until the ROB is empty and all stores have drained in
6512316SN/A        // order to enter the interrupt.
6522292SN/A        if (rob->isEmpty() && !iewStage->hasStoresToWB()) {
6532292SN/A            // Not sure which thread should be the one to interrupt.  For now
6542292SN/A            // always do thread 0.
6552292SN/A            assert(!thread[0]->inSyscall);
6562292SN/A            thread[0]->inSyscall = true;
6572292SN/A
6582292SN/A            // CPU will handle implementation of the interrupt.
6592292SN/A            cpu->processInterrupts();
6602292SN/A
6612292SN/A            // Now squash or record that I need to squash this cycle.
6622292SN/A            commitStatus[0] = TrapPending;
6632292SN/A
6642292SN/A            // Exit state update mode to avoid accidental updating.
6652292SN/A            thread[0]->inSyscall = false;
6662292SN/A
6672292SN/A            // Generate trap squash event.
6682292SN/A            generateTrapEvent(0);
6692292SN/A
6702292SN/A            toIEW->commitInfo[0].clearInterrupt = true;
6712292SN/A
6722292SN/A            DPRINTF(Commit, "Interrupt detected.\n");
6732292SN/A        } else {
6742292SN/A            DPRINTF(Commit, "Interrupt pending, waiting for ROB to empty.\n");
6752292SN/A        }
6761060SN/A    }
6771060SN/A#endif // FULL_SYSTEM
6781060SN/A
6791060SN/A    ////////////////////////////////////
6802316SN/A    // Check for any possible squashes, handle them first
6811060SN/A    ////////////////////////////////////
6821060SN/A
6832292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
6841060SN/A
6852292SN/A    while (threads != (*activeThreads).end()) {
6862292SN/A        unsigned tid = *threads++;
6871060SN/A
6882292SN/A        // Not sure which one takes priority.  I think if we have
6892292SN/A        // both, that's a bad sign.
6902292SN/A        if (trapSquash[tid] == true) {
6912680Sktlim@umich.edu            assert(!tcSquash[tid]);
6922292SN/A            squashFromTrap(tid);
6932680Sktlim@umich.edu        } else if (tcSquash[tid] == true) {
6942680Sktlim@umich.edu            squashFromTC(tid);
6952292SN/A        }
6961061SN/A
6972292SN/A        // Squashed sequence number must be older than youngest valid
6982292SN/A        // instruction in the ROB. This prevents squashes from younger
6992292SN/A        // instructions overriding squashes from older instructions.
7002292SN/A        if (fromIEW->squash[tid] &&
7012292SN/A            commitStatus[tid] != TrapPending &&
7022292SN/A            fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) {
7031061SN/A
7042292SN/A            DPRINTF(Commit, "[tid:%i]: Squashing due to PC %#x [sn:%i]\n",
7052292SN/A                    tid,
7062292SN/A                    fromIEW->mispredPC[tid],
7072292SN/A                    fromIEW->squashedSeqNum[tid]);
7081061SN/A
7092292SN/A            DPRINTF(Commit, "[tid:%i]: Redirecting to PC %#x\n",
7102292SN/A                    tid,
7112292SN/A                    fromIEW->nextPC[tid]);
7121061SN/A
7132292SN/A            commitStatus[tid] = ROBSquashing;
7141061SN/A
7152292SN/A            // If we want to include the squashing instruction in the squash,
7162292SN/A            // then use one older sequence number.
7172292SN/A            InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid];
7181062SN/A
7192292SN/A            if (fromIEW->includeSquashInst[tid] == true)
7202292SN/A                squashed_inst--;
7212292SN/A
7222292SN/A            // All younger instructions will be squashed. Set the sequence
7232292SN/A            // number as the youngest instruction in the ROB.
7242292SN/A            youngestSeqNum[tid] = squashed_inst;
7252292SN/A
7262292SN/A            rob->squash(squashed_inst, tid);
7272292SN/A            changedROBNumEntries[tid] = true;
7282292SN/A
7292292SN/A            toIEW->commitInfo[tid].doneSeqNum = squashed_inst;
7302292SN/A
7312292SN/A            toIEW->commitInfo[tid].squash = true;
7322292SN/A
7332292SN/A            // Send back the rob squashing signal so other stages know that
7342292SN/A            // the ROB is in the process of squashing.
7352292SN/A            toIEW->commitInfo[tid].robSquashing = true;
7362292SN/A
7372292SN/A            toIEW->commitInfo[tid].branchMispredict =
7382292SN/A                fromIEW->branchMispredict[tid];
7392292SN/A
7402292SN/A            toIEW->commitInfo[tid].branchTaken =
7412292SN/A                fromIEW->branchTaken[tid];
7422292SN/A
7432292SN/A            toIEW->commitInfo[tid].nextPC = fromIEW->nextPC[tid];
7442292SN/A
7452316SN/A            toIEW->commitInfo[tid].mispredPC = fromIEW->mispredPC[tid];
7462292SN/A
7472292SN/A            if (toIEW->commitInfo[tid].branchMispredict) {
7482292SN/A                ++branchMispredicts;
7492292SN/A            }
7501062SN/A        }
7512292SN/A
7521060SN/A    }
7531060SN/A
7542292SN/A    setNextStatus();
7552292SN/A
7562292SN/A    if (squashCounter != numThreads) {
7571061SN/A        // If we're not currently squashing, then get instructions.
7581060SN/A        getInsts();
7591060SN/A
7601061SN/A        // Try to commit any instructions.
7611060SN/A        commitInsts();
7621060SN/A    }
7631060SN/A
7642292SN/A    //Check for any activity
7652292SN/A    threads = (*activeThreads).begin();
7662292SN/A
7672292SN/A    while (threads != (*activeThreads).end()) {
7682292SN/A        unsigned tid = *threads++;
7692292SN/A
7702292SN/A        if (changedROBNumEntries[tid]) {
7712292SN/A            toIEW->commitInfo[tid].usedROB = true;
7722292SN/A            toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid);
7732292SN/A
7742292SN/A            if (rob->isEmpty(tid)) {
7752292SN/A                toIEW->commitInfo[tid].emptyROB = true;
7762292SN/A            }
7772292SN/A
7782292SN/A            wroteToTimeBuffer = true;
7792292SN/A            changedROBNumEntries[tid] = false;
7802292SN/A        }
7811060SN/A    }
7821060SN/A}
7831060SN/A
7841061SN/Atemplate <class Impl>
7851060SN/Avoid
7862292SN/ADefaultCommit<Impl>::commitInsts()
7871060SN/A{
7881060SN/A    ////////////////////////////////////
7891060SN/A    // Handle commit
7902316SN/A    // Note that commit will be handled prior to putting new
7912316SN/A    // instructions in the ROB so that the ROB only tries to commit
7922316SN/A    // instructions it has in this current cycle, and not instructions
7932316SN/A    // it is writing in during this cycle.  Can't commit and squash
7942316SN/A    // things at the same time...
7951060SN/A    ////////////////////////////////////
7961060SN/A
7972292SN/A    DPRINTF(Commit, "Trying to commit instructions in the ROB.\n");
7981060SN/A
7991060SN/A    unsigned num_committed = 0;
8001060SN/A
8012292SN/A    DynInstPtr head_inst;
8022316SN/A
8031060SN/A    // Commit as many instructions as possible until the commit bandwidth
8041060SN/A    // limit is reached, or it becomes impossible to commit any more.
8052292SN/A    while (num_committed < commitWidth) {
8062292SN/A        int commit_thread = getCommittingThread();
8071060SN/A
8082292SN/A        if (commit_thread == -1 || !rob->isHeadReady(commit_thread))
8092292SN/A            break;
8102292SN/A
8112292SN/A        head_inst = rob->readHeadInst(commit_thread);
8122292SN/A
8132292SN/A        int tid = head_inst->threadNumber;
8142292SN/A
8152292SN/A        assert(tid == commit_thread);
8162292SN/A
8172292SN/A        DPRINTF(Commit, "Trying to commit head instruction, [sn:%i] [tid:%i]\n",
8182292SN/A                head_inst->seqNum, tid);
8192132SN/A
8202316SN/A        // If the head instruction is squashed, it is ready to retire
8212316SN/A        // (be removed from the ROB) at any time.
8221060SN/A        if (head_inst->isSquashed()) {
8231060SN/A
8242292SN/A            DPRINTF(Commit, "Retiring squashed instruction from "
8251060SN/A                    "ROB.\n");
8261060SN/A
8272292SN/A            rob->retireHead(commit_thread);
8281060SN/A
8291062SN/A            ++commitSquashedInsts;
8301062SN/A
8312292SN/A            // Record that the number of ROB entries has changed.
8322292SN/A            changedROBNumEntries[tid] = true;
8331060SN/A        } else {
8342292SN/A            PC[tid] = head_inst->readPC();
8352292SN/A            nextPC[tid] = head_inst->readNextPC();
8362292SN/A
8371060SN/A            // Increment the total number of non-speculative instructions
8381060SN/A            // executed.
8391060SN/A            // Hack for now: it really shouldn't happen until after the
8401061SN/A            // commit is deemed to be successful, but this count is needed
8411061SN/A            // for syscalls.
8422292SN/A            thread[tid]->funcExeInst++;
8431060SN/A
8441060SN/A            // Try to commit the head instruction.
8451060SN/A            bool commit_success = commitHead(head_inst, num_committed);
8461060SN/A
8471062SN/A            if (commit_success) {
8481060SN/A                ++num_committed;
8491060SN/A
8502292SN/A                changedROBNumEntries[tid] = true;
8512292SN/A
8522292SN/A                // Set the doneSeqNum to the youngest committed instruction.
8532292SN/A                toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum;
8541060SN/A
8551062SN/A                ++commitCommittedInsts;
8561062SN/A
8572292SN/A                // To match the old model, don't count nops and instruction
8582292SN/A                // prefetches towards the total commit count.
8592292SN/A                if (!head_inst->isNop() && !head_inst->isInstPrefetch()) {
8602292SN/A                    cpu->instDone(tid);
8611062SN/A                }
8622292SN/A
8632292SN/A                PC[tid] = nextPC[tid];
8642307SN/A                nextPC[tid] = nextPC[tid] + sizeof(TheISA::MachInst);
8652292SN/A#if FULL_SYSTEM
8662292SN/A                int count = 0;
8672292SN/A                Addr oldpc;
8682292SN/A                do {
8692316SN/A                    // Debug statement.  Checks to make sure we're not
8702316SN/A                    // currently updating state while handling PC events.
8712292SN/A                    if (count == 0)
8722316SN/A                        assert(!thread[tid]->inSyscall &&
8732316SN/A                               !thread[tid]->trapPending);
8742292SN/A                    oldpc = PC[tid];
8752292SN/A                    cpu->system->pcEventQueue.service(
8762690Sktlim@umich.edu                        thread[tid]->getTC());
8772292SN/A                    count++;
8782292SN/A                } while (oldpc != PC[tid]);
8792292SN/A                if (count > 1) {
8802292SN/A                    DPRINTF(Commit, "PC skip function event, stopping commit\n");
8812292SN/A                    break;
8822292SN/A                }
8832292SN/A#endif
8841060SN/A            } else {
8852292SN/A                DPRINTF(Commit, "Unable to commit head instruction PC:%#x "
8862292SN/A                        "[tid:%i] [sn:%i].\n",
8872292SN/A                        head_inst->readPC(), tid ,head_inst->seqNum);
8881060SN/A                break;
8891060SN/A            }
8901060SN/A        }
8911060SN/A    }
8921062SN/A
8931063SN/A    DPRINTF(CommitRate, "%i\n", num_committed);
8942292SN/A    numCommittedDist.sample(num_committed);
8952307SN/A
8962307SN/A    if (num_committed == commitWidth) {
8972349SN/A        commitEligibleSamples++;
8982307SN/A    }
8991060SN/A}
9001060SN/A
9011061SN/Atemplate <class Impl>
9021060SN/Abool
9032292SN/ADefaultCommit<Impl>::commitHead(DynInstPtr &head_inst, unsigned inst_num)
9041060SN/A{
9051060SN/A    assert(head_inst);
9061060SN/A
9072292SN/A    int tid = head_inst->threadNumber;
9082292SN/A
9092316SN/A    // If the instruction is not executed yet, then it will need extra
9102316SN/A    // handling.  Signal backwards that it should be executed.
9111061SN/A    if (!head_inst->isExecuted()) {
9121061SN/A        // Keep this number correct.  We have not yet actually executed
9131061SN/A        // and committed this instruction.
9142292SN/A        thread[tid]->funcExeInst--;
9151062SN/A
9162731Sktlim@umich.edu        head_inst->setAtCommit();
9171060SN/A
9182292SN/A        if (head_inst->isNonSpeculative() ||
9192348SN/A            head_inst->isStoreConditional() ||
9202292SN/A            head_inst->isMemBarrier() ||
9212292SN/A            head_inst->isWriteBarrier()) {
9222316SN/A
9232316SN/A            DPRINTF(Commit, "Encountered a barrier or non-speculative "
9242316SN/A                    "instruction [sn:%lli] at the head of the ROB, PC %#x.\n",
9252316SN/A                    head_inst->seqNum, head_inst->readPC());
9262316SN/A
9272292SN/A#if !FULL_SYSTEM
9282316SN/A            // Hack to make sure syscalls/memory barriers/quiesces
9292316SN/A            // aren't executed until all stores write back their data.
9302316SN/A            // This direct communication shouldn't be used for
9312316SN/A            // anything other than this.
9322292SN/A            if (inst_num > 0 || iewStage->hasStoresToWB())
9332292SN/A#else
9342292SN/A            if ((head_inst->isMemBarrier() || head_inst->isWriteBarrier() ||
9352292SN/A                    head_inst->isQuiesce()) &&
9362292SN/A                iewStage->hasStoresToWB())
9372292SN/A#endif
9382292SN/A            {
9392292SN/A                DPRINTF(Commit, "Waiting for all stores to writeback.\n");
9402292SN/A                return false;
9412292SN/A            }
9422292SN/A
9432292SN/A            toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum;
9441061SN/A
9451061SN/A            // Change the instruction so it won't try to commit again until
9461061SN/A            // it is executed.
9471061SN/A            head_inst->clearCanCommit();
9481061SN/A
9491062SN/A            ++commitNonSpecStalls;
9501062SN/A
9511061SN/A            return false;
9522292SN/A        } else if (head_inst->isLoad()) {
9532292SN/A            DPRINTF(Commit, "[sn:%lli]: Uncached load, PC %#x.\n",
9542292SN/A                    head_inst->seqNum, head_inst->readPC());
9552292SN/A
9562292SN/A            // Send back the non-speculative instruction's sequence
9572316SN/A            // number.  Tell the lsq to re-execute the load.
9582292SN/A            toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum;
9592292SN/A            toIEW->commitInfo[tid].uncached = true;
9602292SN/A            toIEW->commitInfo[tid].uncachedLoad = head_inst;
9612292SN/A
9622292SN/A            head_inst->clearCanCommit();
9632292SN/A
9642292SN/A            return false;
9651061SN/A        } else {
9662292SN/A            panic("Trying to commit un-executed instruction "
9671061SN/A                  "of unknown type!\n");
9681061SN/A        }
9691060SN/A    }
9701060SN/A
9712316SN/A    if (head_inst->isThreadSync()) {
9722292SN/A        // Not handled for now.
9732316SN/A        panic("Thread sync instructions are not handled yet.\n");
9742132SN/A    }
9752132SN/A
9762316SN/A    // Stores mark themselves as completed.
9772310SN/A    if (!head_inst->isStore()) {
9782310SN/A        head_inst->setCompleted();
9792310SN/A    }
9802310SN/A
9812733Sktlim@umich.edu#if USE_CHECKER
9822316SN/A    // Use checker prior to updating anything due to traps or PC
9832316SN/A    // based events.
9842316SN/A    if (cpu->checker) {
9852732Sktlim@umich.edu        cpu->checker->verify(head_inst);
9861060SN/A    }
9872733Sktlim@umich.edu#endif
9881060SN/A
9891060SN/A    // Check if the instruction caused a fault.  If so, trap.
9902132SN/A    Fault inst_fault = head_inst->getFault();
9911681SN/A
9922112SN/A    if (inst_fault != NoFault) {
9932316SN/A        head_inst->setCompleted();
9941858SN/A#if FULL_SYSTEM
9952316SN/A        DPRINTF(Commit, "Inst [sn:%lli] PC %#x has a fault\n",
9962316SN/A                head_inst->seqNum, head_inst->readPC());
9972292SN/A
9982316SN/A        if (iewStage->hasStoresToWB() || inst_num > 0) {
9992316SN/A            DPRINTF(Commit, "Stores outstanding, fault must wait.\n");
10002316SN/A            return false;
10012316SN/A        }
10022310SN/A
10032733Sktlim@umich.edu#if USE_CHECKER
10042316SN/A        if (cpu->checker && head_inst->isStore()) {
10052732Sktlim@umich.edu            cpu->checker->verify(head_inst);
10062316SN/A        }
10072733Sktlim@umich.edu#endif
10082292SN/A
10092316SN/A        assert(!thread[tid]->inSyscall);
10102292SN/A
10112316SN/A        // Mark that we're in state update mode so that the trap's
10122316SN/A        // execution doesn't generate extra squashes.
10132316SN/A        thread[tid]->inSyscall = true;
10142292SN/A
10152316SN/A        // DTB will sometimes need the machine instruction for when
10162316SN/A        // faults happen.  So we will set it here, prior to the DTB
10172316SN/A        // possibly needing it for its fault.
10182316SN/A        thread[tid]->setInst(
10192316SN/A            static_cast<TheISA::MachInst>(head_inst->staticInst->machInst));
10202292SN/A
10212316SN/A        // Execute the trap.  Although it's slightly unrealistic in
10222316SN/A        // terms of timing (as it doesn't wait for the full timing of
10232316SN/A        // the trap event to complete before updating state), it's
10242316SN/A        // needed to update the state as soon as possible.  This
10252316SN/A        // prevents external agents from changing any specific state
10262316SN/A        // that the trap need.
10272316SN/A        cpu->trap(inst_fault, tid);
10282292SN/A
10292316SN/A        // Exit state update mode to avoid accidental updating.
10302316SN/A        thread[tid]->inSyscall = false;
10312292SN/A
10322316SN/A        commitStatus[tid] = TrapPending;
10332292SN/A
10342316SN/A        // Generate trap squash event.
10352316SN/A        generateTrapEvent(tid);
10362316SN/A
10372316SN/A        return false;
10381060SN/A#else // !FULL_SYSTEM
10392316SN/A        panic("fault (%d) detected @ PC %08p", inst_fault,
10402316SN/A              head_inst->PC);
10411062SN/A#endif // FULL_SYSTEM
10421060SN/A    }
10431060SN/A
10442301SN/A    updateComInstStats(head_inst);
10452132SN/A
10462132SN/A    if (head_inst->traceData) {
10472292SN/A        head_inst->traceData->setFetchSeq(head_inst->seqNum);
10482292SN/A        head_inst->traceData->setCPSeq(thread[tid]->numInst);
10492132SN/A        head_inst->traceData->finalize();
10502292SN/A        head_inst->traceData = NULL;
10511060SN/A    }
10521060SN/A
10532292SN/A    // Update the commit rename map
10542292SN/A    for (int i = 0; i < head_inst->numDestRegs(); i++) {
10552292SN/A        renameMap[tid]->setEntry(head_inst->destRegIdx(i),
10562292SN/A                                 head_inst->renamedDestRegIdx(i));
10571060SN/A    }
10581062SN/A
10592292SN/A    // Finally clear the head ROB entry.
10602292SN/A    rob->retireHead(tid);
10611060SN/A
10621060SN/A    // Return true to indicate that we have committed an instruction.
10631060SN/A    return true;
10641060SN/A}
10651060SN/A
10661061SN/Atemplate <class Impl>
10671060SN/Avoid
10682292SN/ADefaultCommit<Impl>::getInsts()
10691060SN/A{
10702316SN/A    // Read any renamed instructions and place them into the ROB.
10711061SN/A    int insts_to_process = min((int)renameWidth, fromRename->size);
10721061SN/A
10732292SN/A    for (int inst_num = 0; inst_num < insts_to_process; ++inst_num)
10741060SN/A    {
10752292SN/A        DynInstPtr inst = fromRename->insts[inst_num];
10762292SN/A        int tid = inst->threadNumber;
10772292SN/A
10782292SN/A        if (!inst->isSquashed() &&
10792292SN/A            commitStatus[tid] != ROBSquashing) {
10802292SN/A            changedROBNumEntries[tid] = true;
10812292SN/A
10822292SN/A            DPRINTF(Commit, "Inserting PC %#x [sn:%i] [tid:%i] into ROB.\n",
10832292SN/A                    inst->readPC(), inst->seqNum, tid);
10842292SN/A
10852292SN/A            rob->insertInst(inst);
10862292SN/A
10872292SN/A            assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid));
10882292SN/A
10892292SN/A            youngestSeqNum[tid] = inst->seqNum;
10901061SN/A        } else {
10912292SN/A            DPRINTF(Commit, "Instruction PC %#x [sn:%i] [tid:%i] was "
10921061SN/A                    "squashed, skipping.\n",
10932292SN/A                    inst->readPC(), inst->seqNum, tid);
10941061SN/A        }
10951060SN/A    }
10961060SN/A}
10971060SN/A
10981061SN/Atemplate <class Impl>
10991060SN/Avoid
11002292SN/ADefaultCommit<Impl>::markCompletedInsts()
11011060SN/A{
11021060SN/A    // Grab completed insts out of the IEW instruction queue, and mark
11031060SN/A    // instructions completed within the ROB.
11041060SN/A    for (int inst_num = 0;
11051681SN/A         inst_num < fromIEW->size && fromIEW->insts[inst_num];
11061060SN/A         ++inst_num)
11071060SN/A    {
11082292SN/A        if (!fromIEW->insts[inst_num]->isSquashed()) {
11092316SN/A            DPRINTF(Commit, "[tid:%i]: Marking PC %#x, [sn:%lli] ready "
11102316SN/A                    "within ROB.\n",
11112292SN/A                    fromIEW->insts[inst_num]->threadNumber,
11122292SN/A                    fromIEW->insts[inst_num]->readPC(),
11132292SN/A                    fromIEW->insts[inst_num]->seqNum);
11141060SN/A
11152292SN/A            // Mark the instruction as ready to commit.
11162292SN/A            fromIEW->insts[inst_num]->setCanCommit();
11172292SN/A        }
11181060SN/A    }
11191060SN/A}
11201060SN/A
11211061SN/Atemplate <class Impl>
11222292SN/Abool
11232292SN/ADefaultCommit<Impl>::robDoneSquashing()
11241060SN/A{
11252292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
11262292SN/A
11272292SN/A    while (threads != (*activeThreads).end()) {
11282292SN/A        unsigned tid = *threads++;
11292292SN/A
11302292SN/A        if (!rob->isDoneSquashing(tid))
11312292SN/A            return false;
11322292SN/A    }
11332292SN/A
11342292SN/A    return true;
11351060SN/A}
11362292SN/A
11372301SN/Atemplate <class Impl>
11382301SN/Avoid
11392301SN/ADefaultCommit<Impl>::updateComInstStats(DynInstPtr &inst)
11402301SN/A{
11412301SN/A    unsigned thread = inst->threadNumber;
11422301SN/A
11432301SN/A    //
11442301SN/A    //  Pick off the software prefetches
11452301SN/A    //
11462301SN/A#ifdef TARGET_ALPHA
11472301SN/A    if (inst->isDataPrefetch()) {
11482316SN/A        statComSwp[thread]++;
11492301SN/A    } else {
11502316SN/A        statComInst[thread]++;
11512301SN/A    }
11522301SN/A#else
11532316SN/A    statComInst[thread]++;
11542301SN/A#endif
11552301SN/A
11562301SN/A    //
11572301SN/A    //  Control Instructions
11582301SN/A    //
11592301SN/A    if (inst->isControl())
11602316SN/A        statComBranches[thread]++;
11612301SN/A
11622301SN/A    //
11632301SN/A    //  Memory references
11642301SN/A    //
11652301SN/A    if (inst->isMemRef()) {
11662316SN/A        statComRefs[thread]++;
11672301SN/A
11682301SN/A        if (inst->isLoad()) {
11692316SN/A            statComLoads[thread]++;
11702301SN/A        }
11712301SN/A    }
11722301SN/A
11732301SN/A    if (inst->isMemBarrier()) {
11742316SN/A        statComMembars[thread]++;
11752301SN/A    }
11762301SN/A}
11772301SN/A
11782292SN/A////////////////////////////////////////
11792292SN/A//                                    //
11802316SN/A//  SMT COMMIT POLICY MAINTAINED HERE //
11812292SN/A//                                    //
11822292SN/A////////////////////////////////////////
11832292SN/Atemplate <class Impl>
11842292SN/Aint
11852292SN/ADefaultCommit<Impl>::getCommittingThread()
11862292SN/A{
11872292SN/A    if (numThreads > 1) {
11882292SN/A        switch (commitPolicy) {
11892292SN/A
11902292SN/A          case Aggressive:
11912292SN/A            //If Policy is Aggressive, commit will call
11922292SN/A            //this function multiple times per
11932292SN/A            //cycle
11942292SN/A            return oldestReady();
11952292SN/A
11962292SN/A          case RoundRobin:
11972292SN/A            return roundRobin();
11982292SN/A
11992292SN/A          case OldestReady:
12002292SN/A            return oldestReady();
12012292SN/A
12022292SN/A          default:
12032292SN/A            return -1;
12042292SN/A        }
12052292SN/A    } else {
12062292SN/A        int tid = (*activeThreads).front();
12072292SN/A
12082292SN/A        if (commitStatus[tid] == Running ||
12092292SN/A            commitStatus[tid] == Idle ||
12102292SN/A            commitStatus[tid] == FetchTrapPending) {
12112292SN/A            return tid;
12122292SN/A        } else {
12132292SN/A            return -1;
12142292SN/A        }
12152292SN/A    }
12162292SN/A}
12172292SN/A
12182292SN/Atemplate<class Impl>
12192292SN/Aint
12202292SN/ADefaultCommit<Impl>::roundRobin()
12212292SN/A{
12222292SN/A    list<unsigned>::iterator pri_iter = priority_list.begin();
12232292SN/A    list<unsigned>::iterator end      = priority_list.end();
12242292SN/A
12252292SN/A    while (pri_iter != end) {
12262292SN/A        unsigned tid = *pri_iter;
12272292SN/A
12282292SN/A        if (commitStatus[tid] == Running ||
12292292SN/A            commitStatus[tid] == Idle) {
12302292SN/A
12312292SN/A            if (rob->isHeadReady(tid)) {
12322292SN/A                priority_list.erase(pri_iter);
12332292SN/A                priority_list.push_back(tid);
12342292SN/A
12352292SN/A                return tid;
12362292SN/A            }
12372292SN/A        }
12382292SN/A
12392292SN/A        pri_iter++;
12402292SN/A    }
12412292SN/A
12422292SN/A    return -1;
12432292SN/A}
12442292SN/A
12452292SN/Atemplate<class Impl>
12462292SN/Aint
12472292SN/ADefaultCommit<Impl>::oldestReady()
12482292SN/A{
12492292SN/A    unsigned oldest = 0;
12502292SN/A    bool first = true;
12512292SN/A
12522292SN/A    list<unsigned>::iterator threads = (*activeThreads).begin();
12532292SN/A
12542292SN/A    while (threads != (*activeThreads).end()) {
12552292SN/A        unsigned tid = *threads++;
12562292SN/A
12572292SN/A        if (!rob->isEmpty(tid) &&
12582292SN/A            (commitStatus[tid] == Running ||
12592292SN/A             commitStatus[tid] == Idle ||
12602292SN/A             commitStatus[tid] == FetchTrapPending)) {
12612292SN/A
12622292SN/A            if (rob->isHeadReady(tid)) {
12632292SN/A
12642292SN/A                DynInstPtr head_inst = rob->readHeadInst(tid);
12652292SN/A
12662292SN/A                if (first) {
12672292SN/A                    oldest = tid;
12682292SN/A                    first = false;
12692292SN/A                } else if (head_inst->seqNum < oldest) {
12702292SN/A                    oldest = tid;
12712292SN/A                }
12722292SN/A            }
12732292SN/A        }
12742292SN/A    }
12752292SN/A
12762292SN/A    if (!first) {
12772292SN/A        return oldest;
12782292SN/A    } else {
12792292SN/A        return -1;
12802292SN/A    }
12812292SN/A}
1282