From patchwork Tue Jun 10 21:28:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 895214 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp2481803wrb; Tue, 10 Jun 2025 14:29:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUBsZY0eaxQrSr6J4vy20CucIpEKYF+4T+NX7AEalvL3NbxkGn0SYkqIiz8xB3vAElR1DPHCg==@linaro.org X-Google-Smtp-Source: AGHT+IH+w0udjteTz2/LZ5o33IBXaReOoHdOqLzyLiEme+3V7jtwyTi8sNKA7YQJhV/6FYGnDtFo X-Received: by 2002:a05:622a:5594:b0:476:6b20:2cf3 with SMTP id d75a77b69052e-4a713c42852mr17278411cf.33.1749590971085; Tue, 10 Jun 2025 14:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749590971; cv=none; d=google.com; s=arc-20240605; b=X/3G+1MAUj/5ewj12RSAOc5+X/RNrGnfGHA9nv9OFSSR6rTve38FG3ioAM8M6klEYI 3k9TpcOTvP/M1HA7mso1sIo9jDkJNQ7SSSQ/JwasTMG5XgzJ/76z46Zho1wSf6U9TPk/ XdR8hNLU7pigvsHUCjYRXG8aLpOq4C0W+TubsdERbzYwiY7dxIBCSyuZPu6RLXWF0v7U jBYRNBL8XrCptK+QXS8R8h/M0OGp+7wL+SJ/wRHsON3G9BV4PonvvOZOg0NWImRgaX6M nrizL6cZw05DFnuYZJ46uOi2nAvpiTnyU5dBxRqCrYkjuXveDP9V/w4cDPvD8sRM52zs GmqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZVY2h3n6p5UCM76x7xGwJIthJDO3448sqBl62JxkyBE=; fh=RNU6ObMmAHdv2zYyK3niE6AOcfJGNa59S2ay+ofsGOo=; b=ThFkLyGge8NABLMoJbcqzPZW+VQD7wejw3wHXND1B/JERfHYRIkyh038hZ5cuS9jkO AAOI4lEU2y2KHtVjdE8Y0zfSY/UlAJDthGfT5B956ky4cc2tvuO8F0rYbVFJmRQywKeT TyPis2jJ6eEYKeQyPR4fKtSL8stsLz+vGia8Q9pCG36j6KSTGhFgBp+RJxQzKcYdImwO SS4WiJkiZ3i32me6AA/EfnXeUKkXPwNgeh4irXfAlWUSFlu/QR2d5A5M51tAwtgM1pvW SxXJ4oAAlTslCo6svVe4VjpZi/CNpzWzjBMo4jT5UGyTJuIiwQL1D58Ue3qnFCsvKHwd p7wQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m5bOhuLD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4a61985f0b4si115340871cf.179.2025.06.10.14.29.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jun 2025 14:29:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m5bOhuLD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uP6Wd-0005Zs-Bp; Tue, 10 Jun 2025 17:28:55 -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 1uP6WY-0005Ui-P5 for qemu-devel@nongnu.org; Tue, 10 Jun 2025 17:28:50 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uP6WX-0000h0-3h for qemu-devel@nongnu.org; Tue, 10 Jun 2025 17:28:50 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-74865da80c4so608229b3a.3 for ; Tue, 10 Jun 2025 14:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749590928; x=1750195728; 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=ZVY2h3n6p5UCM76x7xGwJIthJDO3448sqBl62JxkyBE=; b=m5bOhuLDaqavMLzVhEliOA/dXEkCEk26nmZ/dYPPJ1ZdMMMtgMWCizk/rG5E6aiPVf QHFr0iiUPzntEeX8FN5i97v9kgBl6TPTqsjlmMnV+y/MwOtw03SSGCQ3CW7yJiIThKHB 81cMu9GImK6y43FVOQr3gWN7ZZHV3B/12IS+xQ6SjiSbHkScaVot+0xSQZDjb7ZGLDqb a2xFIFDL8mljTT38YLbflpWTSOCoatn4y7Luns3CFACJtrq48y51ItSW9IWqSHuO0vzv Y5HeS+XdSQPX6wsuEhSR4o8pfjno5Jv7D2xC3H4bwzzA87BsHV0Ep1agylUAwnDAA3ZI 278A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749590928; x=1750195728; 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=ZVY2h3n6p5UCM76x7xGwJIthJDO3448sqBl62JxkyBE=; b=FGn+uwEKyIkX+1TvTkwxoV08IMoYUhfsGRhJ2JyBUajqMMKGLljpH3xCaEx8McFbag KjgPILPeLqs3UTi4D5r7ABNm+mntZaW7O6bAxffblbWbqRIuyjmH46p9TQpDcvkQ8jGq a1851CpVoxO4ZD0N5xXxIXPrJ98FfTfAIKVNLF+nky0jhhNLPvWVQIgOzvNfoH6elZDo 6Fu6xYvIW+1CLS8/MOAUI65o3foyN57dkYv3VPxZxsZ9NRIxThh6QEa9j8iS6MMeRIRk sdUUmS/EanCqKuMEx8zljQxDqXcYI0TNdr9fDRT/sTv38jZzdIU0uTzWrAd2ujVwYacm ATSw== X-Gm-Message-State: AOJu0YwwnzGcmk7otWyZEJo3+2Kig+f4zT593BfPtaKHsEWSrhet3GSW C1qr4aDOhCP9XUHqxkiQVzxPyblrDdFdzvHuQHFISzcIj4lqdsxcyaH7pjy0r+PhjpZo/Jmyp9v y4raw X-Gm-Gg: ASbGncsAbtQZvA5r/pI1T9BWALw7Fobe+r+KqABIOFe0tvu8B+dzjzgQkAwXimVR6Do nLUqqLb48JS+Zp/hF7HLOoebR8q4/5HsFnRM333x4OpS/fi1smgo5moSOwC/UnlvlVZfmXhqo5S AUP/OaewP2G20EYKE933+y/cvl2Kc1Q2x/RKUfEnHu31aS4SFNRGQ7aJSBi5CBICHadhE3WhJrf lo8QhoNCmvbs7LzPDmvTR+FAkfKqZEaN6GmSrc4pAP35Y55G+55u8LZjB7GEY9OYs/EAYS+t2Zd 1z037waLwL3NIppMR/VtxZIt2ITFYglMu7hCfSjP+XMBuQfv+WMnefdHpd0LZQ== X-Received: by 2002:a05:6a00:814:b0:740:b5f8:ac15 with SMTP id d2e1a72fcca58-7486cb71816mr1267571b3a.10.1749590927779; Tue, 10 Jun 2025 14:28:47 -0700 (PDT) Received: from pc.. ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7482b0c0613sm7864225b3a.122.2025.06.10.14.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 14:28:47 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: philmd@linaro.org, berrange@redhat.com, peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, Thomas Huth , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH 1/2] qemu/timer: introduce time dilation factor Date: Tue, 10 Jun 2025 14:28:28 -0700 Message-ID: <20250610212829.2818792-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250610212829.2818792-1-pierrick.bouvier@linaro.org> References: <20250610212829.2818792-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x436.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This factor is applied to time spent since we read clock for the first time. It impacts value returned by get_clock() and get_clock_realtime(). Signed-off-by: Pierrick Bouvier --- include/qemu/timer.h | 22 ++++++++++++++++------ util/qemu-timer-common.c | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index abd2204f3be..9c3b8e5506d 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -801,6 +801,18 @@ static inline int64_t get_max_clock_jump(void) return 60 * NANOSECONDS_PER_SECOND; } +extern int64_t clock_start; +extern double clock_time_dilation; + +static inline int64_t dilate_time(int64_t now) +{ + g_assert(now >= clock_start); + if (!clock_time_dilation) { + return now; + } + return clock_start + (now - clock_start) * clock_time_dilation; +} + /* * Low level clock functions */ @@ -811,11 +823,9 @@ static inline int64_t get_clock_realtime(void) struct timeval tv; gettimeofday(&tv, NULL); - return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000); + return dilate_time(tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000)); } -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 +836,7 @@ static inline int64_t get_clock(void) { LARGE_INTEGER ti; QueryPerformanceCounter(&ti); - return muldiv64(ti.QuadPart, NANOSECONDS_PER_SECOND, clock_freq); + dilate_time(muldiv64(ti.QuadPart, NANOSECONDS_PER_SECOND, clock_freq)); } #else @@ -838,10 +848,10 @@ 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; + return dilate_time(ts.tv_sec * 1000000000LL + ts.tv_nsec); } 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(); } } diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c index cc1326f7264..d8895aaccad 100644 --- a/util/qemu-timer-common.c +++ b/util/qemu-timer-common.c @@ -28,6 +28,7 @@ /* real time host monotonic timer */ int64_t clock_start; +double clock_time_dilation; #ifdef _WIN32