system.cc revision 10700
12689Sktlim@umich.edu/*
28703Sandreas.hansson@arm.com * Copyright (c) 2011-2014 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/remote_gdb.hh"
493960Sgblack@eecs.umich.edu#include "arch/utility.hh"
504194Ssaidi@eecs.umich.edu#include "base/loader/object_file.hh"
518769Sgblack@eecs.umich.edu#include "base/loader/symtab.hh"
521070SN/A#include "base/str.hh"
531070SN/A#include "base/trace.hh"
549142Ssteve.reinhardt@amd.com#include "cpu/thread_context.hh"
552521SN/A#include "debug/Loader.hh"
566658Snate@binkert.org#include "debug/WorkItems.hh"
578229Snate@binkert.org#include "mem/abstract_mem.hh"
588232Snate@binkert.org#include "mem/physical.hh"
598666SPrakash.Ramrakhyani@arm.com#include "params/System.hh"
608769Sgblack@eecs.umich.edu#include "sim/byteswap.hh"
619293Sandreas.hansson@arm.com#include "sim/debug.hh"
622522SN/A#include "sim/full_system.hh"
638769Sgblack@eecs.umich.edu#include "sim/system.hh"
642037SN/A
658229Snate@binkert.org/**
668769Sgblack@eecs.umich.edu * To avoid linking errors with LTO, only include the header if we
6756SN/A * actually have a definition.
686658Snate@binkert.org */
692SN/A#if THE_ISA != NULL_ISA
702107SN/A#include "kern/kernel_stats.hh"
712SN/A#endif
722SN/A
732SN/Ausing namespace std;
742SN/Ausing namespace TheISA;
752SN/A
761070SN/Avector<System *> System::systemList;
778703Sandreas.hansson@arm.com
788703Sandreas.hansson@arm.comint System::numSystemsRunning = 0;
798826Snilay@cs.wisc.edu
802521SN/ASystem::System(Params *p)
818852Sandreas.hansson@arm.com    : MemObject(p), _systemPort("system_port", this),
828852Sandreas.hansson@arm.com      _numContexts(0),
837580SAli.Saidi@arm.com      pagePtr(0),
847770SAli.Saidi@ARM.com      init_param(p->init_param),
859293Sandreas.hansson@arm.com      physProxy(_systemPort, p->cache_line_size),
867914SBrad.Beckmann@amd.com      kernelSymtab(nullptr),
877914SBrad.Beckmann@amd.com      kernel(nullptr),
887914SBrad.Beckmann@amd.com      loadAddrMask(p->load_addr_mask),
898666SPrakash.Ramrakhyani@arm.com      loadAddrOffset(p->load_offset),
907914SBrad.Beckmann@amd.com      nextPID(0),
918666SPrakash.Ramrakhyani@arm.com      physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
927897Shestness@cs.utexas.edu      memoryMode(p->mem_mode),
932SN/A      _cacheLineSize(p->cache_line_size),
941070SN/A      workItemsBegin(0),
951070SN/A      workItemsEnd(0),
961070SN/A      numWorkIds(p->num_work_ids),
978769Sgblack@eecs.umich.edu      _params(p),
988769Sgblack@eecs.umich.edu      totalNumInsts(0),
998769Sgblack@eecs.umich.edu      instEventQueue("system instruction-based event queue")
1008769Sgblack@eecs.umich.edu{
1018666SPrakash.Ramrakhyani@arm.com    // add self to global system list
1028832SAli.Saidi@ARM.com    systemList.push_back(this);
1038832SAli.Saidi@ARM.com
1048832SAli.Saidi@ARM.com    if (FullSystem) {
1058832SAli.Saidi@ARM.com        kernelSymtab = new SymbolTable;
1068832SAli.Saidi@ARM.com        if (!debugSymbolTable)
1078832SAli.Saidi@ARM.com            debugSymbolTable = new SymbolTable;
1088832SAli.Saidi@ARM.com    }
1098832SAli.Saidi@ARM.com
1108832SAli.Saidi@ARM.com    // check if the cache line size is a value known to work
1118832SAli.Saidi@ARM.com    if (!(_cacheLineSize == 16 || _cacheLineSize == 32 ||
1128885SAli.Saidi@ARM.com          _cacheLineSize == 64 || _cacheLineSize == 128))
1138885SAli.Saidi@ARM.com        warn_once("Cache line size is neither 16, 32, 64 nor 128 bytes.\n");
1148885SAli.Saidi@ARM.com
1159147Snilay@cs.wisc.edu    // Get the generic system master IDs
1169147Snilay@cs.wisc.edu    MasterID tmp_id M5_VAR_USED;
1179147Snilay@cs.wisc.edu    tmp_id = getMasterId("writebacks");
1188885SAli.Saidi@ARM.com    assert(tmp_id == Request::wbMasterId);
1198885SAli.Saidi@ARM.com    tmp_id = getMasterId("functional");
1208885SAli.Saidi@ARM.com    assert(tmp_id == Request::funcMasterId);
1218885SAli.Saidi@ARM.com    tmp_id = getMasterId("interrupt");
1228885SAli.Saidi@ARM.com    assert(tmp_id == Request::intMasterId);
1238885SAli.Saidi@ARM.com
1248885SAli.Saidi@ARM.com    if (FullSystem) {
1258885SAli.Saidi@ARM.com        if (params()->kernel == "") {
1268885SAli.Saidi@ARM.com            inform("No kernel set for full system simulation. "
1278885SAli.Saidi@ARM.com                   "Assuming you know what you're doing\n");
1288885SAli.Saidi@ARM.com        } else {
1298885SAli.Saidi@ARM.com            // Get the kernel code
1308885SAli.Saidi@ARM.com            kernel = createObjectFile(params()->kernel);
1318885SAli.Saidi@ARM.com            inform("kernel located at: %s", params()->kernel);
1328885SAli.Saidi@ARM.com
1338885SAli.Saidi@ARM.com            if (kernel == NULL)
1348885SAli.Saidi@ARM.com                fatal("Could not load kernel file %s", params()->kernel);
1358885SAli.Saidi@ARM.com
1368885SAli.Saidi@ARM.com            // setup entry points
1378885SAli.Saidi@ARM.com            kernelStart = kernel->textBase();
1388885SAli.Saidi@ARM.com            kernelEnd = kernel->bssBase() + kernel->bssSize();
1398885SAli.Saidi@ARM.com            kernelEntry = kernel->entryPoint();
1408885SAli.Saidi@ARM.com
1418885SAli.Saidi@ARM.com            // load symbols
1428885SAli.Saidi@ARM.com            if (!kernel->loadGlobalSymbols(kernelSymtab))
1438885SAli.Saidi@ARM.com                fatal("could not load kernel symbols\n");
1448885SAli.Saidi@ARM.com
1458885SAli.Saidi@ARM.com            if (!kernel->loadLocalSymbols(kernelSymtab))
1468885SAli.Saidi@ARM.com                fatal("could not load kernel local symbols\n");
1478885SAli.Saidi@ARM.com
1488885SAli.Saidi@ARM.com            if (!kernel->loadGlobalSymbols(debugSymbolTable))
1498885SAli.Saidi@ARM.com                fatal("could not load kernel symbols\n");
1508885SAli.Saidi@ARM.com
1518885SAli.Saidi@ARM.com            if (!kernel->loadLocalSymbols(debugSymbolTable))
1529053Sdam.sunwoo@arm.com                fatal("could not load kernel local symbols\n");
1539053Sdam.sunwoo@arm.com
1549053Sdam.sunwoo@arm.com            // Loading only needs to happen once and after memory system is
1552SN/A            // connected so it will happen in initState()
1562SN/A        }
1572SN/A    }
1582SN/A
1591070SN/A    // increment the number of running systms
1601070SN/A    numSystemsRunning++;
1618666SPrakash.Ramrakhyani@arm.com
1628666SPrakash.Ramrakhyani@arm.com    // Set back pointers to the system in all memories
1638666SPrakash.Ramrakhyani@arm.com    for (int x = 0; x < params()->memories.size(); x++)
1642SN/A        params()->memories[x]->system(this);
1652SN/A}
1668706Sandreas.hansson@arm.com
1678706Sandreas.hansson@arm.comSystem::~System()
1688706Sandreas.hansson@arm.com{
1698706Sandreas.hansson@arm.com    delete kernelSymtab;
1708706Sandreas.hansson@arm.com    delete kernel;
1718706Sandreas.hansson@arm.com
1728706Sandreas.hansson@arm.com    for (uint32_t j = 0; j < numWorkIds; j++)
1738706Sandreas.hansson@arm.com        delete workItemStats[j];
1748922Swilliam.wang@arm.com}
1758922Swilliam.wang@arm.com
1768703Sandreas.hansson@arm.comvoid
1778703Sandreas.hansson@arm.comSystem::init()
1788922Swilliam.wang@arm.com{
1798703Sandreas.hansson@arm.com    // check that the system port is connected
1808703Sandreas.hansson@arm.com    if (!_systemPort.isConnected())
1812901Ssaidi@eecs.umich.edu        panic("System port on %s is not connected.\n", name());
1824762Snate@binkert.org}
1832901Ssaidi@eecs.umich.edu
1842901Ssaidi@eecs.umich.eduBaseMasterPort&
1852901Ssaidi@eecs.umich.eduSystem::getMasterPort(const std::string &if_name, PortID idx)
1862901Ssaidi@eecs.umich.edu{
1872901Ssaidi@eecs.umich.edu    // no need to distinguish at the moment (besides checking)
1883960Sgblack@eecs.umich.edu    return _systemPort;
1893960Sgblack@eecs.umich.edu}
1904095Sbinkertn@umich.edu
1914095Sbinkertn@umich.eduvoid
1924095Sbinkertn@umich.eduSystem::setMemoryMode(Enums::MemoryMode mode)
1933960Sgblack@eecs.umich.edu{
1943960Sgblack@eecs.umich.edu    assert(getDrainState() == Drainable::Drained);
1957445Ssteve.reinhardt@amd.com    memoryMode = mode;
1967445Ssteve.reinhardt@amd.com}
1977445Ssteve.reinhardt@amd.com
1987445Ssteve.reinhardt@amd.combool System::breakpoint()
1997445Ssteve.reinhardt@amd.com{
2007445Ssteve.reinhardt@amd.com    if (remoteGDB.size())
2017445Ssteve.reinhardt@amd.com        return remoteGDB[0]->breakpoint();
202180SN/A    return false;
2035718Shsul@eecs.umich.edu}
2042SN/A
2055712Shsul@eecs.umich.edu/**
2065718Shsul@eecs.umich.edu * Setting rgdb_wait to a positive integer waits for a remote debugger to
2075718Shsul@eecs.umich.edu * connect to that context ID before continuing.  This should really
2085718Shsul@eecs.umich.edu   be a parameter on the CPU object or something...
2095718Shsul@eecs.umich.edu */
2105718Shsul@eecs.umich.eduint rgdb_wait = -1;
2115718Shsul@eecs.umich.edu
2125718Shsul@eecs.umich.eduint
2135718Shsul@eecs.umich.eduSystem::registerThreadContext(ThreadContext *tc, int assigned)
2145718Shsul@eecs.umich.edu{
2155718Shsul@eecs.umich.edu    int id;
2165718Shsul@eecs.umich.edu    if (assigned == -1) {
2175718Shsul@eecs.umich.edu        for (id = 0; id < threadContexts.size(); id++) {
2181806SN/A            if (!threadContexts[id])
2191806SN/A                break;
2202680Sktlim@umich.edu        }
2215823Ssaidi@eecs.umich.edu
2221806SN/A        if (threadContexts.size() <= id)
2232680Sktlim@umich.edu            threadContexts.resize(id + 1);
2245714Shsul@eecs.umich.edu    } else {
2251070SN/A        if (threadContexts.size() <= assigned)
2265512SMichael.Adler@intel.com            threadContexts.resize(assigned + 1);
2277445Ssteve.reinhardt@amd.com        id = assigned;
2284095Sbinkertn@umich.edu    }
2295512SMichael.Adler@intel.com
2304095Sbinkertn@umich.edu    if (threadContexts[id])
2317445Ssteve.reinhardt@amd.com        fatal("Cannot have two CPUs with the same id (%d)\n", id);
2324095Sbinkertn@umich.edu
2334095Sbinkertn@umich.edu    threadContexts[id] = tc;
2341070SN/A    _numContexts++;
2354095Sbinkertn@umich.edu
2364095Sbinkertn@umich.edu#if THE_ISA != NULL_ISA
2374095Sbinkertn@umich.edu    int port = getRemoteGDBPort();
2384095Sbinkertn@umich.edu    if (port) {
2394095Sbinkertn@umich.edu        RemoteGDB *rgdb = new RemoteGDB(this, tc);
2401070SN/A        GDBListener *gdbl = new GDBListener(rgdb, port + id);
2411070SN/A        gdbl->listen();
2427914SBrad.Beckmann@amd.com
2437914SBrad.Beckmann@amd.com        if (rgdb_wait != -1 && rgdb_wait == id)
2441806SN/A            gdbl->accept();
245180SN/A
24675SN/A        if (remoteGDB.size() <= id) {
2476029Ssteve.reinhardt@amd.com            remoteGDB.resize(id + 1);
2486029Ssteve.reinhardt@amd.com        }
2496029Ssteve.reinhardt@amd.com
2506029Ssteve.reinhardt@amd.com        remoteGDB[id] = rgdb;
2516029Ssteve.reinhardt@amd.com    }
2526029Ssteve.reinhardt@amd.com#endif
2536029Ssteve.reinhardt@amd.com
2546029Ssteve.reinhardt@amd.com    activeCpus.push_back(false);
2556029Ssteve.reinhardt@amd.com
2566029Ssteve.reinhardt@amd.com    return id;
2576029Ssteve.reinhardt@amd.com}
258180SN/A
2597733SAli.Saidi@ARM.comint
2601129SN/ASystem::numRunningContexts()
2618769Sgblack@eecs.umich.edu{
2629172Snilay@cs.wisc.edu    int running = 0;
2638769Sgblack@eecs.umich.edu    for (int i = 0; i < _numContexts; ++i) {
2648799Sgblack@eecs.umich.edu        if (threadContexts[i]->status() != ThreadContext::Halted)
2658799Sgblack@eecs.umich.edu            ++running;
2668799Sgblack@eecs.umich.edu    }
2678799Sgblack@eecs.umich.edu    return running;
2688799Sgblack@eecs.umich.edu}
2698885SAli.Saidi@ARM.com
2709187SKrishnendra.Nathella@arm.comvoid
2719187SKrishnendra.Nathella@arm.comSystem::initState()
2729187SKrishnendra.Nathella@arm.com{
2739187SKrishnendra.Nathella@arm.com    if (FullSystem) {
2749187SKrishnendra.Nathella@arm.com        for (int i = 0; i < threadContexts.size(); i++)
2759187SKrishnendra.Nathella@arm.com            TheISA::startupCPU(threadContexts[i], i);
2769187SKrishnendra.Nathella@arm.com        // Moved from the constructor to here since it relies on the
2778799Sgblack@eecs.umich.edu        // address map being resolved in the interconnect
2788799Sgblack@eecs.umich.edu        /**
2798706Sandreas.hansson@arm.com         * Load the kernel code into memory
2808799Sgblack@eecs.umich.edu         */
2818799Sgblack@eecs.umich.edu        if (params()->kernel != "")  {
2828799Sgblack@eecs.umich.edu            if (params()->kernel_addr_check) {
2838799Sgblack@eecs.umich.edu                // Validate kernel mapping before loading binary
2848799Sgblack@eecs.umich.edu                if (!(isMemAddr((kernelStart & loadAddrMask) +
2858706Sandreas.hansson@arm.com                                loadAddrOffset) &&
2868706Sandreas.hansson@arm.com                      isMemAddr((kernelEnd & loadAddrMask) +
2878706Sandreas.hansson@arm.com                                loadAddrOffset))) {
2881129SN/A                    fatal("Kernel is mapped to invalid location (not memory). "
2891129SN/A                          "kernelStart 0x(%x) - kernelEnd 0x(%x) %#x:%#x\n",
2901129SN/A                          kernelStart,
2915713Shsul@eecs.umich.edu                          kernelEnd, (kernelStart & loadAddrMask) +
292180SN/A                          loadAddrOffset,
2935713Shsul@eecs.umich.edu                          (kernelEnd & loadAddrMask) + loadAddrOffset);
2942680Sktlim@umich.edu                }
2955713Shsul@eecs.umich.edu            }
296180SN/A            // Load program sections into memory
297180SN/A            kernel->loadSections(physProxy, loadAddrMask, loadAddrOffset);
2985713Shsul@eecs.umich.edu
2995713Shsul@eecs.umich.edu            DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
3005713Shsul@eecs.umich.edu            DPRINTF(Loader, "Kernel end   = %#x\n", kernelEnd);
3012SN/A            DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
3022SN/A            DPRINTF(Loader, "Kernel loaded...\n");
3032378SN/A        }
3048601Ssteve.reinhardt@amd.com    }
3052378SN/A
3067770SAli.Saidi@ARM.com    activeCpus.clear();
3078601Ssteve.reinhardt@amd.com}
3089007Slena@cs.wisc.edu
3093162Ssaidi@eecs.umich.eduvoid
3102378SN/ASystem::replaceThreadContext(ThreadContext *tc, int context_id)
3112378SN/A{
3125795Ssaidi@eecs.umich.edu    if (context_id >= threadContexts.size()) {
3135795Ssaidi@eecs.umich.edu        panic("replaceThreadContext: bad id, %d >= %d\n",
3148931Sandreas.hansson@arm.com              context_id, threadContexts.size());
3155795Ssaidi@eecs.umich.edu    }
3168931Sandreas.hansson@arm.com
3175795Ssaidi@eecs.umich.edu    threadContexts[context_id] = tc;
3185795Ssaidi@eecs.umich.edu    if (context_id < remoteGDB.size())
3195795Ssaidi@eecs.umich.edu        remoteGDB[context_id]->replaceThreadContext(tc);
3208931Sandreas.hansson@arm.com}
3215795Ssaidi@eecs.umich.edu
3228931Sandreas.hansson@arm.comAddr
3235795Ssaidi@eecs.umich.eduSystem::allocPhysPages(int npages)
3245795Ssaidi@eecs.umich.edu{
3258460SAli.Saidi@ARM.com    Addr return_addr = pagePtr << PageShift;
3268931Sandreas.hansson@arm.com    pagePtr += npages;
3278460SAli.Saidi@ARM.com
3288931Sandreas.hansson@arm.com    Addr next_return_addr = pagePtr << PageShift;
3298460SAli.Saidi@ARM.com
3308460SAli.Saidi@ARM.com    AddrRange m5opRange(0xffff0000, 0xffffffff);
3311070SN/A    if (m5opRange.contains(next_return_addr)) {
3327897Shestness@cs.utexas.edu        warn("Reached m5ops MMIO region\n");
3337897Shestness@cs.utexas.edu        return_addr = 0xffffffff;
3347897Shestness@cs.utexas.edu        pagePtr = 0xffffffff >> PageShift;
3357897Shestness@cs.utexas.edu    }
3367897Shestness@cs.utexas.edu
3377897Shestness@cs.utexas.edu    if ((pagePtr << PageShift) > physmem.totalSize())
3387897Shestness@cs.utexas.edu        fatal("Out of memory, please increase size of physical memory.");
3391070SN/A    return return_addr;
3401070SN/A}
3418769Sgblack@eecs.umich.edu
3428769Sgblack@eecs.umich.eduAddr
3437770SAli.Saidi@ARM.comSystem::memSize() const
3447770SAli.Saidi@ARM.com{
3459292Sandreas.hansson@arm.com    return physmem.totalSize();
3469293Sandreas.hansson@arm.com}
3479293Sandreas.hansson@arm.com
3489293Sandreas.hansson@arm.comAddr
3499293Sandreas.hansson@arm.comSystem::freeMemSize() const
3501070SN/A{
3511070SN/A   return physmem.totalSize() - (pagePtr << PageShift);
3521070SN/A}
3531070SN/A
3541070SN/Abool
3551070SN/ASystem::isMemAddr(Addr addr) const
3568769Sgblack@eecs.umich.edu{
3578769Sgblack@eecs.umich.edu    return physmem.isMemAddr(addr);
3587770SAli.Saidi@ARM.com}
3597770SAli.Saidi@ARM.com
3609292Sandreas.hansson@arm.comunsigned int
3619293Sandreas.hansson@arm.comSystem::drain(DrainManager *dm)
3629293Sandreas.hansson@arm.com{
3639293Sandreas.hansson@arm.com    setDrainState(Drainable::Drained);
3641070SN/A    return 0;
3652SN/A}
3662SN/A
3678666SPrakash.Ramrakhyani@arm.comvoid
3688666SPrakash.Ramrakhyani@arm.comSystem::drainResume()
3698666SPrakash.Ramrakhyani@arm.com{
3708666SPrakash.Ramrakhyani@arm.com    Drainable::drainResume();
3718666SPrakash.Ramrakhyani@arm.com    totalNumInsts = 0;
3728666SPrakash.Ramrakhyani@arm.com}
3738666SPrakash.Ramrakhyani@arm.com
3748666SPrakash.Ramrakhyani@arm.comvoid
3758666SPrakash.Ramrakhyani@arm.comSystem::serialize(ostream &os)
3768666SPrakash.Ramrakhyani@arm.com{
3778666SPrakash.Ramrakhyani@arm.com    if (FullSystem)
3788666SPrakash.Ramrakhyani@arm.com        kernelSymtab->serialize("kernel_symtab", os);
3798666SPrakash.Ramrakhyani@arm.com    SERIALIZE_SCALAR(pagePtr);
3808666SPrakash.Ramrakhyani@arm.com    SERIALIZE_SCALAR(nextPID);
3818666SPrakash.Ramrakhyani@arm.com    serializeSymtab(os);
3828666SPrakash.Ramrakhyani@arm.com
3838666SPrakash.Ramrakhyani@arm.com    // also serialize the memories in the system
3848666SPrakash.Ramrakhyani@arm.com    nameOut(os, csprintf("%s.physmem", name()));
3858666SPrakash.Ramrakhyani@arm.com    physmem.serialize(os);
3868666SPrakash.Ramrakhyani@arm.com}
3878666SPrakash.Ramrakhyani@arm.com
3888666SPrakash.Ramrakhyani@arm.com
3898666SPrakash.Ramrakhyani@arm.comvoid
3908666SPrakash.Ramrakhyani@arm.comSystem::unserialize(Checkpoint *cp, const string &section)
3918666SPrakash.Ramrakhyani@arm.com{
3928666SPrakash.Ramrakhyani@arm.com    if (FullSystem)
3938666SPrakash.Ramrakhyani@arm.com        kernelSymtab->unserialize("kernel_symtab", cp, section);
3948666SPrakash.Ramrakhyani@arm.com    UNSERIALIZE_SCALAR(pagePtr);
3958666SPrakash.Ramrakhyani@arm.com    UNSERIALIZE_SCALAR(nextPID);
3968666SPrakash.Ramrakhyani@arm.com    unserializeSymtab(cp, section);
3978666SPrakash.Ramrakhyani@arm.com
3982SN/A    // also unserialize the memories in the system
3992SN/A    physmem.unserialize(cp, csprintf("%s.physmem", name()));
4002SN/A}
4012SN/A
4022SN/Avoid
4032SN/ASystem::regStats()
4042SN/A{
4052SN/A    for (uint32_t j = 0; j < numWorkIds ; j++) {
4062SN/A        workItemStats[j] = new Stats::Histogram();
4072SN/A        stringstream namestr;
4082SN/A        ccprintf(namestr, "work_item_type%d", j);
4092SN/A        workItemStats[j]->init(20)
4102SN/A                         .name(name() + "." + namestr.str())
4112SN/A                         .desc("Run time stat for" + namestr.str())
4122SN/A                         .prereq(*workItemStats[j]);
4132SN/A    }
4148832SAli.Saidi@ARM.com}
4158832SAli.Saidi@ARM.com
4168832SAli.Saidi@ARM.comvoid
4178832SAli.Saidi@ARM.comSystem::workItemEnd(uint32_t tid, uint32_t workid)
4189142Ssteve.reinhardt@amd.com{
4198832SAli.Saidi@ARM.com    std::pair<uint32_t,uint32_t> p(tid, workid);
4208832SAli.Saidi@ARM.com    if (!lastWorkItemStarted.count(p))
4218832SAli.Saidi@ARM.com        return;
4228832SAli.Saidi@ARM.com
4238832SAli.Saidi@ARM.com    Tick samp = curTick() - lastWorkItemStarted[p];
4248832SAli.Saidi@ARM.com    DPRINTF(WorkItems, "Work item end: %d\t%d\t%lld\n", tid, workid, samp);
4258832SAli.Saidi@ARM.com
4268832SAli.Saidi@ARM.com    if (workid >= numWorkIds)
4278832SAli.Saidi@ARM.com        fatal("Got workid greater than specified in system configuration\n");
4288986SAli.Saidi@ARM.com
4298986SAli.Saidi@ARM.com    workItemStats[workid]->sample(samp);
4308986SAli.Saidi@ARM.com    lastWorkItemStarted.erase(p);
4318832SAli.Saidi@ARM.com}
4328986SAli.Saidi@ARM.com
4338832SAli.Saidi@ARM.comvoid
4348832SAli.Saidi@ARM.comSystem::printSystems()
4358832SAli.Saidi@ARM.com{
4368832SAli.Saidi@ARM.com    ios::fmtflags flags(cerr.flags());
4378832SAli.Saidi@ARM.com
4388832SAli.Saidi@ARM.com    vector<System *>::iterator i = systemList.begin();
4398832SAli.Saidi@ARM.com    vector<System *>::iterator end = systemList.end();
4408832SAli.Saidi@ARM.com    for (; i != end; ++i) {
4418832SAli.Saidi@ARM.com        System *sys = *i;
4428832SAli.Saidi@ARM.com        cerr << "System " << sys->name() << ": " << hex << sys << endl;
4438832SAli.Saidi@ARM.com    }
4448832SAli.Saidi@ARM.com
4458832SAli.Saidi@ARM.com    cerr.flags(flags);
4468832SAli.Saidi@ARM.com}
4478832SAli.Saidi@ARM.com
4488832SAli.Saidi@ARM.comvoid
4498832SAli.Saidi@ARM.comprintSystems()
4502902Ssaidi@eecs.umich.edu{
4512902Ssaidi@eecs.umich.edu    System::printSystems();
4522902Ssaidi@eecs.umich.edu}
4534762Snate@binkert.org
4544762Snate@binkert.orgMasterID
4552424SN/ASystem::getMasterId(std::string master_name)
4565530Snate@binkert.org{
4572424SN/A    // strip off system name if the string starts with it
458    if (startswith(master_name, name()))
459        master_name = master_name.erase(0, name().size() + 1);
460
461    // CPUs in switch_cpus ask for ids again after switching
462    for (int i = 0; i < masterIds.size(); i++) {
463        if (masterIds[i] == master_name) {
464            return i;
465        }
466    }
467
468    // Verify that the statistics haven't been enabled yet
469    // Otherwise objects will have sized their stat buckets and
470    // they will be too small
471
472    if (Stats::enabled()) {
473        fatal("Can't request a masterId after regStats(). "
474                "You must do so in init().\n");
475    }
476
477    masterIds.push_back(master_name);
478
479    return masterIds.size() - 1;
480}
481
482std::string
483System::getMasterName(MasterID master_id)
484{
485    if (master_id >= masterIds.size())
486        fatal("Invalid master_id passed to getMasterName()\n");
487
488    return masterIds[master_id];
489}
490
491System *
492SystemParams::create()
493{
494    return new System(this);
495}
496