All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Subject: [Qemu-devel] [PULL 06/18] cpu: replay instructions sequence
Date: Thu,  5 Nov 2015 13:13:51 +0100	[thread overview]
Message-ID: <1446725643-82458-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1446725643-82458-1-git-send-email-pbonzini@redhat.com>

From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>

This patch adds calls to replay functions into the icount setup block.
In record mode number of executed instructions is written to the log.
In replay mode number of istructions to execute is taken from the replay log.
When replayed instructions counter is expired qemu_notify_event()
function is called to wake up the iothread.

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

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20150917162405.8676.31890.stgit@PASHA-ISP.def.inno>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c                  | 38 +++++++++++++++++++++++++-------------
 include/sysemu/replay.h |  4 ++++
 replay/replay.c         | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/cpus.c b/cpus.c
index d2e9e4f..f07cac2 100644
--- a/cpus.c
+++ b/cpus.c
@@ -42,6 +42,7 @@
 #include "qemu/seqlock.h"
 #include "qapi-event.h"
 #include "hw/nmi.h"
+#include "sysemu/replay.h"
 
 #ifndef _WIN32
 #include "qemu/compatfd.h"
@@ -1411,6 +1412,28 @@ int vm_stop_force_state(RunState state)
     }
 }
 
+static int64_t tcg_get_icount_limit(void)
+{
+    int64_t deadline;
+
+    if (replay_mode != REPLAY_MODE_PLAY) {
+        deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
+
+        /* Maintain prior (possibly buggy) behaviour where if no deadline
+         * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
+         * INT32_MAX nanoseconds ahead, we still use INT32_MAX
+         * nanoseconds.
+         */
+        if ((deadline < 0) || (deadline > INT32_MAX)) {
+            deadline = INT32_MAX;
+        }
+
+        return qemu_icount_round(deadline);
+    } else {
+        return replay_get_instructions();
+    }
+}
+
 static int tcg_cpu_exec(CPUState *cpu)
 {
     int ret;
@@ -1423,24 +1446,12 @@ static int tcg_cpu_exec(CPUState *cpu)
 #endif
     if (use_icount) {
         int64_t count;
-        int64_t deadline;
         int decr;
         timers_state.qemu_icount -= (cpu->icount_decr.u16.low
                                     + cpu->icount_extra);
         cpu->icount_decr.u16.low = 0;
         cpu->icount_extra = 0;
-        deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
-
-        /* Maintain prior (possibly buggy) behaviour where if no deadline
-         * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
-         * INT32_MAX nanoseconds ahead, we still use INT32_MAX
-         * nanoseconds.
-         */
-        if ((deadline < 0) || (deadline > INT32_MAX)) {
-            deadline = INT32_MAX;
-        }
-
-        count = qemu_icount_round(deadline);
+        count = tcg_get_icount_limit();
         timers_state.qemu_icount += count;
         decr = (count > 0xffff) ? 0xffff : count;
         count -= decr;
@@ -1458,6 +1469,7 @@ static int tcg_cpu_exec(CPUState *cpu)
                         + cpu->icount_extra);
         cpu->icount_decr.u32 = 0;
         cpu->icount_extra = 0;
+        replay_account_executed_instructions();
     }
     return ret;
 }
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index a03c748..d19715f 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -22,5 +22,9 @@ extern ReplayMode replay_mode;
 
 /*! Returns number of executed instructions. */
 uint64_t replay_get_current_step(void);
+/*! Returns number of instructions to execute in replay mode. */
+int replay_get_instructions(void);
+/*! Updates instructions counter in replay mode. */
+void replay_account_executed_instructions(void);
 
 #endif
diff --git a/replay/replay.c b/replay/replay.c
index 62e8aba..b2c6750 100644
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -13,6 +13,7 @@
 #include "sysemu/replay.h"
 #include "replay-internal.h"
 #include "qemu/timer.h"
+#include "qemu/main-loop.h"
 
 ReplayMode replay_mode = REPLAY_MODE_NONE;
 
@@ -45,3 +46,36 @@ uint64_t replay_get_current_step(void)
 {
     return cpu_get_icount_raw();
 }
+
+int replay_get_instructions(void)
+{
+    int res = 0;
+    replay_mutex_lock();
+    if (replay_next_event_is(EVENT_INSTRUCTION)) {
+        res = replay_state.instructions_count;
+    }
+    replay_mutex_unlock();
+    return res;
+}
+
+void replay_account_executed_instructions(void)
+{
+    if (replay_mode == REPLAY_MODE_PLAY) {
+        replay_mutex_lock();
+        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;
+            if (replay_state.instructions_count == 0) {
+                assert(replay_data_kind == EVENT_INSTRUCTION);
+                replay_finish_event();
+                /* Wake up iothread. This is required because
+                   timers will not expire until clock counters
+                   will be read from the log. */
+                qemu_notify_event();
+            }
+        }
+        replay_mutex_unlock();
+    }
+}
-- 
1.8.3.1

  parent reply	other threads:[~2015-11-05 12:14 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 12:13 [Qemu-devel] [PULL 00/18] Record/replay core for 2.5-rc1 Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 01/18] replay: global variables and function stubs Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 02/18] replay: internal functions for replay log Paolo Bonzini
2018-05-11  9:27   ` Peter Maydell
2018-05-11  9:51     ` Paolo Bonzini
2018-05-11  9:56       ` Pavel Dovgalyuk
2018-05-14  6:34       ` Markus Armbruster
2015-11-05 12:13 ` [Qemu-devel] [PULL 03/18] replay: introduce mutex to protect the " Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 04/18] replay: introduce icount event Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 05/18] cpu-exec: allow temporary disabling icount Paolo Bonzini
2015-11-05 12:13 ` Paolo Bonzini [this message]
2015-11-05 12:13 ` [Qemu-devel] [PULL 07/18] replay: interrupts and exceptions Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 08/18] replay: asynchronous events infrastructure Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 09/18] replay: recording and replaying clock ticks Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 10/18] replay: shutdown event Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 11/18] icount: improve counting for record/replay Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 12/18] replay: checkpoints Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 13/18] bottom halves: introduce bh call function Paolo Bonzini
2015-11-05 12:13 ` [Qemu-devel] [PULL 14/18] replay: ptimer Paolo Bonzini
2015-11-05 12:14 ` [Qemu-devel] [PULL 15/18] replay: initialization and deinitialization Paolo Bonzini
2015-11-05 12:14 ` [Qemu-devel] [PULL 16/18] replay: replay blockers for devices Paolo Bonzini
2015-11-05 12:14 ` [Qemu-devel] [PULL 17/18] replay: command line options Paolo Bonzini
2015-11-05 12:14 ` [Qemu-devel] [PULL 18/18] replay: recording of the user input Paolo Bonzini
2015-11-05 14:00 ` [Qemu-devel] [PULL 00/18] Record/replay core for 2.5-rc1 Peter Maydell
2015-11-05 14:07   ` Paolo Bonzini
2015-11-06  5:10     ` Pavel Dovgaluk
  -- strict thread matches above, loose matches on Subject: below --
2015-11-04 16:17 [Qemu-devel] [PULL 00/18] Record/replay core for QEMU 2.4-rc1 Paolo Bonzini
2015-11-04 16:17 ` [Qemu-devel] [PULL 06/18] cpu: replay instructions sequence Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446725643-82458-7-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.