sim: added option to serialize SimLoopExitEvent
authorDam Sunwoo <dam.sunwoo@arm.com>
Thu, 31 Oct 2013 18:41:13 +0000 (13:41 -0500)
committerDam Sunwoo <dam.sunwoo@arm.com>
Thu, 31 Oct 2013 18:41:13 +0000 (13:41 -0500)
SimLoopExitEvents weren't serialized by default. Some benchmarks
utilize a delayed m5 exit pseudo op call to terminate the simulation
and this event was lost when resuming from a checkpoint generated
after the pseudo op call. This patch adds the capability to serialize
the SimLoopExitEvents and enable serialization for m5_exit and m5_fail
pseudo ops by default. Does not affect other generic
SimLoopExitEvents.

src/sim/pseudo_inst.cc
src/sim/sim_events.cc
src/sim/sim_events.hh
src/sim/sim_exit.hh

index f4666a0cd3366d484cd8bf6f8a9d469b623be759..e85e3d19ae27cdf3a4cc2cb05ddf98d60d691ce3 100644 (file)
@@ -347,7 +347,7 @@ m5exit(ThreadContext *tc, Tick delay)
 {
     DPRINTF(PseudoInst, "PseudoInst::m5exit(%i)\n", delay);
     Tick when = curTick() + delay * SimClock::Int::ns;
-    exitSimLoop("m5_exit instruction encountered", 0, when);
+    exitSimLoop("m5_exit instruction encountered", 0, when, 0, true);
 }
 
 void
@@ -355,7 +355,7 @@ m5fail(ThreadContext *tc, Tick delay, uint64_t code)
 {
     DPRINTF(PseudoInst, "PseudoInst::m5fail(%i, %i)\n", delay, code);
     Tick when = curTick() + delay * SimClock::Int::ns;
-    exitSimLoop("m5_fail instruction encountered", code, when);
+    exitSimLoop("m5_fail instruction encountered", code, when, 0, true);
 }
 
 void
index 0ae7e573ee63b4c10e33c4db149257ceccaf9d80..5380ddd83960051308849d1a1693126176f028f3 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2013 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) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
 
 using namespace std;
 
-SimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r)
-    : Event(Sim_Exit_Pri, IsExitEvent), cause(_cause), code(c), repeat(r)
+SimLoopExitEvent::SimLoopExitEvent()
+    : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
+      cause(""), code(0), repeat(0)
+{
+}
+
+SimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r,
+                                   bool serialize)
+    : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
+      cause(_cause), code(c), repeat(r)
 {
 }
 
@@ -77,9 +97,39 @@ SimLoopExitEvent::description() const
 }
 
 void
-exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat)
+SimLoopExitEvent::serialize(ostream &os)
+{
+    paramOut(os, "type", string("SimLoopExitEvent"));
+    Event::serialize(os);
+
+    SERIALIZE_SCALAR(cause);
+    SERIALIZE_SCALAR(code);
+    SERIALIZE_SCALAR(repeat);
+}
+
+void
+SimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
+{
+    Event::unserialize(cp, section);
+
+    UNSERIALIZE_SCALAR(cause);
+    UNSERIALIZE_SCALAR(code);
+    UNSERIALIZE_SCALAR(repeat);
+}
+
+Serializable *
+SimLoopExitEvent::createForUnserialize(Checkpoint *cp, const string &section)
+{
+    return new SimLoopExitEvent();
+}
+
+REGISTER_SERIALIZEABLE("SimLoopExitEvent", SimLoopExitEvent)
+
+void
+exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
+            bool serialize)
 {
-    Event *event = new SimLoopExitEvent(message, exit_code, repeat);
+    Event *event = new SimLoopExitEvent(message, exit_code, repeat, serialize);
     mainEventQueue.schedule(event, when);
 }
 
index 6ea361a05278007ca80efba51639f0590ee6b64a..4abfb317cbfd5f89be6b14dce4d53408cc94f440 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2013 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) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
@@ -32,6 +44,7 @@
 #define __SIM_SIM_EVENTS_HH__
 
 #include "sim/eventq.hh"
+#include "sim/serialize.hh"
 
 //
 // Event to terminate simulation at a particular cycle/instruction
@@ -45,7 +58,10 @@ class SimLoopExitEvent : public Event
     Tick repeat;
 
   public:
-    SimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0);
+    // non-scheduling version for createForUnserialize()
+    SimLoopExitEvent();
+    SimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0,
+                     bool serialize = false);
 
     std::string getCause() { return cause; }
     int getCode() { return code; }
@@ -53,6 +69,11 @@ class SimLoopExitEvent : public Event
     void process();     // process event
 
     virtual const char *description() const;
+
+    virtual void serialize(std::ostream &os);
+    virtual void unserialize(Checkpoint *cp, const std::string &section);
+    static Serializable *createForUnserialize(Checkpoint *cp,
+                                              const std::string &section);
 };
 
 class CountedDrainEvent : public Event
index da71cc912cb33a4ae9ee0ab1c18cf3b4f9d5ba66..ef73d822d80cec29843bd459de0e6747127e20d1 100644 (file)
@@ -51,6 +51,7 @@ void registerExitCallback(Callback *);
 /// and exit_code parameters are saved in the SimLoopExitEvent to
 /// indicate why the exit occurred.
 void exitSimLoop(const std::string &message, int exit_code = 0,
-                 Tick when = curTick(), Tick repeat = 0);
+                 Tick when = curTick(), Tick repeat = 0,
+                 bool serialize = false);
 
 #endif // __SIM_EXIT_HH__