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;
57 class TranslatingPort;
60 * Struct for holding general thread state that is needed across CPU
61 * models. This includes things such as pointers to the process,
62 * memory, quiesce events, and certain stats. This can be expanded
63 * to hold more thread-specific stats within it.
66 typedef ThreadContext::Status Status;
69 ThreadState(BaseCPU *cpu, int _cpuId, int _tid);
71 ThreadState(BaseCPU *cpu, int _cpuId, int _tid, Process *_process,
77 void serialize(std::ostream &os);
79 void unserialize(Checkpoint *cp, const std::string §ion);
81 void setCpuId(int id) { cpuId = id; }
83 int readCpuId() { return cpuId; }
85 void setTid(int id) { tid = id; }
87 int readTid() { return tid; }
89 Tick readLastActivate() { return lastActivate; }
91 Tick readLastSuspend() { return lastSuspend; }
94 void connectMemPorts(ThreadContext *tc);
96 void connectPhysPort();
98 void connectVirtPort(ThreadContext *tc);
100 void dumpFuncProfile();
102 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
106 void profileSample();
108 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
110 FunctionalPort *getPhysPort() { return physPort; }
112 void setPhysPort(FunctionalPort *port) { physPort = port; }
114 VirtualPort *getVirtPort() { return virtPort; }
116 Process *getProcessPtr() { return process; }
118 TranslatingPort *getMemPort();
120 void setMemPort(TranslatingPort *_port) { port = _port; }
122 int getInstAsid() { return asid; }
123 int getDataAsid() { return asid; }
126 /** Sets the current instruction being committed. */
127 void setInst(TheISA::MachInst _inst) { inst = _inst; }
129 /** Returns the current instruction being committed. */
130 TheISA::MachInst getInst() { return inst; }
132 /** Reads the number of instructions functionally executed and
135 Counter readFuncExeInst() { return funcExeInst; }
137 /** Sets the total number of instructions functionally executed
140 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
142 /** Returns the status of this thread. */
143 Status status() const { return _status; }
145 /** Sets the status of this thread. */
146 void setStatus(Status new_status) { _status = new_status; }
149 /** Connects port to the functional port of the memory object
151 void connectToMemFunc(Port *port);
153 /** Number of instructions committed. */
155 /** Stat for number instructions committed. */
156 Stats::Scalar<> numInsts;
157 /** Stat for number of memory references. */
158 Stats::Scalar<> numMemRefs;
160 /** Number of simulated loads, used for tracking events based on
161 * the number of loads committed.
165 /** The number of simulated loads committed prior to this run. */
166 Counter startNumLoad;
169 ThreadContext::Status _status;
171 // Pointer to the base CPU.
174 // ID of this context w.r.t. the System or Process object to which
175 // it belongs. For full-system mode, this is the system CPU ID.
178 // Index of hardware thread context on the CPU that this represents.
182 /** Last time activate was called on this thread. */
185 /** Last time suspend was called on this thread. */
190 FunctionProfile *profile;
191 ProfileNode *profileNode;
193 EndQuiesceEvent *quiesceEvent;
195 TheISA::Kernel::Statistics *kernelStats;
197 /** A functional port outgoing only for functional accesses to physical
199 FunctionalPort *physPort;
201 /** A functional port, outgoing only, for functional accesse to virtual
203 VirtualPort *virtPort;
205 TranslatingPort *port;
209 // Address space ID. Note that this is used for TIMING cache
210 // simulation only; all functional memory accesses should use
211 // one of the FunctionalMemory pointers above.
216 /** Current instruction the thread is committing. Only set and
217 * used for DTB faults currently.
219 TheISA::MachInst inst;
221 /** The current microcode pc for the currently executing macro
226 /** The next microcode pc for the currently executing macro
233 * Temporary storage to pass the source address from copy_load to
235 * @todo Remove this temporary when we have a better way to do it.
239 * Temp storage for the physical source address of a copy.
240 * @todo Remove this temporary when we have a better way to do it.
242 Addr copySrcPhysAddr;
245 * number of executed instructions, for matching with syscall trace
246 * points in EIO files.
251 // Count failed store conditionals so we can warn of apparent
252 // application deadlock situations.
253 unsigned storeCondFailures;
256 #endif // __CPU_THREAD_STATE_HH__