de6997a23a56266fad5307e011d752f7475cd0fe
2 * Copyright (c) 2012, 2016-2017 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
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.
15 * Copyright (c) 2006 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
42 #include "cpu/thread_context.hh"
44 #include "arch/generic/vec_pred_reg.hh"
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"
57 ThreadContext::compare(ThreadContext
*one
, ThreadContext
*two
)
59 DPRINTF(Context
, "Comparing thread contexts\n");
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
);
66 panic("Int reg idx %d doesn't match, one: %#x, two: %#x",
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
);
75 panic("Float reg idx %d doesn't match, one: %#x, two: %#x",
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
);
85 panic("Vec reg idx %d doesn't match, one: %#x, two: %#x",
89 // Then loop through the predicate registers.
90 for (int i
= 0; i
< TheISA::NumVecPredRegs
; ++i
) {
91 RegId
rid(VecPredRegClass
, i
);
92 const TheISA::VecPredRegContainer
& t1
= one
->readVecPredReg(rid
);
93 const TheISA::VecPredRegContainer
& t2
= two
->readVecPredReg(rid
);
95 panic("Pred reg idx %d doesn't match, one: %#x, two: %#x",
99 for (int i
= 0; i
< TheISA::NumMiscRegs
; ++i
) {
100 RegVal t1
= one
->readMiscRegNoEffect(i
);
101 RegVal t2
= two
->readMiscRegNoEffect(i
);
103 panic("Misc reg idx %d doesn't match, one: %#x, two: %#x",
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
);
112 panic("CC reg idx %d doesn't match, one: %#x, two: %#x",
115 if (!(one
->pcState() == two
->pcState()))
116 panic("PC state doesn't match.");
117 int id1
= one
->cpuId();
118 int id2
= two
->cpuId();
120 panic("CPU ids don't match, one: %d, two: %d", id1
, id2
);
122 const ContextID cid1
= one
->contextId();
123 const ContextID cid2
= two
->contextId();
125 panic("Context ids don't match, one: %d, two: %d", id1
, id2
);
131 ThreadContext::quiesce()
133 if (!getCpuPtr()->params()->do_quiesce
)
136 DPRINTF(Quiesce
, "%s: quiesce()\n", getCpuPtr()->name());
139 if (getKernelStats())
140 getKernelStats()->quiesce();
145 ThreadContext::quiesceTick(Tick resume
)
147 BaseCPU
*cpu
= getCpuPtr();
149 if (!cpu
->params()->do_quiesce
)
152 EndQuiesceEvent
*quiesceEvent
= getQuiesceEvent();
154 cpu
->reschedule(quiesceEvent
, resume
, true);
156 DPRINTF(Quiesce
, "%s: quiesceTick until %lu\n", cpu
->name(), resume
);
159 if (getKernelStats())
160 getKernelStats()->quiesce();
164 serialize(const ThreadContext
&tc
, CheckpointOut
&cp
)
166 using namespace TheISA
;
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
173 arrayParamOut(cp
, "floatRegs.i", floatRegs
, NumFloatRegs
);
175 std::vector
<TheISA::VecRegContainer
> vecRegs(NumVecRegs
);
176 for (int i
= 0; i
< NumVecRegs
; ++i
) {
177 vecRegs
[i
] = tc
.readVecRegFlat(i
);
179 SERIALIZE_CONTAINER(vecRegs
);
181 std::vector
<TheISA::VecPredRegContainer
> vecPredRegs(NumVecPredRegs
);
182 for (int i
= 0; i
< NumVecPredRegs
; ++i
) {
183 vecPredRegs
[i
] = tc
.readVecPredRegFlat(i
);
185 SERIALIZE_CONTAINER(vecPredRegs
);
187 RegVal intRegs
[NumIntRegs
];
188 for (int i
= 0; i
< NumIntRegs
; ++i
)
189 intRegs
[i
] = tc
.readIntRegFlat(i
);
190 SERIALIZE_ARRAY(intRegs
, NumIntRegs
);
193 RegVal ccRegs
[NumCCRegs
];
194 for (int i
= 0; i
< NumCCRegs
; ++i
)
195 ccRegs
[i
] = tc
.readCCRegFlat(i
);
196 SERIALIZE_ARRAY(ccRegs
, NumCCRegs
);
199 tc
.pcState().serialize(cp
);
201 // thread_num and cpu_id are deterministic from the config
205 unserialize(ThreadContext
&tc
, CheckpointIn
&cp
)
207 using namespace TheISA
;
209 RegVal floatRegs
[NumFloatRegs
];
210 // This is a bit ugly, but needed to maintain backwards
212 arrayParamIn(cp
, "floatRegs.i", floatRegs
, NumFloatRegs
);
213 for (int i
= 0; i
< NumFloatRegs
; ++i
)
214 tc
.setFloatRegFlat(i
, floatRegs
[i
]);
216 std::vector
<TheISA::VecRegContainer
> vecRegs(NumVecRegs
);
217 UNSERIALIZE_CONTAINER(vecRegs
);
218 for (int i
= 0; i
< NumVecRegs
; ++i
) {
219 tc
.setVecRegFlat(i
, vecRegs
[i
]);
222 std::vector
<TheISA::VecPredRegContainer
> vecPredRegs(NumVecPredRegs
);
223 UNSERIALIZE_CONTAINER(vecPredRegs
);
224 for (int i
= 0; i
< NumVecPredRegs
; ++i
) {
225 tc
.setVecPredRegFlat(i
, vecPredRegs
[i
]);
228 RegVal intRegs
[NumIntRegs
];
229 UNSERIALIZE_ARRAY(intRegs
, NumIntRegs
);
230 for (int i
= 0; i
< NumIntRegs
; ++i
)
231 tc
.setIntRegFlat(i
, intRegs
[i
]);
234 RegVal ccRegs
[NumCCRegs
];
235 UNSERIALIZE_ARRAY(ccRegs
, NumCCRegs
);
236 for (int i
= 0; i
< NumCCRegs
; ++i
)
237 tc
.setCCRegFlat(i
, ccRegs
[i
]);
241 pcState
.unserialize(cp
);
244 // thread_num and cpu_id are deterministic from the config
248 takeOverFrom(ThreadContext
&ntc
, ThreadContext
&otc
)
250 assert(ntc
.getProcessPtr() == otc
.getProcessPtr());
252 ntc
.setStatus(otc
.status());
253 ntc
.copyArchRegs(&otc
);
254 ntc
.setContextId(otc
.contextId());
255 ntc
.setThreadId(otc
.threadId());
258 assert(ntc
.getSystemPtr() == otc
.getSystemPtr());
260 BaseCPU
*ncpu(ntc
.getCpuPtr());
262 EndQuiesceEvent
*oqe(otc
.getQuiesceEvent());
264 assert(oqe
->tc
== &otc
);
266 BaseCPU
*ocpu(otc
.getCpuPtr());
268 EndQuiesceEvent
*nqe(ntc
.getQuiesceEvent());
270 assert(nqe
->tc
== &ntc
);
272 if (oqe
->scheduled()) {
273 ncpu
->schedule(nqe
, oqe
->when());
274 ocpu
->deschedule(oqe
);
278 otc
.setStatus(ThreadContext::Halted
);