All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhongjun@sangfor.com.cn" <zhongjun@sangfor.com.cn>
To: Paolo Bonzini <pbonzini@redhat.com>, 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 16:34:11 +0800	[thread overview]
Message-ID: <201609201628008915271@sangfor.com.cn> (raw)
In-Reply-To: 67acae98-2704-22e8-1953-b2ae6714a41c@redhat.com

yes, the full options on clock is '-rtc driftfix=slew,clock=rt,base=localtime'



zhongjun@sangfor.com.cn
 
From: Paolo Bonzini
Date: 2016-09-20 16:17
To: zhongjun@sangfor.com.cn; qemu-devel
CC: Michael S. Tsirkin
Subject: Re: [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration
 
 
On 20/09/2016 09:19, zhongjun@sangfor.com.cn wrote:
> qemu tracks guest time based on vector [base_rtc, last_update], in which
> last_update stands for a monotonic tick which is actually uptime of the host.
 
But last_update is not a monotonic tick, it's basically gettimeofday
unless you're using the "-rtc clock=..." option.
 
> +static void rtc_flush_time(RTCState *s)
> +{
> +    struct tm ret;
> +    time_t guest_sec;
> +    int64_t guest_nsec;
> +    uint64_t guest_clock = qemu_clock_get_ns(rtc_clock);
> +
> +    guest_nsec = s->base_rtc * NANOSECONDS_PER_SECOND
> +                 + guest_clock - s->last_update;
> +    guest_sec = (guest_nsec + NANOSECONDS_PER_SECOND/2)/ NANOSECONDS_PER_SECOND;
> +    gmtime_r(&guest_sec, &ret);
> +
> +    rtc_set_cmos(s, &ret);
 
This should be just rtc_update_time(s).
 
Similarly:
 
> 
> +    rtc_get_time(s, &tm);
> +    diff = mktimegm(&tm) - s->base_rtc;
> +    assert(diff >= 0);
> +    s->last_update = qemu_clock_get_ns(rtc_clock)
> +                    - diff * NANOSECONDS_PER_SECOND;
 
This should be rtc_set_time.
 
However, there are two problems with this approach.  First, if you
migrate old QEMU to new QEMU, the new QEMU expects to have an up-to-date
s->base_rtc, while old QEMU provided an old QEMU.  Second, every
migration will delay the RTC by a few tenths of a second.  So the call
to rtc_set_time should be conditional on rtc_clock == QEMU_CLOCK_REALTIME.
 
Paolo

  reply	other threads:[~2016-09-20  8:42 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 [this message]
2016-09-20  8:38     ` Paolo Bonzini
2016-09-20 12:54   ` zhongjun
2016-09-20 13:12     ` Paolo Bonzini
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=201609201628008915271@sangfor.com.cn \
    --to=zhongjun@sangfor.com.cn \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.