thread_state.hh revision 8706:b1838faf3bcc
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Kevin Lim
29 */
30
31#ifndef __CPU_THREAD_STATE_HH__
32#define __CPU_THREAD_STATE_HH__
33
34#include "arch/types.hh"
35#include "config/the_isa.hh"
36#include "cpu/base.hh"
37#include "cpu/profile.hh"
38#include "cpu/thread_context.hh"
39
40#if !FULL_SYSTEM
41#include "mem/mem_object.hh"
42#include "sim/process.hh"
43#endif
44
45#if FULL_SYSTEM
46class EndQuiesceEvent;
47class FunctionProfile;
48class ProfileNode;
49namespace TheISA {
50    namespace Kernel {
51        class Statistics;
52    };
53};
54#endif
55
56class Checkpoint;
57class PortProxy;
58class SETranslatingPort;
59class FSTranslatingPort;
60
61/**
62 *  Struct for holding general thread state that is needed across CPU
63 *  models.  This includes things such as pointers to the process,
64 *  memory, quiesce events, and certain stats.  This can be expanded
65 *  to hold more thread-specific stats within it.
66 */
67struct ThreadState {
68    typedef ThreadContext::Status Status;
69
70#if FULL_SYSTEM
71    ThreadState(BaseCPU *cpu, ThreadID _tid);
72#else
73    ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
74#endif
75
76    ~ThreadState();
77
78    void serialize(std::ostream &os);
79
80    void unserialize(Checkpoint *cp, const std::string &section);
81
82    int cpuId() { return baseCpu->cpuId(); }
83
84    int contextId() { return _contextId; }
85
86    void setContextId(int id) { _contextId = id; }
87
88    void setThreadId(ThreadID id) { _threadId = id; }
89
90    ThreadID threadId() { return _threadId; }
91
92    Tick readLastActivate() { return lastActivate; }
93
94    Tick readLastSuspend() { return lastSuspend; }
95
96#if FULL_SYSTEM
97    /**
98     * Initialise the physical and virtual port proxies and tie them to
99     * the data port of the CPU.
100     *
101     * tc ThreadContext for the virtual-to-physical translation
102     */
103    void initMemProxies(ThreadContext *tc);
104
105    void dumpFuncProfile();
106
107    EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
108
109    void profileClear();
110
111    void profileSample();
112
113    TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
114
115    PortProxy* getPhysProxy() { return physProxy; }
116
117    FSTranslatingPortProxy* getVirtProxy() { return virtProxy; }
118#else
119    Process *getProcessPtr() { return process; }
120
121    SETranslatingPortProxy* getMemProxy();
122#endif
123
124    /** Reads the number of instructions functionally executed and
125     * committed.
126     */
127    Counter readFuncExeInst() { return funcExeInst; }
128
129    /** Sets the total number of instructions functionally executed
130     * and committed.
131     */
132    void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
133
134    /** Returns the status of this thread. */
135    Status status() const { return _status; }
136
137    /** Sets the status of this thread. */
138    void setStatus(Status new_status) { _status = new_status; }
139
140  public:
141
142    /** Number of instructions committed. */
143    Counter numInst;
144    /** Stat for number instructions committed. */
145    Stats::Scalar numInsts;
146    /** Stat for number of memory references. */
147    Stats::Scalar numMemRefs;
148
149    /** Number of simulated loads, used for tracking events based on
150     * the number of loads committed.
151     */
152    Counter numLoad;
153
154    /** The number of simulated loads committed prior to this run. */
155    Counter startNumLoad;
156
157  protected:
158    ThreadContext::Status _status;
159
160    // Pointer to the base CPU.
161    BaseCPU *baseCpu;
162
163    // system wide HW context id
164    int _contextId;
165
166    // Index of hardware thread context on the CPU that this represents.
167    ThreadID _threadId;
168
169  public:
170    /** Last time activate was called on this thread. */
171    Tick lastActivate;
172
173    /** Last time suspend was called on this thread. */
174    Tick lastSuspend;
175
176#if FULL_SYSTEM
177  public:
178    FunctionProfile *profile;
179    ProfileNode *profileNode;
180    Addr profilePC;
181    EndQuiesceEvent *quiesceEvent;
182
183    TheISA::Kernel::Statistics *kernelStats;
184  protected:
185    /** A port proxy outgoing only for functional accesses to physical
186     * addresses.*/
187    PortProxy *physProxy;
188
189    /** A translating port proxy, outgoing only, for functional
190     * accesse to virtual addresses. */
191    FSTranslatingPortProxy* virtProxy;
192#else
193    SETranslatingPortProxy* proxy;
194
195    Process *process;
196#endif
197
198  public:
199    /*
200     * number of executed instructions, for matching with syscall trace
201     * points in EIO files.
202     */
203    Counter funcExeInst;
204
205    //
206    // Count failed store conditionals so we can warn of apparent
207    // application deadlock situations.
208    unsigned storeCondFailures;
209};
210
211#endif // __CPU_THREAD_STATE_HH__
212