mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Griffoul,
	Fred" <fgriffo@amazon.com>
Cc: Paul Durrant <paul@xen.org>,
	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 22:38:31 +0000	[thread overview]
Message-ID: <ae179410922c40cbca7a2e9a94a6695db6eae069.camel@infradead.org> (raw)
In-Reply-To: <19cdf9362d469ac6de8503aa335b864ab5fc2553.camel@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

On Tue, 2023-10-31 at 19:45 +0000, David Woodhouse wrote:
> On Mon, 2023-10-30 at 15:50 +0000, David Woodhouse wrote:
> > 
> > +static int do_monotonic(s64 *t, u64 *tsc_timestamp)
> > +{
> > +	struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
> > +	unsigned long seq;
> > +	int mode;
> > +	u64 ns;
> > +
> > +	do {
> > +		seq = read_seqcount_begin(&gtod->seq);
> > +		ns = gtod->clock.base_cycles;
> > +		ns += vgettsc(&gtod->clock, tsc_timestamp, &mode);
> > +		ns >>= gtod->clock.shift;
> > +		ns += ktime_to_ns(ktime_add(gtod->clock.offset, gtod->offs_boot));
> > +	} while (unlikely(read_seqcount_retry(&gtod->seq, seq)));
> > +	*t = ns;
> > +
> > +	return mode;
> > +}
> > +
> 
> Hrm, that's basically cargo-culted from do_monotonic_raw() immediately
> above it. Should it be adding gtod->offs_boot?
> 
> Empirically the answer would appear to be 'no'. When gtod->offs_boot is
> non-zero, I see kvm_get_monotonic_and_clockread() returning values
> which are precisely that far in advance of what ktime_get() reports.


.... because the do_monotonic_raw() function, despite the simple
clarity of its name... doesn't actually return the CLOCK_MONOTONIC_RAW
time. Of course it doesn't. Why would a function with that name return
the MONOTONIC_RAW clock?

It actually returns the same as get_kvmclock_base_ns(), which is

	/* Count up from boot time, but with the frequency of the raw clock.  */
	return ktime_to_ns(ktime_add(ktime_get_raw(), pvclock_gtod_data.offs_boot));

I feel that Grey's Law is starting to apply to this clock stuff. This
is starting to be indistinguishable from malice ;)


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]

  reply	other threads:[~2023-10-31 22:38 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
2023-10-31 19:45 ` David Woodhouse
2023-10-31 22:38   ` David Woodhouse [this message]
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=ae179410922c40cbca7a2e9a94a6695db6eae069.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fgriffo@amazon.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 \
    /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®