base.cc revision 9294
12SN/A/* 28922Swilliam.wang@arm.com * Copyright (c) 2011-2012 ARM Limited 38707Sandreas.hansson@arm.com * All rights reserved 48707Sandreas.hansson@arm.com * 58707Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68707Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78707Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88707Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98707Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108707Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118707Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128707Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138707Sandreas.hansson@arm.com * 141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 157897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California 162SN/A * All rights reserved. 172SN/A * 182SN/A * Redistribution and use in source and binary forms, with or without 192SN/A * modification, are permitted provided that the following conditions are 202SN/A * met: redistributions of source code must retain the above copyright 212SN/A * notice, this list of conditions and the following disclaimer; 222SN/A * redistributions in binary form must reproduce the above copyright 232SN/A * notice, this list of conditions and the following disclaimer in the 242SN/A * documentation and/or other materials provided with the distribution; 252SN/A * neither the name of the copyright holders nor the names of its 262SN/A * contributors may be used to endorse or promote products derived from 272SN/A * this software without specific prior written permission. 282SN/A * 292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 422665Ssaidi@eecs.umich.edu * Nathan Binkert 437897Shestness@cs.utexas.edu * Rick Strong 442SN/A */ 452SN/A 461388SN/A#include <iostream> 478229Snate@binkert.org#include <sstream> 482SN/A#include <string> 492SN/A 507781SAli.Saidi@ARM.com#include "arch/tlb.hh" 518229Snate@binkert.org#include "base/loader/symtab.hh" 521191SN/A#include "base/cprintf.hh" 531191SN/A#include "base/misc.hh" 541388SN/A#include "base/output.hh" 555529Snate@binkert.org#include "base/trace.hh" 561717SN/A#include "cpu/base.hh" 578887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 582651Ssaidi@eecs.umich.edu#include "cpu/cpuevent.hh" 598229Snate@binkert.org#include "cpu/profile.hh" 602680Sktlim@umich.edu#include "cpu/thread_context.hh" 618232Snate@binkert.org#include "debug/SyscallVerbose.hh" 625529Snate@binkert.org#include "params/BaseCPU.hh" 638779Sgblack@eecs.umich.edu#include "sim/full_system.hh" 642190SN/A#include "sim/process.hh" 6556SN/A#include "sim/sim_events.hh" 668229Snate@binkert.org#include "sim/sim_exit.hh" 672190SN/A#include "sim/system.hh" 682SN/A 692359SN/A// Hack 702359SN/A#include "sim/stat_control.hh" 712359SN/A 722SN/Ausing namespace std; 732SN/A 742SN/Avector<BaseCPU *> BaseCPU::cpuList; 752SN/A 762SN/A// This variable reflects the max number of threads in any CPU. Be 772SN/A// careful to only use it once all the CPUs that you care about have 782SN/A// been initialized 792SN/Aint maxThreadsPerCPU = 1; 802SN/A 815606Snate@binkert.orgCPUProgressEvent::CPUProgressEvent(BaseCPU *_cpu, Tick ival) 826144Sksewell@umich.edu : Event(Event::Progress_Event_Pri), _interval(ival), lastNumInst(0), 836144Sksewell@umich.edu cpu(_cpu), _repeatEvent(true) 843126Sktlim@umich.edu{ 856144Sksewell@umich.edu if (_interval) 867823Ssteve.reinhardt@amd.com cpu->schedule(this, curTick() + _interval); 873126Sktlim@umich.edu} 883126Sktlim@umich.edu 892356SN/Avoid 902356SN/ACPUProgressEvent::process() 912356SN/A{ 928834Satgutier@umich.edu Counter temp = cpu->totalOps(); 932356SN/A#ifndef NDEBUG 949179Sandreas.hansson@arm.com double ipc = double(temp - lastNumInst) / (_interval / cpu->clockPeriod()); 952367SN/A 966144Sksewell@umich.edu DPRINTFN("%s progress event, total committed:%i, progress insts committed: " 976144Sksewell@umich.edu "%lli, IPC: %0.8d\n", cpu->name(), temp, temp - lastNumInst, 986144Sksewell@umich.edu ipc); 992356SN/A ipc = 0.0; 1002367SN/A#else 1016144Sksewell@umich.edu cprintf("%lli: %s progress event, total committed:%i, progress insts " 1027823Ssteve.reinhardt@amd.com "committed: %lli\n", curTick(), cpu->name(), temp, 1036144Sksewell@umich.edu temp - lastNumInst); 1042367SN/A#endif 1052356SN/A lastNumInst = temp; 1066144Sksewell@umich.edu 1076144Sksewell@umich.edu if (_repeatEvent) 1087823Ssteve.reinhardt@amd.com cpu->schedule(this, curTick() + _interval); 1092356SN/A} 1102356SN/A 1112356SN/Aconst char * 1125336Shines@cs.fsu.eduCPUProgressEvent::description() const 1132356SN/A{ 1144873Sstever@eecs.umich.edu return "CPU Progress"; 1152356SN/A} 1162356SN/A 1178876Sandreas.hansson@arm.comBaseCPU::BaseCPU(Params *p, bool is_checker) 1189157Sandreas.hansson@arm.com : MemObject(p), instCnt(0), _cpuId(p->cpu_id), 1198832SAli.Saidi@ARM.com _instMasterId(p->system->getMasterId(name() + ".inst")), 1208832SAli.Saidi@ARM.com _dataMasterId(p->system->getMasterId(name() + ".data")), 1219220Shestness@cs.wisc.edu interrupts(p->interrupts), profileEvent(NULL), 1229157Sandreas.hansson@arm.com numThreads(p->numThreads), system(p->system) 1232SN/A{ 1245712Shsul@eecs.umich.edu // if Python did not provide a valid ID, do it here 1255712Shsul@eecs.umich.edu if (_cpuId == -1 ) { 1265712Shsul@eecs.umich.edu _cpuId = cpuList.size(); 1275712Shsul@eecs.umich.edu } 1285712Shsul@eecs.umich.edu 1292SN/A // add self to global list of CPUs 1302SN/A cpuList.push_back(this); 1312SN/A 1325712Shsul@eecs.umich.edu DPRINTF(SyscallVerbose, "Constructing CPU with id %d\n", _cpuId); 1335712Shsul@eecs.umich.edu 1346221Snate@binkert.org if (numThreads > maxThreadsPerCPU) 1356221Snate@binkert.org maxThreadsPerCPU = numThreads; 1362SN/A 1372SN/A // allocate per-thread instruction-based event queues 1386221Snate@binkert.org comInstEventQueue = new EventQueue *[numThreads]; 1396221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) 1406221Snate@binkert.org comInstEventQueue[tid] = 1416221Snate@binkert.org new EventQueue("instruction-based event queue"); 1422SN/A 1432SN/A // 1442SN/A // set up instruction-count-based termination events, if any 1452SN/A // 1465606Snate@binkert.org if (p->max_insts_any_thread != 0) { 1475606Snate@binkert.org const char *cause = "a thread reached the max instruction count"; 1486221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) { 1495606Snate@binkert.org Event *event = new SimLoopExitEvent(cause, 0); 1506221Snate@binkert.org comInstEventQueue[tid]->schedule(event, p->max_insts_any_thread); 1515606Snate@binkert.org } 1525606Snate@binkert.org } 1532SN/A 1541400SN/A if (p->max_insts_all_threads != 0) { 1555606Snate@binkert.org const char *cause = "all threads reached the max instruction count"; 1565606Snate@binkert.org 1572SN/A // allocate & initialize shared downcounter: each event will 1582SN/A // decrement this when triggered; simulation will terminate 1592SN/A // when counter reaches 0 1602SN/A int *counter = new int; 1616221Snate@binkert.org *counter = numThreads; 1626221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) { 1635606Snate@binkert.org Event *event = new CountedExitEvent(cause, *counter); 1646670Shsul@eecs.umich.edu comInstEventQueue[tid]->schedule(event, p->max_insts_all_threads); 1655606Snate@binkert.org } 1662SN/A } 1672SN/A 168124SN/A // allocate per-thread load-based event queues 1696221Snate@binkert.org comLoadEventQueue = new EventQueue *[numThreads]; 1706221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) 1716221Snate@binkert.org comLoadEventQueue[tid] = new EventQueue("load-based event queue"); 172124SN/A 173124SN/A // 174124SN/A // set up instruction-count-based termination events, if any 175124SN/A // 1765606Snate@binkert.org if (p->max_loads_any_thread != 0) { 1775606Snate@binkert.org const char *cause = "a thread reached the max load count"; 1786221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) { 1795606Snate@binkert.org Event *event = new SimLoopExitEvent(cause, 0); 1806221Snate@binkert.org comLoadEventQueue[tid]->schedule(event, p->max_loads_any_thread); 1815606Snate@binkert.org } 1825606Snate@binkert.org } 183124SN/A 1841400SN/A if (p->max_loads_all_threads != 0) { 1855606Snate@binkert.org const char *cause = "all threads reached the max load count"; 186124SN/A // allocate & initialize shared downcounter: each event will 187124SN/A // decrement this when triggered; simulation will terminate 188124SN/A // when counter reaches 0 189124SN/A int *counter = new int; 1906221Snate@binkert.org *counter = numThreads; 1916221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; ++tid) { 1925606Snate@binkert.org Event *event = new CountedExitEvent(cause, *counter); 1936221Snate@binkert.org comLoadEventQueue[tid]->schedule(event, p->max_loads_all_threads); 1945606Snate@binkert.org } 195124SN/A } 196124SN/A 1971191SN/A functionTracingEnabled = false; 1985529Snate@binkert.org if (p->function_trace) { 1998634Schris.emmons@arm.com const string fname = csprintf("ftrace.%s", name()); 2008634Schris.emmons@arm.com functionTraceStream = simout.find(fname); 2018634Schris.emmons@arm.com if (!functionTraceStream) 2028634Schris.emmons@arm.com functionTraceStream = simout.create(fname); 2038634Schris.emmons@arm.com 2041191SN/A currentFunctionStart = currentFunctionEnd = 0; 2055529Snate@binkert.org functionEntryTick = p->function_trace_start; 2061191SN/A 2075529Snate@binkert.org if (p->function_trace_start == 0) { 2081191SN/A functionTracingEnabled = true; 2091191SN/A } else { 2105606Snate@binkert.org typedef EventWrapper<BaseCPU, &BaseCPU::enableFunctionTrace> wrap; 2115606Snate@binkert.org Event *event = new wrap(this, true); 2125606Snate@binkert.org schedule(event, p->function_trace_start); 2131191SN/A } 2141191SN/A } 2158876Sandreas.hansson@arm.com 2168876Sandreas.hansson@arm.com // The interrupts should always be present unless this CPU is 2178876Sandreas.hansson@arm.com // switched in later or in case it is a checker CPU 2188876Sandreas.hansson@arm.com if (!params()->defer_registration && !is_checker) { 2198876Sandreas.hansson@arm.com if (interrupts) { 2208876Sandreas.hansson@arm.com interrupts->setCPU(this); 2218876Sandreas.hansson@arm.com } else { 2228876Sandreas.hansson@arm.com fatal("CPU %s has no interrupt controller.\n" 2238876Sandreas.hansson@arm.com "Ensure createInterruptController() is called.\n", name()); 2248876Sandreas.hansson@arm.com } 2258876Sandreas.hansson@arm.com } 2265810Sgblack@eecs.umich.edu 2278779Sgblack@eecs.umich.edu if (FullSystem) { 2288779Sgblack@eecs.umich.edu if (params()->profile) 2298779Sgblack@eecs.umich.edu profileEvent = new ProfileEvent(this, params()->profile); 2308779Sgblack@eecs.umich.edu } 2315529Snate@binkert.org tracer = params()->tracer; 2321917SN/A} 2331191SN/A 2341191SN/Avoid 2351191SN/ABaseCPU::enableFunctionTrace() 2361191SN/A{ 2371191SN/A functionTracingEnabled = true; 2381191SN/A} 2391191SN/A 2401191SN/ABaseCPU::~BaseCPU() 2411191SN/A{ 2429086Sandreas.hansson@arm.com delete profileEvent; 2439086Sandreas.hansson@arm.com delete[] comLoadEventQueue; 2449086Sandreas.hansson@arm.com delete[] comInstEventQueue; 2451191SN/A} 2461191SN/A 2471129SN/Avoid 2481129SN/ABaseCPU::init() 2491129SN/A{ 2505529Snate@binkert.org if (!params()->defer_registration) 2512680Sktlim@umich.edu registerThreadContexts(); 2521129SN/A} 253180SN/A 2542SN/Avoid 2551917SN/ABaseCPU::startup() 2561917SN/A{ 2578779Sgblack@eecs.umich.edu if (FullSystem) { 2588779Sgblack@eecs.umich.edu if (!params()->defer_registration && profileEvent) 2598779Sgblack@eecs.umich.edu schedule(profileEvent, curTick()); 2608779Sgblack@eecs.umich.edu } 2612356SN/A 2625529Snate@binkert.org if (params()->progress_interval) { 2639179Sandreas.hansson@arm.com new CPUProgressEvent(this, params()->progress_interval); 2642356SN/A } 2651917SN/A} 2661917SN/A 2671917SN/A 2681917SN/Avoid 2692SN/ABaseCPU::regStats() 2702SN/A{ 271729SN/A using namespace Stats; 272707SN/A 273707SN/A numCycles 274707SN/A .name(name() + ".numCycles") 275707SN/A .desc("number of cpu cycles simulated") 276707SN/A ; 277707SN/A 2787914SBrad.Beckmann@amd.com numWorkItemsStarted 2797914SBrad.Beckmann@amd.com .name(name() + ".numWorkItemsStarted") 2807914SBrad.Beckmann@amd.com .desc("number of work items this cpu started") 2817914SBrad.Beckmann@amd.com ; 2827914SBrad.Beckmann@amd.com 2837914SBrad.Beckmann@amd.com numWorkItemsCompleted 2847914SBrad.Beckmann@amd.com .name(name() + ".numWorkItemsCompleted") 2857914SBrad.Beckmann@amd.com .desc("number of work items this cpu completed") 2867914SBrad.Beckmann@amd.com ; 2877914SBrad.Beckmann@amd.com 2882680Sktlim@umich.edu int size = threadContexts.size(); 2892SN/A if (size > 1) { 2902SN/A for (int i = 0; i < size; ++i) { 2912SN/A stringstream namestr; 2922SN/A ccprintf(namestr, "%s.ctx%d", name(), i); 2932680Sktlim@umich.edu threadContexts[i]->regStats(namestr.str()); 2942SN/A } 2952SN/A } else if (size == 1) 2962680Sktlim@umich.edu threadContexts[0]->regStats(name()); 2972SN/A} 2982SN/A 2999294Sandreas.hansson@arm.comBaseMasterPort & 3009294Sandreas.hansson@arm.comBaseCPU::getMasterPort(const string &if_name, PortID idx) 3018850Sandreas.hansson@arm.com{ 3028850Sandreas.hansson@arm.com // Get the right port based on name. This applies to all the 3038850Sandreas.hansson@arm.com // subclasses of the base CPU and relies on their implementation 3048850Sandreas.hansson@arm.com // of getDataPort and getInstPort. In all cases there methods 3058850Sandreas.hansson@arm.com // return a CpuPort pointer. 3068850Sandreas.hansson@arm.com if (if_name == "dcache_port") 3078922Swilliam.wang@arm.com return getDataPort(); 3088850Sandreas.hansson@arm.com else if (if_name == "icache_port") 3098922Swilliam.wang@arm.com return getInstPort(); 3108850Sandreas.hansson@arm.com else 3118922Swilliam.wang@arm.com return MemObject::getMasterPort(if_name, idx); 3128850Sandreas.hansson@arm.com} 3138850Sandreas.hansson@arm.com 314180SN/Avoid 3152680Sktlim@umich.eduBaseCPU::registerThreadContexts() 316180SN/A{ 3176221Snate@binkert.org ThreadID size = threadContexts.size(); 3186221Snate@binkert.org for (ThreadID tid = 0; tid < size; ++tid) { 3196221Snate@binkert.org ThreadContext *tc = threadContexts[tid]; 3202378SN/A 3215718Shsul@eecs.umich.edu /** This is so that contextId and cpuId match where there is a 3225718Shsul@eecs.umich.edu * 1cpu:1context relationship. Otherwise, the order of registration 3235718Shsul@eecs.umich.edu * could affect the assignment and cpu 1 could have context id 3, for 3245718Shsul@eecs.umich.edu * example. We may even want to do something like this for SMT so that 3255718Shsul@eecs.umich.edu * cpu 0 has the lowest thread contexts and cpu N has the highest, but 3265718Shsul@eecs.umich.edu * I'll just do this for now 3275718Shsul@eecs.umich.edu */ 3286221Snate@binkert.org if (numThreads == 1) 3295718Shsul@eecs.umich.edu tc->setContextId(system->registerThreadContext(tc, _cpuId)); 3305718Shsul@eecs.umich.edu else 3315718Shsul@eecs.umich.edu tc->setContextId(system->registerThreadContext(tc)); 3328779Sgblack@eecs.umich.edu 3338779Sgblack@eecs.umich.edu if (!FullSystem) 3348779Sgblack@eecs.umich.edu tc->getProcessPtr()->assignThreadContext(tc->contextId()); 335180SN/A } 336180SN/A} 337180SN/A 338180SN/A 3394000Ssaidi@eecs.umich.eduint 3404000Ssaidi@eecs.umich.eduBaseCPU::findContext(ThreadContext *tc) 3414000Ssaidi@eecs.umich.edu{ 3426221Snate@binkert.org ThreadID size = threadContexts.size(); 3436221Snate@binkert.org for (ThreadID tid = 0; tid < size; ++tid) { 3446221Snate@binkert.org if (tc == threadContexts[tid]) 3456221Snate@binkert.org return tid; 3464000Ssaidi@eecs.umich.edu } 3474000Ssaidi@eecs.umich.edu return 0; 3484000Ssaidi@eecs.umich.edu} 3494000Ssaidi@eecs.umich.edu 350180SN/Avoid 3512798Sktlim@umich.eduBaseCPU::switchOut() 352180SN/A{ 3532359SN/A if (profileEvent && profileEvent->scheduled()) 3545606Snate@binkert.org deschedule(profileEvent); 355180SN/A} 356180SN/A 357180SN/Avoid 3588737Skoansin.tan@gmail.comBaseCPU::takeOverFrom(BaseCPU *oldCPU) 359180SN/A{ 3602680Sktlim@umich.edu assert(threadContexts.size() == oldCPU->threadContexts.size()); 3619152Satgutier@umich.edu assert(_cpuId == oldCPU->cpuId()); 3625712Shsul@eecs.umich.edu 3636221Snate@binkert.org ThreadID size = threadContexts.size(); 3646221Snate@binkert.org for (ThreadID i = 0; i < size; ++i) { 3652680Sktlim@umich.edu ThreadContext *newTC = threadContexts[i]; 3662680Sktlim@umich.edu ThreadContext *oldTC = oldCPU->threadContexts[i]; 367180SN/A 3682680Sktlim@umich.edu newTC->takeOverFrom(oldTC); 3692651Ssaidi@eecs.umich.edu 3702680Sktlim@umich.edu CpuEvent::replaceThreadContext(oldTC, newTC); 3712651Ssaidi@eecs.umich.edu 3725714Shsul@eecs.umich.edu assert(newTC->contextId() == oldTC->contextId()); 3735715Shsul@eecs.umich.edu assert(newTC->threadId() == oldTC->threadId()); 3745714Shsul@eecs.umich.edu system->replaceThreadContext(newTC, newTC->contextId()); 3752359SN/A 3765875Ssteve.reinhardt@amd.com /* This code no longer works since the zero register (e.g., 3775875Ssteve.reinhardt@amd.com * r31 on Alpha) doesn't necessarily contain zero at this 3785875Ssteve.reinhardt@amd.com * point. 3795875Ssteve.reinhardt@amd.com if (DTRACE(Context)) 3805217Ssaidi@eecs.umich.edu ThreadContext::compare(oldTC, newTC); 3815875Ssteve.reinhardt@amd.com */ 3827781SAli.Saidi@ARM.com 3839294Sandreas.hansson@arm.com BaseMasterPort *old_itb_port = oldTC->getITBPtr()->getMasterPort(); 3849294Sandreas.hansson@arm.com BaseMasterPort *old_dtb_port = oldTC->getDTBPtr()->getMasterPort(); 3859294Sandreas.hansson@arm.com BaseMasterPort *new_itb_port = newTC->getITBPtr()->getMasterPort(); 3869294Sandreas.hansson@arm.com BaseMasterPort *new_dtb_port = newTC->getDTBPtr()->getMasterPort(); 3877781SAli.Saidi@ARM.com 3887781SAli.Saidi@ARM.com // Move over any table walker ports if they exist 3899178Sandreas.hansson@arm.com if (new_itb_port) { 3909178Sandreas.hansson@arm.com assert(!new_itb_port->isConnected()); 3917781SAli.Saidi@ARM.com assert(old_itb_port); 3929178Sandreas.hansson@arm.com assert(old_itb_port->isConnected()); 3939294Sandreas.hansson@arm.com BaseSlavePort &slavePort = old_itb_port->getSlavePort(); 3949178Sandreas.hansson@arm.com old_itb_port->unbind(); 3958922Swilliam.wang@arm.com new_itb_port->bind(slavePort); 3967781SAli.Saidi@ARM.com } 3979178Sandreas.hansson@arm.com if (new_dtb_port) { 3989178Sandreas.hansson@arm.com assert(!new_dtb_port->isConnected()); 3997781SAli.Saidi@ARM.com assert(old_dtb_port); 4009178Sandreas.hansson@arm.com assert(old_dtb_port->isConnected()); 4019294Sandreas.hansson@arm.com BaseSlavePort &slavePort = old_dtb_port->getSlavePort(); 4029178Sandreas.hansson@arm.com old_dtb_port->unbind(); 4038922Swilliam.wang@arm.com new_dtb_port->bind(slavePort); 4047781SAli.Saidi@ARM.com } 4058733Sgeoffrey.blake@arm.com 4068887Sgeoffrey.blake@arm.com // Checker whether or not we have to transfer CheckerCPU 4078887Sgeoffrey.blake@arm.com // objects over in the switch 4088887Sgeoffrey.blake@arm.com CheckerCPU *oldChecker = oldTC->getCheckerCpuPtr(); 4098887Sgeoffrey.blake@arm.com CheckerCPU *newChecker = newTC->getCheckerCpuPtr(); 4108887Sgeoffrey.blake@arm.com if (oldChecker && newChecker) { 4119294Sandreas.hansson@arm.com BaseMasterPort *old_checker_itb_port = 4128922Swilliam.wang@arm.com oldChecker->getITBPtr()->getMasterPort(); 4139294Sandreas.hansson@arm.com BaseMasterPort *old_checker_dtb_port = 4148922Swilliam.wang@arm.com oldChecker->getDTBPtr()->getMasterPort(); 4159294Sandreas.hansson@arm.com BaseMasterPort *new_checker_itb_port = 4168922Swilliam.wang@arm.com newChecker->getITBPtr()->getMasterPort(); 4179294Sandreas.hansson@arm.com BaseMasterPort *new_checker_dtb_port = 4188922Swilliam.wang@arm.com newChecker->getDTBPtr()->getMasterPort(); 4198733Sgeoffrey.blake@arm.com 4208887Sgeoffrey.blake@arm.com // Move over any table walker ports if they exist for checker 4219178Sandreas.hansson@arm.com if (new_checker_itb_port) { 4229178Sandreas.hansson@arm.com assert(!new_checker_itb_port->isConnected()); 4238887Sgeoffrey.blake@arm.com assert(old_checker_itb_port); 4249178Sandreas.hansson@arm.com assert(old_checker_itb_port->isConnected()); 4259294Sandreas.hansson@arm.com BaseSlavePort &slavePort = 4269294Sandreas.hansson@arm.com old_checker_itb_port->getSlavePort(); 4279178Sandreas.hansson@arm.com old_checker_itb_port->unbind(); 4288922Swilliam.wang@arm.com new_checker_itb_port->bind(slavePort); 4298887Sgeoffrey.blake@arm.com } 4309178Sandreas.hansson@arm.com if (new_checker_dtb_port) { 4319178Sandreas.hansson@arm.com assert(!new_checker_dtb_port->isConnected()); 4328887Sgeoffrey.blake@arm.com assert(old_checker_dtb_port); 4339178Sandreas.hansson@arm.com assert(old_checker_dtb_port->isConnected()); 4349294Sandreas.hansson@arm.com BaseSlavePort &slavePort = 4359294Sandreas.hansson@arm.com old_checker_dtb_port->getSlavePort(); 4369178Sandreas.hansson@arm.com old_checker_dtb_port->unbind(); 4378922Swilliam.wang@arm.com new_checker_dtb_port->bind(slavePort); 4388887Sgeoffrey.blake@arm.com } 4398733Sgeoffrey.blake@arm.com } 440180SN/A } 441605SN/A 4423520Sgblack@eecs.umich.edu interrupts = oldCPU->interrupts; 4435810Sgblack@eecs.umich.edu interrupts->setCPU(this); 4449152Satgutier@umich.edu oldCPU->interrupts = NULL; 4452254SN/A 4468779Sgblack@eecs.umich.edu if (FullSystem) { 4478779Sgblack@eecs.umich.edu for (ThreadID i = 0; i < size; ++i) 4488779Sgblack@eecs.umich.edu threadContexts[i]->profileClear(); 4492254SN/A 4508779Sgblack@eecs.umich.edu if (profileEvent) 4518779Sgblack@eecs.umich.edu schedule(profileEvent, curTick()); 4528779Sgblack@eecs.umich.edu } 4534192Sktlim@umich.edu 4549178Sandreas.hansson@arm.com // All CPUs have an instruction and a data port, and the new CPU's 4559178Sandreas.hansson@arm.com // ports are dangling while the old CPU has its ports connected 4569178Sandreas.hansson@arm.com // already. Unbind the old CPU and then bind the ports of the one 4579178Sandreas.hansson@arm.com // we are switching to. 4589178Sandreas.hansson@arm.com assert(!getInstPort().isConnected()); 4599178Sandreas.hansson@arm.com assert(oldCPU->getInstPort().isConnected()); 4609294Sandreas.hansson@arm.com BaseSlavePort &inst_peer_port = oldCPU->getInstPort().getSlavePort(); 4619178Sandreas.hansson@arm.com oldCPU->getInstPort().unbind(); 4629178Sandreas.hansson@arm.com getInstPort().bind(inst_peer_port); 4634192Sktlim@umich.edu 4649178Sandreas.hansson@arm.com assert(!getDataPort().isConnected()); 4659178Sandreas.hansson@arm.com assert(oldCPU->getDataPort().isConnected()); 4669294Sandreas.hansson@arm.com BaseSlavePort &data_peer_port = oldCPU->getDataPort().getSlavePort(); 4679178Sandreas.hansson@arm.com oldCPU->getDataPort().unbind(); 4689178Sandreas.hansson@arm.com getDataPort().bind(data_peer_port); 469180SN/A} 470180SN/A 471180SN/A 4725536Srstrong@hp.comBaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, Tick _interval) 4735606Snate@binkert.org : cpu(_cpu), interval(_interval) 4741917SN/A{ } 4751917SN/A 4761917SN/Avoid 4771917SN/ABaseCPU::ProfileEvent::process() 4781917SN/A{ 4796221Snate@binkert.org ThreadID size = cpu->threadContexts.size(); 4806221Snate@binkert.org for (ThreadID i = 0; i < size; ++i) { 4812680Sktlim@umich.edu ThreadContext *tc = cpu->threadContexts[i]; 4822680Sktlim@umich.edu tc->profileSample(); 4831917SN/A } 4842254SN/A 4857823Ssteve.reinhardt@amd.com cpu->schedule(this, curTick() + interval); 4861917SN/A} 4871917SN/A 4882SN/Avoid 489921SN/ABaseCPU::serialize(std::ostream &os) 490921SN/A{ 4914000Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(instCnt); 4925647Sgblack@eecs.umich.edu interrupts->serialize(os); 493921SN/A} 494921SN/A 495921SN/Avoid 496921SN/ABaseCPU::unserialize(Checkpoint *cp, const std::string §ion) 497921SN/A{ 4984000Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(instCnt); 4995647Sgblack@eecs.umich.edu interrupts->unserialize(cp, section); 500921SN/A} 501921SN/A 5021191SN/Avoid 5031191SN/ABaseCPU::traceFunctionsInternal(Addr pc) 5041191SN/A{ 5051191SN/A if (!debugSymbolTable) 5061191SN/A return; 5071191SN/A 5081191SN/A // if pc enters different function, print new function symbol and 5091191SN/A // update saved range. Otherwise do nothing. 5101191SN/A if (pc < currentFunctionStart || pc >= currentFunctionEnd) { 5111191SN/A string sym_str; 5121191SN/A bool found = debugSymbolTable->findNearestSymbol(pc, sym_str, 5131191SN/A currentFunctionStart, 5141191SN/A currentFunctionEnd); 5151191SN/A 5161191SN/A if (!found) { 5171191SN/A // no symbol found: use addr as label 5181191SN/A sym_str = csprintf("0x%x", pc); 5191191SN/A currentFunctionStart = pc; 5201191SN/A currentFunctionEnd = pc + 1; 5211191SN/A } 5221191SN/A 5231191SN/A ccprintf(*functionTraceStream, " (%d)\n%d: %s", 5247823Ssteve.reinhardt@amd.com curTick() - functionEntryTick, curTick(), sym_str); 5257823Ssteve.reinhardt@amd.com functionEntryTick = curTick(); 5261191SN/A } 5271191SN/A} 5288707Sandreas.hansson@arm.com 5298707Sandreas.hansson@arm.combool 5308975Sandreas.hansson@arm.comBaseCPU::CpuPort::recvTimingResp(PacketPtr pkt) 5318707Sandreas.hansson@arm.com{ 5328948Sandreas.hansson@arm.com panic("BaseCPU doesn't expect recvTiming!\n"); 5338707Sandreas.hansson@arm.com return true; 5348707Sandreas.hansson@arm.com} 5358707Sandreas.hansson@arm.com 5368707Sandreas.hansson@arm.comvoid 5378707Sandreas.hansson@arm.comBaseCPU::CpuPort::recvRetry() 5388707Sandreas.hansson@arm.com{ 5398948Sandreas.hansson@arm.com panic("BaseCPU doesn't expect recvRetry!\n"); 5408707Sandreas.hansson@arm.com} 5418707Sandreas.hansson@arm.com 5428707Sandreas.hansson@arm.comvoid 5438948Sandreas.hansson@arm.comBaseCPU::CpuPort::recvFunctionalSnoop(PacketPtr pkt) 5448707Sandreas.hansson@arm.com{ 5458948Sandreas.hansson@arm.com // No internal storage to update (in the general case). A CPU with 5468948Sandreas.hansson@arm.com // internal storage, e.g. an LSQ that should be part of the 5478948Sandreas.hansson@arm.com // coherent memory has to check against stored data. 5488707Sandreas.hansson@arm.com} 549