cpu: convert thread_state to new style stats
[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/thread_context.hh"
36 #include "sim/process.hh"
37
38 class Checkpoint;
39
40 /**
41 * Struct for holding general thread state that is needed across CPU
42 * models. This includes things such as pointers to the process,
43 * memory, quiesce events, and certain stats. This can be expanded
44 * to hold more thread-specific stats within it.
45 */
46 struct ThreadState : public Serializable {
47 typedef ThreadContext::Status Status;
48
49 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
50
51 virtual ~ThreadState();
52
53 void serialize(CheckpointOut &cp) const override;
54
55 void unserialize(CheckpointIn &cp) override;
56
57 int cpuId() const { return baseCpu->cpuId(); }
58
59 uint32_t socketId() const { return baseCpu->socketId(); }
60
61 ContextID contextId() const { return _contextId; }
62
63 void setContextId(ContextID id) { _contextId = id; }
64
65 void setThreadId(ThreadID id) { _threadId = id; }
66
67 ThreadID threadId() const { return _threadId; }
68
69 Tick readLastActivate() const { return lastActivate; }
70
71 Tick readLastSuspend() const { return lastSuspend; }
72
73 /**
74 * Initialise the physical and virtual port proxies and tie them to
75 * the data port of the CPU.
76 *
77 * @param tc ThreadContext for the virtual-to-physical translation
78 */
79 void initMemProxies(ThreadContext *tc);
80
81 PortProxy &getPhysProxy();
82
83 PortProxy &getVirtProxy();
84
85 Process *getProcessPtr() { return process; }
86
87 void setProcessPtr(Process *p) { process = p; }
88
89 /** Reads the number of instructions functionally executed and
90 * committed.
91 */
92 Counter readFuncExeInst() const { return funcExeInst; }
93
94 /** Sets the total number of instructions functionally executed
95 * and committed.
96 */
97 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
98
99 /** Returns the status of this thread. */
100 Status status() const { return _status; }
101
102 /** Sets the status of this thread. */
103 void setStatus(Status new_status) { _status = new_status; }
104
105 public:
106
107 /** Number of instructions committed. */
108 Counter numInst;
109 /** Number of ops (including micro ops) committed. */
110 Counter numOp;
111 // Defining the stat group
112 struct ThreadStateStats : public Stats::Group
113 {
114 ThreadStateStats(BaseCPU *cpu, ThreadState *thread);
115 /** Stat for number instructions committed. */
116 Stats::Scalar numInsts;
117 /** Stat for number ops (including micro ops) committed. */
118 Stats::Scalar numOps;
119 /** Stat for number of memory references. */
120 Stats::Scalar numMemRefs;
121 } threadStats;
122
123 /** Number of simulated loads, used for tracking events based on
124 * the number of loads committed.
125 */
126 Counter numLoad;
127
128 /** The number of simulated loads committed prior to this run. */
129 Counter startNumLoad;
130
131 protected:
132 ThreadContext::Status _status;
133
134 // Pointer to the base CPU.
135 BaseCPU *baseCpu;
136
137 // system wide HW context id
138 ContextID _contextId;
139
140 // Index of hardware thread context on the CPU that this represents.
141 ThreadID _threadId;
142
143 public:
144 /** Last time activate was called on this thread. */
145 Tick lastActivate;
146
147 /** Last time suspend was called on this thread. */
148 Tick lastSuspend;
149
150 protected:
151 Process *process;
152
153 /** A port proxy outgoing only for functional accesses to physical
154 * addresses.*/
155 PortProxy *physProxy;
156
157 /** A translating port proxy, outgoing only, for functional
158 * accesse to virtual addresses. */
159 PortProxy *virtProxy;
160
161 public:
162 /*
163 * number of executed instructions, for matching with syscall trace
164 * points in EIO files.
165 */
166 Counter funcExeInst;
167
168 //
169 // Count failed store conditionals so we can warn of apparent
170 // application deadlock situations.
171 unsigned storeCondFailures;
172 };
173
174 #endif // __CPU_THREAD_STATE_HH__