thread_state.hh revision 2362
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
29#ifndef __CPU_THREAD_STATE_HH__
30#define __CPU_THREAD_STATE_HH__
31
32#include "cpu/exec_context.hh"
33#include "cpu/profile.hh"
34
35#if FULL_SYSTEM
36class EndQuiesceEvent;
37class FunctionProfile;
38class ProfileNode;
39namespace Kernel {
40    class Statistics;
41};
42#else
43class FunctionalMemory;
44class Process;
45#endif
46
47/**
48 *  Struct for holding general thread state that is needed across CPU
49 *  models.  This includes things such as pointers to the process,
50 *  memory, quiesce events, and certain stats.  This can be expanded
51 *  to hold more thread-specific stats within it.
52 */
53struct ThreadState {
54#if FULL_SYSTEM
55    ThreadState(int _cpuId, int _tid, FunctionalMemory *_mem)
56        : cpuId(_cpuId), tid(_tid), mem(_mem), lastActivate(0), lastSuspend(0),
57          profile(NULL), profileNode(NULL), profilePC(0), quiesceEvent(NULL)
58#else
59    ThreadState(int _cpuId, int _tid, FunctionalMemory *_mem,
60                Process *_process, short _asid)
61        : cpuId(_cpuId), tid(_tid), mem(_mem), process(_process), asid(_asid)
62#endif
63    {
64        numInst = 0;
65        funcExeInst = 0;
66        storeCondFailures = 0;
67    }
68
69    ExecContext::Status status;
70
71    int cpuId;
72
73    // Index of hardware thread context on the CPU that this represents.
74    int tid;
75
76    Counter numInst;
77    Stats::Scalar<> numInsts;
78    Stats::Scalar<> numMemRefs;
79
80    // number of simulated loads
81    Counter numLoad;
82    Counter startNumLoad;
83
84    FunctionalMemory *mem;	// functional storage for process address space
85
86#if FULL_SYSTEM
87    Tick lastActivate;
88    Tick lastSuspend;
89
90    FunctionProfile *profile;
91    ProfileNode *profileNode;
92    Addr profilePC;
93
94    EndQuiesceEvent *quiesceEvent;
95
96    Kernel::Statistics *kernelStats;
97#else
98    Process *process;
99
100    // Address space ID.  Note that this is used for TIMING cache
101    // simulation only; all functional memory accesses should use
102    // one of the FunctionalMemory pointers above.
103    short asid;
104
105#endif
106
107#if FULL_SYSTEM
108    void profileClear()
109    {
110        if (profile)
111            profile->clear();
112    }
113
114    void profileSample()
115    {
116        if (profile)
117            profile->sample(profileNode, profilePC);
118    }
119#endif
120
121    /**
122     * Temporary storage to pass the source address from copy_load to
123     * copy_store.
124     * @todo Remove this temporary when we have a better way to do it.
125     */
126    Addr copySrcAddr;
127    /**
128     * Temp storage for the physical source address of a copy.
129     * @todo Remove this temporary when we have a better way to do it.
130     */
131    Addr copySrcPhysAddr;
132
133    /*
134     * number of executed instructions, for matching with syscall trace
135     * points in EIO files.
136     */
137    Counter funcExeInst;
138
139    //
140    // Count failed store conditionals so we can warn of apparent
141    // application deadlock situations.
142    unsigned storeCondFailures;
143};
144
145#endif // __CPU_THREAD_STATE_HH__
146