thread_state.hh revision 2362
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 29#ifndef __CPU_O3_THREAD_STATE_HH__ 30#define __CPU_O3_THREAD_STATE_HH__ 31 32#include "arch/faults.hh" 33#include "arch/isa_traits.hh" 34#include "base/callback.hh" 35#include "base/output.hh" 36#include "cpu/exec_context.hh" 37#include "cpu/thread_state.hh" 38#include "sim/sim_exit.hh" 39 40class Event; 41class Process; 42 43#if FULL_SYSTEM 44class EndQuiesceEvent; 45class FunctionProfile; 46class ProfileNode; 47#else 48class FunctionalMemory; 49class Process; 50#endif 51 52/** 53 * Class that has various thread state, such as the status, the 54 * current instruction being processed, whether or not the thread has 55 * a trap pending or is being externally updated, the ExecContext 56 * proxy pointer, etc. It also handles anything related to a specific 57 * thread's process, such as syscalls and checking valid addresses. 58 */ 59template <class Impl> 60struct O3ThreadState : public ThreadState { 61 typedef ExecContext::Status Status; 62 typedef typename Impl::FullCPU FullCPU; 63 64 /** Current status of the thread. */ 65 Status _status; 66 67 /** Current instruction the thread is committing. Only set and 68 * used for DTB faults currently. 69 */ 70 TheISA::MachInst inst; 71 72 private: 73 /** Pointer to the CPU. */ 74 FullCPU *cpu; 75 public: 76 /** Whether or not the thread is currently in syscall mode, and 77 * thus able to be externally updated without squashing. 78 */ 79 bool inSyscall; 80 81 /** Whether or not the thread is currently waiting on a trap, and 82 * thus able to be externally updated without squashing. 83 */ 84 bool trapPending; 85 86#if FULL_SYSTEM 87 O3ThreadState(FullCPU *_cpu, int _thread_num, FunctionalMemory *_mem) 88 : ThreadState(-1, _thread_num, _mem), 89 cpu(_cpu), inSyscall(0), trapPending(0) 90 { 91 if (cpu->params->profile) { 92 profile = new FunctionProfile(cpu->params->system->kernelSymtab); 93 Callback *cb = 94 new MakeCallback<O3ThreadState, 95 &O3ThreadState::dumpFuncProfile>(this); 96 registerExitCallback(cb); 97 } 98 99 // let's fill with a dummy node for now so we don't get a segfault 100 // on the first cycle when there's no node available. 101 static ProfileNode dummyNode; 102 profileNode = &dummyNode; 103 profilePC = 3; 104 } 105#else 106 O3ThreadState(FullCPU *_cpu, int _thread_num, Process *_process, int _asid) 107 : ThreadState(-1, _thread_num, _process->getMemory(), _process, _asid), 108 cpu(_cpu), inSyscall(0), trapPending(0) 109 { } 110 111 O3ThreadState(FullCPU *_cpu, int _thread_num, FunctionalMemory *_mem, 112 int _asid) 113 : ThreadState(-1, _thread_num, _mem, NULL, _asid), 114 cpu(_cpu), inSyscall(0), trapPending(0) 115 { } 116#endif 117 118 /** Pointer to the ExecContext of this thread. @todo: Don't call 119 this a proxy.*/ 120 ExecContext *xcProxy; 121 122 /** Returns a pointer to the XC of this thread. */ 123 ExecContext *getXCProxy() { return xcProxy; } 124 125 /** Returns the status of this thread. */ 126 Status status() const { return _status; } 127 128 /** Sets the status of this thread. */ 129 void setStatus(Status new_status) { _status = new_status; } 130 131#if !FULL_SYSTEM 132 /** Returns if this address is a valid instruction address. */ 133 bool validInstAddr(Addr addr) 134 { return process->validInstAddr(addr); } 135 136 /** Returns if this address is a valid data address. */ 137 bool validDataAddr(Addr addr) 138 { return process->validDataAddr(addr); } 139#endif 140 141 /** Sets the current instruction being committed. */ 142 void setInst(TheISA::MachInst _inst) { inst = _inst; } 143 144 /** Reads the number of instructions functionally executed and 145 * committed. 146 */ 147 Counter readFuncExeInst() { return funcExeInst; } 148 149 /** Sets the total number of instructions functionally executed 150 * and committed. 151 */ 152 void setFuncExeInst(Counter new_val) { funcExeInst = new_val; } 153 154#if !FULL_SYSTEM 155 /** Handles the syscall. */ 156 void syscall() { process->syscall(xcProxy); } 157#endif 158 159#if FULL_SYSTEM 160 void dumpFuncProfile() 161 { 162 std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 163 profile->dump(xcProxy, *os); 164 } 165#endif 166}; 167 168#endif // __CPU_O3_THREAD_STATE_HH__ 169