thread_state.hh revision 8777
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
408777Sgblack@eecs.umich.educlass EndQuiesceEvent;
412292SN/Aclass Event;
428777Sgblack@eecs.umich.educlass FunctionalMemory;
438777Sgblack@eecs.umich.educlass FunctionProfile;
442292SN/Aclass Process;
452292SN/Aclass ProfileNode;
462292SN/A
472329SN/A/**
482329SN/A * Class that has various thread state, such as the status, the
492329SN/A * current instruction being processed, whether or not the thread has
502680Sktlim@umich.edu * a trap pending or is being externally updated, the ThreadContext
512680Sktlim@umich.edu * pointer, etc.  It also handles anything related to a specific
522329SN/A * thread's process, such as syscalls and checking valid addresses.
532329SN/A */
542292SN/Atemplate <class Impl>
552292SN/Astruct O3ThreadState : public ThreadState {
562680Sktlim@umich.edu    typedef ThreadContext::Status Status;
572733Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
582292SN/A
592292SN/A  private:
602348SN/A    /** Pointer to the CPU. */
612733Sktlim@umich.edu    O3CPU *cpu;
622292SN/A  public:
632348SN/A    /** Whether or not the thread is currently in syscall mode, and
642348SN/A     * thus able to be externally updated without squashing.
652348SN/A     */
662292SN/A    bool inSyscall;
672292SN/A
682348SN/A    /** Whether or not the thread is currently waiting on a trap, and
692348SN/A     * thus able to be externally updated without squashing.
702348SN/A     */
712292SN/A    bool trapPending;
722292SN/A
738766Sgblack@eecs.umich.edu    O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process)
748766Sgblack@eecs.umich.edu        : ThreadState(_cpu, _thread_num, _process),
752362SN/A          cpu(_cpu), inSyscall(0), trapPending(0)
762362SN/A    {
778766Sgblack@eecs.umich.edu#if FULL_SYSTEM
785529Snate@binkert.org        if (cpu->params()->profile) {
795529Snate@binkert.org            profile = new FunctionProfile(cpu->params()->system->kernelSymtab);
802362SN/A            Callback *cb =
812362SN/A                new MakeCallback<O3ThreadState,
822362SN/A                &O3ThreadState::dumpFuncProfile>(this);
832362SN/A            registerExitCallback(cb);
842362SN/A        }
852362SN/A
862362SN/A        // let's fill with a dummy node for now so we don't get a segfault
872362SN/A        // on the first cycle when there's no node available.
882362SN/A        static ProfileNode dummyNode;
892362SN/A        profileNode = &dummyNode;
902362SN/A        profilePC = 3;
918766Sgblack@eecs.umich.edu#endif
922362SN/A    }
932292SN/A
942680Sktlim@umich.edu    /** Pointer to the ThreadContext of this thread. */
952680Sktlim@umich.edu    ThreadContext *tc;
962292SN/A
972680Sktlim@umich.edu    /** Returns a pointer to the TC of this thread. */
982680Sktlim@umich.edu    ThreadContext *getTC() { return tc; }
992292SN/A
1002348SN/A    /** Handles the syscall. */
1012680Sktlim@umich.edu    void syscall(int64_t callnum) { process->syscall(callnum, tc); }
1022362SN/A
1032362SN/A    void dumpFuncProfile()
1042362SN/A    {
1052362SN/A        std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name()));
1063126Sktlim@umich.edu        profile->dump(tc, *os);
1072362SN/A    }
1082292SN/A};
1092292SN/A
1102292SN/A#endif // __CPU_O3_THREAD_STATE_HH__
111