2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __CPU_THREAD_STATE_HH__
30 #define __CPU_THREAD_STATE_HH__
32 #include "arch/types.hh"
33 #include "config/the_isa.hh"
34 #include "cpu/base.hh"
35 #include "cpu/profile.hh"
36 #include "cpu/thread_context.hh"
37 #include "sim/process.hh"
39 class EndQuiesceEvent;
40 class FunctionProfile;
48 class FSTranslatingPortProxy;
49 class SETranslatingPortProxy;
52 * Struct for holding general thread state that is needed across CPU
53 * models. This includes things such as pointers to the process,
54 * memory, quiesce events, and certain stats. This can be expanded
55 * to hold more thread-specific stats within it.
57 struct ThreadState : public Serializable {
58 typedef ThreadContext::Status Status;
60 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
62 virtual ~ThreadState();
64 void serialize(CheckpointOut &cp) const override;
66 void unserialize(CheckpointIn &cp) override;
68 int cpuId() const { return baseCpu->cpuId(); }
70 uint32_t socketId() const { return baseCpu->socketId(); }
72 ContextID contextId() const { return _contextId; }
74 void setContextId(ContextID id) { _contextId = id; }
76 void setThreadId(ThreadID id) { _threadId = id; }
78 ThreadID threadId() const { return _threadId; }
80 Tick readLastActivate() const { return lastActivate; }
82 Tick readLastSuspend() const { return lastSuspend; }
85 * Initialise the physical and virtual port proxies and tie them to
86 * the data port of the CPU.
88 * @param tc ThreadContext for the virtual-to-physical translation
90 void initMemProxies(ThreadContext *tc);
92 void dumpFuncProfile();
94 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
100 Kernel::Statistics *getKernelStats() { return kernelStats; }
102 PortProxy &getPhysProxy();
104 PortProxy &getVirtProxy();
106 Process *getProcessPtr() { return process; }
108 void setProcessPtr(Process *p)
112 * When the process pointer changes while operating in SE Mode,
113 * the se translating port proxy needs to be reinitialized since it
114 * holds a pointer to the process class.
119 initMemProxies(NULL);
123 /** Reads the number of instructions functionally executed and
126 Counter readFuncExeInst() const { return funcExeInst; }
128 /** Sets the total number of instructions functionally executed
131 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
133 /** Returns the status of this thread. */
134 Status status() const { return _status; }
136 /** Sets the status of this thread. */
137 void setStatus(Status new_status) { _status = new_status; }
141 /** Number of instructions committed. */
143 /** Stat for number instructions committed. */
144 Stats::Scalar numInsts;
145 /** Number of ops (including micro ops) committed. */
147 /** Stat for number ops (including micro ops) committed. */
148 Stats::Scalar numOps;
149 /** Stat for number of memory references. */
150 Stats::Scalar numMemRefs;
152 /** Number of simulated loads, used for tracking events based on
153 * the number of loads committed.
157 /** The number of simulated loads committed prior to this run. */
158 Counter startNumLoad;
161 ThreadContext::Status _status;
163 // Pointer to the base CPU.
166 // system wide HW context id
167 ContextID _contextId;
169 // Index of hardware thread context on the CPU that this represents.
173 /** Last time activate was called on this thread. */
176 /** Last time suspend was called on this thread. */
180 FunctionProfile *profile;
181 ProfileNode *profileNode;
183 EndQuiesceEvent *quiesceEvent;
185 Kernel::Statistics *kernelStats;
190 /** A port proxy outgoing only for functional accesses to physical
192 PortProxy *physProxy;
194 /** A translating port proxy, outgoing only, for functional
195 * accesse to virtual addresses. */
196 PortProxy *virtProxy;
200 * number of executed instructions, for matching with syscall trace
201 * points in EIO files.
206 // Count failed store conditionals so we can warn of apparent
207 // application deadlock situations.
208 unsigned storeCondFailures;
211 #endif // __CPU_THREAD_STATE_HH__