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.
31 #ifndef __CPU_THREAD_STATE_HH__
32 #define __CPU_THREAD_STATE_HH__
34 #include "arch/types.hh"
35 #include "cpu/profile.hh"
36 #include "cpu/thread_context.hh"
39 #include "mem/mem_object.hh"
40 #include "sim/process.hh"
44 class EndQuiesceEvent;
45 class FunctionProfile;
55 class TranslatingPort;
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.
64 typedef ThreadContext::Status Status;
67 ThreadState(BaseCPU *cpu, int _cpuId, int _tid);
69 ThreadState(BaseCPU *cpu, int _cpuId, int _tid, Process *_process,
75 void serialize(std::ostream &os);
77 void unserialize(Checkpoint *cp, const std::string §ion);
79 void setCpuId(int id) { cpuId = id; }
81 int readCpuId() { return cpuId; }
83 void setTid(int id) { tid = id; }
85 int readTid() { return tid; }
87 Tick readLastActivate() { return lastActivate; }
89 Tick readLastSuspend() { return lastSuspend; }
92 void dumpFuncProfile();
94 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
100 Kernel::Statistics *getKernelStats() { return kernelStats; }
102 FunctionalPort *getPhysPort() { return physPort; }
104 void setPhysPort(FunctionalPort *port) { physPort = port; }
106 VirtualPort *getVirtPort(ThreadContext *tc = NULL) { return virtPort; }
108 void setVirtPort(VirtualPort *port) { virtPort = port; }
110 Process *getProcessPtr() { return process; }
112 TranslatingPort *getMemPort();
114 void setMemPort(TranslatingPort *_port) { port = _port; }
116 int getInstAsid() { return asid; }
117 int getDataAsid() { return asid; }
120 /** Sets the current instruction being committed. */
121 void setInst(TheISA::MachInst _inst) { inst = _inst; }
123 /** Returns the current instruction being committed. */
124 TheISA::MachInst getInst() { return inst; }
126 /** Reads the number of instructions functionally executed and
129 Counter readFuncExeInst() { return funcExeInst; }
131 /** Sets the total number of instructions functionally executed
134 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
136 /** Returns the status of this thread. */
137 Status status() const { return _status; }
139 /** Sets the status of this thread. */
140 void setStatus(Status new_status) { _status = new_status; }
143 /** Gets a functional port from the memory object that's connected
145 Port *getMemFuncPort();
148 /** Number of instructions committed. */
150 /** Stat for number instructions committed. */
151 Stats::Scalar<> numInsts;
152 /** Stat for number of memory references. */
153 Stats::Scalar<> numMemRefs;
155 /** Number of simulated loads, used for tracking events based on
156 * the number of loads committed.
160 /** The number of simulated loads committed prior to this run. */
161 Counter startNumLoad;
164 ThreadContext::Status _status;
166 // Pointer to the base CPU.
169 // ID of this context w.r.t. the System or Process object to which
170 // it belongs. For full-system mode, this is the system CPU ID.
173 // Index of hardware thread context on the CPU that this represents.
177 /** Last time activate was called on this thread. */
180 /** Last time suspend was called on this thread. */
185 FunctionProfile *profile;
186 ProfileNode *profileNode;
188 EndQuiesceEvent *quiesceEvent;
190 Kernel::Statistics *kernelStats;
192 /** A functional port outgoing only for functional accesses to physical
194 FunctionalPort *physPort;
196 /** A functional port, outgoing only, for functional accesse to virtual
197 * addresses. That doen't require execution context information */
198 VirtualPort *virtPort;
200 TranslatingPort *port;
204 // Address space ID. Note that this is used for TIMING cache
205 // simulation only; all functional memory accesses should use
206 // one of the FunctionalMemory pointers above.
211 /** Current instruction the thread is committing. Only set and
212 * used for DTB faults currently.
214 TheISA::MachInst inst;
216 /** The current microcode pc for the currently executing macro
221 /** The next microcode pc for the currently executing macro
228 * Temporary storage to pass the source address from copy_load to
230 * @todo Remove this temporary when we have a better way to do it.
234 * Temp storage for the physical source address of a copy.
235 * @todo Remove this temporary when we have a better way to do it.
237 Addr copySrcPhysAddr;
240 * number of executed instructions, for matching with syscall trace
241 * points in EIO files.
246 // Count failed store conditionals so we can warn of apparent
247 // application deadlock situations.
248 unsigned storeCondFailures;
251 #endif // __CPU_THREAD_STATE_HH__