simple_thread.cc revision 10537
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" 373565Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh" 385529Snate@binkert.org#include "arch/stacktrace.hh" 398777Sgblack@eecs.umich.edu#include "arch/utility.hh" 401917SN/A#include "base/callback.hh" 411070SN/A#include "base/cprintf.hh" 421917SN/A#include "base/output.hh" 432188SN/A#include "base/trace.hh" 448777Sgblack@eecs.umich.edu#include "config/the_isa.hh" 458777Sgblack@eecs.umich.edu#include "cpu/base.hh" 461917SN/A#include "cpu/profile.hh" 472290SN/A#include "cpu/quiesce_event.hh" 488777Sgblack@eecs.umich.edu#include "cpu/simple_thread.hh" 498777Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 508706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 518799Sgblack@eecs.umich.edu#include "mem/se_translating_port_proxy.hh" 528809Sgblack@eecs.umich.edu#include "params/BaseCPU.hh" 5310319SAndreas.Sandberg@ARM.com#include "sim/faults.hh" 548793Sgblack@eecs.umich.edu#include "sim/full_system.hh" 558777Sgblack@eecs.umich.edu#include "sim/process.hh" 561070SN/A#include "sim/serialize.hh" 571917SN/A#include "sim/sim_exit.hh" 582519SN/A#include "sim/system.hh" 592SN/A 602SN/Ausing namespace std; 612SN/A 622SN/A// constructor 638820Sgblack@eecs.umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys, 648820Sgblack@eecs.umich.edu Process *_process, TheISA::TLB *_itb, 659384SAndreas.Sandberg@arm.com TheISA::TLB *_dtb, TheISA::ISA *_isa) 6610537Sandreas.hansson@arm.com : ThreadState(_cpu, _thread_num, _process), isa(_isa), 6710537Sandreas.hansson@arm.com predicate(false), system(_sys), 689384SAndreas.Sandberg@arm.com itb(_itb), dtb(_dtb) 698766Sgblack@eecs.umich.edu{ 708766Sgblack@eecs.umich.edu clearArchRegs(); 718766Sgblack@eecs.umich.edu tc = new ProxyThreadContext<SimpleThread>(this); 728766Sgblack@eecs.umich.edu} 739377Sgblack@eecs.umich.edu 742683Sktlim@umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys, 756022Sgblack@eecs.umich.edu TheISA::TLB *_itb, TheISA::TLB *_dtb, 769384SAndreas.Sandberg@arm.com TheISA::ISA *_isa, bool use_kernel_stats) 779384SAndreas.Sandberg@arm.com : ThreadState(_cpu, _thread_num, NULL), isa(_isa), system(_sys), itb(_itb), 789384SAndreas.Sandberg@arm.com dtb(_dtb) 792SN/A{ 802683Sktlim@umich.edu tc = new ProxyThreadContext<SimpleThread>(this); 812190SN/A 822680SN/A quiesceEvent = new EndQuiesceEvent(tc); 832290SN/A 846316Sgblack@eecs.umich.edu clearArchRegs(); 851917SN/A 868735Sandreas.hanson@arm.com if (baseCpu->params()->profile) { 871982SN/A profile = new FunctionProfile(system->kernelSymtab); 881917SN/A Callback *cb = 892683Sktlim@umich.edu new MakeCallback<SimpleThread, 902683Sktlim@umich.edu &SimpleThread::dumpFuncProfile>(this); 911917SN/A registerExitCallback(cb); 921917SN/A } 931917SN/A 941917SN/A // let's fill with a dummy node for now so we don't get a segfault 951917SN/A // on the first cycle when there's no node available. 961917SN/A static ProfileNode dummyNode; 971917SN/A profileNode = &dummyNode; 981917SN/A profilePC = 3; 992521SN/A 1005482Snate@binkert.org if (use_kernel_stats) 1013548Sgblack@eecs.umich.edu kernelStats = new TheISA::Kernel::Statistics(system); 1022SN/A} 1032862Sktlim@umich.edu 1042683Sktlim@umich.eduSimpleThread::~SimpleThread() 1051070SN/A{ 1062680SN/A delete tc; 1071070SN/A} 1081070SN/A 1091917SN/Avoid 1102683Sktlim@umich.eduSimpleThread::takeOverFrom(ThreadContext *oldContext) 111180SN/A{ 1129441SAndreas.Sandberg@ARM.com ::takeOverFrom(*tc, *oldContext); 1139478Snilay@cs.wisc.edu decoder.takeOverFrom(oldContext->getDecoderPtr()); 114180SN/A 1159441SAndreas.Sandberg@ARM.com kernelStats = oldContext->getKernelStats(); 1169441SAndreas.Sandberg@ARM.com funcExeInst = oldContext->readFuncExeInst(); 117180SN/A storeCondFailures = 0; 1182864Sktlim@umich.edu} 1192864Sktlim@umich.edu 1202864Sktlim@umich.eduvoid 1212862Sktlim@umich.eduSimpleThread::copyState(ThreadContext *oldContext) 1222862Sktlim@umich.edu{ 1232862Sktlim@umich.edu // copy over functional state 1242862Sktlim@umich.edu _status = oldContext->status(); 1252862Sktlim@umich.edu copyArchRegs(oldContext); 1268793Sgblack@eecs.umich.edu if (FullSystem) 1278793Sgblack@eecs.umich.edu funcExeInst = oldContext->readFuncExeInst(); 1285714Shsul@eecs.umich.edu 1295715Shsul@eecs.umich.edu _threadId = oldContext->threadId(); 1305714Shsul@eecs.umich.edu _contextId = oldContext->contextId(); 1312862Sktlim@umich.edu} 1322862Sktlim@umich.edu 1332862Sktlim@umich.eduvoid 1342683Sktlim@umich.eduSimpleThread::serialize(ostream &os) 135217SN/A{ 1362862Sktlim@umich.edu ThreadState::serialize(os); 1379428SAndreas.Sandberg@ARM.com ::serialize(*tc, os); 138217SN/A} 139217SN/A 140217SN/A 141217SN/Avoid 1422683Sktlim@umich.eduSimpleThread::unserialize(Checkpoint *cp, const std::string §ion) 143217SN/A{ 1442862Sktlim@umich.edu ThreadState::unserialize(cp, section); 1459428SAndreas.Sandberg@ARM.com ::unserialize(*tc, cp, section); 146217SN/A} 147217SN/A 1482683Sktlim@umich.eduvoid 1499461Snilay@cs.wisc.eduSimpleThread::startup() 1509461Snilay@cs.wisc.edu{ 1519461Snilay@cs.wisc.edu isa->startup(tc); 1529461Snilay@cs.wisc.edu} 1539461Snilay@cs.wisc.edu 1549461Snilay@cs.wisc.eduvoid 1552683Sktlim@umich.eduSimpleThread::dumpFuncProfile() 1562683Sktlim@umich.edu{ 1578735Sandreas.hanson@arm.com std::ostream *os = simout.create(csprintf("profile.%s.dat", 1588735Sandreas.hanson@arm.com baseCpu->name())); 1592683Sktlim@umich.edu profile->dump(tc, *os); 1602683Sktlim@umich.edu} 161217SN/A 162217SN/Avoid 16310407Smitch.hayenga@arm.comSimpleThread::activate() 1642SN/A{ 1652680SN/A if (status() == ThreadContext::Active) 1662SN/A return; 1672SN/A 1687823Ssteve.reinhardt@amd.com lastActivate = curTick(); 1692680SN/A _status = ThreadContext::Active; 17010407Smitch.hayenga@arm.com baseCpu->activateContext(_threadId); 171393SN/A} 172393SN/A 173393SN/Avoid 1742683Sktlim@umich.eduSimpleThread::suspend() 175393SN/A{ 1762680SN/A if (status() == ThreadContext::Suspended) 177393SN/A return; 178393SN/A 1797823Ssteve.reinhardt@amd.com lastActivate = curTick(); 1807823Ssteve.reinhardt@amd.com lastSuspend = curTick(); 1812680SN/A _status = ThreadContext::Suspended; 1828735Sandreas.hanson@arm.com baseCpu->suspendContext(_threadId); 1832SN/A} 1842SN/A 185393SN/A 186393SN/Avoid 1872683Sktlim@umich.eduSimpleThread::halt() 188393SN/A{ 1892680SN/A if (status() == ThreadContext::Halted) 190393SN/A return; 191393SN/A 1922680SN/A _status = ThreadContext::Halted; 1938735Sandreas.hanson@arm.com baseCpu->haltContext(_threadId); 194393SN/A} 195393SN/A 196393SN/A 197393SN/Avoid 1982683Sktlim@umich.eduSimpleThread::regStats(const string &name) 1992SN/A{ 2008793Sgblack@eecs.umich.edu if (FullSystem && kernelStats) 2012341SN/A kernelStats->regStats(name + ".kern"); 2022SN/A} 203716SN/A 204716SN/Avoid 2052683Sktlim@umich.eduSimpleThread::copyArchRegs(ThreadContext *src_tc) 2062190SN/A{ 2072680SN/A TheISA::copyRegs(src_tc, tc); 2082190SN/A} 2092190SN/A 21010319SAndreas.Sandberg@ARM.com// The following methods are defined in src/arch/alpha/ev5.cc for 21110319SAndreas.Sandberg@ARM.com// Alpha. 21210319SAndreas.Sandberg@ARM.com#if THE_ISA != ALPHA_ISA 21310319SAndreas.Sandberg@ARM.comFault 21410319SAndreas.Sandberg@ARM.comSimpleThread::hwrei() 21510319SAndreas.Sandberg@ARM.com{ 21610319SAndreas.Sandberg@ARM.com return NoFault; 21710319SAndreas.Sandberg@ARM.com} 21810319SAndreas.Sandberg@ARM.com 21910319SAndreas.Sandberg@ARM.combool 22010319SAndreas.Sandberg@ARM.comSimpleThread::simPalCheck(int palFunc) 22110319SAndreas.Sandberg@ARM.com{ 22210319SAndreas.Sandberg@ARM.com return true; 22310319SAndreas.Sandberg@ARM.com} 22410319SAndreas.Sandberg@ARM.com#endif 225