From: Paolo Bonzini <pbonzini@redhat.com>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-stable <qemu-stable@nongnu.org>
Subject: Re: [PATCH] icount: don't adjust virtual time backwards after warp
Date: Tue, 27 Jun 2023 09:00:26 +0200 [thread overview]
Message-ID: <8edd4b7f-5c6b-db99-a838-484cb49bcb27@redhat.com> (raw)
In-Reply-To: <20230627061406.241847-1-npiggin@gmail.com>
On 6/27/23 08:14, Nicholas Piggin wrote:
> The icount-based QEMU_CLOCK_VIRTUAL runs ahead of the RT clock at times.
> When warping, it is possible it is still ahead at the end of the warp,
> which causes icount adaptive mode to adjust it backward. This can result
> in the machine observing time going backwards.
>
> Prevent this by clamping adaptive adjustment to 0 at minimum.
Queued, thanks.
Paolo
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> softmmu/icount.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/softmmu/icount.c b/softmmu/icount.c
> index 4504433e16..486ea7ef41 100644
> --- a/softmmu/icount.c
> +++ b/softmmu/icount.c
> @@ -259,11 +259,16 @@ static void icount_warp_rt(void)
> warp_delta = clock - timers_state.vm_clock_warp_start;
> if (icount_enabled() == 2) {
> /*
> - * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too
> - * far ahead of real time.
> + * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too far
> + * ahead of real time (it might already be ahead so careful not
> + * to go backwards).
> */
> int64_t cur_icount = icount_get_locked();
> int64_t delta = clock - cur_icount;
> +
> + if (delta < 0) {
> + delta = 0;
> + }
> warp_delta = MIN(warp_delta, delta);
> }
> qatomic_set_i64(&timers_state.qemu_icount_bias,
prev parent reply other threads:[~2023-06-27 7:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 6:14 [PATCH] icount: don't adjust virtual time backwards after warp Nicholas Piggin
2023-06-27 7:00 ` Paolo Bonzini [this message]
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=8edd4b7f-5c6b-db99-a838-484cb49bcb27@redhat.com \
--to=pbonzini@redhat.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/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).