From: Jamie Lokier <jamie@shareable.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Timer/clock for Linux
Date: Tue, 25 Apr 2006 22:34:55 +0100 [thread overview]
Message-ID: <20060425213455.GA3092@mail.shareable.org> (raw)
In-Reply-To: <444E905B.5050703@bellard.org>
Fabrice Bellard wrote:
> Jamie Lokier wrote:
> >Fabrice Bellard wrote:
> >
> >>Can other people confirm that it is better to always use /dev/rtc on
> >>Linux ? Is there a way to get the real resolution of the host timer ?
> >
> >
> >Yes, on recent Linux kernels you can do
> >clock_getres(CLOCK_MONOTONIC,&ts) [or CLOCK_REALTIME], and it will
> >return the length of a timer tick. On my kernel it's 4.00025 ms. On
> >other x86 kernels it can be ~10ms or ~1ms.
> >
> >Also the recent Linux kernels (more recent) offer "high-resolution
> >timers"; you can guess what that means. They should be more accurate
> >than /dev/rtc when they're available, because they reprogram the timer
> >chip, though I have never tried them. I'd guess that kernels
> >featuring them would return a small value from clock_getres().
>
> Using clock_getres() seems a good idea if I can test that it is
> supported. If it is not supported then /dev/rtc will be used in any case.
You'll need to check for -lrt, something like this:
AC_SEARCH_LIBS([clock_getres], [rt posix4])
> >It's unfortunate that even on kernels where the kernel tick time is
> >1ms, setitimer() will cost you a 2ms delay. But: why should that make
> >Windows run slower? Doesn't qemu read the kernel clock to determine
> >that the guest is due approx. 2 timer interrupts for each host wakeup?
> >Naturally you can't let that count increase indefinitely, if the
> >emulator is too slow to run the guest at full speed, but it might be
> >an idea to count up to a small number, so that short pauses in host
> >kernel scheduling won't cause a guest to lose time.
>
> QEMU reads the clock at each host wakeup, but it cannot compensate if
> the guest OS requires a higher frequency than the host timer frequency.
> Having a 1 ms period is definitively better to be able to run a wide
> range of guest OSes.
I was thinking that if the host is woken later than it intended
(e.g. after 2ms with setitimer; could be any amount with any syscall
due to other scheduling delays), then it could fake the timer chip
time it presents to the guest for a short while as if there wasn't
really a timing gap, effectively delaying the faked clock for that
gap, and then running the faked clock faster than normal to catch up
with real time. A control loop would ensure the amount of adjustment
stays small, converting to slippage if that's not possible. In this
way a guest would get 1000Hz interrupts (if that's what it wants), or
any other frequency. It would also read the values it's expecting
from the emulated timer chip as if there was no host scheduling gap,
so the guest's timing logic would function properly, counting ticks,
timing times, and still tracking real clock time.
-- Jamie
next prev parent reply other threads:[~2006-04-25 21:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-12 2:10 [Qemu-devel] [PATCH] Timer/clock for Linux Kazu
[not found] ` <443E93A3.5060508@weilnetz.de>
2006-04-13 18:11 ` [Qemu-devel] [PATCH] Fix message in configure Stefan Weil
2006-04-24 21:41 ` [Qemu-devel] [PATCH] Timer/clock for Linux Fabrice Bellard
2006-04-25 0:16 ` Jamie Lokier
2006-04-25 21:10 ` Fabrice Bellard
2006-04-25 21:34 ` Jamie Lokier [this message]
2006-04-25 21:49 ` Paul Brook
2006-04-26 13:01 ` Jamie Lokier
2006-04-26 14:21 ` Paul Brook
2006-04-26 17:26 ` Jamie Lokier
2006-04-25 11:04 ` NyOS
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=20060425213455.GA3092@mail.shareable.org \
--to=jamie@shareable.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).