cpu.cc revision 3093
11689SN/A/* 22325SN/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 292756Sksewell@umich.edu * Korey Sewell 301689SN/A */ 311689SN/A 321858SN/A#include "config/full_system.hh" 332733Sktlim@umich.edu#include "config/use_checker.hh" 341858SN/A 351858SN/A#if FULL_SYSTEM 361060SN/A#include "sim/system.hh" 371060SN/A#else 381060SN/A#include "sim/process.hh" 391060SN/A#endif 401060SN/A 412325SN/A#include "cpu/activity.hh" 422683Sktlim@umich.edu#include "cpu/simple_thread.hh" 432680Sktlim@umich.edu#include "cpu/thread_context.hh" 442817Sksewell@umich.edu#include "cpu/o3/isa_specific.hh" 451717SN/A#include "cpu/o3/cpu.hh" 461060SN/A 472325SN/A#include "sim/root.hh" 482292SN/A#include "sim/stat_control.hh" 492292SN/A 502794Sktlim@umich.edu#if USE_CHECKER 512794Sktlim@umich.edu#include "cpu/checker/cpu.hh" 522794Sktlim@umich.edu#endif 532794Sktlim@umich.edu 541060SN/Ausing namespace std; 552669Sktlim@umich.eduusing namespace TheISA; 561060SN/A 572733Sktlim@umich.eduBaseO3CPU::BaseO3CPU(Params *params) 582292SN/A : BaseCPU(params), cpu_id(0) 591060SN/A{ 601060SN/A} 611060SN/A 622292SN/Avoid 632733Sktlim@umich.eduBaseO3CPU::regStats() 642292SN/A{ 652292SN/A BaseCPU::regStats(); 662292SN/A} 672292SN/A 681060SN/Atemplate <class Impl> 691755SN/AFullO3CPU<Impl>::TickEvent::TickEvent(FullO3CPU<Impl> *c) 701060SN/A : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) 711060SN/A{ 721060SN/A} 731060SN/A 741060SN/Atemplate <class Impl> 751060SN/Avoid 761755SN/AFullO3CPU<Impl>::TickEvent::process() 771060SN/A{ 781060SN/A cpu->tick(); 791060SN/A} 801060SN/A 811060SN/Atemplate <class Impl> 821060SN/Aconst char * 831755SN/AFullO3CPU<Impl>::TickEvent::description() 841060SN/A{ 851755SN/A return "FullO3CPU tick event"; 861060SN/A} 871060SN/A 881060SN/Atemplate <class Impl> 892829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::ActivateThreadEvent() 902829Sksewell@umich.edu : Event(&mainEventQueue, CPU_Tick_Pri) 912829Sksewell@umich.edu{ 922829Sksewell@umich.edu} 932829Sksewell@umich.edu 942829Sksewell@umich.edutemplate <class Impl> 952829Sksewell@umich.eduvoid 962829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::init(int thread_num, 972829Sksewell@umich.edu FullO3CPU<Impl> *thread_cpu) 982829Sksewell@umich.edu{ 992829Sksewell@umich.edu tid = thread_num; 1002829Sksewell@umich.edu cpu = thread_cpu; 1012829Sksewell@umich.edu} 1022829Sksewell@umich.edu 1032829Sksewell@umich.edutemplate <class Impl> 1042829Sksewell@umich.eduvoid 1052829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::process() 1062829Sksewell@umich.edu{ 1072829Sksewell@umich.edu cpu->activateThread(tid); 1082829Sksewell@umich.edu} 1092829Sksewell@umich.edu 1102829Sksewell@umich.edutemplate <class Impl> 1112829Sksewell@umich.educonst char * 1122829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::description() 1132829Sksewell@umich.edu{ 1142829Sksewell@umich.edu return "FullO3CPU \"Activate Thread\" event"; 1152829Sksewell@umich.edu} 1162829Sksewell@umich.edu 1172829Sksewell@umich.edutemplate <class Impl> 1182875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::DeallocateContextEvent() 1192875Sksewell@umich.edu : Event(&mainEventQueue, CPU_Tick_Pri) 1202875Sksewell@umich.edu{ 1212875Sksewell@umich.edu} 1222875Sksewell@umich.edu 1232875Sksewell@umich.edutemplate <class Impl> 1242875Sksewell@umich.eduvoid 1252875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::init(int thread_num, 1262875Sksewell@umich.edu FullO3CPU<Impl> *thread_cpu) 1272875Sksewell@umich.edu{ 1282875Sksewell@umich.edu tid = thread_num; 1292875Sksewell@umich.edu cpu = thread_cpu; 1302875Sksewell@umich.edu} 1312875Sksewell@umich.edu 1322875Sksewell@umich.edutemplate <class Impl> 1332875Sksewell@umich.eduvoid 1342875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::process() 1352875Sksewell@umich.edu{ 1362875Sksewell@umich.edu cpu->deactivateThread(tid); 1372875Sksewell@umich.edu cpu->removeThread(tid); 1382875Sksewell@umich.edu} 1392875Sksewell@umich.edu 1402875Sksewell@umich.edutemplate <class Impl> 1412875Sksewell@umich.educonst char * 1422875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::description() 1432875Sksewell@umich.edu{ 1442875Sksewell@umich.edu return "FullO3CPU \"Deallocate Context\" event"; 1452875Sksewell@umich.edu} 1462875Sksewell@umich.edu 1472875Sksewell@umich.edutemplate <class Impl> 1482292SN/AFullO3CPU<Impl>::FullO3CPU(Params *params) 1492733Sktlim@umich.edu : BaseO3CPU(params), 1501060SN/A tickEvent(this), 1512292SN/A removeInstsThisCycle(false), 1521060SN/A fetch(params), 1531060SN/A decode(params), 1541060SN/A rename(params), 1551060SN/A iew(params), 1561060SN/A commit(params), 1571060SN/A 1582292SN/A regFile(params->numPhysIntRegs, params->numPhysFloatRegs), 1591060SN/A 1602831Sksewell@umich.edu freeList(params->numberOfThreads, 1612292SN/A TheISA::NumIntRegs, params->numPhysIntRegs, 1622292SN/A TheISA::NumFloatRegs, params->numPhysFloatRegs), 1631060SN/A 1642292SN/A rob(params->numROBEntries, params->squashWidth, 1652292SN/A params->smtROBPolicy, params->smtROBThreshold, 1662292SN/A params->numberOfThreads), 1671060SN/A 1682831Sksewell@umich.edu scoreboard(params->numberOfThreads, 1692292SN/A TheISA::NumIntRegs, params->numPhysIntRegs, 1702292SN/A TheISA::NumFloatRegs, params->numPhysFloatRegs, 1712292SN/A TheISA::NumMiscRegs * number_of_threads, 1722292SN/A TheISA::ZeroReg), 1731060SN/A 1742873Sktlim@umich.edu timeBuffer(params->backComSize, params->forwardComSize), 1752873Sktlim@umich.edu fetchQueue(params->backComSize, params->forwardComSize), 1762873Sktlim@umich.edu decodeQueue(params->backComSize, params->forwardComSize), 1772873Sktlim@umich.edu renameQueue(params->backComSize, params->forwardComSize), 1782873Sktlim@umich.edu iewQueue(params->backComSize, params->forwardComSize), 1792873Sktlim@umich.edu activityRec(NumStages, 1802873Sktlim@umich.edu params->backComSize + params->forwardComSize, 1812873Sktlim@umich.edu params->activity), 1821060SN/A 1831060SN/A globalSeqNum(1), 1841858SN/A#if FULL_SYSTEM 1852292SN/A system(params->system), 1861060SN/A physmem(system->physmem), 1871060SN/A#endif // FULL_SYSTEM 1882292SN/A mem(params->mem), 1892843Sktlim@umich.edu drainCount(0), 1902316SN/A deferRegistration(params->deferRegistration), 1912316SN/A numThreads(number_of_threads) 1921060SN/A{ 1931060SN/A _status = Idle; 1941681SN/A 1952733Sktlim@umich.edu checker = NULL; 1962733Sktlim@umich.edu 1972794Sktlim@umich.edu if (params->checker) { 1982733Sktlim@umich.edu#if USE_CHECKER 1992316SN/A BaseCPU *temp_checker = params->checker; 2002316SN/A checker = dynamic_cast<Checker<DynInstPtr> *>(temp_checker); 2012316SN/A checker->setMemory(mem); 2022316SN/A#if FULL_SYSTEM 2032316SN/A checker->setSystem(params->system); 2042316SN/A#endif 2052794Sktlim@umich.edu#else 2062794Sktlim@umich.edu panic("Checker enabled but not compiled in!"); 2072794Sktlim@umich.edu#endif // USE_CHECKER 2082316SN/A } 2092316SN/A 2101858SN/A#if !FULL_SYSTEM 2112292SN/A thread.resize(number_of_threads); 2122292SN/A tids.resize(number_of_threads); 2131681SN/A#endif 2141681SN/A 2152325SN/A // The stages also need their CPU pointer setup. However this 2162325SN/A // must be done at the upper level CPU because they have pointers 2172325SN/A // to the upper level CPU, and not this FullO3CPU. 2181060SN/A 2192292SN/A // Set up Pointers to the activeThreads list for each stage 2202292SN/A fetch.setActiveThreads(&activeThreads); 2212292SN/A decode.setActiveThreads(&activeThreads); 2222292SN/A rename.setActiveThreads(&activeThreads); 2232292SN/A iew.setActiveThreads(&activeThreads); 2242292SN/A commit.setActiveThreads(&activeThreads); 2251060SN/A 2261060SN/A // Give each of the stages the time buffer they will use. 2271060SN/A fetch.setTimeBuffer(&timeBuffer); 2281060SN/A decode.setTimeBuffer(&timeBuffer); 2291060SN/A rename.setTimeBuffer(&timeBuffer); 2301060SN/A iew.setTimeBuffer(&timeBuffer); 2311060SN/A commit.setTimeBuffer(&timeBuffer); 2321060SN/A 2331060SN/A // Also setup each of the stages' queues. 2341060SN/A fetch.setFetchQueue(&fetchQueue); 2351060SN/A decode.setFetchQueue(&fetchQueue); 2362292SN/A commit.setFetchQueue(&fetchQueue); 2371060SN/A decode.setDecodeQueue(&decodeQueue); 2381060SN/A rename.setDecodeQueue(&decodeQueue); 2391060SN/A rename.setRenameQueue(&renameQueue); 2401060SN/A iew.setRenameQueue(&renameQueue); 2411060SN/A iew.setIEWQueue(&iewQueue); 2421060SN/A commit.setIEWQueue(&iewQueue); 2431060SN/A commit.setRenameQueue(&renameQueue); 2441060SN/A 2452292SN/A commit.setIEWStage(&iew); 2462292SN/A rename.setIEWStage(&iew); 2472292SN/A rename.setCommitStage(&commit); 2482292SN/A 2492292SN/A#if !FULL_SYSTEM 2502307SN/A int active_threads = params->workload.size(); 2512831Sksewell@umich.edu 2522831Sksewell@umich.edu if (active_threads > Impl::MaxThreads) { 2532831Sksewell@umich.edu panic("Workload Size too large. Increase the 'MaxThreads'" 2542831Sksewell@umich.edu "constant in your O3CPU impl. file (e.g. o3/alpha/impl.hh) or " 2552831Sksewell@umich.edu "edit your workload size."); 2562831Sksewell@umich.edu } 2572292SN/A#else 2582307SN/A int active_threads = 1; 2592292SN/A#endif 2602292SN/A 2612316SN/A //Make Sure That this a Valid Architeture 2622292SN/A assert(params->numPhysIntRegs >= numThreads * TheISA::NumIntRegs); 2632292SN/A assert(params->numPhysFloatRegs >= numThreads * TheISA::NumFloatRegs); 2642292SN/A 2652292SN/A rename.setScoreboard(&scoreboard); 2662292SN/A iew.setScoreboard(&scoreboard); 2672292SN/A 2681060SN/A // Setup the rename map for whichever stages need it. 2692292SN/A PhysRegIndex lreg_idx = 0; 2702292SN/A PhysRegIndex freg_idx = params->numPhysIntRegs; //Index to 1 after int regs 2711060SN/A 2722292SN/A for (int tid=0; tid < numThreads; tid++) { 2732307SN/A bool bindRegs = (tid <= active_threads - 1); 2742292SN/A 2752292SN/A commitRenameMap[tid].init(TheISA::NumIntRegs, 2762292SN/A params->numPhysIntRegs, 2772325SN/A lreg_idx, //Index for Logical. Regs 2782292SN/A 2792292SN/A TheISA::NumFloatRegs, 2802292SN/A params->numPhysFloatRegs, 2812325SN/A freg_idx, //Index for Float Regs 2822292SN/A 2832292SN/A TheISA::NumMiscRegs, 2842292SN/A 2852292SN/A TheISA::ZeroReg, 2862292SN/A TheISA::ZeroReg, 2872292SN/A 2882292SN/A tid, 2892292SN/A false); 2902292SN/A 2912292SN/A renameMap[tid].init(TheISA::NumIntRegs, 2922292SN/A params->numPhysIntRegs, 2932325SN/A lreg_idx, //Index for Logical. Regs 2942292SN/A 2952292SN/A TheISA::NumFloatRegs, 2962292SN/A params->numPhysFloatRegs, 2972325SN/A freg_idx, //Index for Float Regs 2982292SN/A 2992292SN/A TheISA::NumMiscRegs, 3002292SN/A 3012292SN/A TheISA::ZeroReg, 3022292SN/A TheISA::ZeroReg, 3032292SN/A 3042292SN/A tid, 3052292SN/A bindRegs); 3062292SN/A } 3072292SN/A 3082292SN/A rename.setRenameMap(renameMap); 3092292SN/A commit.setRenameMap(commitRenameMap); 3102292SN/A 3112292SN/A // Give renameMap & rename stage access to the freeList; 3122292SN/A for (int i=0; i < numThreads; i++) { 3132292SN/A renameMap[i].setFreeList(&freeList); 3142292SN/A } 3151060SN/A rename.setFreeList(&freeList); 3162292SN/A 3171060SN/A // Setup the ROB for whichever stages need it. 3181060SN/A commit.setROB(&rob); 3192292SN/A 3202292SN/A lastRunningCycle = curTick; 3212292SN/A 3222829Sksewell@umich.edu lastActivatedCycle = -1; 3232829Sksewell@umich.edu 3243093Sksewell@umich.edu // Give renameMap & rename stage access to the freeList; 3253093Sksewell@umich.edu //for (int i=0; i < numThreads; i++) { 3263093Sksewell@umich.edu //globalSeqNum[i] = 1; 3273093Sksewell@umich.edu //} 3283093Sksewell@umich.edu 3292292SN/A contextSwitch = false; 3301060SN/A} 3311060SN/A 3321060SN/Atemplate <class Impl> 3331755SN/AFullO3CPU<Impl>::~FullO3CPU() 3341060SN/A{ 3351060SN/A} 3361060SN/A 3371060SN/Atemplate <class Impl> 3381060SN/Avoid 3391755SN/AFullO3CPU<Impl>::fullCPURegStats() 3401062SN/A{ 3412733Sktlim@umich.edu BaseO3CPU::regStats(); 3422292SN/A 3432733Sktlim@umich.edu // Register any of the O3CPU's stats here. 3442292SN/A timesIdled 3452292SN/A .name(name() + ".timesIdled") 3462292SN/A .desc("Number of times that the entire CPU went into an idle state and" 3472292SN/A " unscheduled itself") 3482292SN/A .prereq(timesIdled); 3492292SN/A 3502292SN/A idleCycles 3512292SN/A .name(name() + ".idleCycles") 3522292SN/A .desc("Total number of cycles that the CPU has spent unscheduled due " 3532292SN/A "to idling") 3542292SN/A .prereq(idleCycles); 3552292SN/A 3562292SN/A // Number of Instructions simulated 3572292SN/A // -------------------------------- 3582292SN/A // Should probably be in Base CPU but need templated 3592292SN/A // MaxThreads so put in here instead 3602292SN/A committedInsts 3612292SN/A .init(numThreads) 3622292SN/A .name(name() + ".committedInsts") 3632292SN/A .desc("Number of Instructions Simulated"); 3642292SN/A 3652292SN/A totalCommittedInsts 3662292SN/A .name(name() + ".committedInsts_total") 3672292SN/A .desc("Number of Instructions Simulated"); 3682292SN/A 3692292SN/A cpi 3702292SN/A .name(name() + ".cpi") 3712292SN/A .desc("CPI: Cycles Per Instruction") 3722292SN/A .precision(6); 3732292SN/A cpi = simTicks / committedInsts; 3742292SN/A 3752292SN/A totalCpi 3762292SN/A .name(name() + ".cpi_total") 3772292SN/A .desc("CPI: Total CPI of All Threads") 3782292SN/A .precision(6); 3792292SN/A totalCpi = simTicks / totalCommittedInsts; 3802292SN/A 3812292SN/A ipc 3822292SN/A .name(name() + ".ipc") 3832292SN/A .desc("IPC: Instructions Per Cycle") 3842292SN/A .precision(6); 3852292SN/A ipc = committedInsts / simTicks; 3862292SN/A 3872292SN/A totalIpc 3882292SN/A .name(name() + ".ipc_total") 3892292SN/A .desc("IPC: Total IPC of All Threads") 3902292SN/A .precision(6); 3912292SN/A totalIpc = totalCommittedInsts / simTicks; 3922292SN/A 3931062SN/A} 3941062SN/A 3951062SN/Atemplate <class Impl> 3962871Sktlim@umich.eduPort * 3972871Sktlim@umich.eduFullO3CPU<Impl>::getPort(const std::string &if_name, int idx) 3982871Sktlim@umich.edu{ 3992871Sktlim@umich.edu if (if_name == "dcache_port") 4002871Sktlim@umich.edu return iew.getDcachePort(); 4012871Sktlim@umich.edu else if (if_name == "icache_port") 4022871Sktlim@umich.edu return fetch.getIcachePort(); 4032871Sktlim@umich.edu else 4042871Sktlim@umich.edu panic("No Such Port\n"); 4052871Sktlim@umich.edu} 4062871Sktlim@umich.edu 4072871Sktlim@umich.edutemplate <class Impl> 4081062SN/Avoid 4091755SN/AFullO3CPU<Impl>::tick() 4101060SN/A{ 4112733Sktlim@umich.edu DPRINTF(O3CPU, "\n\nFullO3CPU: Ticking main, FullO3CPU.\n"); 4121060SN/A 4132292SN/A ++numCycles; 4142292SN/A 4152325SN/A// activity = false; 4162292SN/A 4172292SN/A //Tick each of the stages 4181060SN/A fetch.tick(); 4191060SN/A 4201060SN/A decode.tick(); 4211060SN/A 4221060SN/A rename.tick(); 4231060SN/A 4241060SN/A iew.tick(); 4251060SN/A 4261060SN/A commit.tick(); 4271060SN/A 4282292SN/A#if !FULL_SYSTEM 4292292SN/A doContextSwitch(); 4302292SN/A#endif 4312292SN/A 4322292SN/A // Now advance the time buffers 4331060SN/A timeBuffer.advance(); 4341060SN/A 4351060SN/A fetchQueue.advance(); 4361060SN/A decodeQueue.advance(); 4371060SN/A renameQueue.advance(); 4381060SN/A iewQueue.advance(); 4391060SN/A 4402325SN/A activityRec.advance(); 4412292SN/A 4422292SN/A if (removeInstsThisCycle) { 4432292SN/A cleanUpRemovedInsts(); 4442292SN/A } 4452292SN/A 4462325SN/A if (!tickEvent.scheduled()) { 4472867Sktlim@umich.edu if (_status == SwitchedOut || 4482905Sktlim@umich.edu getState() == SimObject::Drained) { 4492325SN/A // increment stat 4502325SN/A lastRunningCycle = curTick; 4512325SN/A } else if (!activityRec.active()) { 4522325SN/A lastRunningCycle = curTick; 4532325SN/A timesIdled++; 4542325SN/A } else { 4552325SN/A tickEvent.schedule(curTick + cycles(1)); 4562325SN/A } 4572292SN/A } 4582292SN/A 4592292SN/A#if !FULL_SYSTEM 4602292SN/A updateThreadPriority(); 4612292SN/A#endif 4622292SN/A 4631060SN/A} 4641060SN/A 4651060SN/Atemplate <class Impl> 4661060SN/Avoid 4671755SN/AFullO3CPU<Impl>::init() 4681060SN/A{ 4692307SN/A if (!deferRegistration) { 4702680Sktlim@umich.edu registerThreadContexts(); 4712292SN/A } 4721060SN/A 4732292SN/A // Set inSyscall so that the CPU doesn't squash when initially 4742292SN/A // setting up registers. 4752292SN/A for (int i = 0; i < number_of_threads; ++i) 4762292SN/A thread[i]->inSyscall = true; 4772292SN/A 4782292SN/A for (int tid=0; tid < number_of_threads; tid++) { 4791858SN/A#if FULL_SYSTEM 4802680Sktlim@umich.edu ThreadContext *src_tc = threadContexts[tid]; 4811681SN/A#else 4822680Sktlim@umich.edu ThreadContext *src_tc = thread[tid]->getTC(); 4831681SN/A#endif 4842292SN/A // Threads start in the Suspended State 4852680Sktlim@umich.edu if (src_tc->status() != ThreadContext::Suspended) { 4862292SN/A continue; 4871060SN/A } 4881060SN/A 4892292SN/A#if FULL_SYSTEM 4902680Sktlim@umich.edu TheISA::initCPU(src_tc, src_tc->readCpuId()); 4912292SN/A#endif 4922292SN/A } 4932292SN/A 4942292SN/A // Clear inSyscall. 4952292SN/A for (int i = 0; i < number_of_threads; ++i) 4962292SN/A thread[i]->inSyscall = false; 4972292SN/A 4982316SN/A // Initialize stages. 4992292SN/A fetch.initStage(); 5002292SN/A iew.initStage(); 5012292SN/A rename.initStage(); 5022292SN/A commit.initStage(); 5032292SN/A 5042292SN/A commit.setThreads(thread); 5052292SN/A} 5062292SN/A 5072292SN/Atemplate <class Impl> 5082292SN/Avoid 5092875Sksewell@umich.eduFullO3CPU<Impl>::activateThread(unsigned tid) 5102875Sksewell@umich.edu{ 5112875Sksewell@umich.edu list<unsigned>::iterator isActive = find( 5122875Sksewell@umich.edu activeThreads.begin(), activeThreads.end(), tid); 5132875Sksewell@umich.edu 5142875Sksewell@umich.edu if (isActive == activeThreads.end()) { 5152875Sksewell@umich.edu DPRINTF(O3CPU, "[tid:%i]: Adding to active threads list\n", 5162875Sksewell@umich.edu tid); 5172875Sksewell@umich.edu 5182875Sksewell@umich.edu activeThreads.push_back(tid); 5192875Sksewell@umich.edu } 5202875Sksewell@umich.edu} 5212875Sksewell@umich.edu 5222875Sksewell@umich.edutemplate <class Impl> 5232875Sksewell@umich.eduvoid 5242875Sksewell@umich.eduFullO3CPU<Impl>::deactivateThread(unsigned tid) 5252875Sksewell@umich.edu{ 5262875Sksewell@umich.edu //Remove From Active List, if Active 5272875Sksewell@umich.edu list<unsigned>::iterator thread_it = 5282875Sksewell@umich.edu find(activeThreads.begin(), activeThreads.end(), tid); 5292875Sksewell@umich.edu 5302875Sksewell@umich.edu if (thread_it != activeThreads.end()) { 5312875Sksewell@umich.edu DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n", 5322875Sksewell@umich.edu tid); 5332875Sksewell@umich.edu activeThreads.erase(thread_it); 5342875Sksewell@umich.edu } 5352875Sksewell@umich.edu} 5362875Sksewell@umich.edu 5372875Sksewell@umich.edutemplate <class Impl> 5382875Sksewell@umich.eduvoid 5392875Sksewell@umich.eduFullO3CPU<Impl>::activateContext(int tid, int delay) 5402875Sksewell@umich.edu{ 5412875Sksewell@umich.edu // Needs to set each stage to running as well. 5422875Sksewell@umich.edu if (delay){ 5432875Sksewell@umich.edu DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to activate " 5442875Sksewell@umich.edu "on cycle %d\n", tid, curTick + cycles(delay)); 5452875Sksewell@umich.edu scheduleActivateThreadEvent(tid, delay); 5462875Sksewell@umich.edu } else { 5472875Sksewell@umich.edu activateThread(tid); 5482875Sksewell@umich.edu } 5492875Sksewell@umich.edu 5502875Sksewell@umich.edu if(lastActivatedCycle < curTick) { 5512875Sksewell@umich.edu scheduleTickEvent(delay); 5522875Sksewell@umich.edu 5532875Sksewell@umich.edu // Be sure to signal that there's some activity so the CPU doesn't 5542875Sksewell@umich.edu // deschedule itself. 5552875Sksewell@umich.edu activityRec.activity(); 5562875Sksewell@umich.edu fetch.wakeFromQuiesce(); 5572875Sksewell@umich.edu 5582875Sksewell@umich.edu lastActivatedCycle = curTick; 5592875Sksewell@umich.edu 5602875Sksewell@umich.edu _status = Running; 5612875Sksewell@umich.edu } 5622875Sksewell@umich.edu} 5632875Sksewell@umich.edu 5642875Sksewell@umich.edutemplate <class Impl> 5652875Sksewell@umich.eduvoid 5662875Sksewell@umich.eduFullO3CPU<Impl>::deallocateContext(int tid, int delay) 5672875Sksewell@umich.edu{ 5682875Sksewell@umich.edu // Schedule removal of thread data from CPU 5692875Sksewell@umich.edu if (delay){ 5702875Sksewell@umich.edu DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to deallocate " 5712875Sksewell@umich.edu "on cycle %d\n", tid, curTick + cycles(delay)); 5722875Sksewell@umich.edu scheduleDeallocateContextEvent(tid, delay); 5732875Sksewell@umich.edu } else { 5742875Sksewell@umich.edu deactivateThread(tid); 5752875Sksewell@umich.edu removeThread(tid); 5762875Sksewell@umich.edu } 5772875Sksewell@umich.edu} 5782875Sksewell@umich.edu 5792875Sksewell@umich.edutemplate <class Impl> 5802875Sksewell@umich.eduvoid 5812875Sksewell@umich.eduFullO3CPU<Impl>::suspendContext(int tid) 5822875Sksewell@umich.edu{ 5832875Sksewell@umich.edu DPRINTF(O3CPU,"[tid: %i]: Suspending Thread Context.\n", tid); 5842911Sksewell@umich.edu deactivateThread(tid); 5852910Sksewell@umich.edu if (activeThreads.size() == 0) 5862910Sksewell@umich.edu unscheduleTickEvent(); 5872875Sksewell@umich.edu _status = Idle; 5882875Sksewell@umich.edu} 5892875Sksewell@umich.edu 5902875Sksewell@umich.edutemplate <class Impl> 5912875Sksewell@umich.eduvoid 5922875Sksewell@umich.eduFullO3CPU<Impl>::haltContext(int tid) 5932875Sksewell@umich.edu{ 5942910Sksewell@umich.edu //For now, this is the same as deallocate 5952910Sksewell@umich.edu DPRINTF(O3CPU,"[tid:%i]: Halt Context called. Deallocating", tid); 5962910Sksewell@umich.edu deallocateContext(tid, 1); 5972875Sksewell@umich.edu} 5982875Sksewell@umich.edu 5992875Sksewell@umich.edutemplate <class Impl> 6002875Sksewell@umich.eduvoid 6012292SN/AFullO3CPU<Impl>::insertThread(unsigned tid) 6022292SN/A{ 6032847Sksewell@umich.edu DPRINTF(O3CPU,"[tid:%i] Initializing thread into CPU"); 6042292SN/A // Will change now that the PC and thread state is internal to the CPU 6052683Sktlim@umich.edu // and not in the ThreadContext. 6062292SN/A#if FULL_SYSTEM 6072680Sktlim@umich.edu ThreadContext *src_tc = system->threadContexts[tid]; 6082292SN/A#else 6092847Sksewell@umich.edu ThreadContext *src_tc = tcBase(tid); 6102292SN/A#endif 6112292SN/A 6122292SN/A //Bind Int Regs to Rename Map 6132292SN/A for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) { 6142292SN/A PhysRegIndex phys_reg = freeList.getIntReg(); 6152292SN/A 6162292SN/A renameMap[tid].setEntry(ireg,phys_reg); 6172292SN/A scoreboard.setReg(phys_reg); 6182292SN/A } 6192292SN/A 6202292SN/A //Bind Float Regs to Rename Map 6212292SN/A for (int freg = 0; freg < TheISA::NumFloatRegs; freg++) { 6222292SN/A PhysRegIndex phys_reg = freeList.getFloatReg(); 6232292SN/A 6242292SN/A renameMap[tid].setEntry(freg,phys_reg); 6252292SN/A scoreboard.setReg(phys_reg); 6262292SN/A } 6272292SN/A 6282292SN/A //Copy Thread Data Into RegFile 6292847Sksewell@umich.edu //this->copyFromTC(tid); 6302292SN/A 6312847Sksewell@umich.edu //Set PC/NPC/NNPC 6322847Sksewell@umich.edu setPC(src_tc->readPC(), tid); 6332847Sksewell@umich.edu setNextPC(src_tc->readNextPC(), tid); 6343093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 6352847Sksewell@umich.edu setNextNPC(src_tc->readNextNPC(), tid); 6362847Sksewell@umich.edu#endif 6372292SN/A 6382680Sktlim@umich.edu src_tc->setStatus(ThreadContext::Active); 6392292SN/A 6402292SN/A activateContext(tid,1); 6412292SN/A 6422292SN/A //Reset ROB/IQ/LSQ Entries 6432292SN/A commit.rob->resetEntries(); 6442292SN/A iew.resetEntries(); 6452292SN/A} 6462292SN/A 6472292SN/Atemplate <class Impl> 6482292SN/Avoid 6492292SN/AFullO3CPU<Impl>::removeThread(unsigned tid) 6502292SN/A{ 6512877Sksewell@umich.edu DPRINTF(O3CPU,"[tid:%i] Removing thread context from CPU.\n", tid); 6522847Sksewell@umich.edu 6532847Sksewell@umich.edu // Copy Thread Data From RegFile 6542847Sksewell@umich.edu // If thread is suspended, it might be re-allocated 6552847Sksewell@umich.edu //this->copyToTC(tid); 6562847Sksewell@umich.edu 6572847Sksewell@umich.edu // Unbind Int Regs from Rename Map 6582292SN/A for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) { 6592292SN/A PhysRegIndex phys_reg = renameMap[tid].lookup(ireg); 6602292SN/A 6612292SN/A scoreboard.unsetReg(phys_reg); 6622292SN/A freeList.addReg(phys_reg); 6632292SN/A } 6642292SN/A 6652847Sksewell@umich.edu // Unbind Float Regs from Rename Map 6662292SN/A for (int freg = 0; freg < TheISA::NumFloatRegs; freg++) { 6672292SN/A PhysRegIndex phys_reg = renameMap[tid].lookup(freg); 6682292SN/A 6692292SN/A scoreboard.unsetReg(phys_reg); 6702292SN/A freeList.addReg(phys_reg); 6712292SN/A } 6722292SN/A 6732847Sksewell@umich.edu // Squash Throughout Pipeline 6742935Sksewell@umich.edu InstSeqNum squash_seq_num = commit.rob->readHeadInst(tid)->seqNum; 6752935Sksewell@umich.edu fetch.squash(0, squash_seq_num, true, tid); 6762292SN/A decode.squash(tid); 6772935Sksewell@umich.edu rename.squash(squash_seq_num, tid); 6782875Sksewell@umich.edu iew.squash(tid); 6792935Sksewell@umich.edu commit.rob->squash(squash_seq_num, tid); 6802292SN/A 6812292SN/A assert(iew.ldstQueue.getCount(tid) == 0); 6822292SN/A 6832847Sksewell@umich.edu // Reset ROB/IQ/LSQ Entries 6842292SN/A if (activeThreads.size() >= 1) { 6852292SN/A commit.rob->resetEntries(); 6862292SN/A iew.resetEntries(); 6872292SN/A } 6882292SN/A} 6892292SN/A 6902292SN/A 6912292SN/Atemplate <class Impl> 6922292SN/Avoid 6932292SN/AFullO3CPU<Impl>::activateWhenReady(int tid) 6942292SN/A{ 6952733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i]: Checking if resources are available for incoming" 6962292SN/A "(e.g. PhysRegs/ROB/IQ/LSQ) \n", 6972292SN/A tid); 6982292SN/A 6992292SN/A bool ready = true; 7002292SN/A 7012292SN/A if (freeList.numFreeIntRegs() >= TheISA::NumIntRegs) { 7022733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough " 7032292SN/A "Phys. Int. Regs.\n", 7042292SN/A tid); 7052292SN/A ready = false; 7062292SN/A } else if (freeList.numFreeFloatRegs() >= TheISA::NumFloatRegs) { 7072733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough " 7082292SN/A "Phys. Float. Regs.\n", 7092292SN/A tid); 7102292SN/A ready = false; 7112292SN/A } else if (commit.rob->numFreeEntries() >= 7122292SN/A commit.rob->entryAmount(activeThreads.size() + 1)) { 7132733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough " 7142292SN/A "ROB entries.\n", 7152292SN/A tid); 7162292SN/A ready = false; 7172292SN/A } else if (iew.instQueue.numFreeEntries() >= 7182292SN/A iew.instQueue.entryAmount(activeThreads.size() + 1)) { 7192733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough " 7202292SN/A "IQ entries.\n", 7212292SN/A tid); 7222292SN/A ready = false; 7232292SN/A } else if (iew.ldstQueue.numFreeEntries() >= 7242292SN/A iew.ldstQueue.entryAmount(activeThreads.size() + 1)) { 7252733Sktlim@umich.edu DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough " 7262292SN/A "LSQ entries.\n", 7272292SN/A tid); 7282292SN/A ready = false; 7292292SN/A } 7302292SN/A 7312292SN/A if (ready) { 7322292SN/A insertThread(tid); 7332292SN/A 7342292SN/A contextSwitch = false; 7352292SN/A 7362292SN/A cpuWaitList.remove(tid); 7372292SN/A } else { 7382292SN/A suspendContext(tid); 7392292SN/A 7402292SN/A //blocks fetch 7412292SN/A contextSwitch = true; 7422292SN/A 7432875Sksewell@umich.edu //@todo: dont always add to waitlist 7442292SN/A //do waitlist 7452292SN/A cpuWaitList.push_back(tid); 7461060SN/A } 7471060SN/A} 7481060SN/A 7491060SN/Atemplate <class Impl> 7502852Sktlim@umich.eduvoid 7512864Sktlim@umich.eduFullO3CPU<Impl>::serialize(std::ostream &os) 7522864Sktlim@umich.edu{ 7532918Sktlim@umich.edu SimObject::State so_state = SimObject::getState(); 7542918Sktlim@umich.edu SERIALIZE_ENUM(so_state); 7552864Sktlim@umich.edu BaseCPU::serialize(os); 7562864Sktlim@umich.edu nameOut(os, csprintf("%s.tickEvent", name())); 7572864Sktlim@umich.edu tickEvent.serialize(os); 7582864Sktlim@umich.edu 7592864Sktlim@umich.edu // Use SimpleThread's ability to checkpoint to make it easier to 7602864Sktlim@umich.edu // write out the registers. Also make this static so it doesn't 7612864Sktlim@umich.edu // get instantiated multiple times (causes a panic in statistics). 7622864Sktlim@umich.edu static SimpleThread temp; 7632864Sktlim@umich.edu 7642864Sktlim@umich.edu for (int i = 0; i < thread.size(); i++) { 7652864Sktlim@umich.edu nameOut(os, csprintf("%s.xc.%i", name(), i)); 7662864Sktlim@umich.edu temp.copyTC(thread[i]->getTC()); 7672864Sktlim@umich.edu temp.serialize(os); 7682864Sktlim@umich.edu } 7692864Sktlim@umich.edu} 7702864Sktlim@umich.edu 7712864Sktlim@umich.edutemplate <class Impl> 7722864Sktlim@umich.eduvoid 7732864Sktlim@umich.eduFullO3CPU<Impl>::unserialize(Checkpoint *cp, const std::string §ion) 7742864Sktlim@umich.edu{ 7752918Sktlim@umich.edu SimObject::State so_state; 7762918Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 7772864Sktlim@umich.edu BaseCPU::unserialize(cp, section); 7782864Sktlim@umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 7792864Sktlim@umich.edu 7802864Sktlim@umich.edu // Use SimpleThread's ability to checkpoint to make it easier to 7812864Sktlim@umich.edu // read in the registers. Also make this static so it doesn't 7822864Sktlim@umich.edu // get instantiated multiple times (causes a panic in statistics). 7832864Sktlim@umich.edu static SimpleThread temp; 7842864Sktlim@umich.edu 7852864Sktlim@umich.edu for (int i = 0; i < thread.size(); i++) { 7862864Sktlim@umich.edu temp.copyTC(thread[i]->getTC()); 7872864Sktlim@umich.edu temp.unserialize(cp, csprintf("%s.xc.%i", section, i)); 7882864Sktlim@umich.edu thread[i]->getTC()->copyArchRegs(temp.getTC()); 7892864Sktlim@umich.edu } 7902864Sktlim@umich.edu} 7912864Sktlim@umich.edu 7922864Sktlim@umich.edutemplate <class Impl> 7932905Sktlim@umich.eduunsigned int 7942843Sktlim@umich.eduFullO3CPU<Impl>::drain(Event *drain_event) 7951060SN/A{ 7962843Sktlim@umich.edu drainCount = 0; 7972843Sktlim@umich.edu fetch.drain(); 7982843Sktlim@umich.edu decode.drain(); 7992843Sktlim@umich.edu rename.drain(); 8002843Sktlim@umich.edu iew.drain(); 8012843Sktlim@umich.edu commit.drain(); 8022325SN/A 8032325SN/A // Wake the CPU and record activity so everything can drain out if 8042863Sktlim@umich.edu // the CPU was not able to immediately drain. 8052905Sktlim@umich.edu if (getState() != SimObject::Drained) { 8062864Sktlim@umich.edu // A bit of a hack...set the drainEvent after all the drain() 8072864Sktlim@umich.edu // calls have been made, that way if all of the stages drain 8082864Sktlim@umich.edu // immediately, the signalDrained() function knows not to call 8092864Sktlim@umich.edu // process on the drain event. 8102864Sktlim@umich.edu drainEvent = drain_event; 8112843Sktlim@umich.edu 8122863Sktlim@umich.edu wakeCPU(); 8132863Sktlim@umich.edu activityRec.activity(); 8142852Sktlim@umich.edu 8152905Sktlim@umich.edu return 1; 8162863Sktlim@umich.edu } else { 8172905Sktlim@umich.edu return 0; 8182863Sktlim@umich.edu } 8192316SN/A} 8202310SN/A 8212316SN/Atemplate <class Impl> 8222316SN/Avoid 8232843Sktlim@umich.eduFullO3CPU<Impl>::resume() 8242316SN/A{ 8252905Sktlim@umich.edu assert(system->getMemoryMode() == System::Timing); 8262843Sktlim@umich.edu fetch.resume(); 8272843Sktlim@umich.edu decode.resume(); 8282843Sktlim@umich.edu rename.resume(); 8292843Sktlim@umich.edu iew.resume(); 8302843Sktlim@umich.edu commit.resume(); 8312316SN/A 8322905Sktlim@umich.edu changeState(SimObject::Running); 8332905Sktlim@umich.edu 8342864Sktlim@umich.edu if (_status == SwitchedOut || _status == Idle) 8352864Sktlim@umich.edu return; 8362864Sktlim@umich.edu 8372843Sktlim@umich.edu if (!tickEvent.scheduled()) 8382843Sktlim@umich.edu tickEvent.schedule(curTick); 8392843Sktlim@umich.edu _status = Running; 8402843Sktlim@umich.edu} 8412316SN/A 8422843Sktlim@umich.edutemplate <class Impl> 8432843Sktlim@umich.eduvoid 8442843Sktlim@umich.eduFullO3CPU<Impl>::signalDrained() 8452843Sktlim@umich.edu{ 8462843Sktlim@umich.edu if (++drainCount == NumStages) { 8472316SN/A if (tickEvent.scheduled()) 8482316SN/A tickEvent.squash(); 8492863Sktlim@umich.edu 8502905Sktlim@umich.edu changeState(SimObject::Drained); 8512863Sktlim@umich.edu 8522863Sktlim@umich.edu if (drainEvent) { 8532863Sktlim@umich.edu drainEvent->process(); 8542863Sktlim@umich.edu drainEvent = NULL; 8552863Sktlim@umich.edu } 8562310SN/A } 8572843Sktlim@umich.edu assert(drainCount <= 5); 8582843Sktlim@umich.edu} 8592843Sktlim@umich.edu 8602843Sktlim@umich.edutemplate <class Impl> 8612843Sktlim@umich.eduvoid 8622843Sktlim@umich.eduFullO3CPU<Impl>::switchOut() 8632843Sktlim@umich.edu{ 8642843Sktlim@umich.edu fetch.switchOut(); 8652843Sktlim@umich.edu rename.switchOut(); 8662843Sktlim@umich.edu commit.switchOut(); 8672843Sktlim@umich.edu instList.clear(); 8682843Sktlim@umich.edu while (!removeList.empty()) { 8692843Sktlim@umich.edu removeList.pop(); 8702843Sktlim@umich.edu } 8712843Sktlim@umich.edu 8722843Sktlim@umich.edu _status = SwitchedOut; 8732843Sktlim@umich.edu#if USE_CHECKER 8742843Sktlim@umich.edu if (checker) 8752843Sktlim@umich.edu checker->switchOut(); 8762843Sktlim@umich.edu#endif 8771060SN/A} 8781060SN/A 8791060SN/Atemplate <class Impl> 8801060SN/Avoid 8811755SN/AFullO3CPU<Impl>::takeOverFrom(BaseCPU *oldCPU) 8821060SN/A{ 8832325SN/A // Flush out any old data from the time buffers. 8842873Sktlim@umich.edu for (int i = 0; i < timeBuffer.getSize(); ++i) { 8852307SN/A timeBuffer.advance(); 8862307SN/A fetchQueue.advance(); 8872307SN/A decodeQueue.advance(); 8882307SN/A renameQueue.advance(); 8892307SN/A iewQueue.advance(); 8902307SN/A } 8912307SN/A 8922325SN/A activityRec.reset(); 8932307SN/A 8941060SN/A BaseCPU::takeOverFrom(oldCPU); 8951060SN/A 8962307SN/A fetch.takeOverFrom(); 8972307SN/A decode.takeOverFrom(); 8982307SN/A rename.takeOverFrom(); 8992307SN/A iew.takeOverFrom(); 9002307SN/A commit.takeOverFrom(); 9012307SN/A 9021060SN/A assert(!tickEvent.scheduled()); 9031060SN/A 9042325SN/A // @todo: Figure out how to properly select the tid to put onto 9052325SN/A // the active threads list. 9062307SN/A int tid = 0; 9072307SN/A 9082307SN/A list<unsigned>::iterator isActive = find( 9092307SN/A activeThreads.begin(), activeThreads.end(), tid); 9102307SN/A 9112307SN/A if (isActive == activeThreads.end()) { 9122325SN/A //May Need to Re-code this if the delay variable is the delay 9132325SN/A //needed for thread to activate 9142733Sktlim@umich.edu DPRINTF(O3CPU, "Adding Thread %i to active threads list\n", 9152307SN/A tid); 9162307SN/A 9172307SN/A activeThreads.push_back(tid); 9182307SN/A } 9192307SN/A 9202325SN/A // Set all statuses to active, schedule the CPU's tick event. 9212307SN/A // @todo: Fix up statuses so this is handled properly 9222680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 9232680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 9242680Sktlim@umich.edu if (tc->status() == ThreadContext::Active && _status != Running) { 9251681SN/A _status = Running; 9261681SN/A tickEvent.schedule(curTick); 9271681SN/A } 9281060SN/A } 9292307SN/A if (!tickEvent.scheduled()) 9302307SN/A tickEvent.schedule(curTick); 9311060SN/A} 9321060SN/A 9331060SN/Atemplate <class Impl> 9341060SN/Auint64_t 9351755SN/AFullO3CPU<Impl>::readIntReg(int reg_idx) 9361060SN/A{ 9371060SN/A return regFile.readIntReg(reg_idx); 9381060SN/A} 9391060SN/A 9401060SN/Atemplate <class Impl> 9412455SN/AFloatReg 9422455SN/AFullO3CPU<Impl>::readFloatReg(int reg_idx, int width) 9431060SN/A{ 9442455SN/A return regFile.readFloatReg(reg_idx, width); 9451060SN/A} 9461060SN/A 9471060SN/Atemplate <class Impl> 9482455SN/AFloatReg 9492455SN/AFullO3CPU<Impl>::readFloatReg(int reg_idx) 9501060SN/A{ 9512455SN/A return regFile.readFloatReg(reg_idx); 9521060SN/A} 9531060SN/A 9541060SN/Atemplate <class Impl> 9552455SN/AFloatRegBits 9562455SN/AFullO3CPU<Impl>::readFloatRegBits(int reg_idx, int width) 9571060SN/A{ 9582455SN/A return regFile.readFloatRegBits(reg_idx, width); 9592455SN/A} 9602455SN/A 9612455SN/Atemplate <class Impl> 9622455SN/AFloatRegBits 9632455SN/AFullO3CPU<Impl>::readFloatRegBits(int reg_idx) 9642455SN/A{ 9652455SN/A return regFile.readFloatRegBits(reg_idx); 9661060SN/A} 9671060SN/A 9681060SN/Atemplate <class Impl> 9691060SN/Avoid 9701755SN/AFullO3CPU<Impl>::setIntReg(int reg_idx, uint64_t val) 9711060SN/A{ 9721060SN/A regFile.setIntReg(reg_idx, val); 9731060SN/A} 9741060SN/A 9751060SN/Atemplate <class Impl> 9761060SN/Avoid 9772455SN/AFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val, int width) 9781060SN/A{ 9792455SN/A regFile.setFloatReg(reg_idx, val, width); 9801060SN/A} 9811060SN/A 9821060SN/Atemplate <class Impl> 9831060SN/Avoid 9842455SN/AFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val) 9851060SN/A{ 9862455SN/A regFile.setFloatReg(reg_idx, val); 9871060SN/A} 9881060SN/A 9891060SN/Atemplate <class Impl> 9901060SN/Avoid 9912455SN/AFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val, int width) 9921060SN/A{ 9932455SN/A regFile.setFloatRegBits(reg_idx, val, width); 9942455SN/A} 9952455SN/A 9962455SN/Atemplate <class Impl> 9972455SN/Avoid 9982455SN/AFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val) 9992455SN/A{ 10002455SN/A regFile.setFloatRegBits(reg_idx, val); 10011060SN/A} 10021060SN/A 10031060SN/Atemplate <class Impl> 10041060SN/Auint64_t 10052292SN/AFullO3CPU<Impl>::readArchIntReg(int reg_idx, unsigned tid) 10061060SN/A{ 10072292SN/A PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx); 10082292SN/A 10092292SN/A return regFile.readIntReg(phys_reg); 10102292SN/A} 10112292SN/A 10122292SN/Atemplate <class Impl> 10132292SN/Afloat 10142292SN/AFullO3CPU<Impl>::readArchFloatRegSingle(int reg_idx, unsigned tid) 10152292SN/A{ 10162307SN/A int idx = reg_idx + TheISA::FP_Base_DepTag; 10172307SN/A PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10182292SN/A 10192669Sktlim@umich.edu return regFile.readFloatReg(phys_reg); 10202292SN/A} 10212292SN/A 10222292SN/Atemplate <class Impl> 10232292SN/Adouble 10242292SN/AFullO3CPU<Impl>::readArchFloatRegDouble(int reg_idx, unsigned tid) 10252292SN/A{ 10262307SN/A int idx = reg_idx + TheISA::FP_Base_DepTag; 10272307SN/A PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10282292SN/A 10292669Sktlim@umich.edu return regFile.readFloatReg(phys_reg, 64); 10302292SN/A} 10312292SN/A 10322292SN/Atemplate <class Impl> 10332292SN/Auint64_t 10342292SN/AFullO3CPU<Impl>::readArchFloatRegInt(int reg_idx, unsigned tid) 10352292SN/A{ 10362307SN/A int idx = reg_idx + TheISA::FP_Base_DepTag; 10372307SN/A PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10382292SN/A 10392669Sktlim@umich.edu return regFile.readFloatRegBits(phys_reg); 10401060SN/A} 10411060SN/A 10421060SN/Atemplate <class Impl> 10431060SN/Avoid 10442292SN/AFullO3CPU<Impl>::setArchIntReg(int reg_idx, uint64_t val, unsigned tid) 10451060SN/A{ 10462292SN/A PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx); 10472292SN/A 10482292SN/A regFile.setIntReg(phys_reg, val); 10491060SN/A} 10501060SN/A 10511060SN/Atemplate <class Impl> 10521060SN/Avoid 10532292SN/AFullO3CPU<Impl>::setArchFloatRegSingle(int reg_idx, float val, unsigned tid) 10541060SN/A{ 10552918Sktlim@umich.edu int idx = reg_idx + TheISA::FP_Base_DepTag; 10562918Sktlim@umich.edu PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10572292SN/A 10582669Sktlim@umich.edu regFile.setFloatReg(phys_reg, val); 10591060SN/A} 10601060SN/A 10611060SN/Atemplate <class Impl> 10621060SN/Avoid 10632292SN/AFullO3CPU<Impl>::setArchFloatRegDouble(int reg_idx, double val, unsigned tid) 10641060SN/A{ 10652918Sktlim@umich.edu int idx = reg_idx + TheISA::FP_Base_DepTag; 10662918Sktlim@umich.edu PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10672292SN/A 10682669Sktlim@umich.edu regFile.setFloatReg(phys_reg, val, 64); 10691060SN/A} 10701060SN/A 10711060SN/Atemplate <class Impl> 10721060SN/Avoid 10732292SN/AFullO3CPU<Impl>::setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid) 10741060SN/A{ 10752918Sktlim@umich.edu int idx = reg_idx + TheISA::FP_Base_DepTag; 10762918Sktlim@umich.edu PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx); 10771060SN/A 10782669Sktlim@umich.edu regFile.setFloatRegBits(phys_reg, val); 10792292SN/A} 10802292SN/A 10812292SN/Atemplate <class Impl> 10822292SN/Auint64_t 10832292SN/AFullO3CPU<Impl>::readPC(unsigned tid) 10842292SN/A{ 10852292SN/A return commit.readPC(tid); 10861060SN/A} 10871060SN/A 10881060SN/Atemplate <class Impl> 10891060SN/Avoid 10902292SN/AFullO3CPU<Impl>::setPC(Addr new_PC,unsigned tid) 10911060SN/A{ 10922292SN/A commit.setPC(new_PC, tid); 10932292SN/A} 10941060SN/A 10952292SN/Atemplate <class Impl> 10962292SN/Auint64_t 10972292SN/AFullO3CPU<Impl>::readNextPC(unsigned tid) 10982292SN/A{ 10992292SN/A return commit.readNextPC(tid); 11002292SN/A} 11011060SN/A 11022292SN/Atemplate <class Impl> 11032292SN/Avoid 11042292SN/AFullO3CPU<Impl>::setNextPC(uint64_t val,unsigned tid) 11052292SN/A{ 11062292SN/A commit.setNextPC(val, tid); 11072292SN/A} 11081060SN/A 11092756Sksewell@umich.edutemplate <class Impl> 11102756Sksewell@umich.eduuint64_t 11112756Sksewell@umich.eduFullO3CPU<Impl>::readNextNPC(unsigned tid) 11122756Sksewell@umich.edu{ 11132756Sksewell@umich.edu return commit.readNextNPC(tid); 11142756Sksewell@umich.edu} 11152756Sksewell@umich.edu 11162756Sksewell@umich.edutemplate <class Impl> 11172756Sksewell@umich.eduvoid 11182935Sksewell@umich.eduFullO3CPU<Impl>::setNextNPC(uint64_t val,unsigned tid) 11192756Sksewell@umich.edu{ 11202756Sksewell@umich.edu commit.setNextNPC(val, tid); 11212756Sksewell@umich.edu} 11222756Sksewell@umich.edu 11232292SN/Atemplate <class Impl> 11242292SN/Atypename FullO3CPU<Impl>::ListIt 11252292SN/AFullO3CPU<Impl>::addInst(DynInstPtr &inst) 11262292SN/A{ 11272292SN/A instList.push_back(inst); 11281060SN/A 11292292SN/A return --(instList.end()); 11302292SN/A} 11311060SN/A 11322292SN/Atemplate <class Impl> 11332292SN/Avoid 11342292SN/AFullO3CPU<Impl>::instDone(unsigned tid) 11352292SN/A{ 11362292SN/A // Keep an instruction count. 11372292SN/A thread[tid]->numInst++; 11382292SN/A thread[tid]->numInsts++; 11392292SN/A committedInsts[tid]++; 11402292SN/A totalCommittedInsts++; 11412292SN/A 11422292SN/A // Check for instruction-count-based events. 11432292SN/A comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst); 11442292SN/A} 11452292SN/A 11462292SN/Atemplate <class Impl> 11472292SN/Avoid 11482292SN/AFullO3CPU<Impl>::addToRemoveList(DynInstPtr &inst) 11492292SN/A{ 11502292SN/A removeInstsThisCycle = true; 11512292SN/A 11522292SN/A removeList.push(inst->getInstListIt()); 11531060SN/A} 11541060SN/A 11551060SN/Atemplate <class Impl> 11561060SN/Avoid 11571755SN/AFullO3CPU<Impl>::removeFrontInst(DynInstPtr &inst) 11581060SN/A{ 11592733Sktlim@umich.edu DPRINTF(O3CPU, "Removing committed instruction [tid:%i] PC %#x " 11602292SN/A "[sn:%lli]\n", 11612303SN/A inst->threadNumber, inst->readPC(), inst->seqNum); 11621060SN/A 11632292SN/A removeInstsThisCycle = true; 11641060SN/A 11651060SN/A // Remove the front instruction. 11662292SN/A removeList.push(inst->getInstListIt()); 11671060SN/A} 11681060SN/A 11691060SN/Atemplate <class Impl> 11701060SN/Avoid 11712935Sksewell@umich.eduFullO3CPU<Impl>::removeInstsNotInROB(unsigned tid, 11722935Sksewell@umich.edu bool squash_delay_slot, 11732935Sksewell@umich.edu const InstSeqNum &delay_slot_seq_num) 11741060SN/A{ 11752733Sktlim@umich.edu DPRINTF(O3CPU, "Thread %i: Deleting instructions from instruction" 11762292SN/A " list.\n", tid); 11771060SN/A 11782292SN/A ListIt end_it; 11791060SN/A 11802292SN/A bool rob_empty = false; 11812292SN/A 11822292SN/A if (instList.empty()) { 11832292SN/A return; 11842292SN/A } else if (rob.isEmpty(/*tid*/)) { 11852733Sktlim@umich.edu DPRINTF(O3CPU, "ROB is empty, squashing all insts.\n"); 11862292SN/A end_it = instList.begin(); 11872292SN/A rob_empty = true; 11882292SN/A } else { 11892292SN/A end_it = (rob.readTailInst(tid))->getInstListIt(); 11902733Sktlim@umich.edu DPRINTF(O3CPU, "ROB is not empty, squashing insts not in ROB.\n"); 11912292SN/A } 11922292SN/A 11932292SN/A removeInstsThisCycle = true; 11942292SN/A 11952292SN/A ListIt inst_it = instList.end(); 11962292SN/A 11972292SN/A inst_it--; 11982292SN/A 11992292SN/A // Walk through the instruction list, removing any instructions 12002292SN/A // that were inserted after the given instruction iterator, end_it. 12012292SN/A while (inst_it != end_it) { 12022292SN/A assert(!instList.empty()); 12032292SN/A 12043093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 12052935Sksewell@umich.edu if(!squash_delay_slot && 12062935Sksewell@umich.edu delay_slot_seq_num >= (*inst_it)->seqNum) { 12072935Sksewell@umich.edu break; 12082935Sksewell@umich.edu } 12092935Sksewell@umich.edu#endif 12102292SN/A squashInstIt(inst_it, tid); 12112292SN/A 12122292SN/A inst_it--; 12132292SN/A } 12142292SN/A 12152292SN/A // If the ROB was empty, then we actually need to remove the first 12162292SN/A // instruction as well. 12172292SN/A if (rob_empty) { 12182292SN/A squashInstIt(inst_it, tid); 12192292SN/A } 12201060SN/A} 12211060SN/A 12221060SN/Atemplate <class Impl> 12231060SN/Avoid 12242292SN/AFullO3CPU<Impl>::removeInstsUntil(const InstSeqNum &seq_num, 12252292SN/A unsigned tid) 12261062SN/A{ 12272292SN/A assert(!instList.empty()); 12282292SN/A 12292292SN/A removeInstsThisCycle = true; 12302292SN/A 12312292SN/A ListIt inst_iter = instList.end(); 12322292SN/A 12332292SN/A inst_iter--; 12342292SN/A 12352733Sktlim@umich.edu DPRINTF(O3CPU, "Deleting instructions from instruction " 12362292SN/A "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n", 12372292SN/A tid, seq_num, (*inst_iter)->seqNum); 12381062SN/A 12392292SN/A while ((*inst_iter)->seqNum > seq_num) { 12401062SN/A 12412292SN/A bool break_loop = (inst_iter == instList.begin()); 12421062SN/A 12432292SN/A squashInstIt(inst_iter, tid); 12441062SN/A 12452292SN/A inst_iter--; 12461062SN/A 12472292SN/A if (break_loop) 12482292SN/A break; 12492292SN/A } 12502292SN/A} 12512292SN/A 12522292SN/Atemplate <class Impl> 12532292SN/Ainline void 12542292SN/AFullO3CPU<Impl>::squashInstIt(const ListIt &instIt, const unsigned &tid) 12552292SN/A{ 12562292SN/A if ((*instIt)->threadNumber == tid) { 12572733Sktlim@umich.edu DPRINTF(O3CPU, "Squashing instruction, " 12582292SN/A "[tid:%i] [sn:%lli] PC %#x\n", 12592292SN/A (*instIt)->threadNumber, 12602292SN/A (*instIt)->seqNum, 12612292SN/A (*instIt)->readPC()); 12621062SN/A 12631062SN/A // Mark it as squashed. 12642292SN/A (*instIt)->setSquashed(); 12652292SN/A 12662325SN/A // @todo: Formulate a consistent method for deleting 12672325SN/A // instructions from the instruction list 12682292SN/A // Remove the instruction from the list. 12692292SN/A removeList.push(instIt); 12702292SN/A } 12712292SN/A} 12722292SN/A 12732292SN/Atemplate <class Impl> 12742292SN/Avoid 12752292SN/AFullO3CPU<Impl>::cleanUpRemovedInsts() 12762292SN/A{ 12772292SN/A while (!removeList.empty()) { 12782733Sktlim@umich.edu DPRINTF(O3CPU, "Removing instruction, " 12792292SN/A "[tid:%i] [sn:%lli] PC %#x\n", 12802292SN/A (*removeList.front())->threadNumber, 12812292SN/A (*removeList.front())->seqNum, 12822292SN/A (*removeList.front())->readPC()); 12832292SN/A 12842292SN/A instList.erase(removeList.front()); 12852292SN/A 12862292SN/A removeList.pop(); 12871062SN/A } 12881062SN/A 12892292SN/A removeInstsThisCycle = false; 12901062SN/A} 12912325SN/A/* 12921062SN/Atemplate <class Impl> 12931062SN/Avoid 12941755SN/AFullO3CPU<Impl>::removeAllInsts() 12951060SN/A{ 12961060SN/A instList.clear(); 12971060SN/A} 12982325SN/A*/ 12991060SN/Atemplate <class Impl> 13001060SN/Avoid 13011755SN/AFullO3CPU<Impl>::dumpInsts() 13021060SN/A{ 13031060SN/A int num = 0; 13041060SN/A 13052292SN/A ListIt inst_list_it = instList.begin(); 13062292SN/A 13072292SN/A cprintf("Dumping Instruction List\n"); 13082292SN/A 13092292SN/A while (inst_list_it != instList.end()) { 13102292SN/A cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n" 13112292SN/A "Squashed:%i\n\n", 13122292SN/A num, (*inst_list_it)->readPC(), (*inst_list_it)->threadNumber, 13132292SN/A (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(), 13142292SN/A (*inst_list_it)->isSquashed()); 13151060SN/A inst_list_it++; 13161060SN/A ++num; 13171060SN/A } 13181060SN/A} 13192325SN/A/* 13201060SN/Atemplate <class Impl> 13211060SN/Avoid 13221755SN/AFullO3CPU<Impl>::wakeDependents(DynInstPtr &inst) 13231060SN/A{ 13241060SN/A iew.wakeDependents(inst); 13251060SN/A} 13262325SN/A*/ 13272292SN/Atemplate <class Impl> 13282292SN/Avoid 13292292SN/AFullO3CPU<Impl>::wakeCPU() 13302292SN/A{ 13312325SN/A if (activityRec.active() || tickEvent.scheduled()) { 13322325SN/A DPRINTF(Activity, "CPU already running.\n"); 13332292SN/A return; 13342292SN/A } 13352292SN/A 13362325SN/A DPRINTF(Activity, "Waking up CPU\n"); 13372325SN/A 13382325SN/A idleCycles += (curTick - 1) - lastRunningCycle; 13392292SN/A 13402292SN/A tickEvent.schedule(curTick); 13412292SN/A} 13422292SN/A 13432292SN/Atemplate <class Impl> 13442292SN/Aint 13452292SN/AFullO3CPU<Impl>::getFreeTid() 13462292SN/A{ 13472292SN/A for (int i=0; i < numThreads; i++) { 13482292SN/A if (!tids[i]) { 13492292SN/A tids[i] = true; 13502292SN/A return i; 13512292SN/A } 13522292SN/A } 13532292SN/A 13542292SN/A return -1; 13552292SN/A} 13562292SN/A 13572292SN/Atemplate <class Impl> 13582292SN/Avoid 13592292SN/AFullO3CPU<Impl>::doContextSwitch() 13602292SN/A{ 13612292SN/A if (contextSwitch) { 13622292SN/A 13632292SN/A //ADD CODE TO DEACTIVE THREAD HERE (???) 13642292SN/A 13652292SN/A for (int tid=0; tid < cpuWaitList.size(); tid++) { 13662292SN/A activateWhenReady(tid); 13672292SN/A } 13682292SN/A 13692292SN/A if (cpuWaitList.size() == 0) 13702292SN/A contextSwitch = true; 13712292SN/A } 13722292SN/A} 13732292SN/A 13742292SN/Atemplate <class Impl> 13752292SN/Avoid 13762292SN/AFullO3CPU<Impl>::updateThreadPriority() 13772292SN/A{ 13782292SN/A if (activeThreads.size() > 1) 13792292SN/A { 13802292SN/A //DEFAULT TO ROUND ROBIN SCHEME 13812292SN/A //e.g. Move highest priority to end of thread list 13822292SN/A list<unsigned>::iterator list_begin = activeThreads.begin(); 13832292SN/A list<unsigned>::iterator list_end = activeThreads.end(); 13842292SN/A 13852292SN/A unsigned high_thread = *list_begin; 13862292SN/A 13872292SN/A activeThreads.erase(list_begin); 13882292SN/A 13892292SN/A activeThreads.push_back(high_thread); 13902292SN/A } 13912292SN/A} 13921060SN/A 13931755SN/A// Forward declaration of FullO3CPU. 13942818Sksewell@umich.edutemplate class FullO3CPU<O3CPUImpl>; 1395