gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
thread_context.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2016-2017 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 #include "cpu/thread_context.hh"
43 
44 #include <vector>
45 
47 #include "base/logging.hh"
48 #include "base/trace.hh"
49 #include "cpu/base.hh"
50 #include "debug/Context.hh"
51 #include "debug/Quiesce.hh"
52 #include "mem/port.hh"
53 #include "params/BaseCPU.hh"
54 #include "sim/full_system.hh"
55 
56 namespace gem5
57 {
58 
59 void
61 {
62  const auto &regClasses = one->getIsaPtr()->regClasses();
63 
64  DPRINTF(Context, "Comparing thread contexts\n");
65 
66  // First loop through the integer registers.
67  for (auto &id: *regClasses.at(IntRegClass)) {
68  RegVal t1 = one->getReg(id);
69  RegVal t2 = two->getReg(id);
70  if (t1 != t2)
71  panic("Int reg idx %d doesn't match, one: %#x, two: %#x",
72  id.index(), t1, t2);
73  }
74 
75  // Then loop through the floating point registers.
76  for (auto &id: *regClasses.at(FloatRegClass)) {
77  RegVal t1 = one->getReg(id);
78  RegVal t2 = two->getReg(id);
79  if (t1 != t2)
80  panic("Float reg idx %d doesn't match, one: %#x, two: %#x",
81  id.index(), t1, t2);
82  }
83 
84  // Then loop through the vector registers.
85  const auto *vec_class = regClasses.at(VecRegClass);
86  std::vector<uint8_t> vec1(vec_class->regBytes());
87  std::vector<uint8_t> vec2(vec_class->regBytes());
88  for (auto &id: *regClasses.at(VecRegClass)) {
89  one->getReg(id, vec1.data());
90  two->getReg(id, vec2.data());
91  if (vec1 != vec2) {
92  panic("Vec reg idx %d doesn't match, one: %#x, two: %#x",
93  id.index(), vec_class->valString(vec1.data()),
94  vec_class->valString(vec2.data()));
95  }
96  }
97 
98  // Then loop through the predicate registers.
99  const auto *vec_pred_class = regClasses.at(VecPredRegClass);
100  std::vector<uint8_t> pred1(vec_pred_class->regBytes());
101  std::vector<uint8_t> pred2(vec_pred_class->regBytes());
102  for (auto &id: *regClasses.at(VecPredRegClass)) {
103  one->getReg(id, pred1.data());
104  two->getReg(id, pred2.data());
105  if (pred1 != pred2) {
106  panic("Pred reg idx %d doesn't match, one: %s, two: %s",
107  id.index(), vec_pred_class->valString(pred1.data()),
108  vec_pred_class->valString(pred2.data()));
109  }
110  }
111 
112  // Then loop through the matrix registers.
113  const auto *mat_class = regClasses.at(MatRegClass);
114  std::vector<uint8_t> mat1(mat_class->regBytes());
115  std::vector<uint8_t> mat2(mat_class->regBytes());
116  for (auto &id: *regClasses.at(MatRegClass)) {
117  one->getReg(id, mat1.data());
118  two->getReg(id, mat2.data());
119  if (mat1 != mat2) {
120  panic("Mat reg idx %d doesn't match, one: %#x, two: %#x",
121  id.index(), mat_class->valString(mat1.data()),
122  mat_class->valString(mat2.data()));
123  }
124  }
125 
126  for (int i = 0; i < regClasses.at(MiscRegClass)->numRegs(); ++i) {
127  RegVal t1 = one->readMiscRegNoEffect(i);
128  RegVal t2 = two->readMiscRegNoEffect(i);
129  if (t1 != t2)
130  panic("Misc reg idx %d doesn't match, one: %#x, two: %#x",
131  i, t1, t2);
132  }
133 
134  // loop through the Condition Code registers.
135  for (auto &id: *regClasses.at(CCRegClass)) {
136  RegVal t1 = one->getReg(id);
137  RegVal t2 = two->getReg(id);
138  if (t1 != t2)
139  panic("CC reg idx %d doesn't match, one: %#x, two: %#x",
140  id.index(), t1, t2);
141  }
142  if (one->pcState() != two->pcState())
143  panic("PC state doesn't match.");
144  int id1 = one->cpuId();
145  int id2 = two->cpuId();
146  if (id1 != id2)
147  panic("CPU ids don't match, one: %d, two: %d", id1, id2);
148 
149  const ContextID cid1 = one->contextId();
150  const ContextID cid2 = two->contextId();
151  if (cid1 != cid2)
152  panic("Context ids don't match, one: %d, two: %d", id1, id2);
153 
154 
155 }
156 
157 void
159 {
160  const auto *port =
161  dynamic_cast<const RequestPort *>(&getCpuPtr()->getDataPort());
162  assert(port);
163  port->sendFunctional(pkt);
164 }
165 
166 void
168 {
170 }
171 
172 
173 void
175 {
177 }
178 
179 RegVal
181 {
182  RegVal val;
183  getReg(reg, &val);
184  return val;
185 }
186 
187 void
189 {
190  setReg(reg, &val);
191 }
192 
193 void
195 {
196  for (const auto *reg_class: tc.getIsaPtr()->regClasses()) {
197  // MiscRegs are serialized elsewhere.
198  if (reg_class->type() == MiscRegClass)
199  continue;
200 
201  const size_t reg_bytes = reg_class->regBytes();
202  const size_t reg_count = reg_class->numRegs();
203  const size_t array_bytes = reg_bytes * reg_count;
204 
205  uint8_t regs[array_bytes];
206  auto *reg_ptr = regs;
207  for (const auto &id: *reg_class) {
208  tc.getReg(id, reg_ptr);
209  reg_ptr += reg_bytes;
210  }
211 
212  arrayParamOut(cp, std::string("regs.") + reg_class->name(), regs,
213  array_bytes);
214  }
215 
216  tc.pcState().serialize(cp);
217 
218  // thread_num and cpu_id are deterministic from the config
219 }
220 
221 void
223 {
224  for (const auto *reg_class: tc.getIsaPtr()->regClasses()) {
225  // MiscRegs are serialized elsewhere.
226  if (reg_class->type() == MiscRegClass)
227  continue;
228 
229  const size_t reg_bytes = reg_class->regBytes();
230  const size_t reg_count = reg_class->numRegs();
231  const size_t array_bytes = reg_bytes * reg_count;
232 
233  uint8_t regs[array_bytes];
234  arrayParamIn(cp, std::string("regs.") + reg_class->name(), regs,
235  array_bytes);
236 
237  auto *reg_ptr = regs;
238  for (const auto &id: *reg_class) {
239  tc.setReg(id, reg_ptr);
240  reg_ptr += reg_bytes;
241  }
242  }
243 
244  std::unique_ptr<PCStateBase> pc_state(tc.pcState().clone());
245  pc_state->unserialize(cp);
246  tc.pcState(*pc_state);
247 
248  // thread_num and cpu_id are deterministic from the config
249 }
250 
251 void
253 {
254  assert(ntc.getProcessPtr() == otc.getProcessPtr());
255 
256  ntc.setStatus(otc.status());
257  ntc.copyArchRegs(&otc);
258  ntc.setContextId(otc.contextId());
259  ntc.setThreadId(otc.threadId());
260 
261  if (FullSystem)
262  assert(ntc.getSystemPtr() == otc.getSystemPtr());
263 
265 }
266 
267 } // namespace gem5
gem5::unserialize
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Definition: thread_context.cc:222
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::getSystemPtr
virtual System * getSystemPtr()=0
gem5::RegVal
uint64_t RegVal
Definition: types.hh:173
gem5::ThreadContext::Halted
@ Halted
Permanently shut down.
Definition: thread_context.hh:116
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
gem5::ThreadContext::getReg
virtual RegVal getReg(const RegId &reg) const
Definition: thread_context.cc:180
gem5::CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:68
gem5::System::Threads::quiesce
void quiesce(ContextID id)
Definition: system.cc:145
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::ThreadContext::pcState
virtual const PCStateBase & pcState() const =0
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:776
gem5::ThreadContext::setStatus
virtual void setStatus(Status new_status)=0
gem5::ThreadContext::contextId
virtual ContextID contextId() const =0
std::vector< uint8_t >
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::ThreadContext::cpuId
virtual int cpuId() const =0
gem5::VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:66
gem5::takeOverFrom
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
Definition: thread_context.cc:252
gem5::ThreadContext::status
virtual Status status() const =0
gem5::RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:118
gem5::ArmISA::t1
Bitfield< 1 > t1
Definition: misc_types.hh:282
gem5::System::Threads::quiesceTick
void quiesceTick(ContextID id, Tick when)
Definition: system.cc:154
gem5::ThreadContext::setThreadId
virtual void setThreadId(int id)=0
gem5::BaseCPU::getDataPort
virtual Port & getDataPort()=0
Purely virtual method that returns a reference to the data port.
gem5::FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
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
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::MatRegClass
@ MatRegClass
Matrix Register.
Definition: reg_class.hh:67
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::ps2::one
Bitfield< 3 > one
Definition: types.hh:120
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
port.hh
gem5::BaseISA::regClasses
const RegClasses & regClasses() const
Definition: isa.hh:90
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
vec_pred_reg.hh
gem5::ThreadContext::setContextId
virtual void setContextId(ContextID id)=0
gem5::ArmISA::t2
Bitfield< 2 > t2
Definition: misc_types.hh:281
gem5::arrayParamOut
decltype(std::begin(std::declval< const T & >()), std::end(std::declval< const T & >()), void()) arrayParamOut(CheckpointOut &os, const std::string &name, const T &param)
Definition: serialize.hh:409
full_system.hh
gem5::PCStateBase::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pcstate.hh:133
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
gem5::ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
gem5::FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:220
gem5::IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
base.hh
gem5::MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:69
gem5::System::threads
Threads threads
Definition: system.hh:310
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
logging.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::MipsISA::misc_reg::Context
@ Context
Definition: misc.hh:77
gem5::ThreadContext::getCpuPtr
virtual BaseCPU * getCpuPtr()=0
gem5::ThreadContext::threadId
virtual int threadId() const =0
trace.hh
gem5::VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
gem5::ThreadContext::getIsaPtr
virtual BaseISA * getIsaPtr() const =0
gem5::arrayParamIn
void arrayParamIn(CheckpointIn &cp, const std::string &name, CircleBuf< T > &param)
Definition: circlebuf.hh:257
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
thread_context.hh
gem5::PCStateBase::clone
virtual PCStateBase * clone() const =0
gem5::RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:92
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
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