qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] pl031 time across vm save/reload
@ 2019-07-04 16:02 Peter Maydell
  2019-07-05  9:48 ` Paolo Bonzini
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2019-07-04 16:02 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Paolo Bonzini

I've had a report that the way the PL031 model handles time
across a vm save/reload fails to correctly advance the guest
RTC when the host RTC has advanced between the save and reload.
I looked at the code and my correspondent's analysis (which
I quote below, lightly edited) looks correct to me, but I'm not
entirely sure how our RTC stuff is supposed to work. Paolo,
you wrote this (way back in commit b0f26631bc5179006) -- any opinions?

In the pl031 RTC device. the current time is given by:

    int64_t now = qemu_clock_get_ns(rtc_clock);
    return s->tick_offset + now / NANOSECONDS_PER_SECOND;

On save we do:

    /* tick_offset is base_time - rtc_clock base time.  Instead, we want to
     * store the base time relative to the QEMU_CLOCK_VIRTUAL for
backwards-compatibility.  */
    int64_t delta = qemu_clock_get_ns(rtc_clock) -
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
    s->tick_offset_vmstate = s->tick_offset + delta / NANOSECONDS_PER_SECOND;

On restore:

    int64_t delta = qemu_clock_get_ns(rtc_clock) -
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
    s->tick_offset = s->tick_offset_vmstate - delta / NANOSECONDS_PER_SECOND;

So, no matter what is requested, if "qemu_clock_get_ns(rtc_clock)"
increases (eg, because host time increased), then tick_offset
reduces, which makes time follow QEMU_CLOCK_VIRTUAL no matter what
was requested on qemu's command line.

(That is, because we migrate "offset relative to CLOCK_VIRTUAL"
and CLOCK_VIRTUAL does not advance when the VM is stopped,
we don't get the right behaviour of "offset is relative to
the new CLOCK_RTC, which might have advanced".).

thanks
-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-07-08 17:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-04 16:02 [Qemu-devel] pl031 time across vm save/reload Peter Maydell
2019-07-05  9:48 ` Paolo Bonzini
2019-07-05  9:58   ` Peter Maydell
2019-07-05 10:13     ` Paolo Bonzini
2019-07-05 10:21       ` Peter Maydell
2019-07-05 10:32         ` Paolo Bonzini
2019-07-05 10:42           ` Peter Maydell
2019-07-08 17:41         ` Dr. David Alan Gilbert
2019-07-05 10:26   ` Peter Maydell
2019-07-08 14:03   ` Peter Maydell

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).