thread_state.hh (11886:43b882cada33) thread_state.hh (13865:cca49fc49c57)
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 "mem/mem_object.hh"
40#include "sim/process.hh"
41
42class EndQuiesceEvent;
43class FunctionProfile;
44class ProfileNode;
45namespace TheISA {
46 namespace Kernel {
47 class Statistics;
48 }
49}
50
51class Checkpoint;
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 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
103
104 PortProxy &getPhysProxy();
105
106 FSTranslatingPortProxy &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 (proxy) {
119 delete proxy;
120 proxy = NULL;
121 initMemProxies(NULL);
122 }
123 }
124
125 SETranslatingPortProxy &getMemProxy();
126
127 /** Reads the number of instructions functionally executed and
128 * committed.
129 */
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 "mem/mem_object.hh"
40#include "sim/process.hh"
41
42class EndQuiesceEvent;
43class FunctionProfile;
44class ProfileNode;
45namespace TheISA {
46 namespace Kernel {
47 class Statistics;
48 }
49}
50
51class Checkpoint;
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 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
103
104 PortProxy &getPhysProxy();
105
106 FSTranslatingPortProxy &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 (proxy) {
119 delete proxy;
120 proxy = NULL;
121 initMemProxies(NULL);
122 }
123 }
124
125 SETranslatingPortProxy &getMemProxy();
126
127 /** Reads the number of instructions functionally executed and
128 * committed.
129 */
130 Counter readFuncExeInst() { return funcExeInst; }
130 Counter readFuncExeInst() const { return funcExeInst; }
131
132 /** Sets the total number of instructions functionally executed
133 * and committed.
134 */
135 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
136
137 /** Returns the status of this thread. */
138 Status status() const { return _status; }
139
140 /** Sets the status of this thread. */
141 void setStatus(Status new_status) { _status = new_status; }
142
143 public:
144
145 /** Number of instructions committed. */
146 Counter numInst;
147 /** Stat for number instructions committed. */
148 Stats::Scalar numInsts;
149 /** Number of ops (including micro ops) committed. */
150 Counter numOp;
151 /** Stat for number ops (including micro ops) committed. */
152 Stats::Scalar numOps;
153 /** Stat for number of memory references. */
154 Stats::Scalar numMemRefs;
155
156 /** Number of simulated loads, used for tracking events based on
157 * the number of loads committed.
158 */
159 Counter numLoad;
160
161 /** The number of simulated loads committed prior to this run. */
162 Counter startNumLoad;
163
164 protected:
165 ThreadContext::Status _status;
166
167 // Pointer to the base CPU.
168 BaseCPU *baseCpu;
169
170 // system wide HW context id
171 ContextID _contextId;
172
173 // Index of hardware thread context on the CPU that this represents.
174 ThreadID _threadId;
175
176 public:
177 /** Last time activate was called on this thread. */
178 Tick lastActivate;
179
180 /** Last time suspend was called on this thread. */
181 Tick lastSuspend;
182
183 public:
184 FunctionProfile *profile;
185 ProfileNode *profileNode;
186 Addr profilePC;
187 EndQuiesceEvent *quiesceEvent;
188
189 TheISA::Kernel::Statistics *kernelStats;
190
191 protected:
192 Process *process;
193
194 /** A port proxy outgoing only for functional accesses to physical
195 * addresses.*/
196 PortProxy *physProxy;
197
198 /** A translating port proxy, outgoing only, for functional
199 * accesse to virtual addresses. */
200 FSTranslatingPortProxy *virtProxy;
201 SETranslatingPortProxy *proxy;
202
203 public:
204 /*
205 * number of executed instructions, for matching with syscall trace
206 * points in EIO files.
207 */
208 Counter funcExeInst;
209
210 //
211 // Count failed store conditionals so we can warn of apparent
212 // application deadlock situations.
213 unsigned storeCondFailures;
214};
215
216#endif // __CPU_THREAD_STATE_HH__
131
132 /** Sets the total number of instructions functionally executed
133 * and committed.
134 */
135 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
136
137 /** Returns the status of this thread. */
138 Status status() const { return _status; }
139
140 /** Sets the status of this thread. */
141 void setStatus(Status new_status) { _status = new_status; }
142
143 public:
144
145 /** Number of instructions committed. */
146 Counter numInst;
147 /** Stat for number instructions committed. */
148 Stats::Scalar numInsts;
149 /** Number of ops (including micro ops) committed. */
150 Counter numOp;
151 /** Stat for number ops (including micro ops) committed. */
152 Stats::Scalar numOps;
153 /** Stat for number of memory references. */
154 Stats::Scalar numMemRefs;
155
156 /** Number of simulated loads, used for tracking events based on
157 * the number of loads committed.
158 */
159 Counter numLoad;
160
161 /** The number of simulated loads committed prior to this run. */
162 Counter startNumLoad;
163
164 protected:
165 ThreadContext::Status _status;
166
167 // Pointer to the base CPU.
168 BaseCPU *baseCpu;
169
170 // system wide HW context id
171 ContextID _contextId;
172
173 // Index of hardware thread context on the CPU that this represents.
174 ThreadID _threadId;
175
176 public:
177 /** Last time activate was called on this thread. */
178 Tick lastActivate;
179
180 /** Last time suspend was called on this thread. */
181 Tick lastSuspend;
182
183 public:
184 FunctionProfile *profile;
185 ProfileNode *profileNode;
186 Addr profilePC;
187 EndQuiesceEvent *quiesceEvent;
188
189 TheISA::Kernel::Statistics *kernelStats;
190
191 protected:
192 Process *process;
193
194 /** A port proxy outgoing only for functional accesses to physical
195 * addresses.*/
196 PortProxy *physProxy;
197
198 /** A translating port proxy, outgoing only, for functional
199 * accesse to virtual addresses. */
200 FSTranslatingPortProxy *virtProxy;
201 SETranslatingPortProxy *proxy;
202
203 public:
204 /*
205 * number of executed instructions, for matching with syscall trace
206 * points in EIO files.
207 */
208 Counter funcExeInst;
209
210 //
211 // Count failed store conditionals so we can warn of apparent
212 // application deadlock situations.
213 unsigned storeCondFailures;
214};
215
216#endif // __CPU_THREAD_STATE_HH__