gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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
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/thread_context.hh"
54#include "params/BaseCPU.hh"
55#include "sim/faults.hh"
56#include "sim/full_system.hh"
57#include "sim/process.hh"
58#include "sim/serialize.hh"
59#include "sim/sim_exit.hh"
60#include "sim/system.hh"
61
62namespace gem5
63{
64
65// constructor
66SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
67 Process *_process, BaseMMU *_mmu,
68 BaseISA *_isa, InstDecoder *_decoder)
69 : ThreadState(_cpu, _thread_num, _process),
70 regFiles{{
71 {*_isa->regClasses().at(IntRegClass)},
72 {*_isa->regClasses().at(FloatRegClass)},
73 {*_isa->regClasses().at(VecRegClass)},
74 {*_isa->regClasses().at(VecElemClass)},
75 {*_isa->regClasses().at(VecPredRegClass)},
76 {*_isa->regClasses().at(MatRegClass)},
77 {*_isa->regClasses().at(CCRegClass)}
78 }},
79 isa(_isa),
80 predicate(true), memAccPredicate(true),
81 comInstEventQueue("instruction-based event queue"),
82 system(_sys), mmu(_mmu), decoder(_decoder),
83 htmTransactionStarts(0), htmTransactionStops(0)
84{
85 clearArchRegs();
86}
87
88SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
89 BaseMMU *_mmu, BaseISA *_isa, InstDecoder *_decoder)
90 : SimpleThread(_cpu, _thread_num, _sys, nullptr, _mmu, _isa, _decoder)
91{}
92
93void
95{
96 gem5::takeOverFrom(*this, *oldContext);
97 decoder->takeOverFrom(oldContext->getDecoderPtr());
98
99 isa->takeOverFrom(this, oldContext);
100
102}
103
104void
106{
107 // copy over functional state
108 _status = oldContext->status();
109 copyArchRegs(oldContext);
110
111 _threadId = oldContext->threadId();
112 _contextId = oldContext->contextId();
113}
114
115void
121
122
123void
129
130void
132{
134 return;
135
138 baseCpu->activateContext(_threadId);
139}
140
141void
143{
145 return;
146
150 baseCpu->suspendContext(_threadId);
151}
152
153
154void
156{
158 return;
159
161 baseCpu->haltContext(_threadId);
162}
163
164void
169
170// hardware transactional memory
171void
173{
174 baseCpu->htmSendAbortSignal(threadId(), htm_uid, cause);
175
176 // these must be reset after the abort signal has been sent
179}
180
186
187void
189{
190 _htmCheckpoint = std::move(new_cpt);
191}
192
193} // namespace gem5
const RegClasses & regClasses() const
Definition isa.hh:93
virtual void copyRegsFrom(ThreadContext *src)=0
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.
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
void activate() override
Set the status to Active.
std::array< RegFile, CCRegClass+1 > regFiles
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
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)
BaseISA * getIsaPtr() const override
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
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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:127
HtmFailureFaultCause
Definition htm.hh:48
@ VecPredRegClass
Definition reg_class.hh:67
@ MatRegClass
Matrix Register.
Definition reg_class.hh:68
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ CCRegClass
Condition-code register.
Definition reg_class.hh:69
@ VecRegClass
Vector Register.
Definition reg_class.hh:64
@ IntRegClass
Integer register.
Definition reg_class.hh:61
@ VecElemClass
Vector Register Native Elem lane.
Definition reg_class.hh:66
output decoder
Definition nop.cc:61
ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process)
void serialize(CheckpointOut &cp) const override
Serialize an object.
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.

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0