Skip to contentSkip to conversation

re-set rtc date on reset handler

PATCH In review Glauber Costa 9 participants 19 messages Sep 1, 2009 – Sep 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 re-set rtc date on reset handler

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

---
 hw/mc146818rtc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/mc146818rtc.c +2 -0
index 5c8676e..e71a9da 100644
@@ -586,6 +586,8 @@ static void rtc_reset(void *opaque)
     if (rtc_td_hack)
 	    s->irq_coalesced = 0;
 #endif
+
+    rtc_set_date_from_host(s);
 }
 
 RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 8 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

#2 lore raw
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 6 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset

You mean at every ioport read? I actually thought about that, but was too lazy...

Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#3 lore raw
Quoted 7 lines · Glauber Costa
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset

You mean at every ioport read? I actually thought about that, but was too lazy...

You also need to handle the -startdate flag of qemu.
In this case you need to keep the offset and not read the host time.

#4 lore raw
In reply to Blue Swirl
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 8 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

Ah, that looks like a useful approach! We currently face the issue of vRTC drifting away from the host time (as the latter is tuned by NTP).

Do you or anyone else know if switching the PC RTC over to the scheme used in the m48t59 may have some downsides? If not, I would happily hack up a patch ASAP and suggest it for mainline.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 15 lines · Jan Kiszka
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 7 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

Quoted 6 lines

Ah, that looks like a useful approach! We currently face the issue of vRTC drifting away from the host time (as the latter is tuned by NTP).

Do you or anyone else know if switching the PC RTC over to the scheme used in the m48t59 may have some downsides? If not, I would happily hack up a patch ASAP and suggest it for mainline.

Clearly, one downside is that a jumping host time will cause the RTC to jump as well. However, there might by setups where this does not happen, so optionally switching the RTC over rt_clock seems like a reasonable feature to me.

What about consolidating -localtime, -starttime and -rtc-td-hack at this chance? Something like

-rtc base=utc|localtime|date,clock=vm|rt

with 'date' specifying the base as in -starttime. 'clock' would then allow to drive the RTC via the host's CLOCK_REALTIME (with all its pros and cons).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#6 lore raw
Quoted 27 lines · Jan Kiszka
Quoted 14 lines · Jan Kiszka
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 7 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

Quoted 6 lines

Ah, that looks like a useful approach! We currently face the issue of vRTC drifting away from the host time (as the latter is tuned by NTP).

Do you or anyone else know if switching the PC RTC over to the scheme used in the m48t59 may have some downsides? If not, I would happily hack up a patch ASAP and suggest it for mainline.

Clearly, one downside is that a jumping host time will cause the RTC to jump as well. However, there might by setups where this does not happen, so optionally switching the RTC over rt_clock seems like a reasonable feature to me.

Quoted 4 lines

What about consolidating -localtime, -starttime and -rtc-td-hack at this chance? Something like

-rtc base=utc|localtime|date,clock=vm|rt

+ ,td-hack=on|off

of course. Or let's call it "drift-hack".

Quoted 7 lines

with 'date' specifying the base as in -starttime. 'clock' would then allow to drive the RTC via the host's CLOCK_REALTIME (with all its pros and cons).

Jan

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#7 lore raw
Quoted 28 lines · Jan Kiszka
Quoted 27 lines · Jan Kiszka
Quoted 14 lines · Jan Kiszka
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 7 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

Quoted 6 lines

Ah, that looks like a useful approach! We currently face the issue of vRTC drifting away from the host time (as the latter is tuned by NTP).

Do you or anyone else know if switching the PC RTC over to the scheme used in the m48t59 may have some downsides? If not, I would happily hack up a patch ASAP and suggest it for mainline.

Clearly, one downside is that a jumping host time will cause the RTC to jump as well. However, there might by setups where this does not happen, so optionally switching the RTC over rt_clock seems like a reasonable feature to me.

Quoted 8 lines
Quoted 4 lines

What about consolidating -localtime, -starttime and -rtc-td-hack at this chance? Something like

-rtc base=utc|localtime|date,clock=vm|rt

+ ,td-hack=on|off

of course. Or let's call it "drift-hack".

btw: this is not a hack, its virtualization support for rtc. It should be the default when qemu runs along with kvm.

Quoted 11 lines
Quoted 8 lines

with 'date' specifying the base as in -starttime. 'clock' would then allow to drive the RTC via the host's CLOCK_REALTIME (with all its pros and cons).

Jan

Jan

#8 lore raw
Quoted 31 lines · Dor Laor
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Jan Kiszka
Quoted 14 lines · Jan Kiszka
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Glauber Costa

guests without a stable timesource such as kvm-clock will grab the wallclock from our rtc chip. However, we only sync the date when we first launch qemu. If a guest goes through a series of reboot cycles, it will slowly see time getting far behind the host.

Quoted 7 lines
Quoted 3 lines

The proposal of this patch is to set the date to host clock again in the reset handler. With this patch, I see a Fedora guest keeping its clock in sync upon an ulimited number of reboots.

A different approach is used in m48t59.c: the guest clock is generated directly from host clock without any timers and only a fixed offset (to account for time when guest was stopped) is added, so the clock will always in sync.

Quoted 6 lines

Ah, that looks like a useful approach! We currently face the issue of vRTC drifting away from the host time (as the latter is tuned by NTP).

Do you or anyone else know if switching the PC RTC over to the scheme used in the m48t59 may have some downsides? If not, I would happily hack up a patch ASAP and suggest it for mainline.

Clearly, one downside is that a jumping host time will cause the RTC to jump as well. However, there might by setups where this does not happen, so optionally switching the RTC over rt_clock seems like a reasonable feature to me.

What about consolidating -localtime, -starttime and -rtc-td-hack at this chance? Something like

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

-rtc base=utc|localtime|date,clock=vm|rt

+ ,td-hack=on|off

of course. Or let's call it "drift-hack".

btw: this is not a hack, its virtualization support for rtc. It should be the default when qemu runs along with kvm.

OK, will call it 'drift-fix'. But enabling it by default in kvm mode should be filed as a separate patch on top of my queue (which will appear soon).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#9 lore raw
Quoted 8 lines · Jan Kiszka
Quoted 4 lines

btw: this is not a hack, its virtualization support for rtc. It should be the default when qemu runs along with kvm.

OK, will call it 'drift-fix'. But enabling it by default in kvm mode should be filed as a separate patch on top of my queue (which will appear soon).

drift-compensation?

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 3 lines

btw: this is not a hack, its virtualization support for rtc. It should be the default when qemu runs along with kvm.

OK, will call it 'drift-fix'. But enabling it by default in kvm mode should be filed as a separate patch on top of my queue (which will appear soon).

drift-compensation?

'drift-compensation-for-windows-guests' - this is at least what the documentation suggests right now. I was looking for a short tag (but not as short as 'td'...).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#11 lore raw
Quoted 5 lines · Jan Kiszka

'drift-compensation-for-windows-guests' - this is at least what the documentation suggests right now. I was looking for a short tag (but not as short as 'td'...).

It would work for any guest that uses rtc as its main clock source.

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Jan Kiszka

'drift-compensation-for-windows-guests' - this is at least what the documentation suggests right now. I was looking for a short tag (but not as short as 'td'...).

It would work for any guest that uses rtc as its main clock source.

First step is qdev conversion for the RTC. You can then introduce a drift property. I'd suggest something like drift=none|catchup|gradual. The default can be none. We can also introduce a kvm machine type where the default is catchup. Obviously, we don't support gradual today.

You can modify the default rtc settings using the -set operation (we can give the rtc a default id). This lets localtime, td-hack, etc. all be aliases for -set.

Signature · 3 lines
Regards,

Anthony Liguori
#13 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Jan Kiszka

'drift-compensation-for-windows-guests' - this is at least what the documentation suggests right now. I was looking for a short tag (but not as short as 'td'...).

Quoted 8 lines
Quoted 1 line

It would work for any guest that uses rtc as its main clock source.

First step is qdev conversion for the RTC. You can then introduce a drift property. I'd suggest something like drift=none|catchup|gradual. The default can be none. We can also introduce a kvm machine type where the default is catchup. Obviously, we don't support gradual today.

What is "catchup" and what is "gradual"?

--
Gleb.

#14 lore raw
Quoted 2 lines · Gleb Natapov

What is "catchup" and what is "gradual"?

Just placeholders to point out that there are different algorithms to replaying interrupts to a guest. I called what we implemented "catchup" since we pretty much immediately send all of the missed ticks to the guest in order to catch-up.

I'd imagine that a 'gradual' algorithm would shorten the tick interval until you've caught up. The Hyper-V paravirtualization manual has provisions for the guest to request what type of algorithm is used so it makes sense to accommodate this in our syntax.

Signature · 3 lines
Regards,

Anthony Liguori
#15 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 1 line · Gleb Natapov

What is "catchup" and what is "gradual"?

Just placeholders to point out that there are different algorithms to replaying interrupts to a guest. I called what we implemented "catchup" since we pretty much immediately send all of the missed ticks to the guest in order to catch-up.

Quoted 6 lines

I'd imagine that a 'gradual' algorithm would shorten the tick interval until you've caught up. The Hyper-V paravirtualization manual has provisions for the guest to request what type of algorithm is used so it makes sense to accommodate this in our syntax.

We implement gradual then.

--
Gleb.

#16 lore raw
Quoted 11 lines · Gleb Natapov
Quoted 9 lines · Anthony Liguori
Quoted 2 lines · Gleb Natapov

What is "catchup" and what is "gradual"?

Just placeholders to point out that there are different algorithms to replaying interrupts to a guest. I called what we implemented "catchup" since we pretty much immediately send all of the missed ticks to the guest in order to catch-up.

Quoted 9 lines
Quoted 7 lines

I'd imagine that a 'gradual' algorithm would shorten the tick interval until you've caught up. The Hyper-V paravirtualization manual has provisions for the guest to request what type of algorithm is used so it makes sense to accommodate this in our syntax.

We implement gradual then.

You're right.

Regards,

Anthony Liguori

#17 lore raw
In reply to Anthony Liguori
Quoted 2 lines · Anthony Liguori

First step is qdev conversion for the RTC. You can then introduce a drift property. I'd suggest something like drift=none|catchup|gradual. The default can be none. We can also introduce a kvm machine type where the default is catchup. Obviously, we don't support gradual today.

Maybe none|step|slew to avoid alienating mayo lovers.

Should be a global option that applies to all clock sources?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#18 lore raw
Quoted 7 lines · Avi Kivity
Quoted 2 lines · Anthony Liguori

First step is qdev conversion for the RTC. You can then introduce a drift property. I'd suggest something like drift=none|catchup|gradual. The default can be none. We can also introduce a kvm machine type where the default is catchup. Obviously, we don't support gradual today.

Maybe none|step|slew to avoid alienating mayo lovers.

Should be a global option that applies to all clock sources?

Should be an option for all clock devices. And I think it makes sense to have a virtualization machine type that is automatically enabled when using kvm and that automatically enables drift=step.

Signature · 3 lines
Regards,

Anthony Liguori