diff mbox series

[RFC,v1,9/9] replay: gracefully handle backward time events

Message ID 20170403124524.10824-10-alex.bennee@linaro.org
State New
Headers show
Series MTTCG and record/replay fixes for rc3 | expand

Commit Message

Alex Bennée April 3, 2017, 12:45 p.m. UTC
For the purposes of record/replay time can only move forward.

It is possible for the non-vCPU thread to find time has moved from
under its feet as it goes on. This is OK as long as we don't try and
re-wind time.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 replay/replay-internal.c | 7 +++++++
 replay/replay.c          | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

-- 
2.11.0
diff mbox series

Patch

diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index bea7b4aa6b..9656db7102 100644
--- a/replay/replay-internal.c
+++ b/replay/replay-internal.c
@@ -199,6 +199,13 @@  void replay_save_instructions(void)
             replay_put_event(EVENT_INSTRUCTION);
             replay_put_dword(diff);
             replay_state.current_step += diff;
+        } else if (diff < 0) {
+            /* Time has caught up with us, so as far as we are
+             * concerned use now, not the past. We still put an event
+             * in the stream to keep in sync.
+             */
+            replay_put_event(EVENT_INSTRUCTION);
+            replay_put_dword(0);
         }
         replay_mutex_unlock();
     }
diff --git a/replay/replay.c b/replay/replay.c
index 9e0724e756..f4376df0fd 100644
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -84,8 +84,13 @@  void replay_account_executed_instructions(void)
         if (replay_state.instructions_count > 0) {
             int count = (int)(replay_get_current_step()
                               - replay_state.current_step);
-            replay_state.instructions_count -= count;
-            replay_state.current_step += count;
+
+            /* Time only goes forward */
+            if (count >= 0) {
+                replay_state.instructions_count -= count;
+                replay_state.current_step += count;
+            }
+
             if (replay_state.instructions_count == 0) {
                 assert(replay_state.data_kind == EVENT_INSTRUCTION);
                 replay_finish_event();