qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 4/4] cpu_exec: Print to console if the guest is


From: Sebastian Tanase
Subject: [Qemu-devel] [RFC PATCH 4/4] cpu_exec: Print to console if the guest is late
Date: Tue, 27 May 2014 16:54:48 +0200

If the align option is enabled, we print to the user whenever
the guest clock is behind the host clock in order for he/she
to have a hint about the actual performance. The maximum
print interval is 2s so as not to spam the console.

Signed-off-by: Sebastian Tanase <address@hidden>
Tested-by: Camille Bégué <address@hidden>
---
 cpu-exec.c      | 33 ++++++++++++++++++++++++++++++++-
 qemu-options.hx |  5 ++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index eef3cb5..5e81c92 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -230,6 +230,27 @@ static void delay_host(void)
     }
 }
 
+#define THRESHOLD_REDUCE 1.5
+#define MAX_DELAY_PRINT_RATE 2
+static float threshold_delay;
+
+static void print_delay(void)
+{
+    if (-diff_clk / (float)1000000000LL > threshold_delay) {
+        threshold_delay = (-diff_clk / 1000000000LL) + 1;
+        printf("Warning: The guest is late by %.1f to %.1f seconds\n",
+               threshold_delay - 1,
+               threshold_delay);
+    } else if (-diff_clk / (float)1000000000LL <
+              (threshold_delay - THRESHOLD_REDUCE)) {
+        threshold_delay = (-diff_clk / 1000000000LL) + 1;
+        printf("Warning: The guest has reduced the delay and is now "
+               "late by %.1f to %.1f seconds\n",
+               threshold_delay - 1,
+               threshold_delay);
+    }
+}
+
 /* main execution loop */
 
 volatile sig_atomic_t exit_request;
@@ -250,6 +271,8 @@ int cpu_exec(CPUArchState *env)
     uintptr_t next_tb;
     /* Delay algorithm */
     int64_t instr_exec_time, original_extra, original_low;
+    /* Print delay control */
+    static int64_t realtime_clock, last_realtime_clock;
     /* This must be volatile so it is not trashed by longjmp() */
     volatile bool have_tb_lock = false;
 
@@ -311,8 +334,16 @@ int cpu_exec(CPUArchState *env)
            This delay includes the delay of the last cycle, so
            what we have to do is sleep until it is 0. As for the
            advance/delay we gain here, we try to fix it next time. */
+        realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
         diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
-                   qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+                   realtime_clock;
+        /* Print (every 2s max) if the guest is behind the host */
+        if (-diff_clk > 0 &&
+           (realtime_clock - last_realtime_clock) / 1000000000LL
+            >= MAX_DELAY_PRINT_RATE) {
+            print_delay();
+            last_realtime_clock = realtime_clock;
+        }
         original_extra = cpu->icount_extra;
         original_low = cpu->icount_decr.u16.low;
     }
diff --git a/qemu-options.hx b/qemu-options.hx
index 0de30e0..44cb2d4 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2917,9 +2917,12 @@ executed often has little or no correlation with actual 
performance.
 @option{align=on} will activate the delay algorithm which will try to
 to synchronise the host clock and the virtual clock. The goal is to
 have a guest running at the real frequency imposed by
-icount. Currently this option does not work with @code{auto}.
+icount. Whenever the guest clock is behind the host clock and if
address@hidden is specified then we print a messsage to the user
+to inform about the delay.
 You must provide a value for @option{icount} other than @code{auto}
 for the align option to be taken into account.
+Currently this option does not work with @code{auto}.
 Note: The sync algorithm will work on those icounts on which
 the guest clock runs ahead of the host clock. Typically this happens
 when the icount value is high (how high depends on the host machine).
-- 
2.0.0.rc2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]