syscall_emul: [patch 13/22] add system call retry capability
[gem5.git] / src / cpu / o3 / thread_state.hh
index 19cbffb4446a5a3d25991076229bc73cd128e6fc..4b4f51e8faeee0c6f307aecd097e16cce290a9ba 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2012 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2006 The Regents of The University of Michigan
  * All rights reserved.
  *
 #ifndef __CPU_O3_THREAD_STATE_HH__
 #define __CPU_O3_THREAD_STATE_HH__
 
-#include "arch/faults.hh"
-#include "arch/isa_traits.hh"
+#include "base/callback.hh"
+#include "base/output.hh"
 #include "cpu/thread_context.hh"
 #include "cpu/thread_state.hh"
+#include "sim/full_system.hh"
+#include "sim/sim_exit.hh"
 
-class Event;
-class Process;
-
-#if FULL_SYSTEM
 class EndQuiesceEvent;
-class FunctionProfile;
-class ProfileNode;
-#else
+class Event;
 class FunctionalMemory;
+class FunctionProfile;
 class Process;
-#endif
+class ProfileNode;
 
 /**
  * Class that has various thread state, such as the status, the
@@ -64,28 +73,65 @@ struct O3ThreadState : public ThreadState {
     /** Pointer to the CPU. */
     O3CPU *cpu;
   public:
-    /** Whether or not the thread is currently in syscall mode, and
-     * thus able to be externally updated without squashing.
+    /* This variable controls if writes to a thread context should cause a all
+     * dynamic/speculative state to be thrown away. Nominally this is the
+     * desired behavior because the external thread context write has updated
+     * some state that could be used by an inflight instruction, however there
+     * are some cases like in a fault/trap handler where this behavior would
+     * lead to successive restarts and forward progress couldn't be made. This
+     * variable controls if the squashing will occur.
      */
-    bool inSyscall;
+    bool noSquashFromTC;
 
     /** Whether or not the thread is currently waiting on a trap, and
      * thus able to be externally updated without squashing.
      */
     bool trapPending;
 
-#if FULL_SYSTEM
-    O3ThreadState(O3CPU *_cpu, int _thread_num)
-        : ThreadState(-1, _thread_num),
-          inSyscall(0), trapPending(0)
-    { }
-#else
-    O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process, int _asid,
-                  MemObject *mem)
-        : ThreadState(-1, _thread_num, mem, _process, _asid),
-          cpu(_cpu), inSyscall(0), trapPending(0)
-    { }
-#endif
+    O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process)
+        : ThreadState(_cpu, _thread_num, _process),
+          cpu(_cpu), noSquashFromTC(false), trapPending(false),
+          tc(nullptr)
+    {
+        if (!FullSystem)
+            return;
+
+        if (cpu->params()->profile) {
+            profile = new FunctionProfile(
+                    cpu->params()->system->kernelSymtab);
+            Callback *cb =
+                new MakeCallback<O3ThreadState,
+                &O3ThreadState::dumpFuncProfile>(this);
+            registerExitCallback(cb);
+        }
+
+        // let's fill with a dummy node for now so we don't get a segfault
+        // on the first cycle when there's no node available.
+        static ProfileNode dummyNode;
+        profileNode = &dummyNode;
+        profilePC = 3;
+    }
+
+    void serialize(CheckpointOut &cp) const override
+    {
+        ThreadState::serialize(cp);
+        // Use the ThreadContext serialization helper to serialize the
+        // TC.
+        ::serialize(*tc, cp);
+    }
+
+    void unserialize(CheckpointIn &cp) override
+    {
+        // Prevent squashing - we don't have any instructions in
+        // flight that we need to squash since we just instantiated a
+        // clean system.
+        noSquashFromTC = true;
+        ThreadState::unserialize(cp);
+        // Use the ThreadContext serialization helper to unserialize
+        // the TC.
+        ::unserialize(*tc, cp);
+        noSquashFromTC = false;
+    }
 
     /** Pointer to the ThreadContext of this thread. */
     ThreadContext *tc;
@@ -93,10 +139,19 @@ struct O3ThreadState : public ThreadState {
     /** Returns a pointer to the TC of this thread. */
     ThreadContext *getTC() { return tc; }
 
-#if !FULL_SYSTEM
     /** Handles the syscall. */
-    void syscall(int64_t callnum) { process->syscall(callnum, tc); }
-#endif
+    void syscall(int64_t callnum, Fault *fault)
+    {
+        process->syscall(callnum, tc, fault);
+    }
+
+    void dumpFuncProfile()
+    {
+        OutputStream *os(
+            simout.create(csprintf("profile.%s.dat", cpu->name())));
+        profile->dump(tc, *os->stream());
+        simout.close(os);
+    }
 };
 
 #endif // __CPU_O3_THREAD_STATE_HH__