cpu: Delete authors lists from the cpu directory.
[gem5.git] / src / cpu / thread_state.hh
1 /*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 #ifndef __CPU_THREAD_STATE_HH__
30 #define __CPU_THREAD_STATE_HH__
31
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"
38
39 class EndQuiesceEvent;
40 class FunctionProfile;
41 class ProfileNode;
42 namespace Kernel {
43 class Statistics;
44 }
45
46 class Checkpoint;
47
48 class FSTranslatingPortProxy;
49 class SETranslatingPortProxy;
50
51 /**
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.
56 */
57 struct ThreadState : public Serializable {
58 typedef ThreadContext::Status Status;
59
60 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
61
62 virtual ~ThreadState();
63
64 void serialize(CheckpointOut &cp) const override;
65
66 void unserialize(CheckpointIn &cp) override;
67
68 int cpuId() const { return baseCpu->cpuId(); }
69
70 uint32_t socketId() const { return baseCpu->socketId(); }
71
72 ContextID contextId() const { return _contextId; }
73
74 void setContextId(ContextID id) { _contextId = id; }
75
76 void setThreadId(ThreadID id) { _threadId = id; }
77
78 ThreadID threadId() const { return _threadId; }
79
80 Tick readLastActivate() const { return lastActivate; }
81
82 Tick readLastSuspend() const { return lastSuspend; }
83
84 /**
85 * Initialise the physical and virtual port proxies and tie them to
86 * the data port of the CPU.
87 *
88 * @param tc ThreadContext for the virtual-to-physical translation
89 */
90 void initMemProxies(ThreadContext *tc);
91
92 void dumpFuncProfile();
93
94 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
95
96 void profileClear();
97
98 void profileSample();
99
100 Kernel::Statistics *getKernelStats() { return kernelStats; }
101
102 PortProxy &getPhysProxy();
103
104 PortProxy &getVirtProxy();
105
106 Process *getProcessPtr() { return process; }
107
108 void setProcessPtr(Process *p)
109 {
110 process = p;
111 /**
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.
115 */
116 if (virtProxy) {
117 delete virtProxy;
118 virtProxy = NULL;
119 initMemProxies(NULL);
120 }
121 }
122
123 /** Reads the number of instructions functionally executed and
124 * committed.
125 */
126 Counter readFuncExeInst() const { return funcExeInst; }
127
128 /** Sets the total number of instructions functionally executed
129 * and committed.
130 */
131 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
132
133 /** Returns the status of this thread. */
134 Status status() const { return _status; }
135
136 /** Sets the status of this thread. */
137 void setStatus(Status new_status) { _status = new_status; }
138
139 public:
140
141 /** Number of instructions committed. */
142 Counter numInst;
143 /** Stat for number instructions committed. */
144 Stats::Scalar numInsts;
145 /** Number of ops (including micro ops) committed. */
146 Counter numOp;
147 /** Stat for number ops (including micro ops) committed. */
148 Stats::Scalar numOps;
149 /** Stat for number of memory references. */
150 Stats::Scalar numMemRefs;
151
152 /** Number of simulated loads, used for tracking events based on
153 * the number of loads committed.
154 */
155 Counter numLoad;
156
157 /** The number of simulated loads committed prior to this run. */
158 Counter startNumLoad;
159
160 protected:
161 ThreadContext::Status _status;
162
163 // Pointer to the base CPU.
164 BaseCPU *baseCpu;
165
166 // system wide HW context id
167 ContextID _contextId;
168
169 // Index of hardware thread context on the CPU that this represents.
170 ThreadID _threadId;
171
172 public:
173 /** Last time activate was called on this thread. */
174 Tick lastActivate;
175
176 /** Last time suspend was called on this thread. */
177 Tick lastSuspend;
178
179 public:
180 FunctionProfile *profile;
181 ProfileNode *profileNode;
182 Addr profilePC;
183 EndQuiesceEvent *quiesceEvent;
184
185 Kernel::Statistics *kernelStats;
186
187 protected:
188 Process *process;
189
190 /** A port proxy outgoing only for functional accesses to physical
191 * addresses.*/
192 PortProxy *physProxy;
193
194 /** A translating port proxy, outgoing only, for functional
195 * accesse to virtual addresses. */
196 PortProxy *virtProxy;
197
198 public:
199 /*
200 * number of executed instructions, for matching with syscall trace
201 * points in EIO files.
202 */
203 Counter funcExeInst;
204
205 //
206 // Count failed store conditionals so we can warn of apparent
207 // application deadlock situations.
208 unsigned storeCondFailures;
209 };
210
211 #endif // __CPU_THREAD_STATE_HH__