Skip to contentSkip to conversation

Use clock_gettime() on OpenBSD

PATCH In review Brad Smith 2 participants 2 messages Mar 30, 2013

lore
Share & tools
lore

Brad Smith

author
#0 lore raw

PATCH 1/1 Use clock_gettime() on OpenBSD

init_get_clock() already indicates to get_clock() to utilize clock_gettime() with a monotonic clock but OpenBSD was missing from the list of OS's to use a monotonic clock on.

What I don't understand is why is init_get_clock() not called anywhere?

include/qemu/timer.h +2 -1
index 1766b2d..8b86fa5 100644
@@ -118,7 +118,8 @@ extern int use_rt_clock;
 static inline int64_t get_clock(void)
 {
 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
-    || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
+    || defined(__DragonFly__) || defined(__FreeBSD_kernel__) \
+    || defined(__OpenBSD__)
     if (use_rt_clock) {
         struct timespec ts;
         clock_gettime(CLOCK_MONOTONIC, &ts);
Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
#1 lore raw
Quoted 6 lines · Brad Smith

init_get_clock() already indicates to get_clock() to utilize clock_gettime() with a monotonic clock but OpenBSD was missing from the list of OS's to use a monotonic clock on.

What I don't understand is why is init_get_clock() not called anywhere?

It's marked as a constructor so the C runtime will call it.

Quoted 5 lines
include/qemu/timer.h +0 -0
index 1766b2d..8b86fa5 100644

include/qemu/timer.h extern int use_rt_clock; · line 125

Quoted 9 lines
include/qemu/timer.h +2 -1
@@ -118,7 +118,8 @@ extern int use_rt_clock;
 static inline int64_t get_clock(void)
 {
 #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
-    || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
+    || defined(__DragonFly__) || defined(__FreeBSD_kernel__) \
+    || defined(__OpenBSD__)
     if (use_rt_clock) {
         struct timespec ts;
         clock_gettime(CLOCK_MONOTONIC, &ts);

Rather than extending this already long OS dependent #if, could you write a configure test for whatever we're using and then just have a simple #ifdef CONFIG_WHATEVER ?

thanks
-- PMM