gem5  v20.1.0.0
simple_thread.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 2020 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/utility.hh"
46 #include "base/callback.hh"
47 #include "base/compiler.hh"
48 #include "base/cprintf.hh"
49 #include "base/output.hh"
50 #include "base/trace.hh"
51 #include "config/the_isa.hh"
52 #include "cpu/base.hh"
53 #include "cpu/simple/base.hh"
54 #include "cpu/thread_context.hh"
57 #include "params/BaseCPU.hh"
58 #include "sim/faults.hh"
59 #include "sim/full_system.hh"
60 #include "sim/process.hh"
61 #include "sim/serialize.hh"
62 #include "sim/sim_exit.hh"
63 #include "sim/system.hh"
64 
65 using namespace std;
66 
67 // constructor
68 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
69  Process *_process, BaseTLB *_itb,
70  BaseTLB *_dtb, BaseISA *_isa)
71  : ThreadState(_cpu, _thread_num, _process),
72  isa(dynamic_cast<TheISA::ISA *>(_isa)),
73  predicate(true), memAccPredicate(true),
74  comInstEventQueue("instruction-based event queue"),
75  system(_sys), itb(_itb), dtb(_dtb), decoder(isa),
76  htmTransactionStarts(0), htmTransactionStops(0)
77 {
78  assert(isa);
79  clearArchRegs();
80 }
81 
82 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
83  BaseTLB *_itb, BaseTLB *_dtb, BaseISA *_isa)
84  : ThreadState(_cpu, _thread_num, NULL),
85  isa(dynamic_cast<TheISA::ISA *>(_isa)),
86  predicate(true), memAccPredicate(true),
87  comInstEventQueue("instruction-based event queue"),
88  system(_sys), itb(_itb), dtb(_dtb), decoder(isa),
89  htmTransactionStarts(0), htmTransactionStops(0)
90 {
91  assert(isa);
92 
93  clearArchRegs();
94 }
95 
96 void
98 {
99  ::takeOverFrom(*this, *oldContext);
100  decoder.takeOverFrom(oldContext->getDecoderPtr());
101 
102  isa->takeOverFrom(this, oldContext);
103 
104  funcExeInst = oldContext->readFuncExeInst();
105  storeCondFailures = 0;
106 }
107 
108 void
110 {
111  // copy over functional state
112  _status = oldContext->status();
113  copyArchRegs(oldContext);
114  if (FullSystem)
115  funcExeInst = oldContext->readFuncExeInst();
116 
117  _threadId = oldContext->threadId();
118  _contextId = oldContext->contextId();
119 }
120 
121 void
123 {
125  ::serialize(*this, cp);
126 }
127 
128 
129 void
131 {
133  ::unserialize(*this, cp);
134 }
135 
136 void
138 {
139  if (status() == ThreadContext::Active)
140  return;
141 
142  lastActivate = curTick();
145 }
146 
147 void
149 {
151  return;
152 
153  lastActivate = curTick();
154  lastSuspend = curTick();
157 }
158 
159 
160 void
162 {
163  if (status() == ThreadContext::Halted)
164  return;
165 
168 }
169 
170 void
172 {
173  TheISA::copyRegs(src_tc, this);
174 }
175 
176 // hardware transactional memory
177 void
179 {
180  BaseSimpleCPU *baseSimpleCpu = dynamic_cast<BaseSimpleCPU*>(baseCpu);
181  assert(baseSimpleCpu);
182 
183  baseSimpleCpu->htmSendAbortSignal(cause);
184 
185  // these must be reset after the abort signal has been sent
188 }
189 
192 {
193  return _htmCheckpoint;
194 }
195 
196 void
198 {
199  _htmCheckpoint = std::move(new_cpt);
200 }
SimpleThread::clearArchRegs
void clearArchRegs() override
Definition: simple_thread.hh:269
SimpleThread::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: simple_thread.cc:122
SimpleThread::htmAbortTransaction
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
Definition: simple_thread.cc:178
ArmISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:136
ThreadState::funcExeInst
Counter funcExeInst
Definition: thread_state.hh:166
SimpleThread::getHtmCheckpointPtr
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
Definition: simple_thread.cc:191
system.hh
serialize.hh
Process
Definition: process.hh:65
ThreadState::lastActivate
Tick lastActivate
Last time activate was called on this thread.
Definition: thread_state.hh:145
ThreadState::_threadId
ThreadID _threadId
Definition: thread_state.hh:141
TheISA
Definition: decode_cache.hh:37
translating_port_proxy.hh
SimpleThread::suspend
void suspend() override
Set the status to Suspended.
Definition: simple_thread.cc:148
ThreadContext::readFuncExeInst
virtual Counter readFuncExeInst() const =0
SimpleThread::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: simple_thread.cc:130
SimpleThread::isa
TheISA::ISA *const isa
Definition: simple_thread.hh:105
SimpleThread::setHtmCheckpointPtr
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
Definition: simple_thread.cc:197
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:44
SimpleThread::status
Status status() const override
Definition: simple_thread.hh:242
faults.hh
sim_exit.hh
output.hh
SimpleThread::decoder
TheISA::Decoder decoder
Definition: simple_thread.hh:136
BaseTLB
Definition: tlb.hh:50
ThreadContext::threadId
virtual int threadId() const =0
SimpleThread::_htmCheckpoint
std::unique_ptr< BaseHTMCheckpoint > _htmCheckpoint
Definition: simple_thread.hh:110
ThreadState
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:46
ThreadState::_status
ThreadContext::Status _status
Definition: thread_state.hh:132
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
cp
Definition: cprintf.cc:40
SimpleThread::htmTransactionStops
int64_t htmTransactionStops
Definition: simple_thread.hh:140
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
SimpleThread::takeOverFrom
void takeOverFrom(ThreadContext *oldContext) override
Definition: simple_thread.cc:97
ThreadState::lastSuspend
Tick lastSuspend
Last time suspend was called on this thread.
Definition: thread_state.hh:148
System
Definition: system.hh:73
ThreadContext::Halted
@ Halted
Permanently shut down.
Definition: thread_context.hh:115
SimpleThread::SimpleThread
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, BaseTLB *_itb, BaseTLB *_dtb, BaseISA *_isa)
Definition: simple_thread.cc:82
process.hh
BaseSimpleCPU::htmSendAbortSignal
virtual void htmSendAbortSignal(HtmFailureFaultCause cause)=0
This function is used to instruct the memory subsystem that a transaction should be aborted and the s...
BaseCPU::activateContext
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
Definition: base.cc:480
SimpleThread::copyState
void copyState(ThreadContext *oldContext)
Definition: simple_thread.cc:109
ThreadContext::contextId
virtual ContextID contextId() const =0
cprintf.hh
BaseSimpleCPU
Definition: base.hh:80
compiler.hh
SimpleThread::copyArchRegs
void copyArchRegs(ThreadContext *tc) override
Definition: simple_thread.cc:171
ThreadContext::status
virtual Status status() const =0
BaseHTMCheckpointPtr
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:122
ThreadState::baseCpu
BaseCPU * baseCpu
Definition: thread_state.hh:135
SimpleThread::activate
void activate() override
Set the status to Active.
Definition: simple_thread.cc:137
full_system.hh
BaseCPU
Definition: cpu_dummy.hh:43
base.hh
ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:106
simple_thread.hh
BaseCPU::haltContext
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
Definition: base.cc:520
base.hh
SimpleThread::htmTransactionStarts
int64_t htmTransactionStarts
Definition: simple_thread.hh:139
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
ThreadState::storeCondFailures
unsigned storeCondFailures
Definition: thread_state.hh:171
ThreadState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thread_state.cc:71
ThreadContext::Active
@ Active
Running.
Definition: thread_context.hh:102
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
ThreadContext::getDecoderPtr
virtual TheISA::Decoder * getDecoderPtr()=0
BaseCPU::suspendContext
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
Definition: base.cc:494
se_translating_port_proxy.hh
trace.hh
ThreadState::_contextId
ContextID _contextId
Definition: thread_state.hh:138
decoder
output decoder
Definition: nop.cc:61
SimpleThread::halt
void halt() override
Set the status to Halted.
Definition: simple_thread.cc:161
CheckpointIn
Definition: serialize.hh:67
BaseISA
Definition: isa.hh:47
thread_context.hh
callback.hh
ThreadState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thread_state.cc:60
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17