gem5  v20.1.0.0
thread_context_impl.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2012, 2016-2017, 2019 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) 2004-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 #ifndef __CPU_O3_THREAD_CONTEXT_IMPL_HH__
43 #define __CPU_O3_THREAD_CONTEXT_IMPL_HH__
44 
45 #include "arch/generic/traits.hh"
46 #include "arch/registers.hh"
47 #include "config/the_isa.hh"
48 #include "cpu/o3/thread_context.hh"
49 #include "debug/O3CPU.hh"
50 
51 template <class Impl>
52 PortProxy&
54 {
55  return thread->getVirtProxy();
56 }
57 
58 template <class Impl>
59 void
61 {
62  ::takeOverFrom(*this, *old_context);
63 
64  this->getIsaPtr()->takeOverFrom(this, old_context);
65 
66  TheISA::Decoder *newDecoder = getDecoderPtr();
67  TheISA::Decoder *oldDecoder = old_context->getDecoderPtr();
68  newDecoder->takeOverFrom(oldDecoder);
69 
70  thread->funcExeInst = old_context->readFuncExeInst();
71 
72  thread->noSquashFromTC = false;
73  thread->trapPending = false;
74 }
75 
76 template <class Impl>
77 void
79 {
80  DPRINTF(O3CPU, "Calling activate on Thread Context %d\n",
81  threadId());
82 
83  if (thread->status() == ThreadContext::Active)
84  return;
85 
86  thread->lastActivate = curTick();
87  thread->setStatus(ThreadContext::Active);
88 
89  // status() == Suspended
90  cpu->activateContext(thread->threadId());
91 }
92 
93 template <class Impl>
94 void
96 {
97  DPRINTF(O3CPU, "Calling suspend on Thread Context %d\n",
98  threadId());
99 
100  if (thread->status() == ThreadContext::Suspended)
101  return;
102 
103  if (cpu->isDraining()) {
104  DPRINTF(O3CPU, "Ignoring suspend on TC due to pending drain\n");
105  return;
106  }
107 
108  thread->lastActivate = curTick();
109  thread->lastSuspend = curTick();
110 
111  thread->setStatus(ThreadContext::Suspended);
112  cpu->suspendContext(thread->threadId());
113 }
114 
115 template <class Impl>
116 void
118 {
119  DPRINTF(O3CPU, "Calling halt on Thread Context %d\n", threadId());
120 
121  if (thread->status() == ThreadContext::Halting ||
122  thread->status() == ThreadContext::Halted)
123  return;
124 
125  // the thread is not going to halt/terminate immediately in this cycle.
126  // The thread will be removed after an exit trap is processed
127  // (e.g., after trapLatency cycles). Until then, the thread's status
128  // will be Halting.
129  thread->setStatus(ThreadContext::Halting);
130 
131  // add this thread to the exiting list to mark that it is trying to exit.
132  cpu->addThreadToExitingList(thread->threadId());
133 }
134 
135 template <class Impl>
136 Tick
138 {
139  return thread->lastActivate;
140 }
141 
142 template <class Impl>
143 Tick
145 {
146  return thread->lastSuspend;
147 }
148 
149 template <class Impl>
150 void
152 {
153  // Set vector renaming mode before copying registers
154  cpu->vecRenameMode(RenameMode<TheISA::ISA>::mode(tc->pcState()));
155 
156  // Prevent squashing
157  thread->noSquashFromTC = true;
158  TheISA::copyRegs(tc, this);
159  thread->noSquashFromTC = false;
160 
161  if (!FullSystem)
162  this->thread->funcExeInst = tc->readFuncExeInst();
163 }
164 
165 template <class Impl>
166 void
168 {
169  cpu->isa[thread->threadId()]->clear();
170 }
171 
172 template <class Impl>
173 RegVal
175 {
176  return cpu->readArchIntReg(reg_idx, thread->threadId());
177 }
178 
179 template <class Impl>
180 RegVal
182 {
183  return cpu->readArchFloatReg(reg_idx, thread->threadId());
184 }
185 
186 template <class Impl>
189 {
190  return cpu->readArchVecReg(reg_id, thread->threadId());
191 }
192 
193 template <class Impl>
196 {
197  return cpu->getWritableArchVecReg(reg_id, thread->threadId());
198 }
199 
200 template <class Impl>
201 const TheISA::VecElem&
203  const ElemIndex& elemIndex) const
204 {
205  return cpu->readArchVecElem(idx, elemIndex, thread->threadId());
206 }
207 
208 template <class Impl>
211 {
212  return cpu->readArchVecPredReg(reg_id, thread->threadId());
213 }
214 
215 template <class Impl>
218 {
219  return cpu->getWritableArchVecPredReg(reg_id, thread->threadId());
220 }
221 
222 template <class Impl>
223 RegVal
225 {
226  return cpu->readArchCCReg(reg_idx, thread->threadId());
227 }
228 
229 template <class Impl>
230 void
232 {
233  cpu->setArchIntReg(reg_idx, val, thread->threadId());
234 
235  conditionalSquash();
236 }
237 
238 template <class Impl>
239 void
241 {
242  cpu->setArchFloatReg(reg_idx, val, thread->threadId());
243 
244  conditionalSquash();
245 }
246 
247 template <class Impl>
248 void
250  RegIndex reg_idx, const VecRegContainer& val)
251 {
252  cpu->setArchVecReg(reg_idx, val, thread->threadId());
253 
254  conditionalSquash();
255 }
256 
257 template <class Impl>
258 void
260  const ElemIndex& elemIndex, const VecElem& val)
261 {
262  cpu->setArchVecElem(idx, elemIndex, val, thread->threadId());
263  conditionalSquash();
264 }
265 
266 template <class Impl>
267 void
269  const VecPredRegContainer& val)
270 {
271  cpu->setArchVecPredReg(reg_idx, val, thread->threadId());
272 
273  conditionalSquash();
274 }
275 
276 template <class Impl>
277 void
279 {
280  cpu->setArchCCReg(reg_idx, val, thread->threadId());
281 
282  conditionalSquash();
283 }
284 
285 template <class Impl>
286 void
288 {
289  cpu->pcState(val, thread->threadId());
290 
291  conditionalSquash();
292 }
293 
294 template <class Impl>
295 void
297 {
298  cpu->pcState(val, thread->threadId());
299 
300  conditionalSquash();
301 }
302 
303 template <class Impl>
304 RegId
306 {
307  return cpu->isa[thread->threadId()]->flattenRegId(regId);
308 }
309 
310 template <class Impl>
311 void
313 {
314  cpu->setMiscRegNoEffect(misc_reg, val, thread->threadId());
315 
316  conditionalSquash();
317 }
318 
319 template <class Impl>
320 void
322 {
323  cpu->setMiscReg(misc_reg, val, thread->threadId());
324 
325  conditionalSquash();
326 }
327 
328 // hardware transactional memory
329 template <class Impl>
330 void
332  HtmFailureFaultCause cause)
333 {
334  cpu->htmSendAbortSignal(thread->threadId(), htmUid, cause);
335 
336  conditionalSquash();
337 }
338 
339 template <class Impl>
342 {
343  return thread->htmCheckpoint;
344 }
345 
346 template <class Impl>
347 void
349 {
350  thread->htmCheckpoint = std::move(new_cpt);
351 }
352 
353 #endif //__CPU_O3_THREAD_CONTEXT_IMPL_HH__
ArmISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:136
O3ThreadContext::setHtmCheckpointPtr
void setHtmCheckpointPtr(BaseHTMCheckpointPtr new_cpt) override
Definition: thread_context_impl.hh:348
O3ThreadContext::pcStateNoRecord
void pcStateNoRecord(const TheISA::PCState &val) override
Definition: thread_context_impl.hh:296
O3ThreadContext::getWritableVecPredRegFlat
VecPredRegContainer & getWritableVecPredRegFlat(RegIndex idx) override
Definition: thread_context_impl.hh:217
VecPredRegContainer
Generic predicate register container.
Definition: vec_pred_reg.hh:47
ArmISA::VecRegContainer
VecReg::Container VecRegContainer
Definition: registers.hh:71
ThreadContext::Halting
@ Halting
Trying to exit and waiting for an event to completely exit.
Definition: thread_context.hh:110
O3ThreadContext::setVecElemFlat
void setVecElemFlat(RegIndex idx, const ElemIndex &elemIdx, const VecElem &val) override
Definition: thread_context_impl.hh:259
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
ArmISA::VecPredRegContainer
VecPredReg::Container VecPredRegContainer
Definition: registers.hh:77
ThreadContext::readFuncExeInst
virtual Counter readFuncExeInst() const =0
O3ThreadContext::O3CPU
Impl::O3CPU O3CPU
Definition: thread_context.hh:66
O3ThreadContext::readFloatRegFlat
RegVal readFloatRegFlat(RegIndex idx) const override
Definition: thread_context_impl.hh:181
O3ThreadContext::setCCRegFlat
void setCCRegFlat(RegIndex idx, RegVal val) override
Definition: thread_context_impl.hh:278
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:44
RenameMode
Helper structure to get the vector register mode for a given ISA.
Definition: traits.hh:53
O3ThreadContext::takeOverFrom
void takeOverFrom(ThreadContext *old_context) override
Takes over execution of a thread from another CPU.
Definition: thread_context_impl.hh:60
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
O3ThreadContext::halt
void halt() override
Set the status to Halted.
Definition: thread_context_impl.hh:117
ArmISA::VecElem
uint32_t VecElem
Definition: registers.hh:68
O3ThreadContext::setMiscRegNoEffect
void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) override
Sets a misc.
Definition: thread_context_impl.hh:312
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
O3ThreadContext::setVecPredRegFlat
void setVecPredRegFlat(RegIndex idx, const VecPredRegContainer &val) override
Definition: thread_context_impl.hh:268
O3ThreadContext::activate
void activate() override
Set the status to Active.
Definition: thread_context_impl.hh:78
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
O3ThreadContext::readLastActivate
Tick readLastActivate() override
Reads the last tick that this thread was activated on.
Definition: thread_context_impl.hh:137
ThreadContext::Halted
@ Halted
Permanently shut down.
Definition: thread_context.hh:115
O3ThreadContext::htmAbortTransaction
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
Definition: thread_context_impl.hh:331
O3ThreadContext::setVecRegFlat
void setVecRegFlat(RegIndex idx, const VecRegContainer &val) override
Definition: thread_context_impl.hh:249
traits.hh
O3ThreadContext::flattenRegId
RegId flattenRegId(const RegId &regId) const override
Definition: thread_context_impl.hh:305
O3ThreadContext::clearArchRegs
void clearArchRegs() override
Resets all architectural registers to 0.
Definition: thread_context_impl.hh:167
O3ThreadContext::getWritableVecRegFlat
VecRegContainer & getWritableVecRegFlat(RegIndex idx) override
Read vector register operand for modification, flat indexing.
Definition: thread_context_impl.hh:195
O3ThreadContext::readVecElemFlat
const VecElem & readVecElemFlat(RegIndex idx, const ElemIndex &elemIndex) const override
Definition: thread_context_impl.hh:202
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
BaseHTMCheckpointPtr
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:122
O3ThreadContext::readCCRegFlat
RegVal readCCRegFlat(RegIndex idx) const override
Definition: thread_context_impl.hh:224
O3ThreadContext::readVecRegFlat
const VecRegContainer & readVecRegFlat(RegIndex idx) const override
Definition: thread_context_impl.hh:188
O3ThreadContext::setIntRegFlat
void setIntRegFlat(RegIndex idx, RegVal val) override
Definition: thread_context_impl.hh:231
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
O3ThreadContext::getHtmCheckpointPtr
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
Definition: thread_context_impl.hh:341
O3ThreadContext::readIntRegFlat
RegVal readIntRegFlat(RegIndex idx) const override
Definition: thread_context_impl.hh:174
O3ThreadContext::readLastSuspend
Tick readLastSuspend() override
Reads the last tick that this thread was suspended on.
Definition: thread_context_impl.hh:144
O3ThreadContext::readVecPredRegFlat
const VecPredRegContainer & readVecPredRegFlat(RegIndex idx) const override
Definition: thread_context_impl.hh:210
ThreadContext::Suspended
@ Suspended
Temporarily inactive.
Definition: thread_context.hh:106
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
RegIndex
uint16_t RegIndex
Definition: types.hh:52
O3ThreadContext::getVirtProxy
PortProxy & getVirtProxy() override
Definition: thread_context_impl.hh:53
ElemIndex
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:55
O3ThreadContext::suspend
void suspend() override
Set the status to Suspended.
Definition: thread_context_impl.hh:95
ThreadContext::Active
@ Active
Running.
Definition: thread_context.hh:102
thread_context.hh
ThreadContext::getDecoderPtr
virtual TheISA::Decoder * getDecoderPtr()=0
O3ThreadContext::setMiscReg
void setMiscReg(RegIndex misc_reg, RegVal val) override
Sets a misc.
Definition: thread_context_impl.hh:321
takeOverFrom
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
Definition: thread_context.cc:226
O3ThreadContext::setFloatRegFlat
void setFloatRegFlat(RegIndex idx, RegVal val) override
Definition: thread_context_impl.hh:240
O3ThreadContext::copyArchRegs
void copyArchRegs(ThreadContext *tc) override
Copies the architectural registers from another TC into this TC.
Definition: thread_context_impl.hh:151
O3ThreadContext::pcState
TheISA::PCState pcState() const override
Reads this thread's PC state.
Definition: thread_context.hh:352
RegVal
uint64_t RegVal
Definition: types.hh:168
VecRegContainer
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
Definition: vec_reg.hh:156
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17