simple_thread.cc revision 13759
12SN/A/*
213759Sgiacomo.gabrielli@arm.com * Copyright (c) 2018 ARM Limited
313759Sgiacomo.gabrielli@arm.com * All rights reserved
413759Sgiacomo.gabrielli@arm.com *
513759Sgiacomo.gabrielli@arm.com * The license below extends only to copyright in the software and shall
613759Sgiacomo.gabrielli@arm.com * not be construed as granting a license to any other intellectual
713759Sgiacomo.gabrielli@arm.com * property including but not limited to intellectual property relating
813759Sgiacomo.gabrielli@arm.com * to a hardware implementation of the functionality of the software
913759Sgiacomo.gabrielli@arm.com * licensed hereunder.  You may use the software subject to the license
1013759Sgiacomo.gabrielli@arm.com * terms below provided that you ensure that this notice is replicated
1113759Sgiacomo.gabrielli@arm.com * unmodified and in its entirety in all distributions of the software,
1213759Sgiacomo.gabrielli@arm.com * modified or unmodified, in source code or in binary form.
1313759Sgiacomo.gabrielli@arm.com *
142188SN/A * Copyright (c) 2001-2006 The Regents of The University of Michigan
152SN/A * All rights reserved.
162SN/A *
172SN/A * Redistribution and use in source and binary forms, with or without
182SN/A * modification, are permitted provided that the following conditions are
192SN/A * met: redistributions of source code must retain the above copyright
202SN/A * notice, this list of conditions and the following disclaimer;
212SN/A * redistributions in binary form must reproduce the above copyright
222SN/A * notice, this list of conditions and the following disclaimer in the
232SN/A * documentation and/or other materials provided with the distribution;
242SN/A * neither the name of the copyright holders nor the names of its
252SN/A * contributors may be used to endorse or promote products derived from
262SN/A * this software without specific prior written permission.
272SN/A *
282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Steve Reinhardt
412665SN/A *          Nathan Binkert
422665SN/A *          Lisa Hsu
432665SN/A *          Kevin Lim
442SN/A */
452SN/A
4611793Sbrandon.potter@amd.com#include "cpu/simple_thread.hh"
4711793Sbrandon.potter@amd.com
482SN/A#include <string>
492SN/A
502465SN/A#include "arch/isa_traits.hh"
513565Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh"
525529Snate@binkert.org#include "arch/stacktrace.hh"
538777Sgblack@eecs.umich.edu#include "arch/utility.hh"
541917SN/A#include "base/callback.hh"
551070SN/A#include "base/cprintf.hh"
561917SN/A#include "base/output.hh"
572188SN/A#include "base/trace.hh"
588777Sgblack@eecs.umich.edu#include "config/the_isa.hh"
598777Sgblack@eecs.umich.edu#include "cpu/base.hh"
601917SN/A#include "cpu/profile.hh"
612290SN/A#include "cpu/quiesce_event.hh"
628777Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
638706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh"
648799Sgblack@eecs.umich.edu#include "mem/se_translating_port_proxy.hh"
658809Sgblack@eecs.umich.edu#include "params/BaseCPU.hh"
6610319SAndreas.Sandberg@ARM.com#include "sim/faults.hh"
678793Sgblack@eecs.umich.edu#include "sim/full_system.hh"
688777Sgblack@eecs.umich.edu#include "sim/process.hh"
691070SN/A#include "sim/serialize.hh"
701917SN/A#include "sim/sim_exit.hh"
712519SN/A#include "sim/system.hh"
722SN/A
732SN/Ausing namespace std;
742SN/A
752SN/A// constructor
768820Sgblack@eecs.umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
7712406Sgabeblack@google.com                           Process *_process, BaseTLB *_itb,
7812406Sgabeblack@google.com                           BaseTLB *_dtb, TheISA::ISA *_isa)
7910537Sandreas.hansson@arm.com    : ThreadState(_cpu, _thread_num, _process), isa(_isa),
8010537Sandreas.hansson@arm.com      predicate(false), system(_sys),
8113759Sgiacomo.gabrielli@arm.com      itb(_itb), dtb(_dtb), decoder(TheISA::Decoder(_isa))
828766Sgblack@eecs.umich.edu{
838766Sgblack@eecs.umich.edu    clearArchRegs();
848766Sgblack@eecs.umich.edu    tc = new ProxyThreadContext<SimpleThread>(this);
8511627Smichael.lebeane@amd.com    quiesceEvent = new EndQuiesceEvent(tc);
868766Sgblack@eecs.umich.edu}
879377Sgblack@eecs.umich.edu
882683Sktlim@umich.eduSimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
8912406Sgabeblack@google.com                           BaseTLB *_itb, BaseTLB *_dtb,
909384SAndreas.Sandberg@arm.com                           TheISA::ISA *_isa, bool use_kernel_stats)
919384SAndreas.Sandberg@arm.com    : ThreadState(_cpu, _thread_num, NULL), isa(_isa), system(_sys), itb(_itb),
9213759Sgiacomo.gabrielli@arm.com      dtb(_dtb), decoder(TheISA::Decoder(_isa))
932SN/A{
942683Sktlim@umich.edu    tc = new ProxyThreadContext<SimpleThread>(this);
952190SN/A
962680SN/A    quiesceEvent = new EndQuiesceEvent(tc);
972290SN/A
986316Sgblack@eecs.umich.edu    clearArchRegs();
991917SN/A
1008735Sandreas.hanson@arm.com    if (baseCpu->params()->profile) {
1011982SN/A        profile = new FunctionProfile(system->kernelSymtab);
1021917SN/A        Callback *cb =
1032683Sktlim@umich.edu            new MakeCallback<SimpleThread,
1042683Sktlim@umich.edu            &SimpleThread::dumpFuncProfile>(this);
1051917SN/A        registerExitCallback(cb);
1061917SN/A    }
1071917SN/A
1081917SN/A    // let's fill with a dummy node for now so we don't get a segfault
1091917SN/A    // on the first cycle when there's no node available.
1101917SN/A    static ProfileNode dummyNode;
1111917SN/A    profileNode = &dummyNode;
1121917SN/A    profilePC = 3;
1132521SN/A
1145482Snate@binkert.org    if (use_kernel_stats)
11512181Sgabeblack@google.com        kernelStats = new TheISA::Kernel::Statistics();
1162SN/A}
1172862Sktlim@umich.edu
1182683Sktlim@umich.eduSimpleThread::~SimpleThread()
1191070SN/A{
1202680SN/A    delete tc;
1211070SN/A}
1221070SN/A
1231917SN/Avoid
1242683Sktlim@umich.eduSimpleThread::takeOverFrom(ThreadContext *oldContext)
125180SN/A{
1269441SAndreas.Sandberg@ARM.com    ::takeOverFrom(*tc, *oldContext);
1279478Snilay@cs.wisc.edu    decoder.takeOverFrom(oldContext->getDecoderPtr());
128180SN/A
1299441SAndreas.Sandberg@ARM.com    kernelStats = oldContext->getKernelStats();
1309441SAndreas.Sandberg@ARM.com    funcExeInst = oldContext->readFuncExeInst();
131180SN/A    storeCondFailures = 0;
1322864Sktlim@umich.edu}
1332864Sktlim@umich.edu
1342864Sktlim@umich.eduvoid
1352862Sktlim@umich.eduSimpleThread::copyState(ThreadContext *oldContext)
1362862Sktlim@umich.edu{
1372862Sktlim@umich.edu    // copy over functional state
1382862Sktlim@umich.edu    _status = oldContext->status();
1392862Sktlim@umich.edu    copyArchRegs(oldContext);
1408793Sgblack@eecs.umich.edu    if (FullSystem)
1418793Sgblack@eecs.umich.edu        funcExeInst = oldContext->readFuncExeInst();
1425714Shsul@eecs.umich.edu
1435715Shsul@eecs.umich.edu    _threadId = oldContext->threadId();
1445714Shsul@eecs.umich.edu    _contextId = oldContext->contextId();
1452862Sktlim@umich.edu}
1462862Sktlim@umich.edu
1472862Sktlim@umich.eduvoid
14810905Sandreas.sandberg@arm.comSimpleThread::serialize(CheckpointOut &cp) const
149217SN/A{
15010905Sandreas.sandberg@arm.com    ThreadState::serialize(cp);
15110905Sandreas.sandberg@arm.com    ::serialize(*tc, cp);
152217SN/A}
153217SN/A
154217SN/A
155217SN/Avoid
15610905Sandreas.sandberg@arm.comSimpleThread::unserialize(CheckpointIn &cp)
157217SN/A{
15810905Sandreas.sandberg@arm.com    ThreadState::unserialize(cp);
15910905Sandreas.sandberg@arm.com    ::unserialize(*tc, cp);
160217SN/A}
161217SN/A
1622683Sktlim@umich.eduvoid
1639461Snilay@cs.wisc.eduSimpleThread::startup()
1649461Snilay@cs.wisc.edu{
1659461Snilay@cs.wisc.edu    isa->startup(tc);
1669461Snilay@cs.wisc.edu}
1679461Snilay@cs.wisc.edu
1689461Snilay@cs.wisc.eduvoid
1692683Sktlim@umich.eduSimpleThread::dumpFuncProfile()
1702683Sktlim@umich.edu{
17111359Sandreas@sandberg.pp.se    OutputStream *os(simout.create(csprintf("profile.%s.dat", baseCpu->name())));
17211359Sandreas@sandberg.pp.se    profile->dump(tc, *os->stream());
17311359Sandreas@sandberg.pp.se    simout.close(os);
1742683Sktlim@umich.edu}
175217SN/A
176217SN/Avoid
17710407Smitch.hayenga@arm.comSimpleThread::activate()
1782SN/A{
1792680SN/A    if (status() == ThreadContext::Active)
1802SN/A        return;
1812SN/A
1827823Ssteve.reinhardt@amd.com    lastActivate = curTick();
1832680SN/A    _status = ThreadContext::Active;
18410407Smitch.hayenga@arm.com    baseCpu->activateContext(_threadId);
185393SN/A}
186393SN/A
187393SN/Avoid
1882683Sktlim@umich.eduSimpleThread::suspend()
189393SN/A{
1902680SN/A    if (status() == ThreadContext::Suspended)
191393SN/A        return;
192393SN/A
1937823Ssteve.reinhardt@amd.com    lastActivate = curTick();
1947823Ssteve.reinhardt@amd.com    lastSuspend = curTick();
1952680SN/A    _status = ThreadContext::Suspended;
1968735Sandreas.hanson@arm.com    baseCpu->suspendContext(_threadId);
1972SN/A}
1982SN/A
199393SN/A
200393SN/Avoid
2012683Sktlim@umich.eduSimpleThread::halt()
202393SN/A{
2032680SN/A    if (status() == ThreadContext::Halted)
204393SN/A        return;
205393SN/A
2062680SN/A    _status = ThreadContext::Halted;
2078735Sandreas.hanson@arm.com    baseCpu->haltContext(_threadId);
208393SN/A}
209393SN/A
210393SN/A
211393SN/Avoid
2122683Sktlim@umich.eduSimpleThread::regStats(const string &name)
2132SN/A{
2148793Sgblack@eecs.umich.edu    if (FullSystem && kernelStats)
2152341SN/A        kernelStats->regStats(name + ".kern");
2162SN/A}
217716SN/A
218716SN/Avoid
2192683Sktlim@umich.eduSimpleThread::copyArchRegs(ThreadContext *src_tc)
2202190SN/A{
2212680SN/A    TheISA::copyRegs(src_tc, tc);
2222190SN/A}
2232190SN/A
22410319SAndreas.Sandberg@ARM.com// The following methods are defined in src/arch/alpha/ev5.cc for
22510319SAndreas.Sandberg@ARM.com// Alpha.
22610319SAndreas.Sandberg@ARM.com#if THE_ISA != ALPHA_ISA
22710319SAndreas.Sandberg@ARM.comFault
22810319SAndreas.Sandberg@ARM.comSimpleThread::hwrei()
22910319SAndreas.Sandberg@ARM.com{
23010319SAndreas.Sandberg@ARM.com    return NoFault;
23110319SAndreas.Sandberg@ARM.com}
23210319SAndreas.Sandberg@ARM.com
23310319SAndreas.Sandberg@ARM.combool
23410319SAndreas.Sandberg@ARM.comSimpleThread::simPalCheck(int palFunc)
23510319SAndreas.Sandberg@ARM.com{
23610319SAndreas.Sandberg@ARM.com    return true;
23710319SAndreas.Sandberg@ARM.com}
23810319SAndreas.Sandberg@ARM.com#endif
239