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