thread_state.hh revision 8777:dd43f1c9fa0a
112391Sjason@lowepower.com/* 212391Sjason@lowepower.com * Copyright (c) 2006 The Regents of The University of Michigan 312391Sjason@lowepower.com * All rights reserved. 412391Sjason@lowepower.com * 512391Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without 612391Sjason@lowepower.com * modification, are permitted provided that the following conditions are 712391Sjason@lowepower.com * met: redistributions of source code must retain the above copyright 812391Sjason@lowepower.com * notice, this list of conditions and the following disclaimer; 912391Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright 1012391Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the 1112391Sjason@lowepower.com * documentation and/or other materials provided with the distribution; 1212391Sjason@lowepower.com * neither the name of the copyright holders nor the names of its 1312391Sjason@lowepower.com * contributors may be used to endorse or promote products derived from 1412391Sjason@lowepower.com * this software without specific prior written permission. 1512391Sjason@lowepower.com * 1612391Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712391Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812391Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912391Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012391Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112391Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212391Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312391Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412391Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512391Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612391Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712391Sjason@lowepower.com * 2812391Sjason@lowepower.com * Authors: Kevin Lim 2912391Sjason@lowepower.com */ 3012391Sjason@lowepower.com 3112391Sjason@lowepower.com#ifndef __CPU_O3_THREAD_STATE_HH__ 3212391Sjason@lowepower.com#define __CPU_O3_THREAD_STATE_HH__ 3312391Sjason@lowepower.com 3412391Sjason@lowepower.com#include "base/callback.hh" 3512391Sjason@lowepower.com#include "base/output.hh" 3612391Sjason@lowepower.com#include "cpu/thread_context.hh" 3712391Sjason@lowepower.com#include "cpu/thread_state.hh" 3812391Sjason@lowepower.com#include "sim/sim_exit.hh" 3912391Sjason@lowepower.com 4012391Sjason@lowepower.comclass EndQuiesceEvent; 4112391Sjason@lowepower.comclass Event; 4212391Sjason@lowepower.comclass FunctionalMemory; 4312391Sjason@lowepower.comclass FunctionProfile; 4412391Sjason@lowepower.comclass Process; 4512391Sjason@lowepower.comclass ProfileNode; 4612391Sjason@lowepower.com 4712391Sjason@lowepower.com/** 4812391Sjason@lowepower.com * Class that has various thread state, such as the status, the 4912391Sjason@lowepower.com * current instruction being processed, whether or not the thread has 5012391Sjason@lowepower.com * a trap pending or is being externally updated, the ThreadContext 5112391Sjason@lowepower.com * pointer, etc. It also handles anything related to a specific 5212391Sjason@lowepower.com * thread's process, such as syscalls and checking valid addresses. 5312391Sjason@lowepower.com */ 5412391Sjason@lowepower.comtemplate <class Impl> 5512391Sjason@lowepower.comstruct O3ThreadState : public ThreadState { 5612391Sjason@lowepower.com typedef ThreadContext::Status Status; 5712391Sjason@lowepower.com typedef typename Impl::O3CPU O3CPU; 5812391Sjason@lowepower.com 5912391Sjason@lowepower.com private: 6012391Sjason@lowepower.com /** Pointer to the CPU. */ 6112391Sjason@lowepower.com O3CPU *cpu; 6212391Sjason@lowepower.com public: 6312391Sjason@lowepower.com /** Whether or not the thread is currently in syscall mode, and 6412391Sjason@lowepower.com * thus able to be externally updated without squashing. 6512391Sjason@lowepower.com */ 6612391Sjason@lowepower.com bool inSyscall; 6712391Sjason@lowepower.com 6812391Sjason@lowepower.com /** Whether or not the thread is currently waiting on a trap, and 6912391Sjason@lowepower.com * thus able to be externally updated without squashing. 7012391Sjason@lowepower.com */ 7112391Sjason@lowepower.com bool trapPending; 7212391Sjason@lowepower.com 7312391Sjason@lowepower.com O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process) 7412391Sjason@lowepower.com : ThreadState(_cpu, _thread_num, _process), 7512391Sjason@lowepower.com cpu(_cpu), inSyscall(0), trapPending(0) 7612391Sjason@lowepower.com { 7712391Sjason@lowepower.com#if FULL_SYSTEM 7812391Sjason@lowepower.com if (cpu->params()->profile) { 7912391Sjason@lowepower.com profile = new FunctionProfile(cpu->params()->system->kernelSymtab); 8012391Sjason@lowepower.com Callback *cb = 8112391Sjason@lowepower.com new MakeCallback<O3ThreadState, 8212391Sjason@lowepower.com &O3ThreadState::dumpFuncProfile>(this); 8312391Sjason@lowepower.com registerExitCallback(cb); 8412391Sjason@lowepower.com } 8512391Sjason@lowepower.com 8612391Sjason@lowepower.com // let's fill with a dummy node for now so we don't get a segfault 8712391Sjason@lowepower.com // on the first cycle when there's no node available. 8812391Sjason@lowepower.com static ProfileNode dummyNode; 8912391Sjason@lowepower.com profileNode = &dummyNode; 9012391Sjason@lowepower.com profilePC = 3; 9112391Sjason@lowepower.com#endif 9212391Sjason@lowepower.com } 9312391Sjason@lowepower.com 9412391Sjason@lowepower.com /** Pointer to the ThreadContext of this thread. */ 9512391Sjason@lowepower.com ThreadContext *tc; 9612391Sjason@lowepower.com 9712391Sjason@lowepower.com /** Returns a pointer to the TC of this thread. */ 9812391Sjason@lowepower.com ThreadContext *getTC() { return tc; } 9912391Sjason@lowepower.com 10012391Sjason@lowepower.com /** Handles the syscall. */ 10112391Sjason@lowepower.com void syscall(int64_t callnum) { process->syscall(callnum, tc); } 10212391Sjason@lowepower.com 10312391Sjason@lowepower.com void dumpFuncProfile() 10412391Sjason@lowepower.com { 10512391Sjason@lowepower.com std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 10612391Sjason@lowepower.com profile->dump(tc, *os); 10712391Sjason@lowepower.com } 10812391Sjason@lowepower.com}; 109 110#endif // __CPU_O3_THREAD_STATE_HH__ 111