system.cc revision 8986
12689Sktlim@umich.edu/*
28703Sandreas.hansson@arm.com * Copyright (c) 2011-2012 ARM Limited
38666SPrakash.Ramrakhyani@arm.com * All rights reserved
48666SPrakash.Ramrakhyani@arm.com *
58666SPrakash.Ramrakhyani@arm.com * The license below extends only to copyright in the software and shall
68666SPrakash.Ramrakhyani@arm.com * not be construed as granting a license to any other intellectual
78666SPrakash.Ramrakhyani@arm.com * property including but not limited to intellectual property relating
88666SPrakash.Ramrakhyani@arm.com * to a hardware implementation of the functionality of the software
98666SPrakash.Ramrakhyani@arm.com * licensed hereunder.  You may use the software subject to the license
108666SPrakash.Ramrakhyani@arm.com * terms below provided that you ensure that this notice is replicated
118666SPrakash.Ramrakhyani@arm.com * unmodified and in its entirety in all distributions of the software,
128666SPrakash.Ramrakhyani@arm.com * modified or unmodified, in source code or in binary form.
138666SPrakash.Ramrakhyani@arm.com *
142689Sktlim@umich.edu * Copyright (c) 2003-2006 The Regents of The University of Michigan
157897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California
162689Sktlim@umich.edu * All rights reserved.
172689Sktlim@umich.edu *
182689Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without
192689Sktlim@umich.edu * modification, are permitted provided that the following conditions are
202689Sktlim@umich.edu * met: redistributions of source code must retain the above copyright
212689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer;
222689Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright
232689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the
242689Sktlim@umich.edu * documentation and/or other materials provided with the distribution;
252689Sktlim@umich.edu * neither the name of the copyright holders nor the names of its
262689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from
272689Sktlim@umich.edu * this software without specific prior written permission.
282689Sktlim@umich.edu *
292689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402689Sktlim@umich.edu *
412689Sktlim@umich.edu * Authors: Steve Reinhardt
422689Sktlim@umich.edu *          Lisa Hsu
432689Sktlim@umich.edu *          Nathan Binkert
442689Sktlim@umich.edu *          Ali Saidi
457897Shestness@cs.utexas.edu *          Rick Strong
462689Sktlim@umich.edu */
472689Sktlim@umich.edu
482521SN/A#include "arch/isa_traits.hh"
493960Sgblack@eecs.umich.edu#include "arch/remote_gdb.hh"
504194Ssaidi@eecs.umich.edu#include "arch/utility.hh"
518769Sgblack@eecs.umich.edu#include "arch/vtophys.hh"
521070SN/A#include "base/loader/object_file.hh"
531070SN/A#include "base/loader/symtab.hh"
549142Ssteve.reinhardt@amd.com#include "base/trace.hh"
552521SN/A#include "config/the_isa.hh"
566658Snate@binkert.org#include "cpu/thread_context.hh"
578229Snate@binkert.org#include "debug/Loader.hh"
588232Snate@binkert.org#include "debug/WorkItems.hh"
598666SPrakash.Ramrakhyani@arm.com#include "kern/kernel_stats.hh"
608769Sgblack@eecs.umich.edu#include "mem/physical.hh"
612522SN/A#include "params/System.hh"
628769Sgblack@eecs.umich.edu#include "sim/byteswap.hh"
632037SN/A#include "sim/debug.hh"
648229Snate@binkert.org#include "sim/full_system.hh"
658769Sgblack@eecs.umich.edu#include "sim/system.hh"
6656SN/A
676658Snate@binkert.orgusing namespace std;
682SN/Ausing namespace TheISA;
692107SN/A
702SN/Avector<System *> System::systemList;
712SN/A
722SN/Aint System::numSystemsRunning = 0;
732SN/A
742SN/ASystem::System(Params *p)
751070SN/A    : MemObject(p), _systemPort("system_port", this),
768703Sandreas.hansson@arm.com      _numContexts(0),
778703Sandreas.hansson@arm.com      pagePtr(0),
788826Snilay@cs.wisc.edu      init_param(p->init_param),
792521SN/A      physProxy(_systemPort),
808852Sandreas.hansson@arm.com      virtProxy(_systemPort),
818852Sandreas.hansson@arm.com      loadAddrMask(p->load_addr_mask),
827580SAli.Saidi@arm.com      nextPID(0),
837770SAli.Saidi@ARM.com      physmem(p->memories),
848931Sandreas.hansson@arm.com      memoryMode(p->mem_mode),
857914SBrad.Beckmann@amd.com      workItemsBegin(0),
867914SBrad.Beckmann@amd.com      workItemsEnd(0),
877914SBrad.Beckmann@amd.com      numWorkIds(p->num_work_ids),
888666SPrakash.Ramrakhyani@arm.com      _params(p),
897914SBrad.Beckmann@amd.com      totalNumInsts(0),
908666SPrakash.Ramrakhyani@arm.com      instEventQueue("system instruction-based event queue")
917897Shestness@cs.utexas.edu{
922SN/A    // add self to global system list
931070SN/A    systemList.push_back(this);
941070SN/A
951070SN/A    if (FullSystem) {
968769Sgblack@eecs.umich.edu        kernelSymtab = new SymbolTable;
978769Sgblack@eecs.umich.edu        if (!debugSymbolTable)
988769Sgblack@eecs.umich.edu            debugSymbolTable = new SymbolTable;
998769Sgblack@eecs.umich.edu    }
1008666SPrakash.Ramrakhyani@arm.com
1018832SAli.Saidi@ARM.com    // Get the generic system master IDs
1028832SAli.Saidi@ARM.com    MasterID tmp_id M5_VAR_USED;
1038832SAli.Saidi@ARM.com    tmp_id = getMasterId("writebacks");
1048832SAli.Saidi@ARM.com    assert(tmp_id == Request::wbMasterId);
1058832SAli.Saidi@ARM.com    tmp_id = getMasterId("functional");
1068832SAli.Saidi@ARM.com    assert(tmp_id == Request::funcMasterId);
1078832SAli.Saidi@ARM.com    tmp_id = getMasterId("interrupt");
1088832SAli.Saidi@ARM.com    assert(tmp_id == Request::intMasterId);
1098832SAli.Saidi@ARM.com
1108832SAli.Saidi@ARM.com    if (FullSystem) {
1118885SAli.Saidi@ARM.com        if (params()->kernel == "") {
1128885SAli.Saidi@ARM.com            inform("No kernel set for full system simulation. "
1138885SAli.Saidi@ARM.com                    "Assuming you know what you're doing if not SPARC ISA\n");
1149147Snilay@cs.wisc.edu        } else {
1159147Snilay@cs.wisc.edu            // Get the kernel code
1169147Snilay@cs.wisc.edu            kernel = createObjectFile(params()->kernel);
1178885SAli.Saidi@ARM.com            inform("kernel located at: %s", params()->kernel);
1188885SAli.Saidi@ARM.com
1198885SAli.Saidi@ARM.com            if (kernel == NULL)
1208885SAli.Saidi@ARM.com                fatal("Could not load kernel file %s", params()->kernel);
1218885SAli.Saidi@ARM.com
1228885SAli.Saidi@ARM.com            // setup entry points
1238885SAli.Saidi@ARM.com            kernelStart = kernel->textBase();
1248885SAli.Saidi@ARM.com            kernelEnd = kernel->bssBase() + kernel->bssSize();
1258885SAli.Saidi@ARM.com            kernelEntry = kernel->entryPoint();
1268885SAli.Saidi@ARM.com
1278885SAli.Saidi@ARM.com            // load symbols
1288885SAli.Saidi@ARM.com            if (!kernel->loadGlobalSymbols(kernelSymtab))
1298885SAli.Saidi@ARM.com                fatal("could not load kernel symbols\n");
1308885SAli.Saidi@ARM.com
1318885SAli.Saidi@ARM.com            if (!kernel->loadLocalSymbols(kernelSymtab))
1328885SAli.Saidi@ARM.com                fatal("could not load kernel local symbols\n");
1338885SAli.Saidi@ARM.com
1348885SAli.Saidi@ARM.com            if (!kernel->loadGlobalSymbols(debugSymbolTable))
1358885SAli.Saidi@ARM.com                fatal("could not load kernel symbols\n");
1368885SAli.Saidi@ARM.com
1378885SAli.Saidi@ARM.com            if (!kernel->loadLocalSymbols(debugSymbolTable))
1388885SAli.Saidi@ARM.com                fatal("could not load kernel local symbols\n");
1398885SAli.Saidi@ARM.com
1408885SAli.Saidi@ARM.com            // Loading only needs to happen once and after memory system is
1418885SAli.Saidi@ARM.com            // connected so it will happen in initState()
1428885SAli.Saidi@ARM.com        }
1438885SAli.Saidi@ARM.com    }
1448885SAli.Saidi@ARM.com
1458885SAli.Saidi@ARM.com    // increment the number of running systms
1468885SAli.Saidi@ARM.com    numSystemsRunning++;
1478885SAli.Saidi@ARM.com
1488885SAli.Saidi@ARM.com}
1498885SAli.Saidi@ARM.com
1508885SAli.Saidi@ARM.comSystem::~System()
1519053Sdam.sunwoo@arm.com{
1529053Sdam.sunwoo@arm.com    delete kernelSymtab;
1539053Sdam.sunwoo@arm.com    delete kernel;
1542SN/A
1552SN/A    for (uint32_t j = 0; j < numWorkIds; j++)
1562SN/A        delete workItemStats[j];
1572SN/A}
1581070SN/A
1591070SN/Avoid
1608666SPrakash.Ramrakhyani@arm.comSystem::init()
1618666SPrakash.Ramrakhyani@arm.com{
1628666SPrakash.Ramrakhyani@arm.com    // check that the system port is connected
1632SN/A    if (!_systemPort.isConnected())
1642SN/A        panic("System port on %s is not connected.\n", name());
1658706Sandreas.hansson@arm.com}
1668706Sandreas.hansson@arm.com
1678706Sandreas.hansson@arm.comMasterPort&
1688706Sandreas.hansson@arm.comSystem::getMasterPort(const std::string &if_name, int idx)
1698706Sandreas.hansson@arm.com{
1708706Sandreas.hansson@arm.com    // no need to distinguish at the moment (besides checking)
1718706Sandreas.hansson@arm.com    return _systemPort;
1728706Sandreas.hansson@arm.com}
1738922Swilliam.wang@arm.com
1748922Swilliam.wang@arm.comvoid
1758703Sandreas.hansson@arm.comSystem::setMemoryMode(Enums::MemoryMode mode)
1768703Sandreas.hansson@arm.com{
1778922Swilliam.wang@arm.com    assert(getState() == Drained);
1788703Sandreas.hansson@arm.com    memoryMode = mode;
1798703Sandreas.hansson@arm.com}
1802901Ssaidi@eecs.umich.edu
1814762Snate@binkert.orgbool System::breakpoint()
1822901Ssaidi@eecs.umich.edu{
1832901Ssaidi@eecs.umich.edu    if (remoteGDB.size())
1842901Ssaidi@eecs.umich.edu        return remoteGDB[0]->breakpoint();
1852901Ssaidi@eecs.umich.edu    return false;
1862901Ssaidi@eecs.umich.edu}
1873960Sgblack@eecs.umich.edu
1883960Sgblack@eecs.umich.edu/**
1894095Sbinkertn@umich.edu * Setting rgdb_wait to a positive integer waits for a remote debugger to
1904095Sbinkertn@umich.edu * connect to that context ID before continuing.  This should really
1914095Sbinkertn@umich.edu   be a parameter on the CPU object or something...
1923960Sgblack@eecs.umich.edu */
1933960Sgblack@eecs.umich.eduint rgdb_wait = -1;
1947445Ssteve.reinhardt@amd.com
1957445Ssteve.reinhardt@amd.comint
1967445Ssteve.reinhardt@amd.comSystem::registerThreadContext(ThreadContext *tc, int assigned)
1977445Ssteve.reinhardt@amd.com{
1987445Ssteve.reinhardt@amd.com    int id;
1997445Ssteve.reinhardt@amd.com    if (assigned == -1) {
2007445Ssteve.reinhardt@amd.com        for (id = 0; id < threadContexts.size(); id++) {
201180SN/A            if (!threadContexts[id])
2025718Shsul@eecs.umich.edu                break;
2032SN/A        }
2045712Shsul@eecs.umich.edu
2055718Shsul@eecs.umich.edu        if (threadContexts.size() <= id)
2065718Shsul@eecs.umich.edu            threadContexts.resize(id + 1);
2075718Shsul@eecs.umich.edu    } else {
2085718Shsul@eecs.umich.edu        if (threadContexts.size() <= assigned)
2095718Shsul@eecs.umich.edu            threadContexts.resize(assigned + 1);
2105718Shsul@eecs.umich.edu        id = assigned;
2115718Shsul@eecs.umich.edu    }
2125718Shsul@eecs.umich.edu
2135718Shsul@eecs.umich.edu    if (threadContexts[id])
2145718Shsul@eecs.umich.edu        fatal("Cannot have two CPUs with the same id (%d)\n", id);
2155718Shsul@eecs.umich.edu
2165718Shsul@eecs.umich.edu    threadContexts[id] = tc;
2171806SN/A    _numContexts++;
2181806SN/A
2192680Sktlim@umich.edu    int port = getRemoteGDBPort();
2205823Ssaidi@eecs.umich.edu    if (port) {
2211806SN/A        RemoteGDB *rgdb = new RemoteGDB(this, tc);
2222680Sktlim@umich.edu        GDBListener *gdbl = new GDBListener(rgdb, port + id);
2235714Shsul@eecs.umich.edu        gdbl->listen();
2241070SN/A
2255512SMichael.Adler@intel.com        if (rgdb_wait != -1 && rgdb_wait == id)
2267445Ssteve.reinhardt@amd.com            gdbl->accept();
2274095Sbinkertn@umich.edu
2285512SMichael.Adler@intel.com        if (remoteGDB.size() <= id) {
2294095Sbinkertn@umich.edu            remoteGDB.resize(id + 1);
2307445Ssteve.reinhardt@amd.com        }
2314095Sbinkertn@umich.edu
2324095Sbinkertn@umich.edu        remoteGDB[id] = rgdb;
2331070SN/A    }
2344095Sbinkertn@umich.edu
2354095Sbinkertn@umich.edu    activeCpus.push_back(false);
2364095Sbinkertn@umich.edu
2374095Sbinkertn@umich.edu    return id;
2384095Sbinkertn@umich.edu}
2391070SN/A
2401070SN/Aint
2417914SBrad.Beckmann@amd.comSystem::numRunningContexts()
2427914SBrad.Beckmann@amd.com{
2431806SN/A    int running = 0;
244180SN/A    for (int i = 0; i < _numContexts; ++i) {
24575SN/A        if (threadContexts[i]->status() != ThreadContext::Halted)
2466029Ssteve.reinhardt@amd.com            ++running;
2476029Ssteve.reinhardt@amd.com    }
2486029Ssteve.reinhardt@amd.com    return running;
2496029Ssteve.reinhardt@amd.com}
2506029Ssteve.reinhardt@amd.com
2516029Ssteve.reinhardt@amd.comvoid
2526029Ssteve.reinhardt@amd.comSystem::initState()
2536029Ssteve.reinhardt@amd.com{
2546029Ssteve.reinhardt@amd.com    int i;
2556029Ssteve.reinhardt@amd.com    if (FullSystem) {
2566029Ssteve.reinhardt@amd.com        for (i = 0; i < threadContexts.size(); i++)
257180SN/A            TheISA::startupCPU(threadContexts[i], i);
2587733SAli.Saidi@ARM.com        // Moved from the constructor to here since it relies on the
2591129SN/A        // address map being resolved in the interconnect
2608769Sgblack@eecs.umich.edu        /**
2619172Snilay@cs.wisc.edu         * Load the kernel code into memory
2628769Sgblack@eecs.umich.edu         */
2638799Sgblack@eecs.umich.edu        if (params()->kernel != "")  {
2648799Sgblack@eecs.umich.edu            // Load program sections into memory
2658799Sgblack@eecs.umich.edu            kernel->loadSections(physProxy, loadAddrMask);
2668799Sgblack@eecs.umich.edu
2678799Sgblack@eecs.umich.edu            DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
2688885SAli.Saidi@ARM.com            DPRINTF(Loader, "Kernel end   = %#x\n", kernelEnd);
2698799Sgblack@eecs.umich.edu            DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
2708799Sgblack@eecs.umich.edu            DPRINTF(Loader, "Kernel loaded...\n");
2718706Sandreas.hansson@arm.com        }
2728799Sgblack@eecs.umich.edu    }
2738799Sgblack@eecs.umich.edu
2748799Sgblack@eecs.umich.edu    activeCpus.clear();
2758799Sgblack@eecs.umich.edu
2768799Sgblack@eecs.umich.edu    if (!FullSystem)
2778706Sandreas.hansson@arm.com        return;
2788706Sandreas.hansson@arm.com
2798706Sandreas.hansson@arm.com    for (i = 0; i < threadContexts.size(); i++)
2801129SN/A        TheISA::startupCPU(threadContexts[i], i);
2811129SN/A}
2821129SN/A
2835713Shsul@eecs.umich.eduvoid
284180SN/ASystem::replaceThreadContext(ThreadContext *tc, int context_id)
2855713Shsul@eecs.umich.edu{
2862680Sktlim@umich.edu    if (context_id >= threadContexts.size()) {
2875713Shsul@eecs.umich.edu        panic("replaceThreadContext: bad id, %d >= %d\n",
288180SN/A              context_id, threadContexts.size());
289180SN/A    }
2905713Shsul@eecs.umich.edu
2915713Shsul@eecs.umich.edu    threadContexts[context_id] = tc;
2925713Shsul@eecs.umich.edu    if (context_id < remoteGDB.size())
2932SN/A        remoteGDB[context_id]->replaceThreadContext(tc);
2942SN/A}
2952378SN/A
2968601Ssteve.reinhardt@amd.comAddr
2972378SN/ASystem::allocPhysPages(int npages)
2987770SAli.Saidi@ARM.com{
2998601Ssteve.reinhardt@amd.com    Addr return_addr = pagePtr << LogVMPageSize;
3009007Slena@cs.wisc.edu    pagePtr += npages;
3013162Ssaidi@eecs.umich.edu    if (pagePtr > physmem.totalSize())
3022378SN/A        fatal("Out of memory, please increase size of physical memory.");
3032378SN/A    return return_addr;
3045795Ssaidi@eecs.umich.edu}
3055795Ssaidi@eecs.umich.edu
3068931Sandreas.hansson@arm.comAddr
3075795Ssaidi@eecs.umich.eduSystem::memSize() const
3088931Sandreas.hansson@arm.com{
3095795Ssaidi@eecs.umich.edu    return physmem.totalSize();
3105795Ssaidi@eecs.umich.edu}
3115795Ssaidi@eecs.umich.edu
3128931Sandreas.hansson@arm.comAddr
3135795Ssaidi@eecs.umich.eduSystem::freeMemSize() const
3148931Sandreas.hansson@arm.com{
3155795Ssaidi@eecs.umich.edu   return physmem.totalSize() - (pagePtr << LogVMPageSize);
3165795Ssaidi@eecs.umich.edu}
3178460SAli.Saidi@ARM.com
3188931Sandreas.hansson@arm.combool
3198460SAli.Saidi@ARM.comSystem::isMemAddr(Addr addr) const
3208931Sandreas.hansson@arm.com{
3218460SAli.Saidi@ARM.com    return physmem.isMemAddr(addr);
3228460SAli.Saidi@ARM.com}
3231070SN/A
3247897Shestness@cs.utexas.eduvoid
3257897Shestness@cs.utexas.eduSystem::resume()
3267897Shestness@cs.utexas.edu{
3277897Shestness@cs.utexas.edu    SimObject::resume();
3287897Shestness@cs.utexas.edu    totalNumInsts = 0;
3297897Shestness@cs.utexas.edu}
3307897Shestness@cs.utexas.edu
3311070SN/Avoid
3321070SN/ASystem::serialize(ostream &os)
3338769Sgblack@eecs.umich.edu{
3348769Sgblack@eecs.umich.edu    if (FullSystem)
3357770SAli.Saidi@ARM.com        kernelSymtab->serialize("kernel_symtab", os);
3367770SAli.Saidi@ARM.com    SERIALIZE_SCALAR(pagePtr);
3371070SN/A    SERIALIZE_SCALAR(nextPID);
3381070SN/A}
3391070SN/A
3401070SN/A
3411070SN/Avoid
3421070SN/ASystem::unserialize(Checkpoint *cp, const string &section)
3438769Sgblack@eecs.umich.edu{
3448769Sgblack@eecs.umich.edu    if (FullSystem)
3457770SAli.Saidi@ARM.com        kernelSymtab->unserialize("kernel_symtab", cp, section);
3467770SAli.Saidi@ARM.com    UNSERIALIZE_SCALAR(pagePtr);
3471070SN/A    UNSERIALIZE_SCALAR(nextPID);
3482SN/A}
3492SN/A
3508666SPrakash.Ramrakhyani@arm.comvoid
3518666SPrakash.Ramrakhyani@arm.comSystem::regStats()
3528666SPrakash.Ramrakhyani@arm.com{
3538666SPrakash.Ramrakhyani@arm.com    for (uint32_t j = 0; j < numWorkIds ; j++) {
3548666SPrakash.Ramrakhyani@arm.com        workItemStats[j] = new Stats::Histogram();
3558666SPrakash.Ramrakhyani@arm.com        stringstream namestr;
3568666SPrakash.Ramrakhyani@arm.com        ccprintf(namestr, "work_item_type%d", j);
3578666SPrakash.Ramrakhyani@arm.com        workItemStats[j]->init(20)
3588666SPrakash.Ramrakhyani@arm.com                         .name(name() + "." + namestr.str())
3598666SPrakash.Ramrakhyani@arm.com                         .desc("Run time stat for" + namestr.str())
3608666SPrakash.Ramrakhyani@arm.com                         .prereq(*workItemStats[j]);
3618666SPrakash.Ramrakhyani@arm.com    }
3628666SPrakash.Ramrakhyani@arm.com}
3638666SPrakash.Ramrakhyani@arm.com
3648666SPrakash.Ramrakhyani@arm.comvoid
3658666SPrakash.Ramrakhyani@arm.comSystem::workItemEnd(uint32_t tid, uint32_t workid)
3668666SPrakash.Ramrakhyani@arm.com{
3678666SPrakash.Ramrakhyani@arm.com    std::pair<uint32_t,uint32_t> p(tid, workid);
3688666SPrakash.Ramrakhyani@arm.com    if (!lastWorkItemStarted.count(p))
3698666SPrakash.Ramrakhyani@arm.com        return;
3708666SPrakash.Ramrakhyani@arm.com
3718666SPrakash.Ramrakhyani@arm.com    Tick samp = curTick() - lastWorkItemStarted[p];
3728666SPrakash.Ramrakhyani@arm.com    DPRINTF(WorkItems, "Work item end: %d\t%d\t%lld\n", tid, workid, samp);
3738666SPrakash.Ramrakhyani@arm.com
3748666SPrakash.Ramrakhyani@arm.com    if (workid >= numWorkIds)
3758666SPrakash.Ramrakhyani@arm.com        fatal("Got workid greater than specified in system configuration\n");
3768666SPrakash.Ramrakhyani@arm.com
3778666SPrakash.Ramrakhyani@arm.com    workItemStats[workid]->sample(samp);
3788666SPrakash.Ramrakhyani@arm.com    lastWorkItemStarted.erase(p);
3798666SPrakash.Ramrakhyani@arm.com}
3808666SPrakash.Ramrakhyani@arm.com
3812SN/Avoid
3822SN/ASystem::printSystems()
3832SN/A{
3842SN/A    vector<System *>::iterator i = systemList.begin();
3852SN/A    vector<System *>::iterator end = systemList.end();
3862SN/A    for (; i != end; ++i) {
3872SN/A        System *sys = *i;
3882SN/A        cerr << "System " << sys->name() << ": " << hex << sys << endl;
3892SN/A    }
3902SN/A}
3912SN/A
3922SN/Avoid
3932SN/AprintSystems()
3942SN/A{
3952SN/A    System::printSystems();
3962SN/A}
3978832SAli.Saidi@ARM.com
3988832SAli.Saidi@ARM.comMasterID
3998832SAli.Saidi@ARM.comSystem::getMasterId(std::string master_name)
4008832SAli.Saidi@ARM.com{
4019142Ssteve.reinhardt@amd.com    // strip off system name if the string starts with it
4028832SAli.Saidi@ARM.com    if (master_name.size() > name().size() &&
4038832SAli.Saidi@ARM.com                          master_name.compare(0, name().size(), name()) == 0)
4048832SAli.Saidi@ARM.com        master_name = master_name.erase(0, name().size() + 1);
4058832SAli.Saidi@ARM.com
4068832SAli.Saidi@ARM.com    // CPUs in switch_cpus ask for ids again after switching
4078832SAli.Saidi@ARM.com    for (int i = 0; i < masterIds.size(); i++) {
4088832SAli.Saidi@ARM.com        if (masterIds[i] == master_name) {
4098832SAli.Saidi@ARM.com            return i;
4108832SAli.Saidi@ARM.com        }
4118986SAli.Saidi@ARM.com    }
4128986SAli.Saidi@ARM.com
4138986SAli.Saidi@ARM.com    // Verify that the statistics haven't been enabled yet
4148832SAli.Saidi@ARM.com    // Otherwise objects will have sized their stat buckets and
4158986SAli.Saidi@ARM.com    // they will be too small
4168832SAli.Saidi@ARM.com
4178832SAli.Saidi@ARM.com    if (Stats::enabled())
4188832SAli.Saidi@ARM.com        fatal("Can't request a masterId after regStats(). \
4198832SAli.Saidi@ARM.com                You must do so in init().\n");
4208832SAli.Saidi@ARM.com
4218832SAli.Saidi@ARM.com    masterIds.push_back(master_name);
4228832SAli.Saidi@ARM.com
4238832SAli.Saidi@ARM.com    return masterIds.size() - 1;
4248832SAli.Saidi@ARM.com}
4258832SAli.Saidi@ARM.com
4268832SAli.Saidi@ARM.comstd::string
4278832SAli.Saidi@ARM.comSystem::getMasterName(MasterID master_id)
4288832SAli.Saidi@ARM.com{
4298832SAli.Saidi@ARM.com    if (master_id >= masterIds.size())
4308832SAli.Saidi@ARM.com        fatal("Invalid master_id passed to getMasterName()\n");
4318832SAli.Saidi@ARM.com
4328832SAli.Saidi@ARM.com    return masterIds[master_id];
4332902Ssaidi@eecs.umich.edu}
4342902Ssaidi@eecs.umich.edu
4352902Ssaidi@eecs.umich.educonst char *System::MemoryModeStrings[3] = {"invalid", "atomic",
4364762Snate@binkert.org    "timing"};
4374762Snate@binkert.org
4382424SN/ASystem *
4395530Snate@binkert.orgSystemParams::create()
4402424SN/A{
441    return new System(this);
442}
443