diff mbox

[RFC,v8,06/21] replay: introduce icount event

Message ID 20150122085204.5276.65278.stgit@PASHA-ISP.def.inno
State New
Headers show

Commit Message

Pavel Dovgalyuk Jan. 22, 2015, 8:52 a.m. UTC
This patch adds icount event to the replay subsystem. This event corresponds
to execution of several instructions and used to synchronize input events
in the replay phase.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
 replay/replay-internal.c |   16 ++++++++++++++++
 replay/replay-internal.h |   20 ++++++++++++++++++++
 replay/replay.c          |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 replay/replay.h          |    7 +++++++
 4 files changed, 89 insertions(+), 0 deletions(-)

Comments

Paolo Bonzini Jan. 29, 2015, 9:14 a.m. UTC | #1
On 22/01/2015 09:52, Pavel Dovgalyuk wrote:
> This patch adds icount event to the replay subsystem. This event corresponds
> to execution of several instructions and used to synchronize input events
> in the replay phase.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> ---
>  replay/replay-internal.c |   16 ++++++++++++++++
>  replay/replay-internal.h |   20 ++++++++++++++++++++
>  replay/replay.c          |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  replay/replay.h          |    7 +++++++
>  4 files changed, 89 insertions(+), 0 deletions(-)
> 
> diff --git a/replay/replay-internal.c b/replay/replay-internal.c
> index f552dad..49b37a6 100755
> --- a/replay/replay-internal.c
> +++ b/replay/replay-internal.c
> @@ -10,6 +10,7 @@
>   */
>  
>  #include "qemu-common.h"
> +#include "replay.h"
>  #include "replay-internal.h"
>  
>  unsigned int replay_data_kind = -1;
> @@ -164,3 +165,18 @@ void replay_mutex_unlock(void)
>  {
>      qemu_mutex_unlock(&lock);
>  }
> +
> +/*! Saves cached instructions. */
> +void replay_save_instructions(void)
> +{
> +    if (replay_file && replay_mode == REPLAY_MODE_RECORD) {
> +        int diff = (int)(replay_get_current_step() - replay_state.current_step);
> +        if (first_cpu != NULL && diff > 0) {
> +            replay_mutex_lock();
> +            replay_put_event(EVENT_INSTRUCTION);
> +            replay_put_dword(diff);
> +            replay_state.current_step += diff;
> +            replay_mutex_unlock();
> +        }
> +    }
> +}
> diff --git a/replay/replay-internal.h b/replay/replay-internal.h
> index 50ce29b..4d661a1 100755
> --- a/replay/replay-internal.h
> +++ b/replay/replay-internal.h
> @@ -14,6 +14,19 @@
>  
>  #include <stdio.h>
>  
> +enum ReplayEvents {
> +    /* for instruction event */
> +    EVENT_INSTRUCTION
> +};
> +
> +typedef struct ReplayState {
> +    /*! Current step - number of processed instructions and timer events. */
> +    uint64_t current_step;
> +    /*! Number of instructions to be executed before other events happen. */
> +    int instructions_count;
> +} ReplayState;
> +extern ReplayState replay_state;
> +
>  extern unsigned int replay_data_kind;
>  extern unsigned int replay_has_unread_data;
>  
> @@ -54,4 +67,11 @@ void replay_save_instructions(void);
>      Terminates the program in case of error. */
>  void validate_data_kind(int kind);
>  
> +/*! Skips async events until some sync event will be found. */
> +bool skip_async_events(int stop_event);
> +/*! Skips async events invocations from the input,
> +    until required data kind is found. If the requested data is not found
> +    reports an error and stops the execution. */
> +void skip_async_events_until(unsigned int kind);
> +
>  #endif
> diff --git a/replay/replay.c b/replay/replay.c
> index 5ce066f..a43bbbc 100755
> --- a/replay/replay.c
> +++ b/replay/replay.c
> @@ -9,6 +9,52 @@
>   *
>   */
>  
> +#include "qemu-common.h"
>  #include "replay.h"
> +#include "replay-internal.h"
> +#include "qemu/timer.h"
>  
>  ReplayMode replay_mode = REPLAY_MODE_NONE;
> +
> +ReplayState replay_state;
> +
> +bool skip_async_events(int stop_event)
> +{
> +    bool res = false;
> +
> +    /* nothing to skip - not all instructions used */
> +    if (replay_state.instructions_count != 0
> +        && replay_has_unread_data) {
> +        return stop_event == EVENT_INSTRUCTION;
> +    }
> +
> +    while (true) {
> +        replay_fetch_data_kind();
> +        if (stop_event == replay_data_kind) {
> +            res = true;
> +        }
> +        switch (replay_data_kind) {
> +        case EVENT_INSTRUCTION:
> +            replay_state.instructions_count = replay_get_dword();
> +            return res;
> +        default:
> +            /* clock, time_t, checkpoint and other events */
> +            return res;
> +        }
> +    }
> +    return res;
> +}
> +
> +void skip_async_events_until(unsigned int kind)
> +{
> +    if (!skip_async_events(kind)) {
> +        fprintf(stderr, "%"PRId64": Read data kind %d instead of expected %d\n",
> +            replay_get_current_step(), replay_data_kind, kind);
> +        exit(1);
> +    }
> +}
> +
> +uint64_t replay_get_current_step(void)
> +{
> +    return cpu_get_icount_raw();
> +}
> diff --git a/replay/replay.h b/replay/replay.h
> index d6b73c3..a03c748 100755
> --- a/replay/replay.h
> +++ b/replay/replay.h
> @@ -12,8 +12,15 @@
>   *
>   */
>  
> +#include <stdbool.h>
> +#include <stdint.h>
>  #include "qapi-types.h"
>  
>  extern ReplayMode replay_mode;
>  
> +/* Processing the instructions */
> +
> +/*! Returns number of executed instructions. */
> +uint64_t replay_get_current_step(void);
> +
>  #endif
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index f552dad..49b37a6 100755
--- a/replay/replay-internal.c
+++ b/replay/replay-internal.c
@@ -10,6 +10,7 @@ 
  */
 
 #include "qemu-common.h"
+#include "replay.h"
 #include "replay-internal.h"
 
 unsigned int replay_data_kind = -1;
@@ -164,3 +165,18 @@  void replay_mutex_unlock(void)
 {
     qemu_mutex_unlock(&lock);
 }
+
+/*! Saves cached instructions. */
+void replay_save_instructions(void)
+{
+    if (replay_file && replay_mode == REPLAY_MODE_RECORD) {
+        int diff = (int)(replay_get_current_step() - replay_state.current_step);
+        if (first_cpu != NULL && diff > 0) {
+            replay_mutex_lock();
+            replay_put_event(EVENT_INSTRUCTION);
+            replay_put_dword(diff);
+            replay_state.current_step += diff;
+            replay_mutex_unlock();
+        }
+    }
+}
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index 50ce29b..4d661a1 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -14,6 +14,19 @@ 
 
 #include <stdio.h>
 
+enum ReplayEvents {
+    /* for instruction event */
+    EVENT_INSTRUCTION
+};
+
+typedef struct ReplayState {
+    /*! Current step - number of processed instructions and timer events. */
+    uint64_t current_step;
+    /*! Number of instructions to be executed before other events happen. */
+    int instructions_count;
+} ReplayState;
+extern ReplayState replay_state;
+
 extern unsigned int replay_data_kind;
 extern unsigned int replay_has_unread_data;
 
@@ -54,4 +67,11 @@  void replay_save_instructions(void);
     Terminates the program in case of error. */
 void validate_data_kind(int kind);
 
+/*! Skips async events until some sync event will be found. */
+bool skip_async_events(int stop_event);
+/*! Skips async events invocations from the input,
+    until required data kind is found. If the requested data is not found
+    reports an error and stops the execution. */
+void skip_async_events_until(unsigned int kind);
+
 #endif
diff --git a/replay/replay.c b/replay/replay.c
index 5ce066f..a43bbbc 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -9,6 +9,52 @@ 
  *
  */
 
+#include "qemu-common.h"
 #include "replay.h"
+#include "replay-internal.h"
+#include "qemu/timer.h"
 
 ReplayMode replay_mode = REPLAY_MODE_NONE;
+
+ReplayState replay_state;
+
+bool skip_async_events(int stop_event)
+{
+    bool res = false;
+
+    /* nothing to skip - not all instructions used */
+    if (replay_state.instructions_count != 0
+        && replay_has_unread_data) {
+        return stop_event == EVENT_INSTRUCTION;
+    }
+
+    while (true) {
+        replay_fetch_data_kind();
+        if (stop_event == replay_data_kind) {
+            res = true;
+        }
+        switch (replay_data_kind) {
+        case EVENT_INSTRUCTION:
+            replay_state.instructions_count = replay_get_dword();
+            return res;
+        default:
+            /* clock, time_t, checkpoint and other events */
+            return res;
+        }
+    }
+    return res;
+}
+
+void skip_async_events_until(unsigned int kind)
+{
+    if (!skip_async_events(kind)) {
+        fprintf(stderr, "%"PRId64": Read data kind %d instead of expected %d\n",
+            replay_get_current_step(), replay_data_kind, kind);
+        exit(1);
+    }
+}
+
+uint64_t replay_get_current_step(void)
+{
+    return cpu_get_icount_raw();
+}
diff --git a/replay/replay.h b/replay/replay.h
index d6b73c3..a03c748 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -12,8 +12,15 @@ 
  *
  */
 
+#include <stdbool.h>
+#include <stdint.h>
 #include "qapi-types.h"
 
 extern ReplayMode replay_mode;
 
+/* Processing the instructions */
+
+/*! Returns number of executed instructions. */
+uint64_t replay_get_current_step(void);
+
 #endif