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