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 "config/the_isa.hh"
36 #include "cpu/base.hh"
37 #include "cpu/profile.hh"
38 #include "cpu/thread_context.hh"
41 #include "mem/mem_object.hh"
42 #include "sim/process.hh"
46 class EndQuiesceEvent;
47 class FunctionProfile;
58 class TranslatingPort;
61 * Struct for holding general thread state that is needed across CPU
62 * models. This includes things such as pointers to the process,
63 * memory, quiesce events, and certain stats. This can be expanded
64 * to hold more thread-specific stats within it.
67 typedef ThreadContext::Status Status;
70 ThreadState(BaseCPU *cpu, ThreadID _tid);
72 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
77 void serialize(std::ostream &os);
79 void unserialize(Checkpoint *cp, const std::string §ion);
81 int cpuId() { return baseCpu->cpuId(); }
83 int contextId() { return _contextId; }
85 void setContextId(int id) { _contextId = id; }
87 void setThreadId(ThreadID id) { _threadId = id; }
89 ThreadID threadId() { return _threadId; }
91 Tick readLastActivate() { return lastActivate; }
93 Tick readLastSuspend() { return lastSuspend; }
96 void connectMemPorts(ThreadContext *tc);
98 void connectPhysPort();
100 void connectVirtPort(ThreadContext *tc);
102 void dumpFuncProfile();
104 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
108 void profileSample();
110 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
112 FunctionalPort *getPhysPort() { return physPort; }
114 void setPhysPort(FunctionalPort *port) { physPort = port; }
116 VirtualPort *getVirtPort() { return virtPort; }
118 Process *getProcessPtr() { return process; }
120 TranslatingPort *getMemPort();
122 void setMemPort(TranslatingPort *_port) { port = _port; }
125 /** Reads the number of instructions functionally executed and
128 Counter readFuncExeInst() { return funcExeInst; }
130 /** Sets the total number of instructions functionally executed
133 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
135 /** Returns the status of this thread. */
136 Status status() const { return _status; }
138 /** Sets the status of this thread. */
139 void setStatus(Status new_status) { _status = new_status; }
142 /** Connects port to the functional port of the memory object
144 void connectToMemFunc(Port *port);
146 /** Number of instructions committed. */
148 /** Stat for number instructions committed. */
149 Stats::Scalar numInsts;
150 /** Stat for number of memory references. */
151 Stats::Scalar numMemRefs;
153 /** Number of simulated loads, used for tracking events based on
154 * the number of loads committed.
158 /** The number of simulated loads committed prior to this run. */
159 Counter startNumLoad;
162 ThreadContext::Status _status;
164 // Pointer to the base CPU.
167 // system wide HW context id
170 // Index of hardware thread context on the CPU that this represents.
174 /** Last time activate was called on this thread. */
177 /** Last time suspend was called on this thread. */
182 FunctionProfile *profile;
183 ProfileNode *profileNode;
185 EndQuiesceEvent *quiesceEvent;
187 TheISA::Kernel::Statistics *kernelStats;
189 /** A functional port outgoing only for functional accesses to physical
191 FunctionalPort *physPort;
193 /** A functional port, outgoing only, for functional accesse to virtual
195 VirtualPort *virtPort;
197 TranslatingPort *port;
204 * number of executed instructions, for matching with syscall trace
205 * points in EIO files.
210 // Count failed store conditionals so we can warn of apparent
211 // application deadlock situations.
212 unsigned storeCondFailures;
215 #endif // __CPU_THREAD_STATE_HH__