qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Sebastian Tanase <sebastian.tanase@openwide.fr>
Subject: [Qemu-devel] [PULL 09/11] cpu-exec: Print to console if the guest is late
Date: Wed,  6 Aug 2014 18:12:33 +0200	[thread overview]
Message-ID: <1407341555-13173-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1407341555-13173-1-git-send-email-pbonzini@redhat.com>

From: Sebastian Tanase <sebastian.tanase@openwide.fr>

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 and we limit the number of messages to 100.
If desired, this can be changed in cpu-exec.c

Signed-off-by: Sebastian Tanase <sebastian.tanase@openwide.fr>
Tested-by: Camille Bégué <camille.begue@openwide.fr>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpu-exec.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 68f82b6..3c14502 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -29,6 +29,7 @@
 typedef struct SyncClocks {
     int64_t diff_clk;
     int64_t last_cpu_icount;
+    int64_t realtime_clock;
 } SyncClocks;
 
 #if !defined(CONFIG_USER_ONLY)
@@ -37,6 +38,9 @@ typedef struct SyncClocks {
  * oscillate around 0.
  */
 #define VM_CLOCK_ADVANCE 3000000
+#define THRESHOLD_REDUCE 1.5
+#define MAX_DELAY_PRINT_RATE 2000000000LL
+#define MAX_NB_PRINTS 100
 
 static void align_clocks(SyncClocks *sc, const CPUState *cpu)
 {
@@ -68,16 +72,43 @@ static void align_clocks(SyncClocks *sc, const CPUState *cpu)
     }
 }
 
+static void print_delay(const SyncClocks *sc)
+{
+    static float threshold_delay;
+    static int64_t last_realtime_clock;
+    static int nb_prints;
+
+    if (icount_align_option &&
+        sc->realtime_clock - last_realtime_clock >= MAX_DELAY_PRINT_RATE &&
+        nb_prints < MAX_NB_PRINTS) {
+        if ((-sc->diff_clk / (float)1000000000LL > threshold_delay) ||
+            (-sc->diff_clk / (float)1000000000LL <
+             (threshold_delay - THRESHOLD_REDUCE))) {
+            threshold_delay = (-sc->diff_clk / 1000000000LL) + 1;
+            printf("Warning: The guest is now late by %.1f to %.1f seconds\n",
+                   threshold_delay - 1,
+                   threshold_delay);
+            nb_prints++;
+            last_realtime_clock = sc->realtime_clock;
+        }
+    }
+}
+
 static void init_delay_params(SyncClocks *sc,
                               const CPUState *cpu)
 {
     if (!icount_align_option) {
         return;
     }
+    sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
     sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
-                   qemu_clock_get_ns(QEMU_CLOCK_REALTIME) +
+                   sc->realtime_clock +
                    cpu_get_clock_offset();
     sc->last_cpu_icount = cpu->icount_extra + cpu->icount_decr.u16.low;
+
+    /* Print every 2s max if the guest is late. We limit the number
+       of printed messages to NB_PRINT_MAX(currently 100) */
+    print_delay(sc);
 }
 #else
 static void align_clocks(SyncClocks *sc, const CPUState *cpu)
-- 
1.9.3

  parent reply	other threads:[~2014-08-06 16:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-06 16:12 [Qemu-devel] [PULL 00/11] KVM, icount changes for 2014-08-06 Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 01/11] backends: Introduce chr-testdev Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 02/11] icount: put icount variables into TimerState Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 03/11] migration: migrate icount fields Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 04/11] timer: add cpu_icount_to_ns function Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 05/11] icount: Fix virtual clock start value on ARM Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 06/11] icount: Add QemuOpts for icount Paolo Bonzini
2015-06-25 10:33   ` Peter Maydell
2014-08-06 16:12 ` [Qemu-devel] [PULL 07/11] icount: Add align option to icount Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 08/11] cpu-exec: Add sleeping algorithm Paolo Bonzini
2014-08-06 16:12 ` Paolo Bonzini [this message]
2014-08-06 16:12 ` [Qemu-devel] [PULL 10/11] monitor: Add drift info to 'info jit' Paolo Bonzini
2014-08-06 16:12 ` [Qemu-devel] [PULL 11/11] target-mips: Ignore unassigned accesses with KVM Paolo Bonzini
2014-08-07 11:28 ` [Qemu-devel] [PULL 00/11] KVM, icount changes for 2014-08-06 Peter Maydell

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=1407341555-13173-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sebastian.tanase@openwide.fr \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).