gem5  v20.0.0.2
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 
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  DPRINTF(Quiesce, "%s: quiesce()\n", getCpuPtr()->name());
134 
135  suspend();
136  if (getKernelStats())
137  getKernelStats()->quiesce();
138 }
139 
140 
141 void
143 {
144  BaseCPU *cpu = getCpuPtr();
145 
146  EndQuiesceEvent *quiesceEvent = getQuiesceEvent();
147 
148  cpu->reschedule(quiesceEvent, resume, true);
149 
150  DPRINTF(Quiesce, "%s: quiesceTick until %lu\n", cpu->name(), resume);
151 
152  suspend();
153  if (getKernelStats())
154  getKernelStats()->quiesce();
155 }
156 
157 void
159 {
160  using namespace TheISA;
161 
162  RegVal floatRegs[NumFloatRegs];
163  for (int i = 0; i < NumFloatRegs; ++i)
164  floatRegs[i] = tc.readFloatRegFlat(i);
165  // This is a bit ugly, but needed to maintain backwards
166  // compatibility.
167  arrayParamOut(cp, "floatRegs.i", floatRegs, NumFloatRegs);
168 
170  for (int i = 0; i < NumVecRegs; ++i) {
171  vecRegs[i] = tc.readVecRegFlat(i);
172  }
173  SERIALIZE_CONTAINER(vecRegs);
174 
176  for (int i = 0; i < NumVecPredRegs; ++i) {
177  vecPredRegs[i] = tc.readVecPredRegFlat(i);
178  }
179  SERIALIZE_CONTAINER(vecPredRegs);
180 
181  RegVal intRegs[NumIntRegs];
182  for (int i = 0; i < NumIntRegs; ++i)
183  intRegs[i] = tc.readIntRegFlat(i);
184  SERIALIZE_ARRAY(intRegs, NumIntRegs);
185 
186  if (NumCCRegs) {
187  RegVal ccRegs[NumCCRegs];
188  for (int i = 0; i < NumCCRegs; ++i)
189  ccRegs[i] = tc.readCCRegFlat(i);
190  SERIALIZE_ARRAY(ccRegs, NumCCRegs);
191  }
192 
193  tc.pcState().serialize(cp);
194 
195  // thread_num and cpu_id are deterministic from the config
196 }
197 
198 void
200 {
201  using namespace TheISA;
202 
203  RegVal floatRegs[NumFloatRegs];
204  // This is a bit ugly, but needed to maintain backwards
205  // compatibility.
206  arrayParamIn(cp, "floatRegs.i", floatRegs, NumFloatRegs);
207  for (int i = 0; i < NumFloatRegs; ++i)
208  tc.setFloatRegFlat(i, floatRegs[i]);
209 
211  UNSERIALIZE_CONTAINER(vecRegs);
212  for (int i = 0; i < NumVecRegs; ++i) {
213  tc.setVecRegFlat(i, vecRegs[i]);
214  }
215 
217  UNSERIALIZE_CONTAINER(vecPredRegs);
218  for (int i = 0; i < NumVecPredRegs; ++i) {
219  tc.setVecPredRegFlat(i, vecPredRegs[i]);
220  }
221 
222  RegVal intRegs[NumIntRegs];
223  UNSERIALIZE_ARRAY(intRegs, NumIntRegs);
224  for (int i = 0; i < NumIntRegs; ++i)
225  tc.setIntRegFlat(i, intRegs[i]);
226 
227  if (NumCCRegs) {
228  RegVal ccRegs[NumCCRegs];
229  UNSERIALIZE_ARRAY(ccRegs, NumCCRegs);
230  for (int i = 0; i < NumCCRegs; ++i)
231  tc.setCCRegFlat(i, ccRegs[i]);
232  }
233 
235  pcState.unserialize(cp);
236  tc.pcState(pcState);
237 
238  // thread_num and cpu_id are deterministic from the config
239 }
240 
241 void
243 {
244  assert(ntc.getProcessPtr() == otc.getProcessPtr());
245 
246  ntc.setStatus(otc.status());
247  ntc.copyArchRegs(&otc);
248  ntc.setContextId(otc.contextId());
249  ntc.setThreadId(otc.threadId());
250 
251  if (FullSystem) {
252  assert(ntc.getSystemPtr() == otc.getSystemPtr());
253 
254  BaseCPU *ncpu(ntc.getCpuPtr());
255  assert(ncpu);
256  EndQuiesceEvent *oqe(otc.getQuiesceEvent());
257  assert(oqe);
258  assert(oqe->tc == &otc);
259 
260  BaseCPU *ocpu(otc.getCpuPtr());
261  assert(ocpu);
262  EndQuiesceEvent *nqe(ntc.getQuiesceEvent());
263  assert(nqe);
264  assert(nqe->tc == &ntc);
265 
266  if (oqe->scheduled()) {
267  ncpu->schedule(nqe, oqe->when());
268  ocpu->deschedule(oqe);
269  }
270  }
271 
273 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
#define DPRINTF(x,...)
Definition: trace.hh:222
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:1016
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:128
#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
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
const int NumVecRegs
Definition: registers.hh:97

Generated on Mon Jun 8 2020 15:34:38 for gem5 by doxygen 1.8.13