From: Thomas Gleixner <tglx@linutronix.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, chris.j.arges@canonical.com,
kvm@vger.kernel.org, John Stultz <john.stultz@linaro.org>
Subject: Re: [PATCH] KVM: x86: fix kvmclock breakage from timers branch merge
Date: Thu, 4 Sep 2014 22:58:40 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1409042230020.3333@nanos> (raw)
In-Reply-To: <1409835487-14371-1-git-send-email-pbonzini@redhat.com>
On Thu, 4 Sep 2014, Paolo Bonzini wrote:
> Commit cbcf2dd3b3d4 (x86: kvm: Make kvm_get_time_and_clockread() nanoseconds
> based, 2014-07-16) forgot to add tk->xtime_sec, thus breaking kvmclock on
Errm. How is boottime related to xtime_sec?
> hosts that have a reliable TSC. Add it back; and since the field boot_ns
> is not anymore related to the host boot-based clock, rename boot_ns->nsec_base
> and the existing nsec_base->snsec_base.
This is simply wrong.
The original code before that changed did:
vdata->monotonic_time_sec = tk->xtime_sec
+ tk->wall_to_monotonic.tv_sec;
vdata->monotonic_time_snsec = tk->xtime_nsec
+ (tk->wall_to_monotonic.tv_nsec
<< tk->shift);
So this is the momentary monotonic base time
And the readout function did:
ts->tv_nsec = 0;
do {
seq = read_seqcount_begin(>od->seq);
mode = gtod->clock.vclock_mode;
ts->tv_sec = gtod->monotonic_time_sec;
ns = gtod->monotonic_time_snsec;
ns += vgettsc(cycle_now);
ns >>= gtod->clock.shift;
} while (unlikely(read_seqcount_retry(>od->seq, seq)));
timespec_add_ns(ts, ns);
So this does:
now = monotonic_base + delta_nsec
And the caller converted it to boot time with:
monotonic_to_bootbased(&ts);
So the time calculation does:
now = monotonic_base + delta_nsec + mono_to_boot
Because: monotonic_base + mono_to_boot = boot_time_base
The calculation can be written as:
now = boot_time_base + delta_nsec
The new code does
boot_ns = ktime_to_ns(ktime_add(tk->base_mono, tk->offs_boot));
So thats
boot_time_base = monotonic_base + mono_to_boot;
vdata->boot_ns = boot_ns;
vdata->nsec_base = tk->tkr.xtime_nsec;
And the readout does:
do {
seq = read_seqcount_begin(>od->seq);
mode = gtod->clock.vclock_mode;
ns = gtod->nsec_base;
ns += vgettsc(cycle_now);
ns >>= gtod->clock.shift;
ns += gtod->boot_ns;
} while (unlikely(read_seqcount_retry(>od->seq, seq)));
*t = ns;
Which is:
boot_time_base + delta_nsec
Now I have no idea why you think it needs to add xtime_sec. If the
result is wrong, then we need to figure out which one of the supplied
values is wrong and not blindly add xtime_sec just because that makes
it magically correct.
Can you please provide a proper background why you think that adding
xtime_sec is a good idea?
Thanks,
tglx
next prev parent reply other threads:[~2014-09-04 20:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-04 12:58 Paolo Bonzini
2014-09-04 16:00 ` Chris J Arges
2014-09-04 17:14 ` Paolo Bonzini
2014-09-04 18:16 ` Chris J Arges
2014-09-04 19:15 ` Paolo Bonzini
2014-09-04 19:42 ` Paolo Bonzini
2014-09-04 20:37 ` Chris J Arges
2014-09-04 20:40 ` Paolo Bonzini
2014-09-04 20:43 ` Chris J Arges
2014-09-04 19:00 ` John Stultz
2014-09-04 19:14 ` Paolo Bonzini
2014-09-04 17:56 ` Paolo Bonzini
2014-09-04 20:58 ` Thomas Gleixner [this message]
2014-09-04 21:22 ` Paolo Bonzini
2014-09-04 22:24 ` Thomas Gleixner
2014-09-05 15:14 ` Thomas Gleixner
2014-09-05 16:39 ` Paolo Bonzini
2014-09-05 18:33 ` Thomas Gleixner
2014-09-05 20:37 ` Paolo Bonzini
2014-09-05 20:41 ` Thomas Gleixner
2014-09-05 21:00 ` Paolo Bonzini
2014-09-08 15:28 ` Chris J Arges
2014-09-06 11:01 ` [tip:timers/urgent] timekeeping: Update timekeeper before updating vsyscall and pvclock tip-bot for Thomas Gleixner
2014-09-04 21:05 [PATCH] KVM: x86: fix kvmclock breakage from timers branch merge Paolo Bonzini
2014-09-04 21:27 ` Thomas Gleixner
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=alpine.DEB.2.10.1409042230020.3333@nanos \
--to=tglx@linutronix.de \
--cc=chris.j.arges@canonical.com \
--cc=john.stultz@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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®