[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to des
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration |
Date: |
Tue, 20 Sep 2016 10:17:27 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
On 20/09/2016 09:19, address@hidden 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
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration,
Paolo Bonzini <=
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/20
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/20
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, Paolo Bonzini, 2016/09/20
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/21
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/21
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, Paolo Bonzini, 2016/09/21
- Re: [Qemu-devel] [PATCH]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/22
- [Qemu-devel] [PATCH v2]MC146818 RTC: coordinate guest clock base to destination host after migration, address@hidden, 2016/09/25
- Re: [Qemu-devel] [PATCH v2]MC146818 RTC: coordinate guest clock base to destination host after migration, Paolo Bonzini, 2016/09/26