gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
thread_context.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) 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_THREAD_CONTEXT_HH__
43 #define __CPU_THREAD_CONTEXT_HH__
44 
45 #include <iostream>
46 #include <string>
47 
48 #include "arch/generic/htm.hh"
49 #include "arch/generic/isa.hh"
50 #include "arch/generic/pcstate.hh"
51 #include "base/types.hh"
52 #include "cpu/pc_event.hh"
53 #include "cpu/reg_class.hh"
54 
55 namespace gem5
56 {
57 
58 // @todo: Figure out a more architecture independent way to obtain the ITB and
59 // DTB pointers.
60 class BaseCPU;
61 class BaseMMU;
62 class BaseTLB;
63 class CheckerCPU;
64 class Checkpoint;
65 class InstDecoder;
66 class PortProxy;
67 class Process;
68 class System;
69 class Packet;
70 using PacketPtr = Packet *;
71 
89 {
90  protected:
91  bool useForClone = false;
92 
93  public:
94 
95  bool getUseForClone() { return useForClone; }
96 
97  void setUseForClone(bool new_val) { useForClone = new_val; }
98 
99  enum Status
100  {
104 
108 
112 
117  };
118 
119  virtual ~ThreadContext() { };
120 
121  virtual BaseCPU *getCpuPtr() = 0;
122 
123  virtual int cpuId() const = 0;
124 
125  virtual uint32_t socketId() const = 0;
126 
127  virtual int threadId() const = 0;
128 
129  virtual void setThreadId(int id) = 0;
130 
131  virtual ContextID contextId() const = 0;
132 
133  virtual void setContextId(ContextID id) = 0;
134 
135  virtual BaseMMU *getMMUPtr() = 0;
136 
137  virtual CheckerCPU *getCheckerCpuPtr() = 0;
138 
139  virtual BaseISA *getIsaPtr() const = 0;
140 
141  virtual InstDecoder *getDecoderPtr() = 0;
142 
143  virtual System *getSystemPtr() = 0;
144 
145  virtual void sendFunctional(PacketPtr pkt);
146 
147  virtual Process *getProcessPtr() = 0;
148 
149  virtual void setProcessPtr(Process *p) = 0;
150 
151  virtual Status status() const = 0;
152 
153  virtual void setStatus(Status new_status) = 0;
154 
156  virtual void activate() = 0;
157 
159  virtual void suspend() = 0;
160 
162  virtual void halt() = 0;
163 
165  void quiesce();
166 
168  void quiesceTick(Tick resume);
169 
170  virtual void takeOverFrom(ThreadContext *old_context) = 0;
171 
172  virtual void regStats(const std::string &name) {};
173 
174  virtual void scheduleInstCountEvent(Event *event, Tick count) = 0;
175  virtual void descheduleInstCountEvent(Event *event) = 0;
176  virtual Tick getCurrentInstCount() = 0;
177 
178  // Not necessarily the best location for these...
179  // Having an extra function just to read these is obnoxious
180  virtual Tick readLastActivate() = 0;
181  virtual Tick readLastSuspend() = 0;
182 
183  virtual void copyArchRegs(ThreadContext *tc) = 0;
184 
185  virtual void clearArchRegs() = 0;
186 
187  //
188  // New accessors for new decoder.
189  //
190  virtual RegVal getReg(const RegId &reg) const;
191  virtual void getReg(const RegId &reg, void *val) const = 0;
192  virtual void *getWritableReg(const RegId &reg) = 0;
193 
194  virtual void setReg(const RegId &reg, RegVal val);
195  virtual void setReg(const RegId &reg, const void *val) = 0;
196 
197  virtual const PCStateBase &pcState() const = 0;
198 
199  virtual void pcState(const PCStateBase &val) = 0;
200  void
202  {
203  std::unique_ptr<PCStateBase> new_pc(getIsaPtr()->newPCState(addr));
204  pcState(*new_pc);
205  }
206 
207  virtual void pcStateNoRecord(const PCStateBase &val) = 0;
208 
209  virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const = 0;
210 
211  virtual RegVal readMiscReg(RegIndex misc_reg) = 0;
212 
213  virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) = 0;
214 
215  virtual void setMiscReg(RegIndex misc_reg, RegVal val) = 0;
216 
217  // Also not necessarily the best location for these two. Hopefully will go
218  // away once we decide upon where st cond failures goes.
219  virtual unsigned readStCondFailures() const = 0;
220 
221  virtual void setStCondFailures(unsigned sc_failures) = 0;
222 
223  // This function exits the thread context in the CPU and returns
224  // 1 if the CPU has no more active threads (meaning it's OK to exit);
225  // Used in syscall-emulation mode when a thread calls the exit syscall.
226  virtual int exit() { return 1; };
227 
229  static void compare(ThreadContext *one, ThreadContext *two);
230 
231  // hardware transactional memory
232  virtual void htmAbortTransaction(uint64_t htm_uid,
233  HtmFailureFaultCause cause) = 0;
235  virtual void setHtmCheckpointPtr(BaseHTMCheckpointPtr cpt) = 0;
236 };
237 
248 void serialize(const ThreadContext &tc, CheckpointOut &cp);
249 void unserialize(ThreadContext &tc, CheckpointIn &cp);
250 
264 void takeOverFrom(ThreadContext &new_tc, ThreadContext &old_tc);
265 
266 } // namespace gem5
267 
268 #endif
gem5::unserialize
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Definition: thread_context.cc:222
htm.hh
gem5::ThreadContext::compare
static void compare(ThreadContext *one, ThreadContext *two)
function to compare two thread contexts (for debugging)
Definition: thread_context.cc:60
gem5::ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
gem5::ThreadContext::Active
@ Active
Running.
Definition: thread_context.hh:103
gem5::ThreadContext::getSystemPtr
virtual System * getSystemPtr()=0
gem5::BaseHTMCheckpointPtr
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:125
gem5::ThreadContext::readLastSuspend
virtual Tick readLastSuspend()=0
gem5::ThreadContext::getUseForClone
bool getUseForClone()
Definition: thread_context.hh:95
gem5::RegVal
uint64_t RegVal
Definition: types.hh:173
gem5::ThreadContext::Halted
@ Halted
Permanently shut down.
Definition: thread_context.hh:116
gem5::HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:47
gem5::ThreadContext::getReg
virtual RegVal getReg(const RegId &reg) const
Definition: thread_context.cc:180
gem5::ThreadContext::getMMUPtr
virtual BaseMMU * getMMUPtr()=0
gem5::ThreadContext::pcState
virtual const PCStateBase & pcState() const =0
gem5::ThreadContext::pcState
void pcState(Addr addr)
Definition: thread_context.hh:201
gem5::MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:300
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:776
gem5::ThreadContext::setStatus
virtual void setStatus(Status new_status)=0
gem5::ThreadContext::Status
Status
Definition: thread_context.hh:99
gem5::ThreadContext::contextId
virtual ContextID contextId() const =0
gem5::ThreadContext::activate
virtual void activate()=0
Set the status to Active.
gem5::ThreadContext::regStats
virtual void regStats(const std::string &name)
Definition: thread_context.hh:172
gem5::ThreadContext::halt
virtual void halt()=0
Set the status to Halted.
gem5::ThreadContext::setUseForClone
void setUseForClone(bool new_val)
Definition: thread_context.hh:97
gem5::ThreadContext::cpuId
virtual int cpuId() const =0
gem5::ThreadContext::setProcessPtr
virtual void setProcessPtr(Process *p)=0
gem5::takeOverFrom
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
Definition: thread_context.cc:252
gem5::BaseMMU
Definition: mmu.hh:53
gem5::ThreadContext::status
virtual Status status() const =0
gem5::ThreadContext::getCurrentInstCount
virtual Tick getCurrentInstCount()=0
gem5::ThreadContext::setThreadId
virtual void setThreadId(int id)=0
gem5::ThreadContext::copyArchRegs
virtual void copyArchRegs(ThreadContext *tc)=0
gem5::ThreadContext::quiesceTick
void quiesceTick(Tick resume)
Quiesce, suspend, and schedule activate at resume.
Definition: thread_context.cc:174
gem5::ThreadContext::setHtmCheckpointPtr
virtual void setHtmCheckpointPtr(BaseHTMCheckpointPtr cpt)=0
gem5::System
Definition: system.hh:74
gem5::ThreadContext::socketId
virtual uint32_t socketId() const =0
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::ThreadContext::quiesce
void quiesce()
Quiesce thread context.
Definition: thread_context.cc:167
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::InstDecoder
Definition: decoder.hh:42
gem5::ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:107
gem5::Event
Definition: eventq.hh:254
gem5::ps2::one
Bitfield< 3 > one
Definition: types.hh:120
gem5::X86ISA::count
count
Definition: misc.hh:710
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::ThreadContext::getDecoderPtr
virtual InstDecoder * getDecoderPtr()=0
gem5::probing::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:108
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::CheckerCPU
CheckerCPU class.
Definition: cpu.hh:84
gem5::ThreadContext::readLastActivate
virtual Tick readLastActivate()=0
gem5::BaseCPU
Definition: base.hh:104
gem5::ThreadContext::takeOverFrom
virtual void takeOverFrom(ThreadContext *old_context)=0
gem5::serialize
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
Definition: thread_context.cc:194
gem5::ThreadContext::sendFunctional
virtual void sendFunctional(PacketPtr pkt)
Definition: thread_context.cc:158
gem5::ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
gem5::ThreadContext::getHtmCheckpointPtr
virtual BaseHTMCheckpointPtr & getHtmCheckpointPtr()=0
gem5::ThreadContext::readStCondFailures
virtual unsigned readStCondFailures() const =0
gem5::ThreadContext::getWritableReg
virtual void * getWritableReg(const RegId &reg)=0
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ThreadContext::setContextId
virtual void setContextId(ContextID id)=0
name
const std::string & name()
Definition: trace.cc:48
gem5::ThreadContext::htmAbortTransaction
virtual void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause)=0
gem5::ThreadContext::scheduleInstCountEvent
virtual void scheduleInstCountEvent(Event *event, Tick count)=0
gem5::ThreadContext::useForClone
bool useForClone
Definition: thread_context.hh:91
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
gem5::Process
Definition: process.hh:67
gem5::ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
gem5::ThreadContext::pcStateNoRecord
virtual void pcStateNoRecord(const PCStateBase &val)=0
pcstate.hh
isa.hh
gem5::ThreadContext::suspend
virtual void suspend()=0
Set the status to Suspended.
pc_event.hh
gem5::ThreadContext::descheduleInstCountEvent
virtual void descheduleInstCountEvent(Event *event)=0
types.hh
gem5::ThreadContext::~ThreadContext
virtual ~ThreadContext()
Definition: thread_context.hh:119
gem5::ThreadContext::setMiscReg
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
gem5::ThreadContext::Halting
@ Halting
Trying to exit and waiting for an event to completely exit.
Definition: thread_context.hh:111
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
reg_class.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::ThreadContext::getCpuPtr
virtual BaseCPU * getCpuPtr()=0
gem5::ThreadContext::clearArchRegs
virtual void clearArchRegs()=0
gem5::ThreadContext::threadId
virtual int threadId() const =0
gem5::PCStateBase
Definition: pcstate.hh:57
gem5::ThreadContext::getIsaPtr
virtual BaseISA * getIsaPtr() const =0
gem5::BaseISA
Definition: isa.hh:58
gem5::RegIndex
uint16_t RegIndex
Definition: types.hh:176
gem5::ThreadContext::setStCondFailures
virtual void setStCondFailures(unsigned sc_failures)=0
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::ThreadContext::getCheckerCpuPtr
virtual CheckerCPU * getCheckerCpuPtr()=0
gem5::ThreadContext::exit
virtual int exit()
Definition: thread_context.hh:226
gem5::PCEventScope
Definition: pc_event.hh:67
gem5::RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:92
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
gem5::ThreadContext::setReg
virtual void setReg(const RegId &reg, RegVal val)
Definition: thread_context.cc:188

Generated on Sun Jul 30 2023 01:56:47 for gem5 by doxygen 1.8.17