thread_state.hh revision 9382
12847Sksewell@umich.edu/*
27783SGiacomo.Gabrielli@arm.com * Copyright (c) 2006 The Regents of The University of Michigan
39913Ssteve.reinhardt@amd.com * All rights reserved.
47783SGiacomo.Gabrielli@arm.com *
57783SGiacomo.Gabrielli@arm.com * Redistribution and use in source and binary forms, with or without
67783SGiacomo.Gabrielli@arm.com * modification, are permitted provided that the following conditions are
77783SGiacomo.Gabrielli@arm.com * met: redistributions of source code must retain the above copyright
87783SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer;
97783SGiacomo.Gabrielli@arm.com * redistributions in binary form must reproduce the above copyright
107783SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer in the
117783SGiacomo.Gabrielli@arm.com * documentation and/or other materials provided with the distribution;
127783SGiacomo.Gabrielli@arm.com * neither the name of the copyright holders nor the names of its
137783SGiacomo.Gabrielli@arm.com * contributors may be used to endorse or promote products derived from
147783SGiacomo.Gabrielli@arm.com * this software without specific prior written permission.
155596Sgblack@eecs.umich.edu *
162847Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172847Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182847Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192847Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202847Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212847Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222847Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232847Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242847Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252847Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262847Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272847Sksewell@umich.edu *
282847Sksewell@umich.edu * Authors: Kevin Lim
292847Sksewell@umich.edu */
302847Sksewell@umich.edu
312847Sksewell@umich.edu#ifndef __CPU_O3_THREAD_STATE_HH__
322847Sksewell@umich.edu#define __CPU_O3_THREAD_STATE_HH__
332847Sksewell@umich.edu
342847Sksewell@umich.edu#include "base/callback.hh"
352847Sksewell@umich.edu#include "base/output.hh"
362847Sksewell@umich.edu#include "cpu/thread_context.hh"
372847Sksewell@umich.edu#include "cpu/thread_state.hh"
382847Sksewell@umich.edu#include "sim/full_system.hh"
392847Sksewell@umich.edu#include "sim/sim_exit.hh"
402847Sksewell@umich.edu
415596Sgblack@eecs.umich.educlass EndQuiesceEvent;
422847Sksewell@umich.educlass Event;
432847Sksewell@umich.educlass FunctionalMemory;
442847Sksewell@umich.educlass FunctionProfile;
452847Sksewell@umich.educlass Process;
462847Sksewell@umich.educlass ProfileNode;
4710835Sandreas.hansson@arm.com
4810835Sandreas.hansson@arm.com/**
495596Sgblack@eecs.umich.edu * Class that has various thread state, such as the status, the
506658Snate@binkert.org * current instruction being processed, whether or not the thread has
518229Snate@binkert.org * a trap pending or is being externally updated, the ThreadContext
528229Snate@binkert.org * pointer, etc.  It also handles anything related to a specific
535596Sgblack@eecs.umich.edu * thread's process, such as syscalls and checking valid addresses.
545596Sgblack@eecs.umich.edu */
559913Ssteve.reinhardt@amd.comtemplate <class Impl>
562847Sksewell@umich.edustruct O3ThreadState : public ThreadState {
575596Sgblack@eecs.umich.edu    typedef ThreadContext::Status Status;
585596Sgblack@eecs.umich.edu    typedef typename Impl::O3CPU O3CPU;
595596Sgblack@eecs.umich.edu
605596Sgblack@eecs.umich.edu  private:
615596Sgblack@eecs.umich.edu    /** Pointer to the CPU. */
625596Sgblack@eecs.umich.edu    O3CPU *cpu;
635596Sgblack@eecs.umich.edu  public:
645596Sgblack@eecs.umich.edu    /* This variable controls if writes to a thread context should cause a all
655596Sgblack@eecs.umich.edu     * dynamic/speculative state to be thrown away. Nominally this is the
665596Sgblack@eecs.umich.edu     * desired behavior because the external thread context write has updated
675596Sgblack@eecs.umich.edu     * some state that could be used by an inflight instruction, however there
685596Sgblack@eecs.umich.edu     * are some cases like in a fault/trap handler where this behavior would
695596Sgblack@eecs.umich.edu     * lead to successive restarts and forward progress couldn't be made. This
7012104Snathanael.premillieu@arm.com     * variable controls if the squashing will occur.
715596Sgblack@eecs.umich.edu     */
725596Sgblack@eecs.umich.edu    bool noSquashFromTC;
735596Sgblack@eecs.umich.edu
749920Syasuko.eckert@amd.com    /** Whether or not the thread is currently waiting on a trap, and
7510319SAndreas.Sandberg@ARM.com     * thus able to be externally updated without squashing.
7612104Snathanael.premillieu@arm.com     */
775596Sgblack@eecs.umich.edu    bool trapPending;
785596Sgblack@eecs.umich.edu
795596Sgblack@eecs.umich.edu    O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process)
805596Sgblack@eecs.umich.edu        : ThreadState(_cpu, _thread_num, _process),
818902Sandreas.hansson@arm.com          cpu(_cpu), noSquashFromTC(false), trapPending(false)
825596Sgblack@eecs.umich.edu    {
835596Sgblack@eecs.umich.edu        if (!FullSystem)
845596Sgblack@eecs.umich.edu            return;
855596Sgblack@eecs.umich.edu
8610417Sandreas.hansson@arm.com        if (cpu->params()->profile) {
877720Sgblack@eecs.umich.edu            profile = new FunctionProfile(
887720Sgblack@eecs.umich.edu                    cpu->params()->system->kernelSymtab);
895596Sgblack@eecs.umich.edu            Callback *cb =
905596Sgblack@eecs.umich.edu                new MakeCallback<O3ThreadState,
9110417Sandreas.hansson@arm.com                &O3ThreadState::dumpFuncProfile>(this);
9210417Sandreas.hansson@arm.com            registerExitCallback(cb);
935596Sgblack@eecs.umich.edu        }
949252Sdjordje.kovacevic@arm.com
959252Sdjordje.kovacevic@arm.com        // let's fill with a dummy node for now so we don't get a segfault
965596Sgblack@eecs.umich.edu        // on the first cycle when there's no node available.
975596Sgblack@eecs.umich.edu        static ProfileNode dummyNode;
985596Sgblack@eecs.umich.edu        profileNode = &dummyNode;
995596Sgblack@eecs.umich.edu        profilePC = 3;
1005596Sgblack@eecs.umich.edu    }
1015596Sgblack@eecs.umich.edu
1025596Sgblack@eecs.umich.edu    /** Pointer to the ThreadContext of this thread. */
1035596Sgblack@eecs.umich.edu    ThreadContext *tc;
1045596Sgblack@eecs.umich.edu
1055596Sgblack@eecs.umich.edu    /** Returns a pointer to the TC of this thread. */
1065596Sgblack@eecs.umich.edu    ThreadContext *getTC() { return tc; }
1075596Sgblack@eecs.umich.edu
1085596Sgblack@eecs.umich.edu    /** Handles the syscall. */
1097783SGiacomo.Gabrielli@arm.com    void syscall(int64_t callnum) { process->syscall(callnum, tc); }
1109046SAli.Saidi@ARM.com
11110835Sandreas.hansson@arm.com    void dumpFuncProfile()
1129046SAli.Saidi@ARM.com    {
1137783SGiacomo.Gabrielli@arm.com        std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name()));
1147783SGiacomo.Gabrielli@arm.com        profile->dump(tc, *os);
1157783SGiacomo.Gabrielli@arm.com    }
1167783SGiacomo.Gabrielli@arm.com};
11710835Sandreas.hansson@arm.com
1189046SAli.Saidi@ARM.com#endif // __CPU_O3_THREAD_STATE_HH__
1197783SGiacomo.Gabrielli@arm.com