This option sets a factor on time spent for QEMU clocks since the
beginning of execution. It can be used to slow or accelerate time for a
guest, without impacting QEMU speed.

Signed-off-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>
---
 system/rtc.c    | 11 +++++++++++
 system/vl.c     |  3 +++
 qemu-options.hx |  7 ++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/system/rtc.c b/system/rtc.c
index 56951288c40..36c53f0fbd7 100644
--- a/system/rtc.c
+++ b/system/rtc.c
@@ -188,4 +188,15 @@ void configure_rtc(QemuOpts *opts)
             exit(1);
         }
     }
+    value = qemu_opt_get(opts, "time-dilation");
+    if (value) {
+        if (qemu_strtod_finite(value, NULL, &clock_time_dilation)) {
+            error_report("invalid time-dilation factor '%s'", value);
+            exit(1);
+        }
+        if (clock_time_dilation <= 0.0f) {
+            error_report("time-dilation factor must be strictly positive");
+            exit(1);
+        }
+    }
 }
diff --git a/system/vl.c b/system/vl.c
index 3b7057e6c66..e3e3f2f0209 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -243,6 +243,9 @@ static QemuOptsList qemu_rtc_opts = {
         },{
             .name = "driftfix",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "time-dilation",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
diff --git a/qemu-options.hx b/qemu-options.hx
index 4faad5604c0..b8aaf8b3349 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4887,7 +4887,7 @@ SRST
 ERST
 
 DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \
-    "-rtc 
[base=utc|localtime|<datetime>][,clock=host|rt|vm][,driftfix=none|slew]\n" \
+    "-rtc 
[base=utc|localtime|<datetime>][,clock=host|rt|vm][,driftfix=none|slew][,time-dilation=value]\n"
 \
     "                set the RTC base and clock, enable drift fix for clock 
ticks (x86 only)\n",
     QEMU_ARCH_ALL)
 
@@ -4916,6 +4916,11 @@ SRST
     problems, specifically with Windows' ACPI HAL. This option will try
     to figure out how many timer interrupts were not processed by the
     Windows guest and will re-inject them.
+
+    It's possible to slow or accelerate time using ``time-dilation``,
+    which is a factor (real number) applied to QEMU clock. A value of 0.1 will
+    slow time by a factor of 10, and a value of 10 will accelerate it with the
+    same factor.
 ERST
 
 DEF("icount", HAS_ARG, QEMU_OPTION_icount, \
-- 
2.47.2


Reply via email to