thread_state.hh revision 8777
15790Sgblack@eecs.umich.edu/* 25790Sgblack@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 35790Sgblack@eecs.umich.edu * All rights reserved. 45790Sgblack@eecs.umich.edu * 55790Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 65790Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 75790Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 85790Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 95790Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 105790Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 115790Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 125790Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 135790Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 145790Sgblack@eecs.umich.edu * this software without specific prior written permission. 155790Sgblack@eecs.umich.edu * 165790Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175790Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185790Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195790Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205790Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215790Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225790Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235790Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245790Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255790Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265790Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275790Sgblack@eecs.umich.edu * 285790Sgblack@eecs.umich.edu * Authors: Kevin Lim 295790Sgblack@eecs.umich.edu */ 305790Sgblack@eecs.umich.edu 315790Sgblack@eecs.umich.edu#ifndef __CPU_THREAD_STATE_HH__ 325790Sgblack@eecs.umich.edu#define __CPU_THREAD_STATE_HH__ 3312157Sandreas.sandberg@arm.com 345790Sgblack@eecs.umich.edu#include "arch/types.hh" 359898Sandreas@sandberg.pp.se#include "config/the_isa.hh" 369898Sandreas@sandberg.pp.se#include "cpu/base.hh" 379898Sandreas@sandberg.pp.se#include "cpu/profile.hh" 389898Sandreas@sandberg.pp.se#include "cpu/thread_context.hh" 399898Sandreas@sandberg.pp.se#include "mem/mem_object.hh" 409898Sandreas@sandberg.pp.se#include "sim/process.hh" 419898Sandreas@sandberg.pp.se 429898Sandreas@sandberg.pp.seclass EndQuiesceEvent; 439898Sandreas@sandberg.pp.seclass FunctionProfile; 449898Sandreas@sandberg.pp.seclass ProfileNode; 459898Sandreas@sandberg.pp.senamespace TheISA { 469898Sandreas@sandberg.pp.se namespace Kernel { 479898Sandreas@sandberg.pp.se class Statistics; 489898Sandreas@sandberg.pp.se }; 499898Sandreas@sandberg.pp.se}; 509898Sandreas@sandberg.pp.se 519898Sandreas@sandberg.pp.seclass Checkpoint; 529898Sandreas@sandberg.pp.seclass Port; 535790Sgblack@eecs.umich.educlass TranslatingPort; 545790Sgblack@eecs.umich.edu 555790Sgblack@eecs.umich.edu/** 565790Sgblack@eecs.umich.edu * Struct for holding general thread state that is needed across CPU 575790Sgblack@eecs.umich.edu * models. This includes things such as pointers to the process, 585790Sgblack@eecs.umich.edu * memory, quiesce events, and certain stats. This can be expanded 595790Sgblack@eecs.umich.edu * to hold more thread-specific stats within it. 605790Sgblack@eecs.umich.edu */ 615790Sgblack@eecs.umich.edustruct ThreadState { 629898Sandreas@sandberg.pp.se typedef ThreadContext::Status Status; 639898Sandreas@sandberg.pp.se 6412157Sandreas.sandberg@arm.com ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process); 6512157Sandreas.sandberg@arm.com 6612157Sandreas.sandberg@arm.com ~ThreadState(); 6712157Sandreas.sandberg@arm.com 6812157Sandreas.sandberg@arm.com void serialize(std::ostream &os); 6912157Sandreas.sandberg@arm.com 7012157Sandreas.sandberg@arm.com void unserialize(Checkpoint *cp, const std::string §ion); 7112157Sandreas.sandberg@arm.com 7212157Sandreas.sandberg@arm.com int cpuId() { return baseCpu->cpuId(); } 7312157Sandreas.sandberg@arm.com 7412157Sandreas.sandberg@arm.com int contextId() { return _contextId; } 7512157Sandreas.sandberg@arm.com 7612157Sandreas.sandberg@arm.com void setContextId(int id) { _contextId = id; } 7712157Sandreas.sandberg@arm.com 7812157Sandreas.sandberg@arm.com void setThreadId(ThreadID id) { _threadId = id; } 7912157Sandreas.sandberg@arm.com 8012157Sandreas.sandberg@arm.com ThreadID threadId() { return _threadId; } 8112157Sandreas.sandberg@arm.com 8212157Sandreas.sandberg@arm.com Tick readLastActivate() { return lastActivate; } 8312157Sandreas.sandberg@arm.com 8412157Sandreas.sandberg@arm.com Tick readLastSuspend() { return lastSuspend; } 8512157Sandreas.sandberg@arm.com 8612157Sandreas.sandberg@arm.com void connectPhysPort(); 87 88 void connectVirtPort(ThreadContext *tc); 89 90 void connectMemPorts(ThreadContext *tc); 91 92 void dumpFuncProfile(); 93 94 EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; } 95 96 void profileClear(); 97 98 void profileSample(); 99 100 TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; } 101 102 Process *getProcessPtr() { return process; } 103 104 TranslatingPort *getMemPort(); 105 106 void setMemPort(TranslatingPort *_port) { port = _port; } 107 108 VirtualPort *getVirtPort() { return virtPort; } 109 110 FunctionalPort *getPhysPort() { return physPort; } 111 112 void setPhysPort(FunctionalPort *port) { physPort = port; } 113 114 /** Reads the number of instructions functionally executed and 115 * committed. 116 */ 117 Counter readFuncExeInst() { return funcExeInst; } 118 119 /** Sets the total number of instructions functionally executed 120 * and committed. 121 */ 122 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; } 123 124 /** Returns the status of this thread. */ 125 Status status() const { return _status; } 126 127 /** Sets the status of this thread. */ 128 void setStatus(Status new_status) { _status = new_status; } 129 130 public: 131 /** Connects port to the functional port of the memory object 132 * below the CPU. */ 133 void connectToMemFunc(Port *port); 134 135 /** Number of instructions committed. */ 136 Counter numInst; 137 /** Stat for number instructions committed. */ 138 Stats::Scalar numInsts; 139 /** Stat for number of memory references. */ 140 Stats::Scalar numMemRefs; 141 142 /** Number of simulated loads, used for tracking events based on 143 * the number of loads committed. 144 */ 145 Counter numLoad; 146 147 /** The number of simulated loads committed prior to this run. */ 148 Counter startNumLoad; 149 150 protected: 151 ThreadContext::Status _status; 152 153 // Pointer to the base CPU. 154 BaseCPU *baseCpu; 155 156 // system wide HW context id 157 int _contextId; 158 159 // Index of hardware thread context on the CPU that this represents. 160 ThreadID _threadId; 161 162 public: 163 /** Last time activate was called on this thread. */ 164 Tick lastActivate; 165 166 /** Last time suspend was called on this thread. */ 167 Tick lastSuspend; 168 169 public: 170 FunctionProfile *profile; 171 ProfileNode *profileNode; 172 Addr profilePC; 173 EndQuiesceEvent *quiesceEvent; 174 175 TheISA::Kernel::Statistics *kernelStats; 176 177 protected: 178 Process *process; 179 180 TranslatingPort *port; 181 182 /** A functional port, outgoing only, for functional accesse to virtual 183 * addresses. */ 184 VirtualPort *virtPort; 185 186 /** A functional port outgoing only for functional accesses to physical 187 * addresses.*/ 188 FunctionalPort *physPort; 189 190 public: 191 /* 192 * number of executed instructions, for matching with syscall trace 193 * points in EIO files. 194 */ 195 Counter funcExeInst; 196 197 // 198 // Count failed store conditionals so we can warn of apparent 199 // application deadlock situations. 200 unsigned storeCondFailures; 201}; 202 203#endif // __CPU_THREAD_STATE_HH__ 204