O3 IEW: Make incrWb and decrWb clearer
[gem5.git] / src / cpu / base.hh
index 0c1d19856ec721b6a4fc75e37f95fb1eac2a44b4..34b23cea07a7ed8eaa6ff7305ba842f8399fdd61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 ARM Limited
+ * Copyright (c) 2011-2012 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -103,6 +103,20 @@ class BaseCPU : public MemObject
     /** data side request id that must be placed in all requests */
     MasterID _dataMasterId;
 
+    /** An intrenal representation of a task identifier within gem5. This is
+     * used so the CPU can add which taskId (which is an internal representation
+     * of the OS process ID) to each request so components in the memory system
+     * can track which process IDs are ultimately interacting with them
+     */
+    uint32_t _taskId;
+
+    /** The current OS process ID that is executing on this processor. This is
+     * used to generate a taskId */
+    uint32_t _pid;
+
+    /** Is the CPU switched out or active? */
+    bool _switchedOut;
+
     /**
      * Define a base class for the CPU ports (instruction and data)
      * that is refined in the subclasses. This class handles the
@@ -171,7 +185,16 @@ class BaseCPU : public MemObject
      *
      * @return a reference to the port with the given name
      */
-    MasterPort &getMasterPort(const std::string &if_name, int idx = -1);
+    BaseMasterPort &getMasterPort(const std::string &if_name,
+                                  PortID idx = InvalidPortID);
+
+    /** Get cpu task id */
+    uint32_t taskId() const { return _taskId; }
+    /** Set cpu task id */
+    void taskId(uint32_t id) { _taskId = id; }
+
+    uint32_t getPid() const { return _pid; }
+    void setPid(uint32_t pid) { _pid = pid; }
 
     inline void workItemBegin() { numWorkItemsStarted++; }
     inline void workItemEnd() { numWorkItemsCompleted++; }
@@ -300,6 +323,24 @@ class BaseCPU : public MemObject
      */
     virtual void takeOverFrom(BaseCPU *cpu);
 
+    /**
+     * Flush all TLBs in the CPU.
+     *
+     * This method is mainly used to flush stale translations when
+     * switching CPUs. It is also exported to the Python world to
+     * allow it to request a TLB flush after draining the CPU to make
+     * it easier to compare traces when debugging
+     * handover/checkpointing.
+     */
+    void flushTLBs();
+
+    /**
+     * Determine if the CPU is switched out.
+     *
+     * @return True if the CPU is switched out, false otherwise.
+     */
+    bool switchedOut() const { return _switchedOut; }
+
     /**
      *  Number of threads we're actually simulating (<= SMT_MAX_THREADS).
      * This is a constant for the duration of the simulation.
@@ -324,17 +365,47 @@ class BaseCPU : public MemObject
 
     /**
      * Serialize this object to the given output stream.
+     *
+     * @note CPU models should normally overload the serializeThread()
+     * method instead of the serialize() method as this provides a
+     * uniform data format for all CPU models and promotes better code
+     * reuse.
+     *
      * @param os The stream to serialize to.
      */
     virtual void serialize(std::ostream &os);
 
     /**
      * Reconstruct the state of this object from a checkpoint.
+     *
+     * @note CPU models should normally overload the
+     * unserializeThread() method instead of the unserialize() method
+     * as this provides a uniform data format for all CPU models and
+     * promotes better code reuse.
+
      * @param cp The checkpoint use.
-     * @param section The section name of this object
+     * @param section The section name of this object.
      */
     virtual void unserialize(Checkpoint *cp, const std::string &section);
 
+    /**
+     * Serialize a single thread.
+     *
+     * @param os The stream to serialize to.
+     * @param tid ID of the current thread.
+     */
+    virtual void serializeThread(std::ostream &os, ThreadID tid) {};
+
+    /**
+     * Unserialize one thread.
+     *
+     * @param cp The checkpoint use.
+     * @param section The section name of this thread.
+     * @param tid ID of the current thread.
+     */
+    virtual void unserializeThread(Checkpoint *cp, const std::string &section,
+                                   ThreadID tid) {};
+
     /**
      * Return pointer to CPU's branch predictor (NULL if none).
      * @return Branch predictor pointer.