gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
simple_thread.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2012, 2016-2018, 2020 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2001-2006 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef __CPU_SIMPLE_THREAD_HH__
43#define __CPU_SIMPLE_THREAD_HH__
44
45#include <algorithm>
46#include <vector>
47
48#include "arch/generic/htm.hh"
49#include "arch/generic/mmu.hh"
51#include "arch/generic/tlb.hh"
52#include "base/logging.hh"
53#include "base/types.hh"
54#include "cpu/regfile.hh"
55#include "cpu/thread_context.hh"
56#include "cpu/thread_state.hh"
57#include "debug/CCRegs.hh"
58#include "debug/FloatRegs.hh"
59#include "debug/IntRegs.hh"
60#include "debug/MatRegs.hh"
61#include "debug/VecPredRegs.hh"
62#include "debug/VecRegs.hh"
63#include "mem/htm.hh"
64#include "mem/page_table.hh"
65#include "mem/request.hh"
66#include "sim/byteswap.hh"
67#include "sim/eventq.hh"
68#include "sim/full_system.hh"
69#include "sim/process.hh"
70#include "sim/serialize.hh"
71#include "sim/system.hh"
72
73namespace gem5
74{
75
76class BaseCPU;
77class CheckerCPU;
78
92
94{
95 public:
97
98 protected:
99 std::array<RegFile, CCRegClass + 1> regFiles;
100
101 BaseISA *const isa; // one "instance" of the current ISA.
102
103 std::unique_ptr<PCStateBase> _pcState;
104
105 // hardware transactional memory
106 std::unique_ptr<BaseHTMCheckpoint> _htmCheckpoint;
107
110
113
114 public:
115 std::string
116 name() const
117 {
118 return csprintf("%s.[tid:%i]", baseCpu->name(), threadId());
119 }
120
127
129
131
133
134 // hardware transactional memory
137
138 // constructor: initialize SimpleThread from given process structure
139 // FS
140 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
141 BaseMMU *_mmu, BaseISA *_isa, InstDecoder *_decoder);
142 // SE
143 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
144 Process *_process, BaseMMU *_mmu,
145 BaseISA *_isa, InstDecoder *_decoder);
146
147 virtual ~SimpleThread() {}
148
149 void takeOverFrom(ThreadContext *oldContext) override;
150
151 void copyState(ThreadContext *oldContext);
152
153 void serialize(CheckpointOut &cp) const override;
154 void unserialize(CheckpointIn &cp) override;
155
156 /***************************************************************
157 * SimpleThread functions to provide CPU with access to various
158 * state.
159 **************************************************************/
160
165 ThreadContext *getTC() { return this; }
166
167 void
168 demapPage(Addr vaddr, uint64_t asn)
169 {
170 mmu->demapPage(vaddr, asn);
171 }
172
173 /*******************************************
174 * ThreadContext interface functions.
175 ******************************************/
176
177 bool schedule(PCEvent *e) override { return pcEventQueue.schedule(e); }
178 bool remove(PCEvent *e) override { return pcEventQueue.remove(e); }
179
180 void
182 {
183 comInstEventQueue.schedule(event, count);
184 }
185 void
187 {
188 comInstEventQueue.deschedule(event);
189 }
190 Tick
192 {
193 return comInstEventQueue.getCurTick();
194 }
195
196 BaseCPU *getCpuPtr() override { return baseCpu; }
197
198 int cpuId() const override { return ThreadState::cpuId(); }
199 uint32_t socketId() const override { return ThreadState::socketId(); }
200 int threadId() const override { return ThreadState::threadId(); }
201 void setThreadId(int id) override { ThreadState::setThreadId(id); }
202 ContextID contextId() const override { return ThreadState::contextId(); }
204
205 BaseMMU *getMMUPtr() override { return mmu; }
206
207 CheckerCPU *getCheckerCpuPtr() override { return NULL; }
208
209 BaseISA *getIsaPtr() const override { return isa; }
210
211 InstDecoder *getDecoderPtr() override { return decoder; }
212
213 System *getSystemPtr() override { return system; }
214
217
218 Status status() const override { return _status; }
219
220 void setStatus(Status newStatus) override { _status = newStatus; }
221
223 void activate() override;
224
226 void suspend() override;
227
229 void halt() override;
230
231 Tick
233 {
235 }
236 Tick
238 {
240 }
241
242 void copyArchRegs(ThreadContext *tc) override;
243
244 void
245 clearArchRegs() override
246 {
247 set(_pcState, isa->newPCState());
248 for (auto &rf: regFiles)
249 rf.clear();
250 isa->clear();
251 }
252
253 //
254 // New accessors for new decoder.
255 //
256 const PCStateBase &pcState() const override { return *_pcState; }
257 void pcState(const PCStateBase &val) override { set(_pcState, val); }
258
259 void
261 {
262 set(_pcState, val);
263 }
264
265 bool readPredicate() const { return predicate; }
266 void setPredicate(bool val) { predicate = val; }
267
268 RegVal
270 {
271 return isa->readMiscRegNoEffect(misc_reg);
272 }
273
274 RegVal
276 {
277 return isa->readMiscReg(misc_reg);
278 }
279
280 void
282 {
283 return isa->setMiscRegNoEffect(misc_reg, val);
284 }
285
286 void
288 {
289 return isa->setMiscReg(misc_reg, val);
290 }
291
292 unsigned readStCondFailures() const override { return storeCondFailures; }
293
294 bool
296 {
297 return memAccPredicate;
298 }
299
300 void
302 {
304 }
305
306 void
307 setStCondFailures(unsigned sc_failures) override
308 {
309 storeCondFailures = sc_failures;
310 }
311
312 RegVal
313 getReg(const RegId &arch_reg) const override
314 {
315 const RegId reg = arch_reg.flatten(*isa);
316
317 const RegIndex idx = reg.index();
318
319 const auto &reg_file = regFiles[reg.classValue()];
320 const auto &reg_class = reg_file.regClass;
321
322 RegVal val = reg_file.reg(idx);
323 DPRINTFV(reg_class.debug(), "Reading %s reg %s (%d) as %#x.\n",
324 reg.className(), reg_class.regName(arch_reg), idx, val);
325 return val;
326 }
327
328 void
329 getReg(const RegId &arch_reg, void *val) const override
330 {
331 const RegId reg = arch_reg.flatten(*isa);
332
333 const RegIndex idx = reg.index();
334
335 const auto &reg_file = regFiles[reg.classValue()];
336 const auto &reg_class = reg_file.regClass;
337
338 reg_file.get(idx, val);
339 DPRINTFV(reg_class.debug(), "Reading %s register %s (%d) as %s.\n",
340 reg.className(), reg_class.regName(arch_reg), idx,
341 reg_class.valString(val));
342 }
343
344 void *
345 getWritableReg(const RegId &arch_reg) override
346 {
347 const RegId reg = arch_reg.flatten(*isa);
348 const RegIndex idx = reg.index();
349 auto &reg_file = regFiles[reg.classValue()];
350
351 return reg_file.ptr(idx);
352 }
353
354 void
355 setReg(const RegId &arch_reg, RegVal val) override
356 {
357 const RegId reg = arch_reg.flatten(*isa);
358
359 if (reg.is(InvalidRegClass))
360 return;
361
362 const RegIndex idx = reg.index();
363
364 auto &reg_file = regFiles[reg.classValue()];
365 const auto &reg_class = reg_file.regClass;
366
367 DPRINTFV(reg_class.debug(), "Setting %s register %s (%d) to %#x.\n",
368 reg.className(), reg_class.regName(arch_reg), idx, val);
369 reg_file.reg(idx) = val;
370 }
371
372 void
373 setReg(const RegId &arch_reg, const void *val) override
374 {
375 const RegId reg = arch_reg.flatten(*isa);
376
377 const RegIndex idx = reg.index();
378
379 auto &reg_file = regFiles[reg.classValue()];
380 const auto &reg_class = reg_file.regClass;
381
382 DPRINTFV(reg_class.debug(), "Setting %s register %s (%d) to %s.\n",
383 reg.className(), reg_class.regName(arch_reg), idx,
384 reg_class.valString(val));
385 reg_file.set(idx, val);
386 }
387
388 // hardware transactional memory
389 void htmAbortTransaction(uint64_t htm_uid,
390 HtmFailureFaultCause cause) override;
391
393 void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override;
394};
395
396} // namespace gem5
397
398#endif // __CPU_SIMPLE_THREAD_HH__
Generic definitions for hardware transactional memory.
#define DPRINTFV(x,...)
Definition trace.hh:230
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
CheckerCPU class.
Definition cpu.hh:85
Queue of events sorted in time order.
Definition eventq.hh:616
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
RegId flatten(const BaseISA &isa) const
Definition reg_class.hh:285
void setReg(const RegId &arch_reg, const void *val) override
InstDecoder * getDecoderPtr() override
RegVal readMiscRegNoEffect(RegIndex misc_reg) const override
int threadId() const override
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::string name() const
bool readPredicate() const
bool predicate
Did this instruction execute or is it predicated false.
void setPredicate(bool val)
Status status() const override
void pcState(const PCStateBase &val) override
PCEventQueue pcEventQueue
void suspend() override
Set the status to Suspended.
void setProcessPtr(Process *p) override
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
void activate() override
Set the status to Active.
int cpuId() const override
void setContextId(ContextID id) override
bool remove(PCEvent *e) override
EventQueue comInstEventQueue
An instruction-based event queue.
void setStCondFailures(unsigned sc_failures) override
void pcStateNoRecord(const PCStateBase &val) override
BaseCPU * getCpuPtr() override
CheckerCPU * getCheckerCpuPtr() override
std::array< RegFile, CCRegClass+1 > regFiles
std::unique_ptr< PCStateBase > _pcState
System * getSystemPtr() override
const PCStateBase & pcState() const override
void setMiscReg(RegIndex misc_reg, RegVal val) override
void copyState(ThreadContext *oldContext)
void copyArchRegs(ThreadContext *tc) override
void demapPage(Addr vaddr, uint64_t asn)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
BaseISA *const isa
void clearArchRegs() override
ThreadContext::Status Status
void takeOverFrom(ThreadContext *oldContext) override
void setStatus(Status newStatus) override
void setThreadId(int id) override
void getReg(const RegId &arch_reg, void *val) const override
void * getWritableReg(const RegId &arch_reg) override
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
ContextID contextId() const override
Tick getCurrentInstCount() override
Tick readLastSuspend() override
std::unique_ptr< BaseHTMCheckpoint > _htmCheckpoint
unsigned readStCondFailures() const override
void descheduleInstCountEvent(Event *event) override
bool memAccPredicate
True if the memory access should be skipped for this instruction.
void setReg(const RegId &arch_reg, RegVal val) override
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
Process * getProcessPtr() override
bool schedule(PCEvent *e) override
InstDecoder * decoder
void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) override
BaseMMU * getMMUPtr() override
RegVal readMiscReg(RegIndex misc_reg) override
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
void setMemAccPredicate(bool val)
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
RegVal getReg(const RegId &arch_reg) const override
void scheduleInstCountEvent(Event *event, Tick count) override
uint32_t socketId() const override
Tick readLastActivate() override
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 12, 11 > set
Bitfield< 10, 5 > event
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 16 > rf
Definition misc.hh:578
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint16_t RegIndex
Definition types.hh:176
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
int ContextID
Globally unique thread context ID.
Definition types.hh:239
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition htm.hh:127
HtmFailureFaultCause
Definition htm.hh:48
@ InvalidRegClass
Definition reg_class.hh:71
Declarations of a non-full system Page Table.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process)
ThreadID threadId() const
int cpuId() const
Tick readLastActivate() const
unsigned storeCondFailures
Tick readLastSuspend() const
void setProcessPtr(Process *p)
uint32_t socketId() const
ContextID contextId() const
ThreadContext::Status _status
void setContextId(ContextID id)
Process * getProcessPtr()
void setThreadId(ThreadID id)

Generated on Mon May 26 2025 09:19:08 for gem5 by doxygen 1.13.2