12689Sktlim@umich.edu/* 22689Sktlim@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 32689Sktlim@umich.edu * All rights reserved. 42689Sktlim@umich.edu * 52689Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without 62689Sktlim@umich.edu * modification, are permitted provided that the following conditions are 72689Sktlim@umich.edu * met: redistributions of source code must retain the above copyright 82689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer; 92689Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright 102689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the 112689Sktlim@umich.edu * documentation and/or other materials provided with the distribution; 122689Sktlim@umich.edu * neither the name of the copyright holders nor the names of its 132689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from 142689Sktlim@umich.edu * this software without specific prior written permission. 152689Sktlim@umich.edu * 162689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Kevin Lim 292689Sktlim@umich.edu */ 302689Sktlim@umich.edu 3111793Sbrandon.potter@amd.com#include "cpu/thread_state.hh" 3211793Sbrandon.potter@amd.com 332683Sktlim@umich.edu#include "base/output.hh" 343402Sktlim@umich.edu#include "cpu/base.hh" 352683Sktlim@umich.edu#include "cpu/profile.hh" 368793Sgblack@eecs.umich.edu#include "cpu/quiesce_event.hh" 3713905Sgabeblack@google.com#include "kern/kernel_stats.hh" 388799Sgblack@eecs.umich.edu#include "mem/fs_translating_port_proxy.hh" 397679Sgblack@eecs.umich.edu#include "mem/port.hh" 408706Sandreas.hansson@arm.com#include "mem/port_proxy.hh" 418706Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh" 428793Sgblack@eecs.umich.edu#include "sim/full_system.hh" 432862Sktlim@umich.edu#include "sim/serialize.hh" 448706Sandreas.hansson@arm.com#include "sim/system.hh" 452862Sktlim@umich.edu 466331Sgblack@eecs.umich.eduThreadState::ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process) 4710537Sandreas.hansson@arm.com : numInst(0), numOp(0), numLoad(0), startNumLoad(0), 4810537Sandreas.hansson@arm.com _status(ThreadContext::Halted), baseCpu(cpu), 4910537Sandreas.hansson@arm.com _contextId(0), _threadId(_tid), lastActivate(0), lastSuspend(0), 502683Sktlim@umich.edu profile(NULL), profileNode(NULL), profilePC(0), quiesceEvent(NULL), 518799Sgblack@eecs.umich.edu kernelStats(NULL), process(_process), physProxy(NULL), virtProxy(NULL), 5214023Sgabeblack@google.com funcExeInst(0), storeCondFailures(0) 532683Sktlim@umich.edu{ 542683Sktlim@umich.edu} 552683Sktlim@umich.edu 563486Sktlim@umich.eduThreadState::~ThreadState() 573486Sktlim@umich.edu{ 588799Sgblack@eecs.umich.edu if (physProxy != NULL) 598706Sandreas.hansson@arm.com delete physProxy; 608799Sgblack@eecs.umich.edu if (virtProxy != NULL) 618706Sandreas.hansson@arm.com delete virtProxy; 623486Sktlim@umich.edu} 633486Sktlim@umich.edu 642862Sktlim@umich.eduvoid 6510905Sandreas.sandberg@arm.comThreadState::serialize(CheckpointOut &cp) const 662862Sktlim@umich.edu{ 672862Sktlim@umich.edu SERIALIZE_ENUM(_status); 682862Sktlim@umich.edu // thread_num and cpu_id are deterministic from the config 692862Sktlim@umich.edu SERIALIZE_SCALAR(funcExeInst); 702862Sktlim@umich.edu 718806Sgblack@eecs.umich.edu if (!FullSystem) 728806Sgblack@eecs.umich.edu return; 738806Sgblack@eecs.umich.edu 748806Sgblack@eecs.umich.edu Tick quiesceEndTick = 0; 758806Sgblack@eecs.umich.edu if (quiesceEvent->scheduled()) 768806Sgblack@eecs.umich.edu quiesceEndTick = quiesceEvent->when(); 778806Sgblack@eecs.umich.edu SERIALIZE_SCALAR(quiesceEndTick); 788806Sgblack@eecs.umich.edu if (kernelStats) 7910905Sandreas.sandberg@arm.com kernelStats->serialize(cp); 802862Sktlim@umich.edu} 812862Sktlim@umich.edu 822862Sktlim@umich.eduvoid 8310905Sandreas.sandberg@arm.comThreadState::unserialize(CheckpointIn &cp) 842862Sktlim@umich.edu{ 852862Sktlim@umich.edu 862862Sktlim@umich.edu UNSERIALIZE_ENUM(_status); 872862Sktlim@umich.edu // thread_num and cpu_id are deterministic from the config 882862Sktlim@umich.edu UNSERIALIZE_SCALAR(funcExeInst); 892862Sktlim@umich.edu 908806Sgblack@eecs.umich.edu if (!FullSystem) 918806Sgblack@eecs.umich.edu return; 928806Sgblack@eecs.umich.edu 938806Sgblack@eecs.umich.edu Tick quiesceEndTick; 948806Sgblack@eecs.umich.edu UNSERIALIZE_SCALAR(quiesceEndTick); 958806Sgblack@eecs.umich.edu if (quiesceEndTick) 968806Sgblack@eecs.umich.edu baseCpu->schedule(quiesceEvent, quiesceEndTick); 978806Sgblack@eecs.umich.edu if (kernelStats) 9810905Sandreas.sandberg@arm.com kernelStats->unserialize(cp); 992862Sktlim@umich.edu} 1002862Sktlim@umich.edu 1013675Sktlim@umich.eduvoid 1028706Sandreas.hansson@arm.comThreadState::initMemProxies(ThreadContext *tc) 1033675Sktlim@umich.edu{ 1048921Sandreas.hansson@arm.com // The port proxies only refer to the data port on the CPU side 1058921Sandreas.hansson@arm.com // and can safely be done at init() time even if the CPU is not 1068921Sandreas.hansson@arm.com // connected, i.e. when restoring from a checkpoint and later 1078921Sandreas.hansson@arm.com // switching the CPU in. 1088921Sandreas.hansson@arm.com if (FullSystem) { 1098921Sandreas.hansson@arm.com assert(physProxy == NULL); 1108921Sandreas.hansson@arm.com // This cannot be done in the constructor as the thread state 1118852Sandreas.hansson@arm.com // itself is created in the base cpu constructor and the 11214197Sgabeblack@google.com // getSendFunctional is a virtual function 11314197Sgabeblack@google.com physProxy = new PortProxy(baseCpu->getSendFunctional(), 1149814Sandreas.hansson@arm.com baseCpu->cacheLineSize()); 1158921Sandreas.hansson@arm.com 1168921Sandreas.hansson@arm.com assert(virtProxy == NULL); 1178706Sandreas.hansson@arm.com virtProxy = new FSTranslatingPortProxy(tc); 1188921Sandreas.hansson@arm.com } else { 11914023Sgabeblack@google.com assert(virtProxy == NULL); 12014197Sgabeblack@google.com virtProxy = new SETranslatingPortProxy(baseCpu->getSendFunctional(), 1218921Sandreas.hansson@arm.com process, 1228921Sandreas.hansson@arm.com SETranslatingPortProxy::NextPage); 1238921Sandreas.hansson@arm.com } 1243675Sktlim@umich.edu} 1252683Sktlim@umich.edu 1269101SBrad.Beckmann@amd.comPortProxy & 1279101SBrad.Beckmann@amd.comThreadState::getPhysProxy() 1289101SBrad.Beckmann@amd.com{ 1299101SBrad.Beckmann@amd.com assert(FullSystem); 1309101SBrad.Beckmann@amd.com assert(physProxy != NULL); 1319101SBrad.Beckmann@amd.com return *physProxy; 1329101SBrad.Beckmann@amd.com} 1339101SBrad.Beckmann@amd.com 13414022Sgabeblack@google.comPortProxy & 1359101SBrad.Beckmann@amd.comThreadState::getVirtProxy() 1369101SBrad.Beckmann@amd.com{ 13714023Sgabeblack@google.com assert(virtProxy != NULL); 13814023Sgabeblack@google.com return *virtProxy; 1399101SBrad.Beckmann@amd.com} 1409101SBrad.Beckmann@amd.com 1412683Sktlim@umich.eduvoid 1422683Sktlim@umich.eduThreadState::profileClear() 1432683Sktlim@umich.edu{ 1442683Sktlim@umich.edu if (profile) 1452683Sktlim@umich.edu profile->clear(); 1462683Sktlim@umich.edu} 1472683Sktlim@umich.edu 1482683Sktlim@umich.eduvoid 1492683Sktlim@umich.eduThreadState::profileSample() 1502683Sktlim@umich.edu{ 1512683Sktlim@umich.edu if (profile) 1522683Sktlim@umich.edu profile->sample(profileNode, profilePC); 1532683Sktlim@umich.edu} 154