thread_state.hh revision 6221
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" 382362SN/A#include "sim/sim_exit.hh" 392292SN/A 402292SN/Aclass Event; 412292SN/Aclass Process; 422292SN/A 432292SN/A#if FULL_SYSTEM 442292SN/Aclass EndQuiesceEvent; 452292SN/Aclass FunctionProfile; 462292SN/Aclass ProfileNode; 472292SN/A#else 482329SN/Aclass FunctionalMemory; 492292SN/Aclass Process; 502292SN/A#endif 512292SN/A 522329SN/A/** 532329SN/A * Class that has various thread state, such as the status, the 542329SN/A * current instruction being processed, whether or not the thread has 552680Sktlim@umich.edu * a trap pending or is being externally updated, the ThreadContext 562680Sktlim@umich.edu * pointer, etc. It also handles anything related to a specific 572329SN/A * thread's process, such as syscalls and checking valid addresses. 582329SN/A */ 592292SN/Atemplate <class Impl> 602292SN/Astruct O3ThreadState : public ThreadState { 612680Sktlim@umich.edu typedef ThreadContext::Status Status; 622733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 632292SN/A 642292SN/A private: 652348SN/A /** Pointer to the CPU. */ 662733Sktlim@umich.edu O3CPU *cpu; 672292SN/A public: 682348SN/A /** Whether or not the thread is currently in syscall mode, and 692348SN/A * thus able to be externally updated without squashing. 702348SN/A */ 712292SN/A bool inSyscall; 722292SN/A 732348SN/A /** Whether or not the thread is currently waiting on a trap, and 742348SN/A * thus able to be externally updated without squashing. 752348SN/A */ 762292SN/A bool trapPending; 772292SN/A 782292SN/A#if FULL_SYSTEM 792733Sktlim@umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num) 805712Shsul@eecs.umich.edu : ThreadState(_cpu, _thread_num), 812362SN/A cpu(_cpu), inSyscall(0), trapPending(0) 822362SN/A { 835529Snate@binkert.org if (cpu->params()->profile) { 845529Snate@binkert.org profile = new FunctionProfile(cpu->params()->system->kernelSymtab); 852362SN/A Callback *cb = 862362SN/A new MakeCallback<O3ThreadState, 872362SN/A &O3ThreadState::dumpFuncProfile>(this); 882362SN/A registerExitCallback(cb); 892362SN/A } 902362SN/A 912362SN/A // let's fill with a dummy node for now so we don't get a segfault 922362SN/A // on the first cycle when there's no node available. 932362SN/A static ProfileNode dummyNode; 942362SN/A profileNode = &dummyNode; 952362SN/A profilePC = 3; 962362SN/A } 972292SN/A#else 983402Sktlim@umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process, int _asid) 995712Shsul@eecs.umich.edu : ThreadState(_cpu, _thread_num, _process, _asid), 1002292SN/A cpu(_cpu), inSyscall(0), trapPending(0) 1012292SN/A { } 1022292SN/A#endif 1032292SN/A 1042680Sktlim@umich.edu /** Pointer to the ThreadContext of this thread. */ 1052680Sktlim@umich.edu ThreadContext *tc; 1062292SN/A 1072680Sktlim@umich.edu /** Returns a pointer to the TC of this thread. */ 1082680Sktlim@umich.edu ThreadContext *getTC() { return tc; } 1092292SN/A 1102292SN/A#if !FULL_SYSTEM 1112348SN/A /** Handles the syscall. */ 1122680Sktlim@umich.edu void syscall(int64_t callnum) { process->syscall(callnum, tc); } 1132292SN/A#endif 1142362SN/A 1152362SN/A#if FULL_SYSTEM 1162362SN/A void dumpFuncProfile() 1172362SN/A { 1182362SN/A std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 1193126Sktlim@umich.edu profile->dump(tc, *os); 1202362SN/A } 1212362SN/A#endif 1222292SN/A}; 1232292SN/A 1242292SN/A#endif // __CPU_O3_THREAD_STATE_HH__ 125