From: David Woodhouse <dwmw2@infradead.org>
To: paul@xen.org, Paul Durrant <xadimgnik@gmail.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] KVM: x86/xen: improve accuracy of Xen timers
Date: Tue, 31 Oct 2023 16:34:46 +0000 [thread overview]
Message-ID: <908ad29b56fbe5e5f4d99e477e96fbd9d03ba4c6.camel@infradead.org> (raw)
In-Reply-To: <a2a13598-6d37-47a2-8a13-9963acb0f1e5@xen.org>
[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]
On Tue, 2023-10-31 at 12:22 +0000, Paul Durrant wrote:
>
> >
> > As I said, this patch stands even *after* we fix kvmclock, because
> > it handles the timer delta calculation from an single TSC read.
> >
> > But overengineering a timer reset on KVM_REQ_CLOCK_UPDATE would not.
>
> I'm not sure what you intend to do to kvmlock, so not sure whether we'll
> still need the __pvclock_read_cycles(&vcpu->arch.hv_clock, guest_tsc)
> but this patch (with the extra check on validity of hv_clock) does fix
> the drift so...
>
> Reviewed-by: Paul Durrant <paul@xen.org>
Ta. And no, I'm not quite sure what I'm going to do with kvmclock for
the general case yet. The more I look at it, the more I realise how
broken it is.
Last week I thought it was just about the way KVM 'jumps' the kvmclock
and yanks it back to the host's CLOCK_MONOTONIC_RAW, but I thought KVM
at *least* managed to do it right between those times. But no, this
patch is addressing the fact that even *without* those clock jumps, KVM
doesn't manage to calculate the guest clock the same way that it tells
the guest to... and thus doesn't get the same results :)
I think it involves get_kvmclock_ns() using the frequency given in the
KVM-wide (not per-vCPU) KVM_SET_TSC_KHZ ioctl, and scaling via that to
get the guest clock. That should match, without having to have a
specific vCPU's hv_clock to play with. And maybe we can also have a
get_kvmclock_ns_at() which takes a host TSC value, and the timer code
from this patch can use that instead of using __pvclock_read_cycles()
directly.
That's probably the easy part. Fixing the 'resync' to
CLOCK_MONOTONIC_RAW, while keeping things working for the now-
considered-pathological !CONSTANT_TSC case, will be slightly more fun.
As well as suspend etc. in the CONSTANT_TSC case, of course.
And replacing that stupid KVM_CLOCK_REALTIME with something that uses
CLOCK_TAI. Or maybe just making it export the tai_offset at the same
moment?
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]
next prev parent reply other threads:[~2023-10-31 16:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 15:50 David Woodhouse
2023-10-31 10:42 ` Paul Durrant
2023-10-31 11:42 ` David Woodhouse
2023-10-31 12:06 ` Paul Durrant
2023-10-31 12:11 ` David Woodhouse
2023-10-31 12:22 ` Paul Durrant
2023-10-31 16:34 ` David Woodhouse [this message]
2023-10-31 19:45 ` David Woodhouse
2023-10-31 22:38 ` David Woodhouse
2023-10-31 23:13 ` [PATCH v2] " David Woodhouse
2023-11-07 1:44 ` Dongli Zhang
2023-11-07 8:17 ` David Woodhouse
2023-11-07 23:07 ` Dongli Zhang
2023-11-07 23:24 ` David Woodhouse
2023-11-08 1:43 ` Dongli Zhang
2023-11-08 15:25 ` David Woodhouse
2023-11-08 18:22 ` Dongli Zhang
2023-11-08 19:14 ` David Woodhouse
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=908ad29b56fbe5e5f4d99e477e96fbd9d03ba4c6.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xadimgnik@gmail.com \
/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
all inboxes | Powered by JetHome®