cpu: Avoid unnecessary dynamic_pointer_cast in atomic model
[gem5.git] / src / cpu / thread_state.hh
index 972ca895d2eac1cba310509b4fb27a91e8d6f9ce..5cbc3322b1a607426084898afcff1b78689303dc 100644 (file)
@@ -45,12 +45,10 @@ class ProfileNode;
 namespace TheISA {
     namespace Kernel {
         class Statistics;
-    };
-};
+    }
+}
 
 class Checkpoint;
-class Port;
-class TranslatingPort;
 
 /**
  *  Struct for holding general thread state that is needed across CPU
@@ -58,36 +56,40 @@ class TranslatingPort;
  *  memory, quiesce events, and certain stats.  This can be expanded
  *  to hold more thread-specific stats within it.
  */
-struct ThreadState {
+struct ThreadState : public Serializable {
     typedef ThreadContext::Status Status;
 
     ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process);
 
-    ~ThreadState();
-
-    void serialize(std::ostream &os);
+    virtual ~ThreadState();
 
-    void unserialize(Checkpoint *cp, const std::string &section);
+    void serialize(CheckpointOut &cp) const override;
 
-    int cpuId() { return baseCpu->cpuId(); }
+    void unserialize(CheckpointIn &cp) override;
 
-    int contextId() { return _contextId; }
+    int cpuId() const { return baseCpu->cpuId(); }
 
-    void setContextId(int id) { _contextId = id; }
+    uint32_t socketId() const { return baseCpu->socketId(); }
 
-    void setThreadId(ThreadID id) { _threadId = id; }
+    ContextID contextId() const { return _contextId; }
 
-    ThreadID threadId() { return _threadId; }
+    void setContextId(ContextID id) { _contextId = id; }
 
-    Tick readLastActivate() { return lastActivate; }
+    void setThreadId(ThreadID id) { _threadId = id; }
 
-    Tick readLastSuspend() { return lastSuspend; }
+    ThreadID threadId() const { return _threadId; }
 
-    void connectPhysPort();
+    Tick readLastActivate() const { return lastActivate; }
 
-    void connectVirtPort(ThreadContext *tc);
+    Tick readLastSuspend() const { return lastSuspend; }
 
-    void connectMemPorts(ThreadContext *tc);
+    /**
+     * 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 dumpFuncProfile();
 
@@ -99,17 +101,28 @@ struct ThreadState {
 
     TheISA::Kernel::Statistics *getKernelStats() { return kernelStats; }
 
-    Process *getProcessPtr() { return process; }
-
-    TranslatingPort *getMemPort();
-
-    void setMemPort(TranslatingPort *_port) { port = _port; }
+    PortProxy &getPhysProxy();
 
-    VirtualPort *getVirtPort() { return virtPort; }
+    FSTranslatingPortProxy &getVirtProxy();
 
-    FunctionalPort *getPhysPort() { return physPort; }
+    Process *getProcessPtr() { return process; }
 
-    void setPhysPort(FunctionalPort *port) { physPort = port; }
+    void setProcessPtr(Process *p)
+    {
+        process = p;
+        /**
+         * When the process pointer changes while operating in SE Mode,
+         * the se translating port proxy needs to be reinitialized since it
+         * holds a pointer to the process class.
+         */
+        if (proxy) {
+            delete proxy;
+            proxy = NULL;
+            initMemProxies(NULL);
+        }
+    }
+
+    SETranslatingPortProxy &getMemProxy();
 
     /** Reads the number of instructions functionally executed and
      * committed.
@@ -128,14 +141,15 @@ struct ThreadState {
     void setStatus(Status new_status) { _status = new_status; }
 
   public:
-    /** Connects port to the functional port of the memory object
-     * below the CPU. */
-    void connectToMemFunc(Port *port);
 
     /** Number of instructions committed. */
     Counter numInst;
     /** Stat for number instructions committed. */
     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;
 
@@ -154,7 +168,7 @@ struct ThreadState {
     BaseCPU *baseCpu;
 
     // system wide HW context id
-    int _contextId;
+    ContextID _contextId;
 
     // Index of hardware thread context on the CPU that this represents.
     ThreadID _threadId;
@@ -177,15 +191,14 @@ struct ThreadState {
   protected:
     Process *process;
 
-    TranslatingPort *port;
-
-    /** A functional port, outgoing only, for functional accesse to virtual
-     * addresses. */
-    VirtualPort *virtPort;
-
-    /** A functional port outgoing only for functional accesses to physical
+    /** A port proxy outgoing only for functional accesses to physical
      * addresses.*/
-    FunctionalPort *physPort;
+    PortProxy *physProxy;
+
+    /** A translating port proxy, outgoing only, for functional
+     * accesse to virtual addresses. */
+    FSTranslatingPortProxy *virtProxy;
+    SETranslatingPortProxy *proxy;
 
   public:
     /*