gem5  v22.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/generic/decoder.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 "cpu/base.hh"
52 #include "cpu/simple/base.hh"
53 #include "cpu/thread_context.hh"
56 #include "params/BaseCPU.hh"
57 #include "sim/faults.hh"
58 #include "sim/full_system.hh"
59 #include "sim/process.hh"
60 #include "sim/serialize.hh"
61 #include "sim/sim_exit.hh"
62 #include "sim/system.hh"
63 
64 namespace gem5
65 {
66 
67 // constructor
68 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
69  Process *_process, BaseMMU *_mmu,
70  BaseISA *_isa, InstDecoder *_decoder)
71  : ThreadState(_cpu, _thread_num, _process),
72  regFiles{{
73  {*_isa->regClasses().at(IntRegClass)},
74  {*_isa->regClasses().at(FloatRegClass)},
75  {*_isa->regClasses().at(VecRegClass)},
76  {*_isa->regClasses().at(VecElemClass)},
77  {*_isa->regClasses().at(VecPredRegClass)},
78  {*_isa->regClasses().at(CCRegClass)}
79  }},
80  isa(_isa),
81  predicate(true), memAccPredicate(true),
82  comInstEventQueue("instruction-based event queue"),
83  system(_sys), mmu(_mmu), decoder(_decoder),
84  htmTransactionStarts(0), htmTransactionStops(0)
85 {
86  clearArchRegs();
87 }
88 
89 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
90  BaseMMU *_mmu, BaseISA *_isa, InstDecoder *_decoder)
91  : SimpleThread(_cpu, _thread_num, _sys, nullptr, _mmu, _isa, _decoder)
92 {}
93 
94 void
96 {
97  gem5::takeOverFrom(*this, *oldContext);
98  decoder->takeOverFrom(oldContext->getDecoderPtr());
99 
100  isa->takeOverFrom(this, oldContext);
101 
102  storeCondFailures = 0;
103 }
104 
105 void
107 {
108  // copy over functional state
109  _status = oldContext->status();
110  copyArchRegs(oldContext);
111 
112  _threadId = oldContext->threadId();
113  _contextId = oldContext->contextId();
114 }
115 
116 void
118 {
120  gem5::serialize(*this, cp);
121 }
122 
123 
124 void
126 {
128  gem5::unserialize(*this, cp);
129 }
130 
131 void
133 {
134  if (status() == ThreadContext::Active)
135  return;
136 
137  lastActivate = curTick();
140 }
141 
142 void
144 {
146  return;
147 
148  lastActivate = curTick();
149  lastSuspend = curTick();
152 }
153 
154 
155 void
157 {
158  if (status() == ThreadContext::Halted)
159  return;
160 
163 }
164 
165 void
167 {
168  getIsaPtr()->copyRegsFrom(src_tc);
169 }
170 
171 // hardware transactional memory
172 void
174 {
175  baseCpu->htmSendAbortSignal(threadId(), htm_uid, cause);
176 
177  // these must be reset after the abort signal has been sent
180 }
181 
184 {
185  return _htmCheckpoint;
186 }
187 
188 void
190 {
191  _htmCheckpoint = std::move(new_cpt);
192 }
193 
194 } // namespace gem5
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
Definition: base.cc:520
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
Definition: base.cc:494
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
Definition: base.cc:480
virtual void htmSendAbortSignal(ThreadID tid, uint64_t htm_uid, HtmFailureFaultCause cause)
This function is used to instruct the memory subsystem that a transaction should be aborted and the s...
Definition: base.hh:650
const RegClasses & regClasses() const
Definition: isa.hh:86
virtual void copyRegsFrom(ThreadContext *src)=0
virtual void takeOverFrom(ThreadContext *new_tc, ThreadContext *old_tc)
Definition: isa.hh:79
virtual void takeOverFrom(InstDecoder *old)
Take over the state from an old decoder when switching CPUs.
Definition: decoder.hh:89
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
int threadId() const override
void serialize(CheckpointOut &cp) const override
Serialize an object.
Status status() const override
void suspend() override
Set the status to Suspended.
BaseISA * getIsaPtr() const override
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
void activate() override
Set the status to Active.
void copyState(ThreadContext *oldContext)
void copyArchRegs(ThreadContext *tc) override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
BaseISA *const isa
void takeOverFrom(ThreadContext *oldContext) override
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
std::unique_ptr< BaseHTMCheckpoint > _htmCheckpoint
int64_t htmTransactionStarts
InstDecoder * decoder
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
void halt() override
Set the status to Halted.
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, BaseMMU *_mmu, BaseISA *_isa, InstDecoder *_decoder)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
@ Halted
Permanently shut down.
@ Suspended
Temporarily inactive.
virtual InstDecoder * getDecoderPtr()=0
virtual int threadId() const =0
virtual Status status() const =0
virtual ContextID contextId() const =0
Bitfield< 15 > system
Definition: misc.hh:1004
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
std::ostream CheckpointOut
Definition: serialize.hh:66
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:125
HtmFailureFaultCause
Definition: htm.hh:48
@ VecPredRegClass
Definition: reg_class.hh:66
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:67
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:65
output decoder
Definition: nop.cc:61
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:48
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thread_state.cc:54
ContextID _contextId
unsigned storeCondFailures
ThreadContext::Status _status
Tick lastSuspend
Last time suspend was called on this thread.
Tick lastActivate
Last time activate was called on this thread.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thread_state.cc:60

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1