thread_state.hh (8764:e4660687c49f) thread_state.hh (8766:b0773af78423)
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"
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
40#if !FULL_SYSTEM
41#include "mem/mem_object.hh"
42#include "sim/process.hh"
39#include "mem/mem_object.hh"
40#include "sim/process.hh"
43#endif
44
45#if FULL_SYSTEM
46class EndQuiesceEvent;
47class FunctionProfile;
48class ProfileNode;
49namespace TheISA {
50 namespace Kernel {
51 class Statistics;
52 };
53};
54#endif
55
56class Checkpoint;
57class Port;
58class TranslatingPort;
59
60/**
61 * Struct for holding general thread state that is needed across CPU
62 * models. This includes things such as pointers to the process,
63 * memory, quiesce events, and certain stats. This can be expanded
64 * to hold more thread-specific stats within it.
65 */
66struct ThreadState {
67 typedef ThreadContext::Status Status;
68
41
42#if FULL_SYSTEM
43class EndQuiesceEvent;
44class FunctionProfile;
45class ProfileNode;
46namespace TheISA {
47 namespace Kernel {
48 class Statistics;
49 };
50};
51#endif
52
53class Checkpoint;
54class Port;
55class TranslatingPort;
56
57/**
58 * Struct for holding general thread state that is needed across CPU
59 * models. This includes things such as pointers to the process,
60 * memory, quiesce events, and certain stats. This can be expanded
61 * to hold more thread-specific stats within it.
62 */
63struct ThreadState {
64 typedef ThreadContext::Status Status;
65
69#if FULL_SYSTEM
70 ThreadState(BaseCPU *cpu, ThreadID _tid);
71#else
72 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
66 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
73#endif
74
75 ~ThreadState();
76
77 void serialize(std::ostream &os);
78
79 void unserialize(Checkpoint *cp, const std::string &section);
80
81 int cpuId() { return baseCpu->cpuId(); }
82
83 int contextId() { return _contextId; }
84
85 void setContextId(int id) { _contextId = id; }
86
87 void setThreadId(ThreadID id) { _threadId = id; }
88
89 ThreadID threadId() { return _threadId; }
90
91 Tick readLastActivate() { return lastActivate; }
92
93 Tick readLastSuspend() { return lastSuspend; }
94
95 void connectPhysPort();
96
97 void connectVirtPort(ThreadContext *tc);
98
99#if FULL_SYSTEM
100 void connectMemPorts(ThreadContext *tc);
101
102 void dumpFuncProfile();
103
104 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
105
106 void profileClear();
107
108 void profileSample();
109
110 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
111#else
112 Process *getProcessPtr() { return process; }
113#endif
114
115 TranslatingPort *getMemPort();
116
117 void setMemPort(TranslatingPort *_port) { port = _port; }
118
119 VirtualPort *getVirtPort() { return virtPort; }
120
121 FunctionalPort *getPhysPort() { return physPort; }
122
123 void setPhysPort(FunctionalPort *port) { physPort = port; }
124
125 /** Reads the number of instructions functionally executed and
126 * committed.
127 */
128 Counter readFuncExeInst() { 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 /** Connects port to the functional port of the memory object
143 * below the CPU. */
144 void connectToMemFunc(Port *port);
145
146 /** Number of instructions committed. */
147 Counter numInst;
148 /** Stat for number instructions committed. */
149 Stats::Scalar numInsts;
150 /** Stat for number of memory references. */
151 Stats::Scalar numMemRefs;
152
153 /** Number of simulated loads, used for tracking events based on
154 * the number of loads committed.
155 */
156 Counter numLoad;
157
158 /** The number of simulated loads committed prior to this run. */
159 Counter startNumLoad;
160
161 protected:
162 ThreadContext::Status _status;
163
164 // Pointer to the base CPU.
165 BaseCPU *baseCpu;
166
167 // system wide HW context id
168 int _contextId;
169
170 // Index of hardware thread context on the CPU that this represents.
171 ThreadID _threadId;
172
173 public:
174 /** Last time activate was called on this thread. */
175 Tick lastActivate;
176
177 /** Last time suspend was called on this thread. */
178 Tick lastSuspend;
179
180#if FULL_SYSTEM
181 public:
182 FunctionProfile *profile;
183 ProfileNode *profileNode;
184 Addr profilePC;
185 EndQuiesceEvent *quiesceEvent;
186
187 TheISA::Kernel::Statistics *kernelStats;
67
68 ~ThreadState();
69
70 void serialize(std::ostream &os);
71
72 void unserialize(Checkpoint *cp, const std::string &section);
73
74 int cpuId() { return baseCpu->cpuId(); }
75
76 int contextId() { return _contextId; }
77
78 void setContextId(int id) { _contextId = id; }
79
80 void setThreadId(ThreadID id) { _threadId = id; }
81
82 ThreadID threadId() { return _threadId; }
83
84 Tick readLastActivate() { return lastActivate; }
85
86 Tick readLastSuspend() { return lastSuspend; }
87
88 void connectPhysPort();
89
90 void connectVirtPort(ThreadContext *tc);
91
92#if FULL_SYSTEM
93 void connectMemPorts(ThreadContext *tc);
94
95 void dumpFuncProfile();
96
97 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
98
99 void profileClear();
100
101 void profileSample();
102
103 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
104#else
105 Process *getProcessPtr() { return process; }
106#endif
107
108 TranslatingPort *getMemPort();
109
110 void setMemPort(TranslatingPort *_port) { port = _port; }
111
112 VirtualPort *getVirtPort() { return virtPort; }
113
114 FunctionalPort *getPhysPort() { return physPort; }
115
116 void setPhysPort(FunctionalPort *port) { physPort = port; }
117
118 /** Reads the number of instructions functionally executed and
119 * committed.
120 */
121 Counter readFuncExeInst() { return funcExeInst; }
122
123 /** Sets the total number of instructions functionally executed
124 * and committed.
125 */
126 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
127
128 /** Returns the status of this thread. */
129 Status status() const { return _status; }
130
131 /** Sets the status of this thread. */
132 void setStatus(Status new_status) { _status = new_status; }
133
134 public:
135 /** Connects port to the functional port of the memory object
136 * below the CPU. */
137 void connectToMemFunc(Port *port);
138
139 /** Number of instructions committed. */
140 Counter numInst;
141 /** Stat for number instructions committed. */
142 Stats::Scalar numInsts;
143 /** Stat for number of memory references. */
144 Stats::Scalar numMemRefs;
145
146 /** Number of simulated loads, used for tracking events based on
147 * the number of loads committed.
148 */
149 Counter numLoad;
150
151 /** The number of simulated loads committed prior to this run. */
152 Counter startNumLoad;
153
154 protected:
155 ThreadContext::Status _status;
156
157 // Pointer to the base CPU.
158 BaseCPU *baseCpu;
159
160 // system wide HW context id
161 int _contextId;
162
163 // Index of hardware thread context on the CPU that this represents.
164 ThreadID _threadId;
165
166 public:
167 /** Last time activate was called on this thread. */
168 Tick lastActivate;
169
170 /** Last time suspend was called on this thread. */
171 Tick lastSuspend;
172
173#if FULL_SYSTEM
174 public:
175 FunctionProfile *profile;
176 ProfileNode *profileNode;
177 Addr profilePC;
178 EndQuiesceEvent *quiesceEvent;
179
180 TheISA::Kernel::Statistics *kernelStats;
181#endif
188 protected:
182 protected:
189#else
190 Process *process;
183 Process *process;
191#endif
192
193 TranslatingPort *port;
194
195 /** A functional port, outgoing only, for functional accesse to virtual
196 * addresses. */
197 VirtualPort *virtPort;
198
199 /** A functional port outgoing only for functional accesses to physical
200 * addresses.*/
201 FunctionalPort *physPort;
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__
184
185 TranslatingPort *port;
186
187 /** A functional port, outgoing only, for functional accesse to virtual
188 * addresses. */
189 VirtualPort *virtPort;
190
191 /** A functional port outgoing only for functional accesses to physical
192 * addresses.*/
193 FunctionalPort *physPort;
194
195 public:
196 /*
197 * number of executed instructions, for matching with syscall trace
198 * points in EIO files.
199 */
200 Counter funcExeInst;
201
202 //
203 // Count failed store conditionals so we can warn of apparent
204 // application deadlock situations.
205 unsigned storeCondFailures;
206};
207
208#endif // __CPU_THREAD_STATE_HH__