gem5  v21.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, 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 // constructor
66 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
67  Process *_process, BaseMMU *_mmu,
68  BaseISA *_isa)
69  : ThreadState(_cpu, _thread_num, _process),
70  isa(dynamic_cast<TheISA::ISA *>(_isa)),
71  predicate(true), memAccPredicate(true),
72  comInstEventQueue("instruction-based event queue"),
73  system(_sys), mmu(_mmu), decoder(isa),
74  htmTransactionStarts(0), htmTransactionStops(0)
75 {
76  assert(isa);
77  clearArchRegs();
78 }
79 
80 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
81  BaseMMU *_mmu, BaseISA *_isa)
82  : ThreadState(_cpu, _thread_num, NULL),
83  isa(dynamic_cast<TheISA::ISA *>(_isa)),
84  predicate(true), memAccPredicate(true),
85  comInstEventQueue("instruction-based event queue"),
86  system(_sys), mmu(_mmu), decoder(isa),
87  htmTransactionStarts(0), htmTransactionStops(0)
88 {
89  assert(isa);
90 
91  clearArchRegs();
92 }
93 
94 void
96 {
97  ::takeOverFrom(*this, *oldContext);
98  decoder.takeOverFrom(oldContext->getDecoderPtr());
99 
100  isa->takeOverFrom(this, oldContext);
101 
102  funcExeInst = oldContext->readFuncExeInst();
103  storeCondFailures = 0;
104 }
105 
106 void
108 {
109  // copy over functional state
110  _status = oldContext->status();
111  copyArchRegs(oldContext);
112  if (FullSystem)
113  funcExeInst = oldContext->readFuncExeInst();
114 
115  _threadId = oldContext->threadId();
116  _contextId = oldContext->contextId();
117 }
118 
119 void
121 {
123  ::serialize(*this, cp);
124 }
125 
126 
127 void
129 {
131  ::unserialize(*this, cp);
132 }
133 
134 void
136 {
137  if (status() == ThreadContext::Active)
138  return;
139 
140  lastActivate = curTick();
143 }
144 
145 void
147 {
149  return;
150 
151  lastActivate = curTick();
152  lastSuspend = curTick();
155 }
156 
157 
158 void
160 {
161  if (status() == ThreadContext::Halted)
162  return;
163 
166 }
167 
168 void
170 {
171  TheISA::copyRegs(src_tc, this);
172 }
173 
174 // hardware transactional memory
175 void
177 {
178  BaseSimpleCPU *baseSimpleCpu = dynamic_cast<BaseSimpleCPU*>(baseCpu);
179  assert(baseSimpleCpu);
180 
181  baseSimpleCpu->htmSendAbortSignal(cause);
182 
183  // these must be reset after the abort signal has been sent
186 }
187 
190 {
191  return _htmCheckpoint;
192 }
193 
194 void
196 {
197  _htmCheckpoint = std::move(new_cpt);
198 }
SimpleThread::clearArchRegs
void clearArchRegs() override
Definition: simple_thread.hh:253
SimpleThread::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: simple_thread.cc:120
SimpleThread::htmAbortTransaction
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
Definition: simple_thread.cc:176
ArmISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:75
ThreadState::funcExeInst
Counter funcExeInst
Definition: thread_state.hh:166
SimpleThread::getHtmCheckpointPtr
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
Definition: simple_thread.cc:189
system.hh
BaseMMU
Definition: mmu.hh:45
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: thread_context.hh:52
translating_port_proxy.hh
SimpleThread::suspend
void suspend() override
Set the status to Suspended.
Definition: simple_thread.cc:146
ThreadContext::readFuncExeInst
virtual Counter readFuncExeInst() const =0
SimpleThread::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: simple_thread.cc:128
SimpleThread::isa
TheISA::ISA *const isa
Definition: simple_thread.hh:102
SimpleThread::setHtmCheckpointPtr
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
Definition: simple_thread.cc:195
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:204
HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:44
SimpleThread::status
Status status() const override
Definition: simple_thread.hh:226
faults.hh
sim_exit.hh
output.hh
SimpleThread::decoder
TheISA::Decoder decoder
Definition: simple_thread.hh:132
ThreadContext::threadId
virtual int threadId() const =0
SimpleThread::_htmCheckpoint
std::unique_ptr< BaseHTMCheckpoint > _htmCheckpoint
Definition: simple_thread.hh:107
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
SimpleThread::SimpleThread
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, BaseMMU *_mmu, BaseISA *_isa)
Definition: simple_thread.cc:80
cp
Definition: cprintf.cc:37
SimpleThread::htmTransactionStops
int64_t htmTransactionStops
Definition: simple_thread.hh:136
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:95
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:116
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:484
SimpleThread::copyState
void copyState(ThreadContext *oldContext)
Definition: simple_thread.cc:107
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:169
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:135
full_system.hh
BaseCPU
Definition: base.hh:104
base.hh
ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:107
simple_thread.hh
BaseCPU::haltContext
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
Definition: base.cc:524
base.hh
SimpleThread::htmTransactionStarts
int64_t htmTransactionStarts
Definition: simple_thread.hh:135
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:103
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
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:498
se_translating_port_proxy.hh
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
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:159
CheckpointIn
Definition: serialize.hh:68
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

Generated on Tue Mar 23 2021 19:41:25 for gem5 by doxygen 1.8.17