gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
simple_thread.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2001-2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Steve Reinhardt
41  * Nathan Binkert
42  * Lisa Hsu
43  * Kevin Lim
44  */
45 
46 #include "cpu/simple_thread.hh"
47 
48 #include <string>
49 
50 #include "arch/isa_traits.hh"
51 #include "arch/kernel_stats.hh"
52 #include "arch/stacktrace.hh"
53 #include "arch/utility.hh"
54 #include "base/callback.hh"
55 #include "base/cprintf.hh"
56 #include "base/output.hh"
57 #include "base/trace.hh"
58 #include "config/the_isa.hh"
59 #include "cpu/base.hh"
60 #include "cpu/profile.hh"
61 #include "cpu/quiesce_event.hh"
62 #include "cpu/thread_context.hh"
65 #include "params/BaseCPU.hh"
66 #include "sim/faults.hh"
67 #include "sim/full_system.hh"
68 #include "sim/process.hh"
69 #include "sim/serialize.hh"
70 #include "sim/sim_exit.hh"
71 #include "sim/system.hh"
72 
73 using namespace std;
74 
75 // constructor
76 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
77  Process *_process, BaseTLB *_itb,
78  BaseTLB *_dtb, TheISA::ISA *_isa)
79  : ThreadState(_cpu, _thread_num, _process), isa(_isa),
80  predicate(true), memAccPredicate(true),
81  comInstEventQueue("instruction-based event queue"),
82  system(_sys), itb(_itb), dtb(_dtb), decoder(TheISA::Decoder(_isa))
83 {
84  clearArchRegs();
85  quiesceEvent = new EndQuiesceEvent(this);
86 }
87 
88 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
89  BaseTLB *_itb, BaseTLB *_dtb,
90  TheISA::ISA *_isa, bool use_kernel_stats)
91  : ThreadState(_cpu, _thread_num, NULL), isa(_isa),
92  predicate(true), memAccPredicate(true),
93  comInstEventQueue("instruction-based event queue"),
94  system(_sys), itb(_itb), dtb(_dtb), decoder(TheISA::Decoder(_isa))
95 {
96  quiesceEvent = new EndQuiesceEvent(this);
97 
98  clearArchRegs();
99 
100  if (baseCpu->params()->profile) {
102  Callback *cb =
106  }
107 
108  // let's fill with a dummy node for now so we don't get a segfault
109  // on the first cycle when there's no node available.
110  static ProfileNode dummyNode;
111  profileNode = &dummyNode;
112  profilePC = 3;
113 
114  if (use_kernel_stats)
115  kernelStats = new TheISA::Kernel::Statistics();
116 }
117 
118 void
120 {
121  ::takeOverFrom(*this, *oldContext);
122  decoder.takeOverFrom(oldContext->getDecoderPtr());
123 
124  kernelStats = oldContext->getKernelStats();
125  funcExeInst = oldContext->readFuncExeInst();
126  storeCondFailures = 0;
127 }
128 
129 void
131 {
132  // copy over functional state
133  _status = oldContext->status();
134  copyArchRegs(oldContext);
135  if (FullSystem)
136  funcExeInst = oldContext->readFuncExeInst();
137 
138  _threadId = oldContext->threadId();
139  _contextId = oldContext->contextId();
140 }
141 
142 void
144 {
146  ::serialize(*this, cp);
147 }
148 
149 
150 void
152 {
154  ::unserialize(*this, cp);
155 }
156 
157 void
159 {
160  isa->startup(this);
161 }
162 
163 void
165 {
166  OutputStream *os(simout.create(csprintf("profile.%s.dat", baseCpu->name())));
167  profile->dump(this, *os->stream());
168  simout.close(os);
169 }
170 
171 void
173 {
174  if (status() == ThreadContext::Active)
175  return;
176 
177  lastActivate = curTick();
180 }
181 
182 void
184 {
186  return;
187 
188  lastActivate = curTick();
189  lastSuspend = curTick();
192 }
193 
194 
195 void
197 {
198  if (status() == ThreadContext::Halted)
199  return;
200 
203 }
204 
205 
206 void
208 {
209  if (FullSystem && kernelStats)
210  kernelStats->regStats(name + ".kern");
211 }
212 
213 void
215 {
216  TheISA::copyRegs(src_tc, this);
217 }
void halt() override
Set the status to Halted.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
OutputDirectory simout
Definition: output.cc:65
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:59
ProfileNode * profileNode
void suspend() override
Set the status to Suspended.
Status status() const override
BaseTLB * itb
virtual TheISA::Decoder * getDecoderPtr()=0
Generic callback class.
Definition: callback.hh:41
FunctionProfile * profile
Tick lastActivate
Last time activate was called on this thread.
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, BaseTLB *_itb, BaseTLB *_dtb, TheISA::ISA *_isa, bool use_kernel_stats=true)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thread_state.cc:83
OutputStream * create(const std::string &name, bool binary=false, bool no_gz=false)
Creates a file in this directory (optionally compressed).
Definition: output.cc:206
virtual ::Kernel::Statistics * getKernelStats()=0
TheISA::Decoder decoder
void dumpFuncProfile() override
Tick lastSuspend
Last time suspend was called on this thread.
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
Definition: base.cc:491
void clearArchRegs() override
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:136
Counter funcExeInst
virtual void regStats(const std::string &name)
Definition: system.hh:77
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
System * system
Definition: cprintf.cc:42
void takeOverFrom(ThreadContext *oldContext) override
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Event for timing out quiesce instruction.
Bitfield< 17 > os
Definition: misc.hh:805
EndQuiesceEvent * quiesceEvent
std::string name() const
Definition: tlb.hh:52
Tick curTick()
The current simulated tick.
Definition: core.hh:47
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
TheISA::ISA *const isa
void activate() override
Set the status to Active.
void dump(ThreadContext *tc, std::ostream &out) const
Definition: profile.cc:124
virtual Counter readFuncExeInst() const =0
Kernel::Statistics * kernelStats
void close(OutputStream *file)
Closes an output file and free the corresponding OutputFile.
Definition: output.cc:148
void registerExitCallback(Callback *callback)
Register an exit callback.
Definition: core.cc:143
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thread_state.cc:65
virtual const std::string name() const
Definition: sim_object.hh:120
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:221
Bitfield< 15 > system
Definition: misc.hh:999
ThreadContext::Status _status
bool predicate
Did this instruction execute or is it predicated false.
bool memAccPredicate
True if the memory access should be skipped for this instruction.
std::ostream CheckpointOut
Definition: serialize.hh:68
Permanently shut down.
void copyState(ThreadContext *oldContext)
void regStats(const std::string &name) override
virtual int threadId() const =0
BaseCPU * baseCpu
void copyArchRegs(ThreadContext *tc) override
TranslatingPortProxy Object Declaration for FS.
virtual ContextID contextId() const =0
TranslatingPortProxy Object Declaration for SE.
virtual Status status() const =0
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:65
unsigned storeCondFailures
Temporarily inactive.
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
Definition: base.cc:531
Helper template class to turn a simple class member function into a callback.
Definition: callback.hh:64
EventQueue comInstEventQueue
An instruction-based event queue.
ContextID _contextId
const Params * params() const
Definition: base.hh:311
output decoder
Definition: nop.cc:64
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
Definition: base.cc:505
ThreadID _threadId
BaseTLB * dtb

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13