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 "mem/translating_port.hh"
41 #include "sim/process.hh"
45 class EndQuiesceEvent;
46 class FunctionProfile;
56 * Struct for holding general thread state that is needed across CPU
57 * models. This includes things such as pointers to the process,
58 * memory, quiesce events, and certain stats. This can be expanded
59 * to hold more thread-specific stats within it.
62 typedef ThreadContext::Status Status;
65 ThreadState(int _cpuId, int _tid);
67 ThreadState(int _cpuId, int _tid, Process *_process,
68 short _asid, MemObject *mem);
71 void serialize(std::ostream &os);
73 void unserialize(Checkpoint *cp, const std::string §ion);
75 void setCpuId(int id) { cpuId = id; }
77 int readCpuId() { return cpuId; }
79 void setTid(int id) { tid = id; }
81 int readTid() { return tid; }
83 Tick readLastActivate() { return lastActivate; }
85 Tick readLastSuspend() { return lastSuspend; }
88 void dumpFuncProfile();
90 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
96 Kernel::Statistics *getKernelStats() { return kernelStats; }
98 FunctionalPort *getPhysPort() { return physPort; }
100 void setPhysPort(FunctionalPort *port) { physPort = port; }
102 VirtualPort *getVirtPort(ThreadContext *tc = NULL) { return virtPort; }
104 void setVirtPort(VirtualPort *port) { virtPort = port; }
106 Process *getProcessPtr() { return process; }
108 TranslatingPort *getMemPort() { return port; }
110 void setMemPort(TranslatingPort *_port) { port = _port; }
112 int getInstAsid() { return asid; }
113 int getDataAsid() { return asid; }
116 /** Sets the current instruction being committed. */
117 void setInst(TheISA::MachInst _inst) { inst = _inst; }
119 /** Returns the current instruction being committed. */
120 TheISA::MachInst getInst() { return inst; }
122 /** Reads the number of instructions functionally executed and
125 Counter readFuncExeInst() { return funcExeInst; }
127 /** Sets the total number of instructions functionally executed
130 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
132 /** Returns the status of this thread. */
133 Status status() const { return _status; }
135 /** Sets the status of this thread. */
136 void setStatus(Status new_status) { _status = new_status; }
138 /** Number of instructions committed. */
140 /** Stat for number instructions committed. */
141 Stats::Scalar<> numInsts;
142 /** Stat for number of memory references. */
143 Stats::Scalar<> numMemRefs;
145 /** Number of simulated loads, used for tracking events based on
146 * the number of loads committed.
150 /** The number of simulated loads committed prior to this run. */
151 Counter startNumLoad;
154 ThreadContext::Status _status;
156 // ID of this context w.r.t. the System or Process object to which
157 // it belongs. For full-system mode, this is the system CPU ID.
160 // Index of hardware thread context on the CPU that this represents.
164 /** Last time activate was called on this thread. */
167 /** Last time suspend was called on this thread. */
172 FunctionProfile *profile;
173 ProfileNode *profileNode;
175 EndQuiesceEvent *quiesceEvent;
177 Kernel::Statistics *kernelStats;
179 /** A functional port outgoing only for functional accesses to physical
181 FunctionalPort *physPort;
183 /** A functional port, outgoing only, for functional accesse to virtual
184 * addresses. That doen't require execution context information */
185 VirtualPort *virtPort;
187 TranslatingPort *port;
191 // Address space ID. Note that this is used for TIMING cache
192 // simulation only; all functional memory accesses should use
193 // one of the FunctionalMemory pointers above.
198 /** Current instruction the thread is committing. Only set and
199 * used for DTB faults currently.
201 TheISA::MachInst inst;
203 /** The current microcode pc for the currently executing macro
208 /** The next microcode pc for the currently executing macro
215 * Temporary storage to pass the source address from copy_load to
217 * @todo Remove this temporary when we have a better way to do it.
221 * Temp storage for the physical source address of a copy.
222 * @todo Remove this temporary when we have a better way to do it.
224 Addr copySrcPhysAddr;
227 * number of executed instructions, for matching with syscall trace
228 * points in EIO files.
233 // Count failed store conditionals so we can warn of apparent
234 // application deadlock situations.
235 unsigned storeCondFailures;
238 #endif // __CPU_THREAD_STATE_HH__