simple_thread.cc revision 7823
12SN/A/* 22188SN/A * Copyright (c) 2001-2006 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Steve Reinhardt 292665SN/A * Nathan Binkert 302665SN/A * Lisa Hsu 312665SN/A * Kevin Lim 322SN/A */ 332SN/A 342SN/A#include <string> 352SN/A 362465SN/A#include "arch/isa_traits.hh" 377680Sgblack@eecs.umich.edu#include "arch/utility.hh" 386658Snate@binkert.org#include "config/the_isa.hh" 391717SN/A#include "cpu/base.hh" 402683Sktlim@umich.edu#include "cpu/simple_thread.hh" 412680SN/A#include "cpu/thread_context.hh" 425529Snate@binkert.org#include "params/BaseCPU.hh" 432SN/A 441858SN/A#if FULL_SYSTEM 453565Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh" 465529Snate@binkert.org#include "arch/stacktrace.hh" 471917SN/A#include "base/callback.hh" 481070SN/A#include "base/cprintf.hh" 491917SN/A#include "base/output.hh" 502188SN/A#include "base/trace.hh" 511917SN/A#include "cpu/profile.hh" 522290SN/A#include "cpu/quiesce_event.hh" 537723SAli.Saidi@ARM.com#include "mem/vport.hh" 541070SN/A#include "sim/serialize.hh" 551917SN/A#include "sim/sim_exit.hh" 562SN/A#else 575529Snate@binkert.org#include "mem/translating_port.hh" 58360SN/A#include "sim/process.hh" 592519SN/A#include "sim/system.hh" 602SN/A#endif 612SN/A 622SN/Ausing namespace std; 632SN/A 642SN/A// constructor 651858SN/A#if FULL_SYSTEM 662683Sktlim@umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys, 676022Sgblack@eecs.umich.edu TheISA::TLB *_itb, TheISA::TLB *_dtb, 682683Sktlim@umich.edu bool use_kernel_stats) 696324Sgblack@eecs.umich.edu : ThreadState(_cpu, _thread_num), 706324Sgblack@eecs.umich.edu cpu(_cpu), system(_sys), itb(_itb), dtb(_dtb) 712521SN/A 722SN/A{ 732683Sktlim@umich.edu tc = new ProxyThreadContext<SimpleThread>(this); 742190SN/A 752680SN/A quiesceEvent = new EndQuiesceEvent(tc); 762290SN/A 776316Sgblack@eecs.umich.edu clearArchRegs(); 781917SN/A 795529Snate@binkert.org if (cpu->params()->profile) { 801982SN/A profile = new FunctionProfile(system->kernelSymtab); 811917SN/A Callback *cb = 822683Sktlim@umich.edu new MakeCallback<SimpleThread, 832683Sktlim@umich.edu &SimpleThread::dumpFuncProfile>(this); 841917SN/A registerExitCallback(cb); 851917SN/A } 861917SN/A 871917SN/A // let's fill with a dummy node for now so we don't get a segfault 881917SN/A // on the first cycle when there's no node available. 891917SN/A static ProfileNode dummyNode; 901917SN/A profileNode = &dummyNode; 911917SN/A profilePC = 3; 922521SN/A 935482Snate@binkert.org if (use_kernel_stats) 943548Sgblack@eecs.umich.edu kernelStats = new TheISA::Kernel::Statistics(system); 952SN/A} 962SN/A#else 974997Sgblack@eecs.umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process, 986331Sgblack@eecs.umich.edu TheISA::TLB *_itb, TheISA::TLB *_dtb) 996331Sgblack@eecs.umich.edu : ThreadState(_cpu, _thread_num, _process), 1004997Sgblack@eecs.umich.edu cpu(_cpu), itb(_itb), dtb(_dtb) 1012SN/A{ 1026316Sgblack@eecs.umich.edu clearArchRegs(); 1032683Sktlim@umich.edu tc = new ProxyThreadContext<SimpleThread>(this); 1042SN/A} 1052190SN/A 1062862Sktlim@umich.edu#endif 1072862Sktlim@umich.edu 1082864Sktlim@umich.eduSimpleThread::SimpleThread() 1092862Sktlim@umich.edu#if FULL_SYSTEM 1105712Shsul@eecs.umich.edu : ThreadState(NULL, -1) 1112862Sktlim@umich.edu#else 1126331Sgblack@eecs.umich.edu : ThreadState(NULL, -1, NULL) 1132862Sktlim@umich.edu#endif 1142190SN/A{ 1152683Sktlim@umich.edu tc = new ProxyThreadContext<SimpleThread>(this); 1162190SN/A} 1172190SN/A 1182683Sktlim@umich.eduSimpleThread::~SimpleThread() 1191070SN/A{ 1203486Sktlim@umich.edu#if FULL_SYSTEM 1213486Sktlim@umich.edu delete physPort; 1223486Sktlim@umich.edu delete virtPort; 1233486Sktlim@umich.edu#endif 1242680SN/A delete tc; 1251070SN/A} 1261070SN/A 1271917SN/Avoid 1282683Sktlim@umich.eduSimpleThread::takeOverFrom(ThreadContext *oldContext) 129180SN/A{ 130180SN/A // some things should already be set up 1311858SN/A#if FULL_SYSTEM 1322235SN/A assert(system == oldContext->getSystemPtr()); 133180SN/A#else 1342235SN/A assert(process == oldContext->getProcessPtr()); 135180SN/A#endif 136180SN/A 1372862Sktlim@umich.edu copyState(oldContext); 1382862Sktlim@umich.edu#if FULL_SYSTEM 1392313SN/A EndQuiesceEvent *quiesce = oldContext->getQuiesceEvent(); 1402313SN/A if (quiesce) { 1412680SN/A // Point the quiesce event's TC at this TC so that it wakes up 1422313SN/A // the proper CPU. 1432680SN/A quiesce->tc = tc; 1442313SN/A } 1452313SN/A if (quiesceEvent) { 1462680SN/A quiesceEvent->tc = tc; 1472313SN/A } 1482361SN/A 1493548Sgblack@eecs.umich.edu TheISA::Kernel::Statistics *stats = oldContext->getKernelStats(); 1502361SN/A if (stats) { 1512361SN/A kernelStats = stats; 1522361SN/A } 1532235SN/A#endif 154180SN/A 155180SN/A storeCondFailures = 0; 156180SN/A 1576029Ssteve.reinhardt@amd.com oldContext->setStatus(ThreadContext::Halted); 158180SN/A} 159180SN/A 1602SN/Avoid 1612864Sktlim@umich.eduSimpleThread::copyTC(ThreadContext *context) 1622864Sktlim@umich.edu{ 1632864Sktlim@umich.edu copyState(context); 1642864Sktlim@umich.edu 1652864Sktlim@umich.edu#if FULL_SYSTEM 1662864Sktlim@umich.edu EndQuiesceEvent *quiesce = context->getQuiesceEvent(); 1672864Sktlim@umich.edu if (quiesce) { 1682864Sktlim@umich.edu quiesceEvent = quiesce; 1692864Sktlim@umich.edu } 1703548Sgblack@eecs.umich.edu TheISA::Kernel::Statistics *stats = context->getKernelStats(); 1712864Sktlim@umich.edu if (stats) { 1722864Sktlim@umich.edu kernelStats = stats; 1732864Sktlim@umich.edu } 1742864Sktlim@umich.edu#endif 1752864Sktlim@umich.edu} 1762864Sktlim@umich.edu 1772864Sktlim@umich.eduvoid 1782862Sktlim@umich.eduSimpleThread::copyState(ThreadContext *oldContext) 1792862Sktlim@umich.edu{ 1802862Sktlim@umich.edu // copy over functional state 1812862Sktlim@umich.edu _status = oldContext->status(); 1822862Sktlim@umich.edu copyArchRegs(oldContext); 1832862Sktlim@umich.edu#if !FULL_SYSTEM 1842862Sktlim@umich.edu funcExeInst = oldContext->readFuncExeInst(); 1852862Sktlim@umich.edu#endif 1865714Shsul@eecs.umich.edu 1875715Shsul@eecs.umich.edu _threadId = oldContext->threadId(); 1885714Shsul@eecs.umich.edu _contextId = oldContext->contextId(); 1892862Sktlim@umich.edu} 1902862Sktlim@umich.edu 1912862Sktlim@umich.eduvoid 1922683Sktlim@umich.eduSimpleThread::serialize(ostream &os) 193217SN/A{ 1942862Sktlim@umich.edu ThreadState::serialize(os); 1956315Sgblack@eecs.umich.edu SERIALIZE_ARRAY(floatRegs.i, TheISA::NumFloatRegs); 1966316Sgblack@eecs.umich.edu SERIALIZE_ARRAY(intRegs, TheISA::NumIntRegs); 1977720Sgblack@eecs.umich.edu _pcState.serialize(os); 198223SN/A // thread_num and cpu_id are deterministic from the config 1996677SBrad.Beckmann@amd.com 2006677SBrad.Beckmann@amd.com // 2016677SBrad.Beckmann@amd.com // Now must serialize all the ISA dependent state 2026677SBrad.Beckmann@amd.com // 2036678Sgblack@eecs.umich.edu isa.serialize(cpu, os); 204217SN/A} 205217SN/A 206217SN/A 207217SN/Avoid 2082683Sktlim@umich.eduSimpleThread::unserialize(Checkpoint *cp, const std::string §ion) 209217SN/A{ 2102862Sktlim@umich.edu ThreadState::unserialize(cp, section); 2116315Sgblack@eecs.umich.edu UNSERIALIZE_ARRAY(floatRegs.i, TheISA::NumFloatRegs); 2126316Sgblack@eecs.umich.edu UNSERIALIZE_ARRAY(intRegs, TheISA::NumIntRegs); 2137720Sgblack@eecs.umich.edu _pcState.unserialize(cp, section); 214223SN/A // thread_num and cpu_id are deterministic from the config 2156677SBrad.Beckmann@amd.com 2166677SBrad.Beckmann@amd.com // 2176677SBrad.Beckmann@amd.com // Now must unserialize all the ISA dependent state 2186677SBrad.Beckmann@amd.com // 2196678Sgblack@eecs.umich.edu isa.unserialize(cpu, cp, section); 220217SN/A} 221217SN/A 2222683Sktlim@umich.edu#if FULL_SYSTEM 2232683Sktlim@umich.eduvoid 2242683Sktlim@umich.eduSimpleThread::dumpFuncProfile() 2252683Sktlim@umich.edu{ 2262683Sktlim@umich.edu std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 2272683Sktlim@umich.edu profile->dump(tc, *os); 2282683Sktlim@umich.edu} 2292683Sktlim@umich.edu#endif 230217SN/A 231217SN/Avoid 2322683Sktlim@umich.eduSimpleThread::activate(int delay) 2332SN/A{ 2342680SN/A if (status() == ThreadContext::Active) 2352SN/A return; 2362SN/A 2377823Ssteve.reinhardt@amd.com lastActivate = curTick(); 2382188SN/A 2394400Srdreslin@umich.edu// if (status() == ThreadContext::Unallocated) { 2405715Shsul@eecs.umich.edu// cpu->activateWhenReady(_threadId); 2415543Ssaidi@eecs.umich.edu// return; 2424400Srdreslin@umich.edu// } 2432290SN/A 2442680SN/A _status = ThreadContext::Active; 2452290SN/A 2462290SN/A // status() == Suspended 2475715Shsul@eecs.umich.edu cpu->activateContext(_threadId, delay); 248393SN/A} 249393SN/A 250393SN/Avoid 2512683Sktlim@umich.eduSimpleThread::suspend() 252393SN/A{ 2532680SN/A if (status() == ThreadContext::Suspended) 254393SN/A return; 255393SN/A 2567823Ssteve.reinhardt@amd.com lastActivate = curTick(); 2577823Ssteve.reinhardt@amd.com lastSuspend = curTick(); 2582188SN/A/* 2591858SN/A#if FULL_SYSTEM 2602SN/A // Don't change the status from active if there are pending interrupts 2615704Snate@binkert.org if (cpu->checkInterrupts()) { 2622680SN/A assert(status() == ThreadContext::Active); 2632SN/A return; 2642SN/A } 2652SN/A#endif 2662188SN/A*/ 2672680SN/A _status = ThreadContext::Suspended; 2685715Shsul@eecs.umich.edu cpu->suspendContext(_threadId); 2692SN/A} 2702SN/A 271393SN/A 272393SN/Avoid 2732683Sktlim@umich.eduSimpleThread::halt() 274393SN/A{ 2752680SN/A if (status() == ThreadContext::Halted) 276393SN/A return; 277393SN/A 2782680SN/A _status = ThreadContext::Halted; 2795715Shsul@eecs.umich.edu cpu->haltContext(_threadId); 280393SN/A} 281393SN/A 282393SN/A 283393SN/Avoid 2842683Sktlim@umich.eduSimpleThread::regStats(const string &name) 2852SN/A{ 2862330SN/A#if FULL_SYSTEM 2872341SN/A if (kernelStats) 2882341SN/A kernelStats->regStats(name + ".kern"); 2892330SN/A#endif 2902SN/A} 291716SN/A 292716SN/Avoid 2932683Sktlim@umich.eduSimpleThread::copyArchRegs(ThreadContext *src_tc) 2942190SN/A{ 2952680SN/A TheISA::copyRegs(src_tc, tc); 2962190SN/A} 2972190SN/A 298