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