gem5  v20.0.0.3
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 
45 #include "base/logging.hh"
46 #include "base/trace.hh"
47 #include "config/the_isa.hh"
48 #include "cpu/base.hh"
49 #include "cpu/quiesce_event.hh"
50 #include "debug/Context.hh"
51 #include "debug/Quiesce.hh"
52 #include "kern/kernel_stats.hh"
53 #include "params/BaseCPU.hh"
54 #include "sim/full_system.hh"
55 
56 void
58 {
59  DPRINTF(Context, "Comparing thread contexts\n");
60 
61  // First loop through the integer registers.
62  for (int i = 0; i < TheISA::NumIntRegs; ++i) {
63  RegVal t1 = one->readIntReg(i);
64  RegVal t2 = two->readIntReg(i);
65  if (t1 != t2)
66  panic("Int reg idx %d doesn't match, one: %#x, two: %#x",
67  i, t1, t2);
68  }
69 
70  // Then loop through the floating point registers.
71  for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
72  RegVal t1 = one->readFloatReg(i);
73  RegVal t2 = two->readFloatReg(i);
74  if (t1 != t2)
75  panic("Float reg idx %d doesn't match, one: %#x, two: %#x",
76  i, t1, t2);
77  }
78 
79  // Then loop through the vector registers.
80  for (int i = 0; i < TheISA::NumVecRegs; ++i) {
81  RegId rid(VecRegClass, i);
82  const TheISA::VecRegContainer& t1 = one->readVecReg(rid);
83  const TheISA::VecRegContainer& t2 = two->readVecReg(rid);
84  if (t1 != t2)
85  panic("Vec reg idx %d doesn't match, one: %#x, two: %#x",
86  i, t1, t2);
87  }
88 
89  // Then loop through the predicate registers.
90  for (int i = 0; i < TheISA::NumVecPredRegs; ++i) {
91  RegId rid(VecPredRegClass, i);
94  if (t1 != t2)
95  panic("Pred reg idx %d doesn't match, one: %#x, two: %#x",
96  i, t1, t2);
97  }
98 
99  for (int i = 0; i < TheISA::NumMiscRegs; ++i) {
100  RegVal t1 = one->readMiscRegNoEffect(i);
101  RegVal t2 = two->readMiscRegNoEffect(i);
102  if (t1 != t2)
103  panic("Misc reg idx %d doesn't match, one: %#x, two: %#x",
104  i, t1, t2);
105  }
106 
107  // loop through the Condition Code registers.
108  for (int i = 0; i < TheISA::NumCCRegs; ++i) {
109  RegVal t1 = one->readCCReg(i);
110  RegVal t2 = two->readCCReg(i);
111  if (t1 != t2)
112  panic("CC reg idx %d doesn't match, one: %#x, two: %#x",
113  i, t1, t2);
114  }
115  if (!(one->pcState() == two->pcState()))
116  panic("PC state doesn't match.");
117  int id1 = one->cpuId();
118  int id2 = two->cpuId();
119  if (id1 != id2)
120  panic("CPU ids don't match, one: %d, two: %d", id1, id2);
121 
122  const ContextID cid1 = one->contextId();
123  const ContextID cid2 = two->contextId();
124  if (cid1 != cid2)
125  panic("Context ids don't match, one: %d, two: %d", id1, id2);
126 
127 
128 }
129 
130 void
132 {
133  if (!getCpuPtr()->params()->do_quiesce)
134  return;
135 
136  DPRINTF(Quiesce, "%s: quiesce()\n", getCpuPtr()->name());
137 
138  suspend();
139  if (getKernelStats())
140  getKernelStats()->quiesce();
141 }
142 
143 
144 void
146 {
147  BaseCPU *cpu = getCpuPtr();
148 
149  if (!cpu->params()->do_quiesce)
150  return;
151 
152  EndQuiesceEvent *quiesceEvent = getQuiesceEvent();
153 
154  cpu->reschedule(quiesceEvent, resume, true);
155 
156  DPRINTF(Quiesce, "%s: quiesceTick until %lu\n", cpu->name(), resume);
157 
158  suspend();
159  if (getKernelStats())
160  getKernelStats()->quiesce();
161 }
162 
163 void
165 {
166  using namespace TheISA;
167 
168  RegVal floatRegs[NumFloatRegs];
169  for (int i = 0; i < NumFloatRegs; ++i)
170  floatRegs[i] = tc.readFloatRegFlat(i);
171  // This is a bit ugly, but needed to maintain backwards
172  // compatibility.
173  arrayParamOut(cp, "floatRegs.i", floatRegs, NumFloatRegs);
174 
176  for (int i = 0; i < NumVecRegs; ++i) {
177  vecRegs[i] = tc.readVecRegFlat(i);
178  }
179  SERIALIZE_CONTAINER(vecRegs);
180 
182  for (int i = 0; i < NumVecPredRegs; ++i) {
183  vecPredRegs[i] = tc.readVecPredRegFlat(i);
184  }
185  SERIALIZE_CONTAINER(vecPredRegs);
186 
187  RegVal intRegs[NumIntRegs];
188  for (int i = 0; i < NumIntRegs; ++i)
189  intRegs[i] = tc.readIntRegFlat(i);
190  SERIALIZE_ARRAY(intRegs, NumIntRegs);
191 
192  if (NumCCRegs) {
193  RegVal ccRegs[NumCCRegs];
194  for (int i = 0; i < NumCCRegs; ++i)
195  ccRegs[i] = tc.readCCRegFlat(i);
196  SERIALIZE_ARRAY(ccRegs, NumCCRegs);
197  }
198 
199  tc.pcState().serialize(cp);
200 
201  // thread_num and cpu_id are deterministic from the config
202 }
203 
204 void
206 {
207  using namespace TheISA;
208 
209  RegVal floatRegs[NumFloatRegs];
210  // This is a bit ugly, but needed to maintain backwards
211  // compatibility.
212  arrayParamIn(cp, "floatRegs.i", floatRegs, NumFloatRegs);
213  for (int i = 0; i < NumFloatRegs; ++i)
214  tc.setFloatRegFlat(i, floatRegs[i]);
215 
217  UNSERIALIZE_CONTAINER(vecRegs);
218  for (int i = 0; i < NumVecRegs; ++i) {
219  tc.setVecRegFlat(i, vecRegs[i]);
220  }
221 
223  UNSERIALIZE_CONTAINER(vecPredRegs);
224  for (int i = 0; i < NumVecPredRegs; ++i) {
225  tc.setVecPredRegFlat(i, vecPredRegs[i]);
226  }
227 
228  RegVal intRegs[NumIntRegs];
229  UNSERIALIZE_ARRAY(intRegs, NumIntRegs);
230  for (int i = 0; i < NumIntRegs; ++i)
231  tc.setIntRegFlat(i, intRegs[i]);
232 
233  if (NumCCRegs) {
234  RegVal ccRegs[NumCCRegs];
235  UNSERIALIZE_ARRAY(ccRegs, NumCCRegs);
236  for (int i = 0; i < NumCCRegs; ++i)
237  tc.setCCRegFlat(i, ccRegs[i]);
238  }
239 
241  pcState.unserialize(cp);
242  tc.pcState(pcState);
243 
244  // thread_num and cpu_id are deterministic from the config
245 }
246 
247 void
249 {
250  assert(ntc.getProcessPtr() == otc.getProcessPtr());
251 
252  ntc.setStatus(otc.status());
253  ntc.copyArchRegs(&otc);
254  ntc.setContextId(otc.contextId());
255  ntc.setThreadId(otc.threadId());
256 
257  if (FullSystem) {
258  assert(ntc.getSystemPtr() == otc.getSystemPtr());
259 
260  BaseCPU *ncpu(ntc.getCpuPtr());
261  assert(ncpu);
262  EndQuiesceEvent *oqe(otc.getQuiesceEvent());
263  assert(oqe);
264  assert(oqe->tc == &otc);
265 
266  BaseCPU *ocpu(otc.getCpuPtr());
267  assert(ocpu);
268  EndQuiesceEvent *nqe(ntc.getQuiesceEvent());
269  assert(nqe);
270  assert(nqe->tc == &ntc);
271 
272  if (oqe->scheduled()) {
273  ncpu->schedule(nqe, oqe->when());
274  ocpu->deschedule(oqe);
275  }
276  }
277 
279 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
#define DPRINTF(x,...)
Definition: trace.hh:225
virtual System * getSystemPtr()=0
#define UNSERIALIZE_CONTAINER(member)
Definition: serialize.hh:829
const std::string & name()
Definition: trace.cc:50
Bitfield< 7 > i
Bitfield< 2 > t2
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
virtual ::Kernel::Statistics * getKernelStats()=0
virtual void setStatus(Status new_status)=0
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
virtual Process * getProcessPtr()=0
const int NumFloatRegs
Definition: registers.hh:83
virtual const VecPredRegContainer & readVecPredRegFlat(RegIndex idx) const =0
uint64_t RegVal
Definition: types.hh:166
virtual BaseCPU * getCpuPtr()=0
Definition: cprintf.cc:40
virtual RegVal readCCReg(RegIndex reg_idx) const =0
const int NumMiscRegs
Definition: registers.hh:85
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Event for timing out quiesce instruction.
STL vector class.
Definition: stl.hh:37
virtual const VecRegContainer & readVecReg(const RegId &reg) const =0
void quiesce()
Quiesce thread context.
virtual EndQuiesceEvent * getQuiesceEvent()=0
virtual void setContextId(ContextID id)=0
virtual const VecPredRegContainer & readVecPredReg(const RegId &reg) const =0
virtual RegVal readFloatReg(RegIndex reg_idx) const =0
virtual int cpuId() const =0
uint64_t Tick
Tick count type.
Definition: types.hh:61
VecPredReg::Container VecPredRegContainer
Definition: registers.hh:77
virtual RegVal readCCRegFlat(RegIndex idx) const =0
virtual void suspend()=0
Set the status to Suspended.
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
virtual const VecRegContainer & readVecRegFlat(RegIndex idx) const =0
virtual void setFloatRegFlat(RegIndex idx, RegVal val)=0
virtual void setThreadId(int id)=0
void arrayParamOut(CheckpointOut &cp, const std::string &name, const CircleBuf< T > &param)
Definition: circlebuf.hh:174
void reschedule(Event &event, Tick when, bool always=false)
Definition: eventq.hh:952
virtual void setCCRegFlat(RegIndex idx, RegVal val)=0
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:805
Bitfield< 3 > one
Definition: types.hh:110
virtual const std::string name() const
Definition: sim_object.hh:129
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:813
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
#define SERIALIZE_CONTAINER(member)
Definition: serialize.hh:821
Bitfield< 1 > t1
std::ostream CheckpointOut
Definition: serialize.hh:63
VecReg::Container VecRegContainer
Definition: registers.hh:71
const int NumIntRegs
Definition: registers.hh:82
virtual void takeOverFrom(ThreadContext *old_context)=0
Permanently shut down.
virtual void setVecPredRegFlat(RegIndex idx, const VecPredRegContainer &val)=0
static void compare(ThreadContext *one, ThreadContext *two)
function to compare two thread contexts (for debugging)
virtual void copyArchRegs(ThreadContext *tc)=0
const int NumCCRegs
Definition: registers.hh:84
virtual int threadId() const =0
virtual RegVal readIntRegFlat(RegIndex idx) const =0
Flat register interfaces.
virtual ContextID contextId() const =0
virtual Status status() const =0
const int NumVecPredRegs
Definition: registers.hh:98
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void arrayParamIn(CheckpointIn &cp, const std::string &name, CircleBuf< T > &param)
Definition: circlebuf.hh:184
virtual void setVecRegFlat(RegIndex idx, const VecRegContainer &val)=0
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
Vector Register.
Definition: reg_class.hh:56
void quiesceTick(Tick resume)
Quiesce, suspend, and schedule activate at resume.
virtual RegVal readFloatRegFlat(RegIndex idx) const =0
virtual void setIntRegFlat(RegIndex idx, RegVal val)=0
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
const Params * params() const
Definition: base.hh:307
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
const int NumVecRegs
Definition: registers.hh:97

Generated on Fri Jul 3 2020 15:42:38 for gem5 by doxygen 1.8.13