gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
56namespace gem5
57{
58
59void
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);
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
157void
159{
160 const auto *port =
161 dynamic_cast<const RequestPort *>(&getCpuPtr()->getDataPort());
162 assert(port);
163 port->sendFunctional(pkt);
164}
165
166void
171
172
173void
178
179RegVal
181{
182 RegVal val;
183 getReg(reg, &val);
184 return val;
185}
186
187void
192
193void
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
221void
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
251void
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
#define DPRINTF(x,...)
Definition trace.hh:210
virtual Port & getDataPort()=0
Purely virtual method that returns a reference to the data port.
const RegClasses & regClasses() const
Definition isa.hh:93
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition pcstate.hh:141
virtual PCStateBase * clone() const =0
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
void quiesceTick(ContextID id, Tick when)
Definition system.cc:154
void quiesce(ContextID id)
Definition system.cc:145
Threads threads
Definition system.hh:310
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void setStatus(Status new_status)=0
virtual RegVal getReg(const RegId &reg) const
virtual System * getSystemPtr()=0
virtual void copyArchRegs(ThreadContext *tc)=0
static void compare(ThreadContext *one, ThreadContext *two)
function to compare two thread contexts (for debugging)
virtual BaseISA * getIsaPtr() const =0
virtual BaseCPU * getCpuPtr()=0
void quiesceTick(Tick resume)
Quiesce, suspend, and schedule activate at resume.
virtual void setReg(const RegId &reg, RegVal val)
void quiesce()
Quiesce thread context.
@ Halted
Permanently shut down.
virtual const PCStateBase & pcState() const =0
virtual int threadId() const =0
virtual Status status() const =0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
virtual Process * getProcessPtr()=0
virtual ContextID contextId() const =0
virtual void sendFunctional(PacketPtr pkt)
virtual void setThreadId(int id)=0
virtual void setContextId(ContextID id)=0
virtual int cpuId() const =0
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Port Object Declaration.
Bitfield< 2 > t2
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 1 > t1
Bitfield< 30, 0 > index
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void arrayParamOut(CheckpointOut &cp, const std::string &name, const CircleBuf< T > &param)
Definition circlebuf.hh:247
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition root.cc:220
uint64_t Tick
Tick count type.
Definition types.hh:58
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
int ContextID
Globally unique thread context ID.
Definition types.hh:239
void arrayParamIn(CheckpointIn &cp, const std::string &name, CircleBuf< T > &param)
Definition circlebuf.hh:257
@ VecPredRegClass
Definition reg_class.hh:67
@ MatRegClass
Matrix Register.
Definition reg_class.hh:68
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ CCRegClass
Condition-code register.
Definition reg_class.hh:69
@ VecRegClass
Vector Register.
Definition reg_class.hh:64
@ IntRegClass
Integer register.
Definition reg_class.hh:61
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0