arch: Use shared_ptr for all Faults
[gem5.git] / src / cpu / thread_state.hh
index de9b2f14e4fc866dfcec2af3808f988f60dfd0b6..f937964ffa3b052d9fa9e81d0823b9e30b066185 100644 (file)
 #ifndef __CPU_THREAD_STATE_HH__
 #define __CPU_THREAD_STATE_HH__
 
-#include "arch/isa_traits.hh"
+#include "arch/types.hh"
+#include "config/the_isa.hh"
+#include "cpu/base.hh"
+#include "cpu/profile.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;
 class FunctionProfile;
 class ProfileNode;
-namespace Kernel {
-    class Statistics;
-};
-#endif
+namespace TheISA {
+    namespace Kernel {
+        class Statistics;
+    }
+}
+
+class Checkpoint;
 
 /**
  *  Struct for holding general thread state that is needed across CPU
@@ -58,59 +59,55 @@ namespace Kernel {
 struct ThreadState {
     typedef ThreadContext::Status Status;
 
-#if FULL_SYSTEM
-    ThreadState(int _cpuId, int _tid);
-#else
-    ThreadState(int _cpuId, int _tid, MemObject *mem,
-                Process *_process, short _asid);
-#endif
+    ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
 
-    void setCpuId(int id) { cpuId = id; }
+    virtual ~ThreadState();
 
-    int readCpuId() { return cpuId; }
+    void serialize(std::ostream &os);
 
-    void setTid(int id) { tid = id; }
+    void unserialize(Checkpoint *cp, const std::string &section);
 
-    int readTid() { return tid; }
+    int cpuId() const { return baseCpu->cpuId(); }
 
-    Tick readLastActivate() { return lastActivate; }
+    uint32_t socketId() const { return baseCpu->socketId(); }
 
-    Tick readLastSuspend() { return lastSuspend; }
+    int contextId() const { return _contextId; }
 
-#if FULL_SYSTEM
-    void dumpFuncProfile();
+    void setContextId(int id) { _contextId = id; }
 
-    EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
+    void setThreadId(ThreadID id) { _threadId = id; }
 
-    void profileClear();
+    ThreadID threadId() const { return _threadId; }
 
-    void profileSample();
+    Tick readLastActivate() const { return lastActivate; }
 
-    Kernel::Statistics *getKernelStats() { return kernelStats; }
+    Tick readLastSuspend() const { return lastSuspend; }
 
-    FunctionalPort *getPhysPort() { return physPort; }
+    /**
+     * Initialise the physical and virtual port proxies and tie them to
+     * the data port of the CPU.
+     *
+     * @param tc ThreadContext for the virtual-to-physical translation
+     */
+    void initMemProxies(ThreadContext *tc);
 
-    void setPhysPort(FunctionalPort *port) { physPort = port; }
+    void dumpFuncProfile();
 
-    VirtualPort *getVirtPort(ThreadContext *tc = NULL) { return virtPort; }
+    EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; }
 
-    void setVirtPort(VirtualPort *port) { virtPort = port; }
-#else
-    Process *getProcessPtr() { return process; }
+    void profileClear();
+
+    void profileSample();
 
-    TranslatingPort *getMemPort() { return port; }
+    TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
 
-    void setMemPort(TranslatingPort *_port) { port = _port; }
+    PortProxy &getPhysProxy();
 
-    int getInstAsid() { return asid; }
-    int getDataAsid() { return asid; }
-#endif
+    FSTranslatingPortProxy &getVirtProxy();
 
-    /** Sets the current instruction being committed. */
-    void setInst(TheISA::MachInst _inst) { inst = _inst; }
+    Process *getProcessPtr() { return process; }
 
-    /** Returns the current instruction being committed. */
-    TheISA::MachInst getInst() { return inst; }
+    SETranslatingPortProxy &getMemProxy();
 
     /** Reads the number of instructions functionally executed and
      * committed.
@@ -128,12 +125,18 @@ struct ThreadState {
     /** Sets the status of this thread. */
     void setStatus(Status new_status) { _status = new_status; }
 
+  public:
+
     /** Number of instructions committed. */
     Counter numInst;
     /** Stat for number instructions committed. */
-    Stats::Scalar<> numInsts;
+    Stats::Scalar numInsts;
+    /** Number of ops (including micro ops) committed. */
+    Counter numOp;
+    /** Stat for number ops (including micro ops) committed. */
+    Stats::Scalar numOps;
     /** Stat for number of memory references. */
-    Stats::Scalar<> numMemRefs;
+    Stats::Scalar numMemRefs;
 
     /** Number of simulated loads, used for tracking events based on
      * the number of loads committed.
@@ -146,12 +149,14 @@ struct ThreadState {
   protected:
     ThreadContext::Status _status;
 
-    // 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;
+    // Pointer to the base CPU.
+    BaseCPU *baseCpu;
+
+    // system wide HW context id
+    int _contextId;
 
     // Index of hardware thread context on the CPU that this represents.
-    int tid;
+    ThreadID _threadId;
 
   public:
     /** Last time activate was called on this thread. */
@@ -160,51 +165,27 @@ struct ThreadState {
     /** 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;
+    TheISA::Kernel::Statistics *kernelStats;
 
+  protected:
     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
+    /** A port proxy outgoing only for functional accesses to physical
+     * addresses.*/
+    PortProxy *physProxy;
 
-    /** Current instruction the thread is committing.  Only set and
-     * used for DTB faults currently.
-     */
-    TheISA::MachInst inst;
+    /** A translating port proxy, outgoing only, for functional
+     * accesse to virtual addresses. */
+    FSTranslatingPortProxy *virtProxy;
+    SETranslatingPortProxy *proxy;
 
   public:
-    /**
-     * Temporary storage to pass the source address from copy_load to
-     * copy_store.
-     * @todo Remove this temporary when we have a better way to do it.
-     */
-    Addr copySrcAddr;
-    /**
-     * Temp storage for the physical source address of a copy.
-     * @todo Remove this temporary when we have a better way to do it.
-     */
-    Addr copySrcPhysAddr;
-
     /*
      * number of executed instructions, for matching with syscall trace
      * points in EIO files.