[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v1 9/9] replay: gracefully handle backward time
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [RFC PATCH v1 9/9] replay: gracefully handle backward time events |
Date: |
Mon, 3 Apr 2017 13:45:24 +0100 |
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 <address@hidden>
---
replay/replay-internal.c | 7 +++++++
replay/replay.c | 9 +++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
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();
--
2.11.0