Skip to contentSkip to conversation

Autodetect clock_gettime

PATCH François Revol 1 participant 1 message Mar 15, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 2 lines · Paolo Bonzini
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Some POSIX OSes (such as Darwin) doesn't have clock_gettime. This patch falls back on gettimeofday if clock_gettime is not available.

Some code I've seen use #ifdef CLOCK_REALTIME but this doesn't seem right
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

This may be okay as a stopgap measure, but any sane porting target for QEMU should have a monotonic clock. In fact, Darwin has it.

Yes mach primitives could be used. But why isn't a monotonic clock used on Linux ?

cf.
http://www.virtualbox.org/browser/trunk/src/VBox/Runtime/r3/darwin/time-darwin.cpp

You might want to check this as well :
http://www.wand.net.nz/~smr26/wordpress/2009/01/19/monotonic-time-in-mac-os-x/

Quoted 2 lines
Quoted 2 lines

According to man, CLOCK_MONOTONIC is monotonic
while CLOCK_REALTIME isn't.

Yes that's the reason both exist actually...

Quoted 1 line

Unfortunately, pthread timed wait/lock functions are documented to use the realtime clock by default. Using pthread_condattr_setclock is probably not portable enough, and anyway there is no such function for mutexes so we're stuck with CLOCK_REALTIME. What you're patching is fine, but those functions might actually go away soon as they're not supported on Win32.

If you're talking about qemu_mutex_timedlock and qemu_cond_timedwait, I failed to grep them anywhere else than at their own definition.

Quoted 1 line

So, in addition to what you've done, you should probably use those Mach primitives in qemu-timer.h.

Likely.
(though I'd like to get QEMU to just work again here first as I need it running for friday...)

François.