From: Jamie Lokier <jamie@shareable.org>
To: Dor Laor <dlaor@redhat.com>
Cc: Beth Kon <eak@us.ibm.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org,
Alexander Graf <agraf@suse.de>
Subject: Re: [Qemu-devel] [PATCH 1/2] Add HPET emulation to qemu (v3)
Date: Wed, 5 Nov 2008 14:48:55 +0000 [thread overview]
Message-ID: <20081105144855.GH13630@shareable.org> (raw)
In-Reply-To: <491197BB.6080502@redhat.com>
Dor Laor wrote:
> Right, I think if this time drift fix approach is accepted, it should also be
> implemented for qemu_irq_pulse too.
I don't think simply injecting timer interrupts is the right approach.
I suspect doing that to compensate for lost ticks can _cause_ drift in
some guests.
Some guest kernels have lost-timer-interrupt detection. For example,
by reading the local TSC, local APIC timer, PM timer, and/or HPET
counter, they can determine (on a real machine) when some timer
interrupts were missed, and compensate for it.
If a burst of timer interrupts are sent by QEMU to compensate for lost
ones due to host scheduling delays, on servicing the first of those
interrupts the guest may read a timer value which indicates time has
jumped forward, and the guest may adjust it's clock to compensate for
missing interrupts. On servicing the remaining ones injected by QEMU,
the guest will read timer values which haven't increased by much, but
since _extra_ timer interrupts aren't expected on real hardware, the
guest may not implement reverse compensation.
The result will be QEMU sends a burst of timer interrupts, and the
guest clock moves _forward_ by a few ticks.
I think a better to handle this in QEMU is to still inject those
"lost" interrupts but also modify the values returned when the guest
reads timers, so they appear to increment by a normal amount between
each interrupt.
In other words, rather than counting ticks, modify the flow of virtual
time - stretch it when the virtual CPU is supposed to run but is
delayed, and compress it afterwards to resync with real time.
On some architectures, this may be even more important with "tickless"
guest kernels which are busily running high resolution timers with
different delays between each event. Simply counting missed
interrupts and injecting a burst doesn't work if the guest depends on
reprogramming a timer chip to a different delay between each interrupt
event (like x86 PIT), but it's fine with timer chips (like HPET) which
have a free-running counter and alarm register.
That method should work with all guests, whatever timers they use and
whatever their interrupt handler does, and result in _zero_ long term
drift as long as the virtual CPU is not persistantly starved. In the
case of timer chips like HPET, which have specified nominal frequency,
it may mean you don't have to run NTP on the guest at all.
-- Jamie
next prev parent reply other threads:[~2008-11-05 14:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-17 12:17 [Qemu-devel] [PATCH 1/2] Add HPET emulation to qemu (v3) Beth Kon
2008-10-17 13:14 ` rinku buragohain
2008-10-17 15:49 ` Jamie Lokier
2008-10-20 19:08 ` Beth Kon
2008-10-27 10:49 ` Dor Laor
2008-10-30 17:57 ` Beth Kon
2008-11-05 12:55 ` Dor Laor
2008-11-05 14:48 ` Jamie Lokier [this message]
2008-10-21 15:21 ` [Qemu-devel] " Anthony Liguori
2008-10-27 14:07 ` Beth Kon
2008-10-29 3:41 ` Alexander Graf
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=20081105144855.GH13630@shareable.org \
--to=jamie@shareable.org \
--cc=agraf@suse.de \
--cc=dlaor@redhat.com \
--cc=eak@us.ibm.com \
--cc=kvm@vger.kernel.org \
--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 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).