gem5  v20.0.0.3
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 
41 #include "cpu/simple_thread.hh"
42 
43 #include <string>
44 
45 #include "arch/isa_traits.hh"
46 #include "arch/kernel_stats.hh"
47 #include "arch/stacktrace.hh"
48 #include "arch/utility.hh"
49 #include "base/callback.hh"
50 #include "base/cprintf.hh"
51 #include "base/output.hh"
52 #include "base/trace.hh"
53 #include "config/the_isa.hh"
54 #include "cpu/base.hh"
55 #include "cpu/profile.hh"
56 #include "cpu/quiesce_event.hh"
57 #include "cpu/thread_context.hh"
60 #include "params/BaseCPU.hh"
61 #include "sim/faults.hh"
62 #include "sim/full_system.hh"
63 #include "sim/process.hh"
64 #include "sim/serialize.hh"
65 #include "sim/sim_exit.hh"
66 #include "sim/system.hh"
67 
68 using namespace std;
69 
70 // constructor
71 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
72  Process *_process, BaseTLB *_itb,
73  BaseTLB *_dtb, BaseISA *_isa)
74  : ThreadState(_cpu, _thread_num, _process),
75  isa(dynamic_cast<TheISA::ISA *>(_isa)),
76  predicate(true), memAccPredicate(true),
77  comInstEventQueue("instruction-based event queue"),
78  system(_sys), itb(_itb), dtb(_dtb), decoder(TheISA::Decoder(isa))
79 {
80  assert(isa);
81  clearArchRegs();
82  quiesceEvent = new EndQuiesceEvent(this);
83 }
84 
85 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
86  BaseTLB *_itb, BaseTLB *_dtb,
87  BaseISA *_isa, bool use_kernel_stats)
88  : ThreadState(_cpu, _thread_num, NULL),
89  isa(dynamic_cast<TheISA::ISA *>(_isa)),
90  predicate(true), memAccPredicate(true),
91  comInstEventQueue("instruction-based event queue"),
92  system(_sys), itb(_itb), dtb(_dtb), decoder(TheISA::Decoder(isa))
93 {
94  assert(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  isa->takeOverFrom(this, oldContext);
125 
126  kernelStats = oldContext->getKernelStats();
127  funcExeInst = oldContext->readFuncExeInst();
128  storeCondFailures = 0;
129 }
130 
131 void
133 {
134  // copy over functional state
135  _status = oldContext->status();
136  copyArchRegs(oldContext);
137  if (FullSystem)
138  funcExeInst = oldContext->readFuncExeInst();
139 
140  _threadId = oldContext->threadId();
141  _contextId = oldContext->contextId();
142 }
143 
144 void
146 {
148  ::serialize(*this, cp);
149 }
150 
151 
152 void
154 {
156  ::unserialize(*this, cp);
157 }
158 
159 void
161 {
162  isa->startup(this);
163 }
164 
165 void
167 {
168  OutputStream *os(simout.create(csprintf("profile.%s.dat", baseCpu->name())));
169  profile->dump(this, *os->stream());
170  simout.close(os);
171 }
172 
173 void
175 {
176  if (status() == ThreadContext::Active)
177  return;
178 
179  lastActivate = curTick();
182 }
183 
184 void
186 {
188  return;
189 
190  lastActivate = curTick();
191  lastSuspend = curTick();
194 }
195 
196 
197 void
199 {
200  if (status() == ThreadContext::Halted)
201  return;
202 
205 }
206 
207 
208 void
210 {
211  if (FullSystem && kernelStats)
212  kernelStats->regStats(name + ".kern");
213 }
214 
215 void
217 {
218  TheISA::copyRegs(src_tc, this);
219 }
void halt() override
Set the status to Halted.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
OutputDirectory simout
Definition: output.cc:61
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:54
ProfileNode * profileNode
virtual const Loader::SymbolTable * symtab(ThreadContext *tc)=0
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:39
FunctionProfile * profile
Tick lastActivate
Last time activate was called on this thread.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thread_state.cc:81
OutputStream * create(const std::string &name, bool binary=false, bool no_gz=false)
Creates a file in this directory (optionally compressed).
Definition: output.cc:207
virtual ::Kernel::Statistics * getKernelStats()=0
TheISA::Decoder decoder
void dumpFuncProfile() override
Tick lastSuspend
Last time suspend was called on this thread.
virtual void regStats(const std::string &name)
Definition: kernel_stats.cc:42
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
Definition: base.cc:487
void clearArchRegs() override
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, BaseTLB *_itb, BaseTLB *_dtb, BaseISA *_isa, bool use_kernel_stats=true)
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
Counter funcExeInst
Definition: system.hh:72
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
System * system
Definition: cprintf.cc:40
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:803
EndQuiesceEvent * quiesceEvent
std::string name() const
Definition: tlb.hh:50
Tick curTick()
The current simulated tick.
Definition: core.hh:44
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
TheISA::ISA *const isa
void activate() override
Set the status to Active.
void dump(ThreadContext *tc, std::ostream &out) const
Definition: profile.cc:122
virtual Counter readFuncExeInst() const =0
Kernel::Statistics * kernelStats
void close(OutputStream *file)
Closes an output file and free the corresponding OutputFile.
Definition: output.cc:144
void registerExitCallback(Callback *callback)
Register an exit callback.
Definition: core.cc:140
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thread_state.cc:63
Workload * workload
OS kernel.
Definition: system.hh:213
Bitfield< 15 > system
Definition: misc.hh:997
ThreadContext::Status _status
bool predicate
Did this instruction execute or is it predicated false.
virtual const std::string name() const
Definition: sim_object.hh:129
bool memAccPredicate
True if the memory access should be skipped for this instruction.
std::ostream CheckpointOut
Definition: serialize.hh:63
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
virtual ContextID contextId() const =0
virtual Status status() const =0
unsigned storeCondFailures
Temporarily inactive.
Definition: isa.hh:47
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:527
Helper template class to turn a simple class member function into a callback.
Definition: callback.hh:62
EventQueue comInstEventQueue
An instruction-based event queue.
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:136
ContextID _contextId
const Params * params() const
Definition: base.hh:307
output decoder
Definition: nop.cc:61
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
Definition: base.cc:501
ThreadID _threadId
BaseTLB * dtb

Generated on Fri Jul 3 2020 15:53:01 for gem5 by doxygen 1.8.13