thread_state.hh revision 13892:0182a0601f66
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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. 15 * 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. 27 * 28 * Authors: Kevin Lim 29 */ 30 31#ifndef __CPU_THREAD_STATE_HH__ 32#define __CPU_THREAD_STATE_HH__ 33 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" 39#include "sim/process.hh" 40 41class EndQuiesceEvent; 42class FunctionProfile; 43class ProfileNode; 44namespace TheISA { 45 namespace Kernel { 46 class Statistics; 47 } 48} 49 50class Checkpoint; 51 52/** 53 * Struct for holding general thread state that is needed across CPU 54 * models. This includes things such as pointers to the process, 55 * memory, quiesce events, and certain stats. This can be expanded 56 * to hold more thread-specific stats within it. 57 */ 58struct ThreadState : public Serializable { 59 typedef ThreadContext::Status Status; 60 61 ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process); 62 63 virtual ~ThreadState(); 64 65 void serialize(CheckpointOut &cp) const override; 66 67 void unserialize(CheckpointIn &cp) override; 68 69 int cpuId() const { return baseCpu->cpuId(); } 70 71 uint32_t socketId() const { return baseCpu->socketId(); } 72 73 ContextID contextId() const { return _contextId; } 74 75 void setContextId(ContextID id) { _contextId = id; } 76 77 void setThreadId(ThreadID id) { _threadId = id; } 78 79 ThreadID threadId() const { return _threadId; } 80 81 Tick readLastActivate() const { return lastActivate; } 82 83 Tick readLastSuspend() const { return lastSuspend; } 84 85 /** 86 * Initialise the physical and virtual port proxies and tie them to 87 * the data port of the CPU. 88 * 89 * @param tc ThreadContext for the virtual-to-physical translation 90 */ 91 void initMemProxies(ThreadContext *tc); 92 93 void dumpFuncProfile(); 94 95 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; } 96 97 void profileClear(); 98 99 void profileSample(); 100 101 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; } 102 103 PortProxy &getPhysProxy(); 104 105 FSTranslatingPortProxy &getVirtProxy(); 106 107 Process *getProcessPtr() { return process; } 108 109 void setProcessPtr(Process *p) 110 { 111 process = p; 112 /** 113 * When the process pointer changes while operating in SE Mode, 114 * the se translating port proxy needs to be reinitialized since it 115 * holds a pointer to the process class. 116 */ 117 if (proxy) { 118 delete proxy; 119 proxy = NULL; 120 initMemProxies(NULL); 121 } 122 } 123 124 SETranslatingPortProxy &getMemProxy(); 125 126 /** Reads the number of instructions functionally executed and 127 * committed. 128 */ 129 Counter readFuncExeInst() const { return funcExeInst; } 130 131 /** Sets the total number of instructions functionally executed 132 * and committed. 133 */ 134 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; } 135 136 /** Returns the status of this thread. */ 137 Status status() const { return _status; } 138 139 /** Sets the status of this thread. */ 140 void setStatus(Status new_status) { _status = new_status; } 141 142 public: 143 144 /** Number of instructions committed. */ 145 Counter numInst; 146 /** Stat for number instructions committed. */ 147 Stats::Scalar numInsts; 148 /** Number of ops (including micro ops) committed. */ 149 Counter numOp; 150 /** Stat for number ops (including micro ops) committed. */ 151 Stats::Scalar numOps; 152 /** Stat for number of memory references. */ 153 Stats::Scalar numMemRefs; 154 155 /** Number of simulated loads, used for tracking events based on 156 * the number of loads committed. 157 */ 158 Counter numLoad; 159 160 /** The number of simulated loads committed prior to this run. */ 161 Counter startNumLoad; 162 163 protected: 164 ThreadContext::Status _status; 165 166 // Pointer to the base CPU. 167 BaseCPU *baseCpu; 168 169 // system wide HW context id 170 ContextID _contextId; 171 172 // Index of hardware thread context on the CPU that this represents. 173 ThreadID _threadId; 174 175 public: 176 /** Last time activate was called on this thread. */ 177 Tick lastActivate; 178 179 /** Last time suspend was called on this thread. */ 180 Tick lastSuspend; 181 182 public: 183 FunctionProfile *profile; 184 ProfileNode *profileNode; 185 Addr profilePC; 186 EndQuiesceEvent *quiesceEvent; 187 188 TheISA::Kernel::Statistics *kernelStats; 189 190 protected: 191 Process *process; 192 193 /** A port proxy outgoing only for functional accesses to physical 194 * addresses.*/ 195 PortProxy *physProxy; 196 197 /** A translating port proxy, outgoing only, for functional 198 * accesse to virtual addresses. */ 199 FSTranslatingPortProxy *virtProxy; 200 SETranslatingPortProxy *proxy; 201 202 public: 203 /* 204 * number of executed instructions, for matching with syscall trace 205 * points in EIO files. 206 */ 207 Counter funcExeInst; 208 209 // 210 // Count failed store conditionals so we can warn of apparent 211 // application deadlock situations. 212 unsigned storeCondFailures; 213}; 214 215#endif // __CPU_THREAD_STATE_HH__ 216