gem5  v19.0.0.0
thread_context.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012, 2016-2018 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) 2004-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  * Authors: Kevin Lim
42  */
43 
44 #ifndef __CPU_O3_THREAD_CONTEXT_HH__
45 #define __CPU_O3_THREAD_CONTEXT_HH__
46 
47 #include "config/the_isa.hh"
48 #include "cpu/o3/isa_specific.hh"
49 #include "cpu/thread_context.hh"
50 
51 class EndQuiesceEvent;
52 namespace Kernel {
53  class Statistics;
54 }
55 
69 template <class Impl>
70 class O3ThreadContext : public ThreadContext
71 {
72  public:
73  typedef typename Impl::O3CPU O3CPU;
74 
76  O3CPU *cpu;
77 
78  bool
79  schedule(PCEvent *e) override
80  {
81  return thread->pcEventQueue.schedule(e);
82  }
83  bool
84  remove(PCEvent *e) override
85  {
86  return thread->pcEventQueue.remove(e);
87  }
88 
89  void
91  {
92  thread->comInstEventQueue.schedule(event, count);
93  }
94  void
96  {
97  thread->comInstEventQueue.deschedule(event);
98  }
99  Tick
101  {
102  return thread->comInstEventQueue.getCurTick();
103  }
104 
107 
109  BaseTLB *getITBPtr() override { return cpu->itb; }
110 
112  BaseTLB *getDTBPtr() override { return cpu->dtb; }
113 
114  CheckerCPU *getCheckerCpuPtr() override { return NULL; }
115 
116  BaseISA *
117  getIsaPtr() override
118  {
119  return cpu->isa[thread->threadId()];
120  }
121 
122  TheISA::Decoder *
123  getDecoderPtr() override
124  {
125  return cpu->fetch.decoder[thread->threadId()];
126  }
127 
129  BaseCPU *getCpuPtr() override { return cpu; }
130 
132  int cpuId() const override { return cpu->cpuId(); }
133 
135  uint32_t socketId() const override { return cpu->socketId(); }
136 
137  ContextID contextId() const override { return thread->contextId(); }
138 
139  void setContextId(ContextID id) override { thread->setContextId(id); }
140 
142  int threadId() const override { return thread->threadId(); }
143  void setThreadId(int id) override { return thread->setThreadId(id); }
144 
146  System *getSystemPtr() override { return cpu->system; }
147 
150  getKernelStats() override
151  {
152  return thread->kernelStats;
153  }
154 
156  Process *getProcessPtr() override { return thread->getProcessPtr(); }
157 
158  void setProcessPtr(Process *p) override { thread->setProcessPtr(p); }
159 
160  PortProxy &getPhysProxy() override { return thread->getPhysProxy(); }
161 
162  PortProxy &getVirtProxy() override;
163 
164  void
166  {
167  thread->initMemProxies(tc);
168  }
169 
171  Status status() const override { return thread->status(); }
172 
174  void
175  setStatus(Status new_status) override
176  {
177  thread->setStatus(new_status);
178  }
179 
181  void activate() override;
182 
184  void suspend() override;
185 
187  void halt() override;
188 
192  void dumpFuncProfile() override;
193 
195  void takeOverFrom(ThreadContext *old_context) override;
196 
198  void regStats(const std::string &name) override;
199 
201  Tick readLastActivate() override;
203  Tick readLastSuspend() override;
204 
206  void profileClear() override;
208  void profileSample() override;
209 
211  void copyArchRegs(ThreadContext *tc) override;
212 
214  void clearArchRegs() override;
215 
217  RegVal
218  readReg(RegIndex reg_idx)
219  {
220  return readIntRegFlat(flattenRegId(RegId(IntRegClass,
221  reg_idx)).index());
222  }
223  RegVal
224  readIntReg(RegIndex reg_idx) const override
225  {
226  return readIntRegFlat(flattenRegId(RegId(IntRegClass,
227  reg_idx)).index());
228  }
229 
230  RegVal
231  readFloatReg(RegIndex reg_idx) const override
232  {
233  return readFloatRegFlat(flattenRegId(RegId(FloatRegClass,
234  reg_idx)).index());
235  }
236 
237  const VecRegContainer &
238  readVecReg(const RegId& id) const override
239  {
240  return readVecRegFlat(flattenRegId(id).index());
241  }
242 
247  getWritableVecReg(const RegId& id) override
248  {
249  return getWritableVecRegFlat(flattenRegId(id).index());
250  }
251 
256  readVec8BitLaneReg(const RegId& id) const override
257  {
258  return readVecLaneFlat<uint8_t>(flattenRegId(id).index(),
259  id.elemIndex());
260  }
261 
264  readVec16BitLaneReg(const RegId& id) const override
265  {
266  return readVecLaneFlat<uint16_t>(flattenRegId(id).index(),
267  id.elemIndex());
268  }
269 
272  readVec32BitLaneReg(const RegId& id) const override
273  {
274  return readVecLaneFlat<uint32_t>(flattenRegId(id).index(),
275  id.elemIndex());
276  }
277 
280  readVec64BitLaneReg(const RegId& id) const override
281  {
282  return readVecLaneFlat<uint64_t>(flattenRegId(id).index(),
283  id.elemIndex());
284  }
285 
287  void
289  const LaneData<LaneSize::Byte>& val) override
290  {
291  return setVecLaneFlat(flattenRegId(reg).index(), reg.elemIndex(), val);
292  }
293  void
295  const LaneData<LaneSize::TwoByte>& val) override
296  {
297  return setVecLaneFlat(flattenRegId(reg).index(), reg.elemIndex(), val);
298  }
299  void
301  const LaneData<LaneSize::FourByte>& val) override
302  {
303  return setVecLaneFlat(flattenRegId(reg).index(), reg.elemIndex(), val);
304  }
305  void
307  const LaneData<LaneSize::EightByte>& val) override
308  {
309  return setVecLaneFlat(flattenRegId(reg).index(), reg.elemIndex(), val);
310  }
313  const VecElem &
314  readVecElem(const RegId& reg) const override
315  {
316  return readVecElemFlat(flattenRegId(reg).index(), reg.elemIndex());
317  }
318 
319  const VecPredRegContainer &
320  readVecPredReg(const RegId& id) const override
321  {
322  return readVecPredRegFlat(flattenRegId(id).index());
323  }
324 
326  getWritableVecPredReg(const RegId& id) override
327  {
328  return getWritableVecPredRegFlat(flattenRegId(id).index());
329  }
330 
331  RegVal
332  readCCReg(RegIndex reg_idx) const override
333  {
334  return readCCRegFlat(flattenRegId(RegId(CCRegClass,
335  reg_idx)).index());
336  }
337 
339  void
340  setIntReg(RegIndex reg_idx, RegVal val) override
341  {
342  setIntRegFlat(flattenRegId(RegId(IntRegClass, reg_idx)).index(), val);
343  }
344 
345  void
346  setFloatReg(RegIndex reg_idx, RegVal val) override
347  {
348  setFloatRegFlat(flattenRegId(RegId(FloatRegClass,
349  reg_idx)).index(), val);
350  }
351 
352  void
353  setVecReg(const RegId& reg, const VecRegContainer& val) override
354  {
355  setVecRegFlat(flattenRegId(reg).index(), val);
356  }
357 
358  void
359  setVecElem(const RegId& reg, const VecElem& val) override
360  {
361  setVecElemFlat(flattenRegId(reg).index(), reg.elemIndex(), val);
362  }
363 
364  void
366  const VecPredRegContainer& val) override
367  {
368  setVecPredRegFlat(flattenRegId(reg).index(), val);
369  }
370 
371  void
372  setCCReg(RegIndex reg_idx, RegVal val) override
373  {
374  setCCRegFlat(flattenRegId(RegId(CCRegClass, reg_idx)).index(), val);
375  }
376 
379  pcState() const override
380  {
381  return cpu->pcState(thread->threadId());
382  }
383 
385  void pcState(const TheISA::PCState &val) override;
386 
387  void pcStateNoRecord(const TheISA::PCState &val) override;
388 
390  Addr
391  instAddr() const override
392  {
393  return cpu->instAddr(thread->threadId());
394  }
395 
397  Addr
398  nextInstAddr() const override
399  {
400  return cpu->nextInstAddr(thread->threadId());
401  }
402 
404  MicroPC
405  microPC() const override
406  {
407  return cpu->microPC(thread->threadId());
408  }
409 
411  RegVal
412  readMiscRegNoEffect(RegIndex misc_reg) const override
413  {
414  return cpu->readMiscRegNoEffect(misc_reg, thread->threadId());
415  }
416 
419  RegVal
420  readMiscReg(RegIndex misc_reg) override
421  {
422  return cpu->readMiscReg(misc_reg, thread->threadId());
423  }
424 
426  void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) override;
427 
430  void setMiscReg(RegIndex misc_reg, RegVal val) override;
431 
432  RegId flattenRegId(const RegId& regId) const override;
433 
435  // @todo: Figure out where these store cond failures should go.
436  unsigned
437  readStCondFailures() const override
438  {
439  return thread->storeCondFailures;
440  }
441 
443  void
444  setStCondFailures(unsigned sc_failures) override
445  {
446  thread->storeCondFailures = sc_failures;
447  }
448 
450  void
451  syscall(Fault *fault) override
452  {
453  return cpu->syscall(thread->threadId(), fault);
454  }
455 
457  Counter readFuncExeInst() const override { return thread->funcExeInst; }
458 
461  getQuiesceEvent() override
462  {
463  return this->thread->quiesceEvent;
464  }
470  inline void
472  {
473  if (!thread->trapPending && !thread->noSquashFromTC)
474  cpu->squashFromTC(thread->threadId());
475  }
476 
477  RegVal readIntRegFlat(RegIndex idx) const override;
478  void setIntRegFlat(RegIndex idx, RegVal val) override;
479 
480  RegVal readFloatRegFlat(RegIndex idx) const override;
481  void setFloatRegFlat(RegIndex idx, RegVal val) override;
482 
483  const VecRegContainer& readVecRegFlat(RegIndex idx) const override;
485  VecRegContainer& getWritableVecRegFlat(RegIndex idx) override;
486  void setVecRegFlat(RegIndex idx, const VecRegContainer& val) override;
487 
488  template <typename VecElem>
490  readVecLaneFlat(RegIndex idx, int lId) const
491  {
492  return cpu->template readArchVecLane<VecElem>(idx, lId,
493  thread->threadId());
494  }
495 
496  template <typename LD>
497  void
498  setVecLaneFlat(int idx, int lId, const LD& val)
499  {
500  cpu->template setArchVecLane(idx, lId, thread->threadId(), val);
501  }
502 
503  const VecElem &readVecElemFlat(RegIndex idx,
504  const ElemIndex& elemIndex) const override;
505  void setVecElemFlat(RegIndex idx, const ElemIndex& elemIdx,
506  const VecElem& val) override;
507 
508  const VecPredRegContainer& readVecPredRegFlat(RegIndex idx) const override;
509  VecPredRegContainer& getWritableVecPredRegFlat(RegIndex idx) override;
510  void setVecPredRegFlat(RegIndex idx,
511  const VecPredRegContainer& val) override;
512 
513  RegVal readCCRegFlat(RegIndex idx) const override;
514  void setCCRegFlat(RegIndex idx, RegVal val) override;
515 };
516 
517 #endif
count
Definition: misc.hh:705
bool trapPending
Whether or not the thread is currently waiting on a trap, and thus able to be externally updated with...
Definition: thread_state.hh:97
ContextID contextId() const override
RegVal readMiscReg(RegIndex misc_reg) override
Reads a misc.
void setContextId(ContextID id)
Definition: thread_state.hh:76
const VecPredRegContainer & readVecPredReg(const RegId &id) const override
Bitfield< 30, 0 > index
CheckerCPU * getCheckerCpuPtr() override
TheISA::VecElem VecElem
Bitfield< 5, 3 > reg
Definition: types.hh:89
const std::string & name()
Definition: trace.cc:54
Floating-point register.
Definition: reg_class.hh:58
CheckerCPU class.
Definition: cpu.hh:87
Class that has various thread state, such as the status, the current instruction being processed...
Definition: commit.hh:59
BaseTLB * getDTBPtr() override
Returns a pointer to the DTB.
void setVecLane(const RegId &reg, const LaneData< LaneSize::EightByte > &val) override
PortProxy & getPhysProxy()
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
Status status() const override
Returns this thread&#39;s status.
void setIntReg(RegIndex reg_idx, RegVal val) override
Sets an integer register to a value.
RegVal readFloatReg(RegIndex reg_idx) const override
Counter funcExeInst
uint64_t RegVal
Definition: types.hh:168
Definition: system.hh:77
::Kernel::Statistics * getKernelStats() override
Returns a pointer to this thread&#39;s kernel statistics.
void setThreadId(ThreadID id)
Definition: thread_state.hh:78
Counter readFuncExeInst() const override
Reads the funcExeInst counter.
void setCCReg(RegIndex reg_idx, RegVal val) override
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Event for timing out quiesce instruction.
EndQuiesceEvent * quiesceEvent
Process * getProcessPtr() override
Returns a pointer to this thread&#39;s process.
void setVecLane(const RegId &reg, const LaneData< LaneSize::Byte > &val) override
Write a lane of the destination vector register.
Bitfield< 63 > val
Definition: misc.hh:771
int cpuId() const override
Reads this CPU&#39;s ID.
PortProxy & getPhysProxy() override
void setStatus(Status new_status)
Sets the status of this thread.
RegVal readCCReg(RegIndex reg_idx) const override
const RegIndex & elemIndex() const
Elem accessor.
Definition: reg_class.hh:204
void setThreadId(int id) override
bool schedule(PCEvent *e) override
void setFloatReg(RegIndex reg_idx, RegVal val) override
Definition: tlb.hh:52
LaneSize is an abstraction of a LS byte value for the execution and thread contexts to handle values ...
Definition: vec_reg.hh:457
ConstVecLane16 readVec16BitLaneReg(const RegId &id) const override
Reads source vector 16bit operand.
ContextID contextId() const
Definition: thread_state.hh:74
uint16_t RegIndex
Definition: types.hh:42
void setProcessPtr(Process *p)
VecLaneT< VecElem, true > readVecLaneFlat(RegIndex idx, int lId) const
uint64_t Tick
Tick count type.
Definition: types.hh:63
Addr instAddr() const override
Reads this thread&#39;s PC.
const VecElem & readVecElem(const RegId &reg) const override
void setStCondFailures(unsigned sc_failures) override
Sets the number of consecutive store conditional failures.
TheISA::PCState pcState() const override
Reads this thread&#39;s PC state.
Kernel::Statistics * kernelStats
Condition-code register.
Definition: reg_class.hh:64
void setStatus(Status new_status) override
Sets this thread&#39;s status.
const VecRegContainer & readVecReg(const RegId &id) const override
uint16_t MicroPC
Definition: types.hh:144
ConstVecLane8 readVec8BitLaneReg(const RegId &id) const override
Vector Register Lane Interfaces.
TheISA::Decoder * getDecoderPtr() override
ConstVecLane64 readVec64BitLaneReg(const RegId &id) const override
Reads source vector 64bit operand.
ThreadID threadId() const
Definition: thread_state.hh:80
void descheduleInstCountEvent(Event *event) override
EndQuiesceEvent * getQuiesceEvent() override
Returns pointer to the quiesce event.
void setVecElem(const RegId &reg, const VecElem &val) override
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
void scheduleInstCountEvent(Event *event, Tick count) override
System * getSystemPtr() override
Returns a pointer to the system.
void setVecLane(const RegId &reg, const LaneData< LaneSize::FourByte > &val) override
uint32_t socketId() const override
Reads this CPU&#39;s Socket ID.
int64_t Counter
Statistics counter type.
Definition: types.hh:58
Bitfield< 10, 5 > event
MicroPC microPC() const override
Reads this thread&#39;s next PC.
RegVal readMiscRegNoEffect(RegIndex misc_reg) const override
Reads a miscellaneous register.
void takeOverFrom(ThreadContext &new_tc, ThreadContext &old_tc)
Copy state between thread contexts in preparation for CPU handover.
void initMemProxies(ThreadContext *tc)
Initialise the physical and virtual port proxies and tie them to the data port of the CPU...
void setVecLaneFlat(int idx, int lId, const LD &val)
unsigned readStCondFailures() const override
Returns the number of consecutive store conditional failures.
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
Bitfield< 9 > e
RegVal readReg(RegIndex reg_idx)
Reads an integer register.
void setVecPredReg(const RegId &reg, const VecPredRegContainer &val) override
O3CPU * cpu
Pointer to the CPU.
void syscall(Fault *fault) override
Executes a syscall in SE mode.
BaseISA * getIsaPtr() override
VecRegContainer & getWritableVecReg(const RegId &id) override
Read vector register operand for modification, hierarchical indexing.
Process * getProcessPtr()
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:45
void setVecReg(const RegId &reg, const VecRegContainer &val) override
Definition: eventq.hh:189
BaseTLB * getITBPtr() override
Returns a pointer to the ITB.
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
Generic predicate register container.
Definition: vec_pred_reg.hh:51
Impl::O3CPU O3CPU
Tick getCurrentInstCount() override
void setContextId(ContextID id) override
int threadId() const override
Returns this thread&#39;s ID number.
Derived ThreadContext class for use with the O3CPU.
Definition: cpu.hh:76
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
Integer register.
Definition: reg_class.hh:57
unsigned storeCondFailures
void conditionalSquash()
check if the cpu is currently in state update mode and squash if not.
Definition: isa.hh:35
void initMemProxies(ThreadContext *tc) override
Initialise the physical and virtual port proxies and tie them to the data port of the CPU...
Vector Lane abstraction Another view of a container.
Definition: vec_reg.hh:262
void setVecLane(const RegId &reg, const LaneData< LaneSize::TwoByte > &val) override
Bitfield< 0 > p
Status status() const
Returns the status of this thread.
O3ThreadState< Impl > * thread
Pointer to the thread state that this TC corrseponds to.
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
Addr nextInstAddr() const override
Reads this thread&#39;s next PC.
BaseCPU * getCpuPtr() override
Returns a pointer to this CPU.
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
RegVal readIntReg(RegIndex reg_idx) const override
ConstVecLane32 readVec32BitLaneReg(const RegId &id) const override
Reads source vector 32bit operand.
void setProcessPtr(Process *p) override
Bitfield< 26 > halt
Definition: dt_constants.hh:46
VecPredRegContainer & getWritableVecPredReg(const RegId &id) override

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13