From nobody Sat Nov 15 14:51:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1751070350; cv=none; d=zohomail.com; s=zohoarc; b=QGx1NY23nzoWD2sPVUAPBjX/Wq22WmHoOnAiOpJMI9jP+6ALmOKA7ms+O/6JewAN/RuxVgYeIQEH9y0ZgnKt7yAP70g4Wiib/9S3EKs9+J14AfIdQCY+I+ntcoVwH6ieACZQS7/53KQ7vnCILat69q2fPcuUJ3rBhpai3gbRh00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751070350; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lZZyfIWWTCUW5B+tWLq1OrTS8PV+HjtfL+6A4Tz8SxQ=; b=KKbQOPiOlm0XT1jDx58w/8nbI4ejlAAX2Cswhik2gqqSy65iumbeiZgk9sQU9iJTMS71hohZFxbWTMaVLLRwbo4AqD5blBpti2jhcjIrgDI/vRbG2IPJgzyxkiEyu1DxwHGUraIB05R4Y50mhl2LfTifqb5q/P0d3T+myo4sx2s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175107035055827.548136654038444; Fri, 27 Jun 2025 17:25:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uVJN8-0006LX-6D; Fri, 27 Jun 2025 20:24:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uVJN6-0006Kw-34 for qemu-devel@nongnu.org; Fri, 27 Jun 2025 20:24:44 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uVJN4-0000qi-1p for qemu-devel@nongnu.org; Fri, 27 Jun 2025 20:24:43 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-7490cb9a892so2251255b3a.0 for ; Fri, 27 Jun 2025 17:24:41 -0700 (PDT) Received: from pc.. ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74af5579d37sm3025751b3a.81.2025.06.27.17.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jun 2025 17:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751070280; x=1751675080; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lZZyfIWWTCUW5B+tWLq1OrTS8PV+HjtfL+6A4Tz8SxQ=; b=OIqghFCV5XmrAPyA39VgLGGJK4P30LojQjXyNaPQr1iK+y7kdkoKLDjVuq97GCpeN4 EQ6eqhSNkp3ruyQF64/9zuXd7716n9Ebk+Sn4XJe1qa7m+mmfrJczkIh64k3iGBe7pmb Ja8g259YDrVnxURJLTURWlSLl/eYBxJPl2nplnViMneTAEkFwUuoCem1hnaCaSw4YAUM YZusjiz3gGRU9JhcIJT4YUa26ZWAih3OfIJ/Gta4iuHqS+ElJa1OytWh4iiHMSwBOX6H 9xlVA/RmdOpdU85ZczBju0sWtXHDenYmS0rZps6ry/KGy8foIAw1Lo66YFLQMUxs3xZk fT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751070280; x=1751675080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lZZyfIWWTCUW5B+tWLq1OrTS8PV+HjtfL+6A4Tz8SxQ=; b=geon2Cos6fQIy4EcbVV868FLDy2XX0vl3/QeUqgwRasgJZ1+ra3ROPChBJcwCoaZyH ULn25EPc4QXnrG2/ia6PnMgMklVx15umX8GxJ7GfbWkjF4hbKv5ukT6VNdlVIrI6112E k+r10+F9eZXyNg6wShqCAGC/ikm7CdOwj4aXcs/9gDHTHPtQLgYAKbzdMdK2wpn1zHLG bWggSq3yPCi6yhKQTEcG4myY6X/Voexby3rIkmsRMdQKysAtfpkDGwBG83ruq64BBDLU rlTO0uxAFuHfML0cP+/29Z+eeFhdY1hUykt6zU+FUcsBQ7mP1HDlgbGXfoKCG8ENDxdP 5rrQ== X-Gm-Message-State: AOJu0YxWUDw7nhphJtRN/juZQ0sDKubiSf/R8ii/GqT0z9EuSj4kEd42 YtRi2TKB4p0kfKl2sOMho9Yuxyktc9eJNdRKMZEWE+i8Dl9iTDrs9WoU7O1ILWYd8EaRpqHw1nQ q5NLR X-Gm-Gg: ASbGncs3YYeWpb98mDNN4vh9RYxQdvR22JqT21+bR0Ue+p7rKDqR+gq+cBJwOx45O7N e18Gih16eQ9CBqlVPsEMnQSdjXR7F8TD1ps34uODJWzKcgoaBXMtdIOjIMZLlgV1RiyLzi/jVDA /tBfwXBsl2OTuxTvqpxZPYUqaPrBdHdxI5GXJKTQ2n0tQHgnTFj1h5cLPEAl/iU/Mg49bdk47fn J3i/Rq2vHgGHbSbLtLkpfcey3S5nv1hb0PNYIvWuJCUJJTjW/m9R9zf8b5Ae3S0P/PPEK+wRN61 Lg2Z92XmpY9ijdFmDYhhdTSnatQWJGDcMxinUSL216FAKtBbMNt0tmChOhHeBQ== X-Google-Smtp-Source: AGHT+IHV1zrka7Vt4QgDDD1O9uHbzIpUhz1EsKQx8N+Y64bT7qaMSe7hsWuO7PzXjD18wE9Ke6XP0g== X-Received: by 2002:a05:6a00:a87:b0:748:fcfa:8bd5 with SMTP id d2e1a72fcca58-74af6e2f4f3mr8007283b3a.3.1751070280528; Fri, 27 Jun 2025 17:24:40 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: berrange@redhat.com, richard.henderson@linaro.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , peter.maydell@linaro.org, philmd@linaro.org, Pierrick Bouvier Subject: [PATCH v2 1/2] qemu/timer: introduce time dilation factor Date: Fri, 27 Jun 2025 17:24:30 -0700 Message-ID: <20250628002431.41823-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250628002431.41823-1-pierrick.bouvier@linaro.org> References: <20250628002431.41823-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1751070352707116600 Content-Type: text/plain; charset="utf-8" This factor is applied to time spent since we initialized clocks. It impacts value returned by get_clock(), get_clock_realtime() and get_cpu_host_ticks(); < 1: time goes slower. > 1: time goes faster. 1 by default. Signed-off-by: Pierrick Bouvier --- include/qemu/timer.h | 60 ++++++++++++++++++++++++++++------------ util/qemu-timer-common.c | 7 +++++ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index abd2204f3be..ee1877d5cd9 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -801,6 +801,23 @@ static inline int64_t get_max_clock_jump(void) return 60 * NANOSECONDS_PER_SECOND; } =20 +extern int64_t clock_start; +extern int64_t clock_realtime_start; +extern int64_t host_ticks_start; +extern double clock_time_dilation; + +static inline int64_t dilate_time(int64_t start, int64_t now) +{ + if (start =3D=3D 0) { + /* start value is getting fetched */ + return now; + } + g_assert(now >=3D start); + int64_t elapsed =3D now - start; + int64_t elapsed_dilated =3D elapsed * clock_time_dilation; + return start + elapsed_dilated; +} + /* * Low level clock functions */ @@ -811,11 +828,10 @@ static inline int64_t get_clock_realtime(void) struct timeval tv; =20 gettimeofday(&tv, NULL); - return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000); + int64_t now =3D tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000); + return dilate_time(clock_realtime_start, now); } =20 -extern int64_t clock_start; - /* Warning: don't insert tracepoints into these functions, they are also used by simpletrace backend and tracepoints would cause an infinite recursion! */ @@ -826,7 +842,8 @@ static inline int64_t get_clock(void) { LARGE_INTEGER ti; QueryPerformanceCounter(&ti); - return muldiv64(ti.QuadPart, NANOSECONDS_PER_SECOND, clock_freq); + int64_t now =3D muldiv64(ti.QuadPart, NANOSECONDS_PER_SECOND, clock_fr= eq); + return dilate_time(clock_start, now); } =20 #else @@ -838,10 +855,11 @@ static inline int64_t get_clock(void) if (use_rt_clock) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000000000LL + ts.tv_nsec; + int64_t now =3D ts.tv_sec * 1000000000LL + ts.tv_nsec; + return dilate_time(clock_start, now); } else { /* XXX: using gettimeofday leads to problems if the date - changes, so it should be avoided. */ + changes, so it should be avoided. Time is already dilated. */ return get_clock_realtime(); } } @@ -852,7 +870,7 @@ static inline int64_t get_clock(void) =20 #if defined(_ARCH_PPC) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { int64_t retval; #ifdef _ARCH_PPC64 @@ -878,7 +896,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__i386__) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { int64_t val; asm volatile ("rdtsc" : "=3DA" (val)); @@ -887,7 +905,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__x86_64__) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { uint32_t low,high; int64_t val; @@ -900,7 +918,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__hppa__) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { int val; asm volatile ("mfctl %%cr16, %0" : "=3Dr"(val)); @@ -909,7 +927,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__s390__) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { int64_t val; asm volatile("stck 0(%1)" : "=3Dm" (val) : "a" (&val) : "cc"); @@ -918,7 +936,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__sparc__) =20 -static inline int64_t cpu_get_host_ticks (void) +static inline int64_t _cpu_get_host_ticks(void) { #if defined(_LP64) uint64_t rval; @@ -956,7 +974,7 @@ static inline int64_t cpu_get_host_ticks (void) : "=3Dr" (value)); \ } =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { /* On kernels >=3D 2.6.25 rdhwr , $2 and $3 are emulated */ uint32_t count; @@ -972,7 +990,7 @@ static inline int64_t cpu_get_host_ticks(void) =20 #elif defined(__alpha__) =20 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { uint64_t cc; uint32_t cur, ofs; @@ -984,7 +1002,7 @@ static inline int64_t cpu_get_host_ticks(void) } =20 #elif defined(__riscv) && __riscv_xlen =3D=3D 32 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { uint32_t lo, hi, tmph; do { @@ -997,7 +1015,7 @@ static inline int64_t cpu_get_host_ticks(void) } =20 #elif defined(__riscv) && __riscv_xlen > 32 -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { int64_t val; =20 @@ -1006,7 +1024,7 @@ static inline int64_t cpu_get_host_ticks(void) } =20 #elif defined(__loongarch64) -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { uint64_t val; =20 @@ -1018,10 +1036,16 @@ static inline int64_t cpu_get_host_ticks(void) /* The host CPU doesn't have an easily accessible cycle counter. Just return a monotonically increasing value. This will be totally wrong, but hopefully better than nothing. */ -static inline int64_t cpu_get_host_ticks(void) +static inline int64_t _cpu_get_host_ticks(void) { return get_clock(); } #endif =20 +static inline int64_t cpu_get_host_ticks(void) +{ + int64_t now =3D _cpu_get_host_ticks(); + return dilate_time(host_ticks_start, now); +} + #endif diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c index cc1326f7264..5cb36032bc8 100644 --- a/util/qemu-timer-common.c +++ b/util/qemu-timer-common.c @@ -28,6 +28,9 @@ /* real time host monotonic timer */ =20 int64_t clock_start; +int64_t clock_realtime_start; +int64_t host_ticks_start; +double clock_time_dilation =3D 1.0f; =20 #ifdef _WIN32 =20 @@ -44,6 +47,8 @@ static void __attribute__((constructor)) init_get_clock(v= oid) } clock_freq =3D freq.QuadPart; clock_start =3D get_clock(); + clock_realtime_start =3D get_clock_realtime(); + host_ticks_start =3D cpu_get_host_ticks(); } =20 #else @@ -59,5 +64,7 @@ static void __attribute__((constructor)) init_get_clock(v= oid) use_rt_clock =3D 1; } clock_start =3D get_clock(); + clock_realtime_start =3D get_clock_realtime(); + host_ticks_start =3D cpu_get_host_ticks(); } #endif --=20 2.47.2 From nobody Sat Nov 15 14:51:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1751070350; cv=none; d=zohomail.com; s=zohoarc; b=Uk9mCrO6tne0V+kBEujglAtVAfJEItnxXLQTHe7Osoy4FDoLw6Dc2ek+Ql9j6monrnWqTYsroeHgviv1qQGJmdheXgSW16viL+3e9eKQWxKnOvfdJdQA8LYZ5b/wNRYKc3ZkolBJoAa8LXv+ywBDNoZDtPaRXrKFR1OFnGUn5Vc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751070350; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LjQ6iEKLubvqsBp+y2ymquojsyDr9w7rW+VsEASd2l8=; b=KfUN4uLpejD+Z/g0CAOAF472nak6DNynLW5EMn4y1G5c7Hk2+ZBp7KxSB/2gDArreyr7ZaWh/49CmdVyJIsocFpf/R52jbdKsQ72vo267mQyNEBrQMm8EANgh31ELJeKlPLNcCcHwiqZYwY/x7VJnek+eLC+ot1jd2ZCxA42Hfk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751070350801135.62536091345237; Fri, 27 Jun 2025 17:25:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uVJN8-0006LY-Dn; Fri, 27 Jun 2025 20:24:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uVJN6-0006Ky-I0 for qemu-devel@nongnu.org; Fri, 27 Jun 2025 20:24:44 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uVJN4-0000qr-Tj for qemu-devel@nongnu.org; Fri, 27 Jun 2025 20:24:44 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-749248d06faso3077462b3a.2 for ; Fri, 27 Jun 2025 17:24:42 -0700 (PDT) Received: from pc.. ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74af5579d37sm3025751b3a.81.2025.06.27.17.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jun 2025 17:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751070281; x=1751675081; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LjQ6iEKLubvqsBp+y2ymquojsyDr9w7rW+VsEASd2l8=; b=IxzFyYMHiw8IyrLT8tDTALgmsC97htijSG5KNyGQH/qJ/WiTvqMefYMTJ8NwMDtKXP oNbs5kWeiMtmEqg4Lbz4+Gyt8dzWZPwfCYrgwU5bVFp0/TN0aiZ29Wz+4wshSADXdbge sivSA2T7164se25gZX6PIoNPKUu/aCFp+Mef206OqfO1ZAvJMZ+pN+ltKVUMlfhLHkOL fHSf4s8QklbzW7mV9Y0Jc5DIOexuWj1ckUXUv49hRol9bkXoH5bjcLcakOJmNOt0tllb /KGODl+ELFoUqNeYYTR6zIP31K65HZfV6x4C+NoAjvKOxoG61xcjpsCDUX0DhLEFmmjS 4KrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751070281; x=1751675081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LjQ6iEKLubvqsBp+y2ymquojsyDr9w7rW+VsEASd2l8=; b=jeT67QaoUPTPSrpWnAAu5HhyV3+LZt1KHawNyfhPJf4CM73GdrQbNdajvX9O27F/Dr SY713uEGuwpfSfbAKiKFL6xEW8Y6nk+9UKtxmE+LbtmvyH8TTE7ijWRbHbXCSIBAfNsQ 4E2a4i4qlwq8pFBOFhLeNV9VBLEeTNRcJr4p0JjV7Jp9B+vvcTBWFbqoA9UcS/aLshiw lWzoZ66xeQ75+ksghrlwKxvs0xz5cPpd/EBxkgrot4B0SSFUCs/yBj94l+/s/rIB+kq2 Jie6zSy2+aqml4HnpMk5Di2+/fdccCqITYEIJX4w/JI77NOuQNOmZTmJYe+/Z21QNAKR l06A== X-Gm-Message-State: AOJu0YzjuFT//NyRZRqShzIpI64N3shAfUoEa5LlueOgU4DxKQ11vZbn RgpQbhkOT7VnL8CRCS9/+fZ38tmDViZfqVHdLgsMn731oufpAL+mVN1QxVSOI5FO5FDIGlukvHw FUAho X-Gm-Gg: ASbGnctah8duPx3rQV/2GbJedapqGmFxf+K6ZzMF0f3idYjgspjnkZjHfVv/CeEOxXq 4+GQ7lxuMgHn9v4pC/Iu+rHIYCw2r+YkOeS7RHjsVTCfr5mAwzchw5YKhbR/sDKFXvy73wT3oOf Co6AkdvMLL0QOWbDniUf2EI7WqqU4bu1HFKFmVEJ4o3A0jdpP55dT5hEU0hZnrttXEFVDPUv6su iLcJCXrUnTS35zuN8OKtNN3odNovbJxH6L7CdoVaH81h4oLnegUnk8OsvqFBzt2GeQlxTNjEaCq VZF5X89o9Jf4QIHrrjlqIhBeOq492Bnx4cHCuDgWNbbVrg3bqp2vUf2+upX2TQ== X-Google-Smtp-Source: AGHT+IFUUHd6022wWNNFjuqd1W3vn0xZnmFgjKM6M6YpNzHecFpTFcodN4X7092PSlQdfjoWb4CRoQ== X-Received: by 2002:a05:6a00:8c9:b0:748:ff39:a0ed with SMTP id d2e1a72fcca58-74af6f70b6cmr7446542b3a.20.1751070281503; Fri, 27 Jun 2025 17:24:41 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: berrange@redhat.com, richard.henderson@linaro.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , peter.maydell@linaro.org, philmd@linaro.org, Pierrick Bouvier Subject: [PATCH v2 2/2] system/rtc: introduce -rtc speed-factor option Date: Fri, 27 Jun 2025 17:24:31 -0700 Message-ID: <20250628002431.41823-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250628002431.41823-1-pierrick.bouvier@linaro.org> References: <20250628002431.41823-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1751070352601116600 Content-Type: text/plain; charset="utf-8" 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. It can only be used with tcg. Signed-off-by: Pierrick Bouvier --- system/rtc.c | 11 +++++++++++ system/vl.c | 9 +++++++++ qemu-options.hx | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/system/rtc.c b/system/rtc.c index 56951288c40..ec063391b5c 100644 --- a/system/rtc.c +++ b/system/rtc.c @@ -188,4 +188,15 @@ void configure_rtc(QemuOpts *opts) exit(1); } } + value =3D qemu_opt_get(opts, "speed-factor"); + if (value) { + if (qemu_strtod_finite(value, NULL, &clock_time_dilation)) { + error_report("invalid speed-factor factor '%s'", value); + exit(1); + } + if (clock_time_dilation <=3D 0.0f) { + error_report("speed-factor factor must be strictly positive"); + exit(1); + } + } } diff --git a/system/vl.c b/system/vl.c index 3b7057e6c66..e1ea79c683c 100644 --- a/system/vl.c +++ b/system/vl.c @@ -243,6 +243,9 @@ static QemuOptsList qemu_rtc_opts =3D { },{ .name =3D "driftfix", .type =3D QEMU_OPT_STRING, + },{ + .name =3D "speed-factor", + .type =3D QEMU_OPT_STRING, }, { /* end of list */ } }, @@ -2491,6 +2494,12 @@ static void configure_accelerators(const char *progn= ame) error_report("-icount is not allowed with hardware virtualization"= ); exit(1); } + + if (clock_time_dilation !=3D 1.0f && !tcg_enabled()) { + error_report("-rtc speed-factor is not allowed with " + "hardware virtualization"); + exit(1); + } } =20 static void qemu_validate_options(const QDict *machine_opts) diff --git a/qemu-options.hx b/qemu-options.hx index 6bcbb8ccea0..9efdbfb3842 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4887,7 +4887,7 @@ SRST ERST =20 DEF("rtc", HAS_ARG, QEMU_OPTION_rtc, \ - "-rtc [base=3Dutc|localtime|][,clock=3Dhost|rt|vm][,driftfix= =3Dnone|slew]\n" \ + "-rtc [base=3Dutc|localtime|][,clock=3Dhost|rt|vm][,driftfix= =3Dnone|slew][,speed-factor=3Dvalue]\n" \ " set the RTC base and clock, enable drift fix for cloc= k ticks (x86 only)\n", QEMU_ARCH_ALL) =20 @@ -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 ``speed-factor``, + 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 =20 DEF("icount", HAS_ARG, QEMU_OPTION_icount, \ --=20 2.47.2