qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* RTC time could run slow 3s than host time when clock=vm & base=UTC
@ 2024-09-21 11:33 贾庆彤 via
  2024-09-28 10:47 ` Zenghui Yu via
  0 siblings, 1 reply; 2+ messages in thread
From: 贾庆彤 via @ 2024-09-21 11:33 UTC (permalink / raw)
  To: qemu-devel

When start qemu with -rtc base=utc,clock=vm, sometime guest time can 
slower 3s than host.

There's no problem (also didn't be noticed) as we often start ntp 
service, who will adjust our system time.

But let's talk about if we havn't enable NTP service(for example system 
just booted)

After inspect into the code, i found that there are two problem we 
should think about:

1) The RTC time accuracy problem

1. in the call chains 
rtc_realizefn->rtc_set_date_from_host->qemu_get_timedate->qemu_ref_timedate,

the qemu_clock_get_ms(clock) / 1000 will lost ~0.999s at max.

2. In the call chains cmos_ioport_read->rtc_update_time, the guest_sec = 
guest_nsec / NANOSECONDS_PER_SECOND

will also lost ~0.999s at max.

3. after this[1] merged, in configure_rtc, the rtc_ref_start_datetime = 
qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000

will also lost ~0.999s at max.

Therefore, total about 3s the guest time will behind the host.

So what precision should we offer? the RTC Hardware's precision is 
second(that means the smallest step is 1 second,

not the accurate like time error about 8.6 to 1.7 seconds per day),


2)The ref start datetime

After this[1] merged, which intend to solve the -rtc 
base=DATETIME,clock=vm's problem ("It restores determinism

of guest execution when used with clock=vm and specified base value.").

"-rtc base=utc,clock=vm"'s ref start date time changed from the host 
time of the current executing code to

the const time of executing configure_rtc(rtc_ref_start_datetime = 
qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;).

This will add additional time(current approx. 0.4s or other, depend on 
code executing time and how many class_init

  executed etc.),which start from configure_rtc to rtc device init, into 
guest time.

Hence, should we try to split -rtc base=utc,clock=vm's ref start date 
time to the original current host time

qemu_clock_get_ms(QEMU_CLOCK_HOST),not the time(rtc_ref_start_datetime) 
save in configure_rtc,

to achieve more accurate time?(or other better method)


[1] https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg03577.html



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

* Re: RTC time could run slow 3s than host time when clock=vm & base=UTC
  2024-09-21 11:33 RTC time could run slow 3s than host time when clock=vm & base=UTC 贾庆彤 via
@ 2024-09-28 10:47 ` Zenghui Yu via
  0 siblings, 0 replies; 2+ messages in thread
From: Zenghui Yu via @ 2024-09-28 10:47 UTC (permalink / raw)
  To: 贾庆彤
  Cc: qemu-devel, mst, Paolo Bonzini, artem.k.pisarenko

+Cc maintainers and author of [1]

On 2024/9/21 19:33, 贾庆彤 via wrote:
> When start qemu with -rtc base=utc,clock=vm, sometime guest time can
> slower 3s than host.
> 
> There's no problem (also didn't be noticed) as we often start ntp
> service, who will adjust our system time.
> 
> But let's talk about if we havn't enable NTP service(for example system
> just booted)
> 
> After inspect into the code, i found that there are two problem we
> should think about:
> 
> 1) The RTC time accuracy problem
> 
> 1. in the call chains
> rtc_realizefn->rtc_set_date_from_host->qemu_get_timedate->qemu_ref_timedate,
> 
> 
> the qemu_clock_get_ms(clock) / 1000 will lost ~0.999s at max.
> 
> 2. In the call chains cmos_ioport_read->rtc_update_time, the guest_sec =
> guest_nsec / NANOSECONDS_PER_SECOND
> 
> will also lost ~0.999s at max.
> 
> 3. after this[1] merged, in configure_rtc, the rtc_ref_start_datetime =
> qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000
> 
> will also lost ~0.999s at max.
> 
> Therefore, total about 3s the guest time will behind the host.
> 
> So what precision should we offer? the RTC Hardware's precision is
> second(that means the smallest step is 1 second,
> 
> not the accurate like time error about 8.6 to 1.7 seconds per day),
> 
> 
> 2)The ref start datetime
> 
> After this[1] merged, which intend to solve the -rtc
> base=DATETIME,clock=vm's problem ("It restores determinism
> 
> of guest execution when used with clock=vm and specified base value.").
> 
> "-rtc base=utc,clock=vm"'s ref start date time changed from the host
> time of the current executing code to
> 
> the const time of executing configure_rtc(rtc_ref_start_datetime =
> qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;).
> 
> This will add additional time(current approx. 0.4s or other, depend on
> code executing time and how many class_init
> 
>  executed etc.),which start from configure_rtc to rtc device init, into
> guest time.
> 
> Hence, should we try to split -rtc base=utc,clock=vm's ref start date
> time to the original current host time
> 
> qemu_clock_get_ms(QEMU_CLOCK_HOST),not the time(rtc_ref_start_datetime)
> save in configure_rtc,
> 
> to achieve more accurate time?(or other better method)
> 
> 
> [1] https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg03577.html
> 
> 
> .


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

end of thread, other threads:[~2024-09-28 10:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-21 11:33 RTC time could run slow 3s than host time when clock=vm & base=UTC 贾庆彤 via
2024-09-28 10:47 ` Zenghui Yu via

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