gem5  v22.1.0.0
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"
50 #include "arch/generic/pcstate.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/VecPredRegs.hh"
61 #include "debug/VecRegs.hh"
62 #include "mem/htm.hh"
63 #include "mem/page_table.hh"
64 #include "mem/request.hh"
65 #include "sim/byteswap.hh"
66 #include "sim/eventq.hh"
67 #include "sim/full_system.hh"
68 #include "sim/process.hh"
69 #include "sim/serialize.hh"
70 #include "sim/system.hh"
71 
72 namespace gem5
73 {
74 
75 class BaseCPU;
76 class CheckerCPU;
77 
92 class SimpleThread : public ThreadState, public ThreadContext
93 {
94  public:
96 
97  protected:
98  std::array<RegFile, CCRegClass + 1> regFiles;
99 
100  BaseISA *const isa; // one "instance" of the current ISA.
101 
102  std::unique_ptr<PCStateBase> _pcState;
103 
104  // hardware transactional memory
105  std::unique_ptr<BaseHTMCheckpoint> _htmCheckpoint;
106 
108  bool predicate;
109 
112 
113  public:
114  std::string
115  name() const
116  {
117  return csprintf("%s.[tid:%i]", baseCpu->name(), threadId());
118  }
119 
126 
128 
130 
132 
133  // hardware transactional memory
136 
137  // constructor: initialize SimpleThread from given process structure
138  // FS
139  SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
140  BaseMMU *_mmu, BaseISA *_isa, InstDecoder *_decoder);
141  // SE
142  SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
143  Process *_process, BaseMMU *_mmu,
144  BaseISA *_isa, InstDecoder *_decoder);
145 
146  virtual ~SimpleThread() {}
147 
148  void takeOverFrom(ThreadContext *oldContext) override;
149 
150  void copyState(ThreadContext *oldContext);
151 
152  void serialize(CheckpointOut &cp) const override;
153  void unserialize(CheckpointIn &cp) override;
154 
155  /***************************************************************
156  * SimpleThread functions to provide CPU with access to various
157  * state.
158  **************************************************************/
159 
164  ThreadContext *getTC() { return this; }
165 
166  void
167  demapPage(Addr vaddr, uint64_t asn)
168  {
169  mmu->demapPage(vaddr, asn);
170  }
171 
172  /*******************************************
173  * ThreadContext interface functions.
174  ******************************************/
175 
176  bool schedule(PCEvent *e) override { return pcEventQueue.schedule(e); }
177  bool remove(PCEvent *e) override { return pcEventQueue.remove(e); }
178 
179  void
181  {
183  }
184  void
186  {
188  }
189  Tick
191  {
192  return comInstEventQueue.getCurTick();
193  }
194 
195  BaseCPU *getCpuPtr() override { return baseCpu; }
196 
197  int cpuId() const override { return ThreadState::cpuId(); }
198  uint32_t socketId() const override { return ThreadState::socketId(); }
199  int threadId() const override { return ThreadState::threadId(); }
200  void setThreadId(int id) override { ThreadState::setThreadId(id); }
201  ContextID contextId() const override { return ThreadState::contextId(); }
203 
204  BaseMMU *getMMUPtr() override { return mmu; }
205 
206  CheckerCPU *getCheckerCpuPtr() override { return NULL; }
207 
208  BaseISA *getIsaPtr() const override { return isa; }
209 
210  InstDecoder *getDecoderPtr() override { return decoder; }
211 
212  System *getSystemPtr() override { return system; }
213 
216 
217  Status status() const override { return _status; }
218 
219  void setStatus(Status newStatus) override { _status = newStatus; }
220 
222  void activate() override;
223 
225  void suspend() override;
226 
228  void halt() override;
229 
230  Tick
231  readLastActivate() override
232  {
234  }
235  Tick
236  readLastSuspend() override
237  {
239  }
240 
241  void copyArchRegs(ThreadContext *tc) override;
242 
243  void
244  clearArchRegs() override
245  {
246  set(_pcState, isa->newPCState());
247  for (auto &rf: regFiles)
248  rf.clear();
249  isa->clear();
250  }
251 
252  //
253  // New accessors for new decoder.
254  //
255  const PCStateBase &pcState() const override { return *_pcState; }
256  void pcState(const PCStateBase &val) override { set(_pcState, val); }
257 
258  void
259  pcStateNoRecord(const PCStateBase &val) override
260  {
261  set(_pcState, val);
262  }
263 
264  bool readPredicate() const { return predicate; }
265  void setPredicate(bool val) { predicate = val; }
266 
267  RegVal
268  readMiscRegNoEffect(RegIndex misc_reg) const override
269  {
270  return isa->readMiscRegNoEffect(misc_reg);
271  }
272 
273  RegVal
274  readMiscReg(RegIndex misc_reg) override
275  {
276  return isa->readMiscReg(misc_reg);
277  }
278 
279  void
280  setMiscRegNoEffect(RegIndex misc_reg, RegVal val) override
281  {
282  return isa->setMiscRegNoEffect(misc_reg, val);
283  }
284 
285  void
286  setMiscReg(RegIndex misc_reg, RegVal val) override
287  {
288  return isa->setMiscReg(misc_reg, val);
289  }
290 
291  unsigned readStCondFailures() const override { return storeCondFailures; }
292 
293  bool
295  {
296  return memAccPredicate;
297  }
298 
299  void
301  {
303  }
304 
305  void
306  setStCondFailures(unsigned sc_failures) override
307  {
308  storeCondFailures = sc_failures;
309  }
310 
311  RegVal
312  getReg(const RegId &arch_reg) const override
313  {
314  const RegId reg = arch_reg.flatten(*isa);
315 
316  const RegIndex idx = reg.index();
317 
318  const auto &reg_file = regFiles[reg.classValue()];
319  const auto &reg_class = reg_file.regClass;
320 
321  RegVal val = reg_file.reg(idx);
322  DPRINTFV(reg_class.debug(), "Reading %s reg %s (%d) as %#x.\n",
323  reg.className(), reg_class.regName(arch_reg), idx, val);
324  return val;
325  }
326 
327  void
328  getReg(const RegId &arch_reg, void *val) const override
329  {
330  const RegId reg = arch_reg.flatten(*isa);
331 
332  const RegIndex idx = reg.index();
333 
334  const auto &reg_file = regFiles[reg.classValue()];
335  const auto &reg_class = reg_file.regClass;
336 
337  reg_file.get(idx, val);
338  DPRINTFV(reg_class.debug(), "Reading %s register %s (%d) as %s.\n",
339  reg.className(), reg_class.regName(arch_reg), idx,
340  reg_class.valString(val));
341  }
342 
343  void *
344  getWritableReg(const RegId &arch_reg) override
345  {
346  const RegId reg = arch_reg.flatten(*isa);
347  const RegIndex idx = reg.index();
348  auto &reg_file = regFiles[reg.classValue()];
349 
350  return reg_file.ptr(idx);
351  }
352 
353  void
354  setReg(const RegId &arch_reg, RegVal val) override
355  {
356  const RegId reg = arch_reg.flatten(*isa);
357 
358  if (reg.is(InvalidRegClass))
359  return;
360 
361  const RegIndex idx = reg.index();
362 
363  auto &reg_file = regFiles[reg.classValue()];
364  const auto &reg_class = reg_file.regClass;
365 
366  DPRINTFV(reg_class.debug(), "Setting %s register %s (%d) to %#x.\n",
367  reg.className(), reg_class.regName(arch_reg), idx, val);
368  reg_file.reg(idx) = val;
369  }
370 
371  void
372  setReg(const RegId &arch_reg, const void *val) override
373  {
374  const RegId reg = arch_reg.flatten(*isa);
375 
376  const RegIndex idx = reg.index();
377 
378  auto &reg_file = regFiles[reg.classValue()];
379  const auto &reg_class = reg_file.regClass;
380 
381  DPRINTFV(reg_class.debug(), "Setting %s register %s (%d) to %s.\n",
382  reg.className(), reg_class.regName(arch_reg), idx,
383  reg_class.valString(val));
384  reg_file.set(idx, val);
385  }
386 
387  // hardware transactional memory
388  void htmAbortTransaction(uint64_t htm_uid,
389  HtmFailureFaultCause cause) override;
390 
392  void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override;
393 };
394 
395 } // namespace gem5
396 
397 #endif // __CPU_SIMPLE_THREAD_HH__
Generic definitions for hardware transactional memory.
#define DPRINTFV(x,...)
Definition: trace.hh:207
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
virtual void setMiscReg(RegIndex idx, RegVal val)=0
virtual RegVal readMiscReg(RegIndex idx)=0
virtual void clear()
Definition: isa.hh:71
virtual RegVal readMiscRegNoEffect(RegIndex idx) const =0
virtual void setMiscRegNoEffect(RegIndex idx, RegVal val)=0
virtual PCStateBase * newPCState(Addr new_inst_addr=0) const =0
void demapPage(Addr vaddr, uint64_t asn)
Definition: mmu.cc:97
CheckerCPU class.
Definition: cpu.hh:85
Queue of events sorted in time order.
Definition: eventq.hh:623
virtual std::string name() const
Definition: named.hh:47
bool remove(PCEvent *event) override
Definition: pc_event.cc:51
bool schedule(PCEvent *event) override
Definition: pc_event.cc:71
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
RegId flatten(const BaseISA &isa) const
Definition: reg_class.hh:277
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
void setReg(const RegId &arch_reg, const void *val) override
RegVal readMiscRegNoEffect(RegIndex misc_reg) const override
int threadId() const override
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
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)
BaseCPU * getCpuPtr() override
const PCStateBase & pcState() const override
Status status() const override
System * getSystemPtr() override
void pcState(const PCStateBase &val) override
PCEventQueue pcEventQueue
void suspend() override
Set the status to Suspended.
void setProcessPtr(Process *p) override
BaseISA * getIsaPtr() const 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
CheckerCPU * getCheckerCpuPtr() override
InstDecoder * getDecoderPtr() override
EventQueue comInstEventQueue
An instruction-based event queue.
void setStCondFailures(unsigned sc_failures) override
void pcStateNoRecord(const PCStateBase &val) override
std::array< RegFile, CCRegClass+1 > regFiles
std::unique_ptr< PCStateBase > _pcState
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 * getWritableReg(const RegId &arch_reg) override
void takeOverFrom(ThreadContext *oldContext) override
Process * getProcessPtr() override
void setStatus(Status newStatus) override
void setThreadId(int id) override
void getReg(const RegId &arch_reg, void *val) const 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
int64_t htmTransactionStarts
bool schedule(PCEvent *e) override
InstDecoder * decoder
void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) 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)
RegVal getReg(const RegId &arch_reg) const override
BaseMMU * getMMUPtr() 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.
void schedule(Event *event, Tick when, bool global=false)
Schedule the given event on this queue.
Definition: eventq.hh:764
void deschedule(Event *event)
Deschedule the specified event.
Definition: eventq.hh:797
Tick getCurTick() const
While curTick() is useful for any object assigned to this event queue, if an object that is assigned ...
Definition: eventq.hh:857
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
Bitfield< 10, 5 > event
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 16 > rf
Definition: misc.hh:568
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint16_t RegIndex
Definition: types.hh:176
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
uint64_t RegVal
Definition: types.hh:173
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:125
HtmFailureFaultCause
Definition: htm.hh:48
@ InvalidRegClass
Definition: reg_class.hh:69
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 ...
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:48
ThreadID threadId() const
Definition: thread_state.hh:69
int cpuId() const
Definition: thread_state.hh:59
Tick readLastActivate() const
Definition: thread_state.hh:71
Process * getProcessPtr()
Definition: thread_state.hh:75
unsigned storeCondFailures
Tick readLastSuspend() const
Definition: thread_state.hh:73
void setProcessPtr(Process *p)
Definition: thread_state.hh:77
uint32_t socketId() const
Definition: thread_state.hh:61
ContextID contextId() const
Definition: thread_state.hh:63
ThreadContext::Status _status
void setContextId(ContextID id)
Definition: thread_state.hh:65
void setThreadId(ThreadID id)
Definition: thread_state.hh:67

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