Merge zizzer:/z/m5/Bitkeeper/newmem
[gem5.git] / src / cpu / thread_state.hh
index e09cb12fd099bc089ad88955da97cd64721fe532..b03a2e2bb83ee2e1d4cc0b2734f63fc7724696bc 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Kevin Lim
  */
 
 #ifndef __CPU_THREAD_STATE_HH__
 #define __CPU_THREAD_STATE_HH__
 
-#include "cpu/exec_context.hh"
+#include "arch/isa_traits.hh"
+#include "cpu/thread_context.hh"
+
+#if !FULL_SYSTEM
+#include "mem/mem_object.hh"
+#include "mem/translating_port.hh"
+#include "sim/process.hh"
+#endif
 
 #if FULL_SYSTEM
 class EndQuiesceEvent;
@@ -38,11 +47,10 @@ class ProfileNode;
 namespace Kernel {
     class Statistics;
 };
-#else
-class FunctionalMemory;
-class Process;
 #endif
 
+class Checkpoint;
+
 /**
  *  Struct for holding general thread state that is needed across CPU
  *  models.  This includes things such as pointers to the process,
@@ -50,58 +58,147 @@ class Process;
  *  to hold more thread-specific stats within it.
  */
 struct ThreadState {
+    typedef ThreadContext::Status Status;
+
 #if FULL_SYSTEM
-    ThreadState(int _cpuId, int _tid, FunctionalMemory *_mem)
-        : cpuId(_cpuId), tid(_tid), mem(_mem), lastActivate(0), lastSuspend(0),
-          profile(NULL), profileNode(NULL), profilePC(0), quiesceEvent(NULL)
+    ThreadState(int _cpuId, int _tid);
 #else
-    ThreadState(int _cpuId, int _tid, FunctionalMemory *_mem,
-                Process *_process, short _asid)
-        : cpuId(_cpuId), tid(_tid), mem(_mem), process(_process), asid(_asid)
+    ThreadState(int _cpuId, int _tid, Process *_process,
+                short _asid, MemObject *mem);
 #endif
-    {
-        funcExeInst = 0;
-        storeCondFailures = 0;
-    }
 
-    ExecContext::Status status;
+    void serialize(std::ostream &os);
 
-    int cpuId;
+    void unserialize(Checkpoint *cp, const std::string &section);
 
-    // Index of hardware thread context on the CPU that this represents.
-    int tid;
+    void setCpuId(int id) { cpuId = id; }
+
+    int readCpuId() { return cpuId; }
+
+    void setTid(int id) { tid = id; }
+
+    int readTid() { return tid; }
+
+    Tick readLastActivate() { return lastActivate; }
+
+    Tick readLastSuspend() { return lastSuspend; }
+
+#if FULL_SYSTEM
+    void dumpFuncProfile();
+
+    EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
+
+    void profileClear();
+
+    void profileSample();
+
+    Kernel::Statistics *getKernelStats() { return kernelStats; }
+
+    FunctionalPort *getPhysPort() { return physPort; }
+
+    void setPhysPort(FunctionalPort *port) { physPort = port; }
+
+    VirtualPort *getVirtPort(ThreadContext *tc = NULL) { return virtPort; }
+
+    void setVirtPort(VirtualPort *port) { virtPort = port; }
+#else
+    Process *getProcessPtr() { return process; }
+
+    TranslatingPort *getMemPort() { return port; }
 
+    void setMemPort(TranslatingPort *_port) { port = _port; }
+
+    int getInstAsid() { return asid; }
+    int getDataAsid() { return asid; }
+#endif
+
+    /** Sets the current instruction being committed. */
+    void setInst(TheISA::MachInst _inst) { inst = _inst; }
+
+    /** Returns the current instruction being committed. */
+    TheISA::MachInst getInst() { return inst; }
+
+    /** Reads the number of instructions functionally executed and
+     * committed.
+     */
+    Counter readFuncExeInst() { return funcExeInst; }
+
+    /** Sets the total number of instructions functionally executed
+     * and committed.
+     */
+    void setFuncExeInst(Counter new_val) { funcExeInst = new_val; }
+
+    /** Returns the status of this thread. */
+    Status status() const { return _status; }
+
+    /** Sets the status of this thread. */
+    void setStatus(Status new_status) { _status = new_status; }
+
+    /** Number of instructions committed. */
     Counter numInst;
+    /** Stat for number instructions committed. */
     Stats::Scalar<> numInsts;
+    /** Stat for number of memory references. */
     Stats::Scalar<> numMemRefs;
 
-    // number of simulated loads
+    /** Number of simulated loads, used for tracking events based on
+     * the number of loads committed.
+     */
     Counter numLoad;
+
+    /** The number of simulated loads committed prior to this run. */
     Counter startNumLoad;
 
-    FunctionalMemory *mem;     // functional storage for process address space
+  protected:
+    ThreadContext::Status _status;
 
-#if FULL_SYSTEM
+    // ID of this context w.r.t. the System or Process object to which
+    // it belongs.  For full-system mode, this is the system CPU ID.
+    int cpuId;
+
+    // Index of hardware thread context on the CPU that this represents.
+    int tid;
+
+  public:
+    /** Last time activate was called on this thread. */
     Tick lastActivate;
+
+    /** Last time suspend was called on this thread. */
     Tick lastSuspend;
 
+#if FULL_SYSTEM
+  public:
     FunctionProfile *profile;
     ProfileNode *profileNode;
     Addr profilePC;
-
     EndQuiesceEvent *quiesceEvent;
 
     Kernel::Statistics *kernelStats;
+  protected:
+    /** A functional port outgoing only for functional accesses to physical
+     * addresses.*/
+    FunctionalPort *physPort;
+
+    /** A functional port, outgoing only, for functional accesse to virtual
+     * addresses. That doen't require execution context information */
+    VirtualPort *virtPort;
 #else
+    TranslatingPort *port;
+
     Process *process;
 
     // Address space ID.  Note that this is used for TIMING cache
     // simulation only; all functional memory accesses should use
     // one of the FunctionalMemory pointers above.
     short asid;
-
 #endif
 
+    /** Current instruction the thread is committing.  Only set and
+     * used for DTB faults currently.
+     */
+    TheISA::MachInst inst;
+
+  public:
     /**
      * Temporary storage to pass the source address from copy_load to
      * copy_store.