thread_state.hh revision 6331
12391SN/A/* 22391SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32391SN/A * All rights reserved. 42391SN/A * 52391SN/A * Redistribution and use in source and binary forms, with or without 62391SN/A * modification, are permitted provided that the following conditions are 72391SN/A * met: redistributions of source code must retain the above copyright 82391SN/A * notice, this list of conditions and the following disclaimer; 92391SN/A * redistributions in binary form must reproduce the above copyright 102391SN/A * notice, this list of conditions and the following disclaimer in the 112391SN/A * documentation and/or other materials provided with the distribution; 122391SN/A * neither the name of the copyright holders nor the names of its 132391SN/A * contributors may be used to endorse or promote products derived from 142391SN/A * this software without specific prior written permission. 152391SN/A * 162391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 292914Ssaidi@eecs.umich.edu */ 302391SN/A 312391SN/A#ifndef __CPU_O3_THREAD_STATE_HH__ 322391SN/A#define __CPU_O3_THREAD_STATE_HH__ 332391SN/A 342391SN/A#include "base/callback.hh" 352391SN/A#include "base/output.hh" 362391SN/A#include "cpu/thread_context.hh" 372391SN/A#include "cpu/thread_state.hh" 382391SN/A#include "sim/sim_exit.hh" 392391SN/A 402391SN/Aclass Event; 412391SN/Aclass Process; 423348Sbinkertn@umich.edu 432391SN/A#if FULL_SYSTEM 442391SN/Aclass EndQuiesceEvent; 453879Ssaidi@eecs.umich.educlass FunctionProfile; 462394SN/Aclass ProfileNode; 472415SN/A#else 483348Sbinkertn@umich.educlass FunctionalMemory; 492394SN/Aclass Process; 502391SN/A#endif 512423SN/A 522391SN/A/** 534762Snate@binkert.org * Class that has various thread state, such as the status, the 544762Snate@binkert.org * current instruction being processed, whether or not the thread has 552391SN/A * a trap pending or is being externally updated, the ThreadContext 564762Snate@binkert.org * pointer, etc. It also handles anything related to a specific 572391SN/A * thread's process, such as syscalls and checking valid addresses. 582391SN/A */ 592391SN/Atemplate <class Impl> 604762Snate@binkert.orgstruct O3ThreadState : public ThreadState { 613918Ssaidi@eecs.umich.edu typedef ThreadContext::Status Status; 622391SN/A typedef typename Impl::O3CPU O3CPU; 633012Ssaidi@eecs.umich.edu 642391SN/A private: 652391SN/A /** Pointer to the CPU. */ 662391SN/A O3CPU *cpu; 672391SN/A public: 683751Sgblack@eecs.umich.edu /** Whether or not the thread is currently in syscall mode, and 694762Snate@binkert.org * thus able to be externally updated without squashing. 704762Snate@binkert.org */ 713751Sgblack@eecs.umich.edu bool inSyscall; 723012Ssaidi@eecs.umich.edu 732391SN/A /** Whether or not the thread is currently waiting on a trap, and 742391SN/A * thus able to be externally updated without squashing. 752541SN/A */ 762541SN/A bool trapPending; 772541SN/A 784470Sstever@eecs.umich.edu#if FULL_SYSTEM 794470Sstever@eecs.umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num) 804470Sstever@eecs.umich.edu : ThreadState(_cpu, _thread_num), 814470Sstever@eecs.umich.edu cpu(_cpu), inSyscall(0), trapPending(0) 824467Sstever@eecs.umich.edu { 834467Sstever@eecs.umich.edu if (cpu->params()->profile) { 844467Sstever@eecs.umich.edu profile = new FunctionProfile(cpu->params()->system->kernelSymtab); 854467Sstever@eecs.umich.edu Callback *cb = 862541SN/A new MakeCallback<O3ThreadState, 872541SN/A &O3ThreadState::dumpFuncProfile>(this); 882391SN/A registerExitCallback(cb); 892391SN/A } 903012Ssaidi@eecs.umich.edu 914762Snate@binkert.org // let's fill with a dummy node for now so we don't get a segfault 922416SN/A // on the first cycle when there's no node available. 932391SN/A static ProfileNode dummyNode; 942391SN/A profileNode = &dummyNode; 952391SN/A profilePC = 3; 962391SN/A } 972391SN/A#else 983012Ssaidi@eecs.umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process) 994040Ssaidi@eecs.umich.edu : ThreadState(_cpu, _thread_num, _process), 1002391SN/A cpu(_cpu), inSyscall(0), trapPending(0) 1013012Ssaidi@eecs.umich.edu { } 1022391SN/A#endif 1032391SN/A 1042391SN/A /** Pointer to the ThreadContext of this thread. */ 1052408SN/A ThreadContext *tc; 1062408SN/A 1072408SN/A /** Returns a pointer to the TC of this thread. */ 1082409SN/A ThreadContext *getTC() { return tc; } 1092409SN/A 1102408SN/A#if !FULL_SYSTEM 1112408SN/A /** Handles the syscall. */ 1123012Ssaidi@eecs.umich.edu void syscall(int64_t callnum) { process->syscall(callnum, tc); } 1133349Sbinkertn@umich.edu#endif 1143012Ssaidi@eecs.umich.edu 1153012Ssaidi@eecs.umich.edu#if FULL_SYSTEM 1163012Ssaidi@eecs.umich.edu void dumpFuncProfile() 1172413SN/A { 1183170Sstever@eecs.umich.edu std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 1193170Sstever@eecs.umich.edu profile->dump(tc, *os); 1203170Sstever@eecs.umich.edu } 1213170Sstever@eecs.umich.edu#endif 1223170Sstever@eecs.umich.edu}; 1233170Sstever@eecs.umich.edu 1243170Sstever@eecs.umich.edu#endif // __CPU_O3_THREAD_STATE_HH__ 1253170Sstever@eecs.umich.edu