thread_state.hh revision 8799
12329SN/A/* 22329SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32329SN/A * All rights reserved. 42329SN/A * 52329SN/A * Redistribution and use in source and binary forms, with or without 62329SN/A * modification, are permitted provided that the following conditions are 72329SN/A * met: redistributions of source code must retain the above copyright 82329SN/A * notice, this list of conditions and the following disclaimer; 92329SN/A * redistributions in binary form must reproduce the above copyright 102329SN/A * notice, this list of conditions and the following disclaimer in the 112329SN/A * documentation and/or other materials provided with the distribution; 122329SN/A * neither the name of the copyright holders nor the names of its 132329SN/A * contributors may be used to endorse or promote products derived from 142329SN/A * this software without specific prior written permission. 152329SN/A * 162329SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172329SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182329SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192329SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202329SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212329SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222329SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232329SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242329SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252329SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262329SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Kevin Lim 292329SN/A */ 302292SN/A 312292SN/A#ifndef __CPU_O3_THREAD_STATE_HH__ 322292SN/A#define __CPU_O3_THREAD_STATE_HH__ 332292SN/A 342362SN/A#include "base/callback.hh" 352362SN/A#include "base/output.hh" 362680Sktlim@umich.edu#include "cpu/thread_context.hh" 372292SN/A#include "cpu/thread_state.hh" 388793Sgblack@eecs.umich.edu#include "sim/full_system.hh" 392362SN/A#include "sim/sim_exit.hh" 402292SN/A 418777Sgblack@eecs.umich.educlass EndQuiesceEvent; 422292SN/Aclass Event; 438777Sgblack@eecs.umich.educlass FunctionalMemory; 448777Sgblack@eecs.umich.educlass FunctionProfile; 452292SN/Aclass Process; 462292SN/Aclass ProfileNode; 472292SN/A 482329SN/A/** 492329SN/A * Class that has various thread state, such as the status, the 502329SN/A * current instruction being processed, whether or not the thread has 512680Sktlim@umich.edu * a trap pending or is being externally updated, the ThreadContext 522680Sktlim@umich.edu * pointer, etc. It also handles anything related to a specific 532329SN/A * thread's process, such as syscalls and checking valid addresses. 542329SN/A */ 552292SN/Atemplate <class Impl> 562292SN/Astruct O3ThreadState : public ThreadState { 572680Sktlim@umich.edu typedef ThreadContext::Status Status; 582733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 592292SN/A 602292SN/A private: 612348SN/A /** Pointer to the CPU. */ 622733Sktlim@umich.edu O3CPU *cpu; 632292SN/A public: 642348SN/A /** Whether or not the thread is currently in syscall mode, and 652348SN/A * thus able to be externally updated without squashing. 662348SN/A */ 672292SN/A bool inSyscall; 682292SN/A 692348SN/A /** Whether or not the thread is currently waiting on a trap, and 702348SN/A * thus able to be externally updated without squashing. 712348SN/A */ 722292SN/A bool trapPending; 732292SN/A 748766Sgblack@eecs.umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process) 758766Sgblack@eecs.umich.edu : ThreadState(_cpu, _thread_num, _process), 762362SN/A cpu(_cpu), inSyscall(0), trapPending(0) 772362SN/A { 788793Sgblack@eecs.umich.edu if (FullSystem) { 798793Sgblack@eecs.umich.edu if (cpu->params()->profile) { 808793Sgblack@eecs.umich.edu profile = new FunctionProfile( 818793Sgblack@eecs.umich.edu cpu->params()->system->kernelSymtab); 828793Sgblack@eecs.umich.edu Callback *cb = 838793Sgblack@eecs.umich.edu new MakeCallback<O3ThreadState, 848793Sgblack@eecs.umich.edu &O3ThreadState::dumpFuncProfile>(this); 858793Sgblack@eecs.umich.edu registerExitCallback(cb); 868793Sgblack@eecs.umich.edu } 878793Sgblack@eecs.umich.edu 888793Sgblack@eecs.umich.edu // let's fill with a dummy node for now so we don't get a segfault 898793Sgblack@eecs.umich.edu // on the first cycle when there's no node available. 908793Sgblack@eecs.umich.edu static ProfileNode dummyNode; 918793Sgblack@eecs.umich.edu profileNode = &dummyNode; 928793Sgblack@eecs.umich.edu profilePC = 3; 932362SN/A } 942362SN/A } 952292SN/A 962680Sktlim@umich.edu /** Pointer to the ThreadContext of this thread. */ 972680Sktlim@umich.edu ThreadContext *tc; 982292SN/A 992680Sktlim@umich.edu /** Returns a pointer to the TC of this thread. */ 1002680Sktlim@umich.edu ThreadContext *getTC() { return tc; } 1012292SN/A 1022348SN/A /** Handles the syscall. */ 1032680Sktlim@umich.edu void syscall(int64_t callnum) { process->syscall(callnum, tc); } 1042362SN/A 1052362SN/A void dumpFuncProfile() 1062362SN/A { 1072362SN/A std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 1083126Sktlim@umich.edu profile->dump(tc, *os); 1092362SN/A } 1102292SN/A}; 1112292SN/A 1122292SN/A#endif // __CPU_O3_THREAD_STATE_HH__ 113