From: Paolo Bonzini <pbonzini@redhat.com>
To: "zhongjun@sangfor.com.cn" <zhongjun@sangfor.com.cn>,
qemu-devel <qemu-devel@nongnu.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration
Date: Tue, 20 Sep 2016 15:12:57 +0200 [thread overview]
Message-ID: <c575db05-6e48-8671-e524-536302d3f3f2@redhat.com> (raw)
In-Reply-To: <2016092020541069238849@sangfor.com.cn>
On 20/09/2016 14:54, zhongjun@sangfor.com.cn wrote:
> Hi, Paolo
> The reason that use rtc_flush_time/rtc_adjust_timebase pairs instead
> of rtc_update_time/rtc_set_time is a trick.
> what all we do is to coordinate the base point of time line for guest on
> a new host. So, we don't flush realtime
> of the guest when it's stopped into cmos, but only convert vector
> [base_rtc, last_update] into cmos.
Isn't this the same?
In fact, rtc_flush_time and rtc_update_time are exactly the same code,
except that rtc_update_time sums s->offset (which is <1 second) while
rtc_flush_time sums a fixes 500 ns.
Likewise for rtc_set_time and rtc_adjust_timebase, except that
rtc_adjust_timebase leaves s->base_rtc untouched and subtracts it from
s->last_update; rtc_set_time instead changes both. But this makes no
difference because, according to get_guest_rtc_ns, what matters is only
s->base_rtc * NANOSECONDS_PER_SECOND + s->offset - s->last_update. So,
say rtc_set_time would set
s->base_rtc = mktimegm(&tm)
s->last_update = qemu_clock_get_ns(rtc_clock)
while rtc_adjust_timebase would set
s->base_rtc = source_base_rtc
s->last_update = qemu_clock_get_ns(rtc_clock)
- (mktimegm(&tm) - source_base_rtc) * NANOSECONDS_PER_SECOND
Then, after rtc_adjust_timebase, get_guest_rtc_ns returns
s->base_rtc * NANOSECONDS_PER_SECOND + guest_clock - s->last_update + s->offset
= source_base_rtc * NANOSECONDS_PER_SECOND + guest_clock
- qemu_clock_get_ns(rtc_clock)
+ (mktimegm(&tm) - source_base_rtc) * NANOSECONDS_PER_SECOND
+ s->offset
= mktimegm(&tm) * NANOSECONDS_PER_SECOND + guest_clock
- qemu_clock_get_ns(rtc_clock)
+ s->offset
and this is exactly what you'd get after rtc_set_time.
So I don't understand what's the difference, except for rounding the
nanoseconds component.
> On the other hand, the problem of rtc_update_time is it add time up plus
> s->offset, then when rtc_set_time
> recalculate new last_update, it actually introduce s->offset into base
> vector [base_rtc, last_update]. further,
> when guest continue to run and read realtime from cmos, rtc_update_time
> will add s->offset again, so s->offset
> is doubled.
This is true. In fact rtc_post_load is already setting s->offset = 0 after
calling rtc_set_time. Thus the load-side part of the patch can be simply
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index ea625f2..dd4ef5c 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -721,7 +722,7 @@ static int rtc_post_load(void *opaque, int version_id)
{
RTCState *s = opaque;
- if (version_id <= 2) {
+ if (rtc_clock == QEMU_CLOCK_REALTIME || version_id <= 2) {
rtc_set_time(s);
s->offset = 0;
check_update_timer(s);
Thanks,
Paolo
next prev parent reply other threads:[~2016-09-20 13:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <201609201519044580729@sangfor.com.cn>
2016-09-20 8:17 ` [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration Paolo Bonzini
2016-09-20 8:34 ` zhongjun
2016-09-20 8:38 ` Paolo Bonzini
2016-09-20 12:54 ` zhongjun
2016-09-20 13:12 ` Paolo Bonzini [this message]
2016-09-21 7:36 ` zhongjun
2016-09-21 9:38 ` zhongjun
2016-09-21 15:15 ` Paolo Bonzini
2016-09-22 7:00 ` zhongjun
2016-09-26 3:37 ` [Qemu-devel] [PATCH v2]MC146818 " zhongjun
2016-09-26 7:07 ` Paolo Bonzini
2016-09-26 8:42 ` [Qemu-devel] [PATCH v3]MC146818 " zhongjun
2016-09-26 8:59 ` Paolo Bonzini
2016-09-26 10:54 ` [Qemu-devel] [PATCH v4]MC146818 " zhongjun
2016-09-26 11:22 ` Paolo Bonzini
2016-09-26 4:37 ` [Qemu-devel] [PATCH]MC146818 RTC: Get correct guest time when irq coalesced zhongjun
2016-09-26 7:14 ` Paolo Bonzini
2016-09-27 3:13 ` zhongjun
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=c575db05-6e48-8671-e524-536302d3f3f2@redhat.com \
--to=pbonzini@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhongjun@sangfor.com.cn \
/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).