thread_state.hh (10190:fb83d025d1c3) thread_state.hh (10905:a6ca6831e775)
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 */
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 {
59struct ThreadState : public Serializable {
60 typedef ThreadContext::Status Status;
61
62 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
63
64 virtual ~ThreadState();
65
60 typedef ThreadContext::Status Status;
61
62 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
63
64 virtual ~ThreadState();
65
66 void serialize(std::ostream &os);
66 void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
67
67
68 void unserialize(Checkpoint *cp, const std::string &section);
68 void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
69
70 int cpuId() const { return baseCpu->cpuId(); }
71
72 uint32_t socketId() const { return baseCpu->socketId(); }
73
74 int contextId() const { return _contextId; }
75
76 void setContextId(int 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 SETranslatingPortProxy &getMemProxy();
111
112 /** Reads the number of instructions functionally executed and
113 * committed.
114 */
115 Counter readFuncExeInst() { return funcExeInst; }
116
117 /** Sets the total number of instructions functionally executed
118 * and committed.
119 */
120 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
121
122 /** Returns the status of this thread. */
123 Status status() const { return _status; }
124
125 /** Sets the status of this thread. */
126 void setStatus(Status new_status) { _status = new_status; }
127
128 public:
129
130 /** Number of instructions committed. */
131 Counter numInst;
132 /** Stat for number instructions committed. */
133 Stats::Scalar numInsts;
134 /** Number of ops (including micro ops) committed. */
135 Counter numOp;
136 /** Stat for number ops (including micro ops) committed. */
137 Stats::Scalar numOps;
138 /** Stat for number of memory references. */
139 Stats::Scalar numMemRefs;
140
141 /** Number of simulated loads, used for tracking events based on
142 * the number of loads committed.
143 */
144 Counter numLoad;
145
146 /** The number of simulated loads committed prior to this run. */
147 Counter startNumLoad;
148
149 protected:
150 ThreadContext::Status _status;
151
152 // Pointer to the base CPU.
153 BaseCPU *baseCpu;
154
155 // system wide HW context id
156 int _contextId;
157
158 // Index of hardware thread context on the CPU that this represents.
159 ThreadID _threadId;
160
161 public:
162 /** Last time activate was called on this thread. */
163 Tick lastActivate;
164
165 /** Last time suspend was called on this thread. */
166 Tick lastSuspend;
167
168 public:
169 FunctionProfile *profile;
170 ProfileNode *profileNode;
171 Addr profilePC;
172 EndQuiesceEvent *quiesceEvent;
173
174 TheISA::Kernel::Statistics *kernelStats;
175
176 protected:
177 Process *process;
178
179 /** A port proxy outgoing only for functional accesses to physical
180 * addresses.*/
181 PortProxy *physProxy;
182
183 /** A translating port proxy, outgoing only, for functional
184 * accesse to virtual addresses. */
185 FSTranslatingPortProxy *virtProxy;
186 SETranslatingPortProxy *proxy;
187
188 public:
189 /*
190 * number of executed instructions, for matching with syscall trace
191 * points in EIO files.
192 */
193 Counter funcExeInst;
194
195 //
196 // Count failed store conditionals so we can warn of apparent
197 // application deadlock situations.
198 unsigned storeCondFailures;
199};
200
201#endif // __CPU_THREAD_STATE_HH__
69
70 int cpuId() const { return baseCpu->cpuId(); }
71
72 uint32_t socketId() const { return baseCpu->socketId(); }
73
74 int contextId() const { return _contextId; }
75
76 void setContextId(int 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 SETranslatingPortProxy &getMemProxy();
111
112 /** Reads the number of instructions functionally executed and
113 * committed.
114 */
115 Counter readFuncExeInst() { return funcExeInst; }
116
117 /** Sets the total number of instructions functionally executed
118 * and committed.
119 */
120 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
121
122 /** Returns the status of this thread. */
123 Status status() const { return _status; }
124
125 /** Sets the status of this thread. */
126 void setStatus(Status new_status) { _status = new_status; }
127
128 public:
129
130 /** Number of instructions committed. */
131 Counter numInst;
132 /** Stat for number instructions committed. */
133 Stats::Scalar numInsts;
134 /** Number of ops (including micro ops) committed. */
135 Counter numOp;
136 /** Stat for number ops (including micro ops) committed. */
137 Stats::Scalar numOps;
138 /** Stat for number of memory references. */
139 Stats::Scalar numMemRefs;
140
141 /** Number of simulated loads, used for tracking events based on
142 * the number of loads committed.
143 */
144 Counter numLoad;
145
146 /** The number of simulated loads committed prior to this run. */
147 Counter startNumLoad;
148
149 protected:
150 ThreadContext::Status _status;
151
152 // Pointer to the base CPU.
153 BaseCPU *baseCpu;
154
155 // system wide HW context id
156 int _contextId;
157
158 // Index of hardware thread context on the CPU that this represents.
159 ThreadID _threadId;
160
161 public:
162 /** Last time activate was called on this thread. */
163 Tick lastActivate;
164
165 /** Last time suspend was called on this thread. */
166 Tick lastSuspend;
167
168 public:
169 FunctionProfile *profile;
170 ProfileNode *profileNode;
171 Addr profilePC;
172 EndQuiesceEvent *quiesceEvent;
173
174 TheISA::Kernel::Statistics *kernelStats;
175
176 protected:
177 Process *process;
178
179 /** A port proxy outgoing only for functional accesses to physical
180 * addresses.*/
181 PortProxy *physProxy;
182
183 /** A translating port proxy, outgoing only, for functional
184 * accesse to virtual addresses. */
185 FSTranslatingPortProxy *virtProxy;
186 SETranslatingPortProxy *proxy;
187
188 public:
189 /*
190 * number of executed instructions, for matching with syscall trace
191 * points in EIO files.
192 */
193 Counter funcExeInst;
194
195 //
196 // Count failed store conditionals so we can warn of apparent
197 // application deadlock situations.
198 unsigned storeCondFailures;
199};
200
201#endif // __CPU_THREAD_STATE_HH__