2 * Copyright (c) 2006 The Regents of The University of Michigan
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.
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.
29 #ifndef __CPU_THREAD_STATE_HH__
30 #define __CPU_THREAD_STATE_HH__
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"
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.
46 struct ThreadState : public Serializable {
47 typedef ThreadContext::Status Status;
49 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
51 virtual ~ThreadState();
53 void serialize(CheckpointOut &cp) const override;
55 void unserialize(CheckpointIn &cp) override;
57 int cpuId() const { return baseCpu->cpuId(); }
59 uint32_t socketId() const { return baseCpu->socketId(); }
61 ContextID contextId() const { return _contextId; }
63 void setContextId(ContextID id) { _contextId = id; }
65 void setThreadId(ThreadID id) { _threadId = id; }
67 ThreadID threadId() const { return _threadId; }
69 Tick readLastActivate() const { return lastActivate; }
71 Tick readLastSuspend() const { return lastSuspend; }
74 * Initialise the physical and virtual port proxies and tie them to
75 * the data port of the CPU.
77 * @param tc ThreadContext for the virtual-to-physical translation
79 void initMemProxies(ThreadContext *tc);
81 PortProxy &getPhysProxy();
83 PortProxy &getVirtProxy();
85 Process *getProcessPtr() { return process; }
87 void setProcessPtr(Process *p) { process = p; }
89 /** Reads the number of instructions functionally executed and
92 Counter readFuncExeInst() const { return funcExeInst; }
94 /** Sets the total number of instructions functionally executed
97 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
99 /** Returns the status of this thread. */
100 Status status() const { return _status; }
102 /** Sets the status of this thread. */
103 void setStatus(Status new_status) { _status = new_status; }
107 /** Number of instructions committed. */
109 /** Number of ops (including micro ops) committed. */
111 // Defining the stat group
112 struct ThreadStateStats : public Stats::Group
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;
123 /** Number of simulated loads, used for tracking events based on
124 * the number of loads committed.
128 /** The number of simulated loads committed prior to this run. */
129 Counter startNumLoad;
132 ThreadContext::Status _status;
134 // Pointer to the base CPU.
137 // system wide HW context id
138 ContextID _contextId;
140 // Index of hardware thread context on the CPU that this represents.
144 /** Last time activate was called on this thread. */
147 /** Last time suspend was called on this thread. */
153 /** A port proxy outgoing only for functional accesses to physical
155 PortProxy *physProxy;
157 /** A translating port proxy, outgoing only, for functional
158 * accesse to virtual addresses. */
159 PortProxy *virtProxy;
163 * number of executed instructions, for matching with syscall trace
164 * points in EIO files.
169 // Count failed store conditionals so we can warn of apparent
170 // application deadlock situations.
171 unsigned storeCondFailures;
174 #endif // __CPU_THREAD_STATE_HH__