qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test


From: Brad Smith
Subject: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
Date: Tue, 2 Apr 2013 11:42:17 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Replace the hardcoded list of OS's utilizing clock_gettime() for monotonic
time with a configure test. This is to fix the use of monotonic time on
OpenBSD but allows for other POSIX compliant OS's such as NetBSD to also
utilize clock_gettime().


Signed-off-by: Brad Smith <address@hidden>

diff --git a/configure b/configure
index fbea75e..352d6a6 100755
--- a/configure
+++ b/configure
@@ -2896,6 +2896,21 @@ if test "$darwin" != "yes" -a "$mingw32" != "yes" -a 
"$solaris" != yes -a \
 fi
 
 ##########################################
+# clock_gettime() probe, used for monotonic time
+clock_monotonic="no"
+cat > $TMPC << EOF
+#include <time.h>
+int main(void)
+{
+    clock_gettime(CLOCK_MONOTONIC, NULL);
+    return 0;  
+}   
+EOF
+if compile_prog "" "" ; then
+   clock_monotonic="yes"
+fi
+
+##########################################
 # spice probe
 if test "$spice" != "no" ; then
   cat > $TMPC << EOF
@@ -3671,6 +3686,9 @@ fi
 if test "$bswap_h" = "yes" ; then
   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
 fi
+if test "$clock_monotonic" = "yes" ; then
+  echo "CONFIG_CLOCK_MONOTONIC=y" >> $config_host_mak
+fi
 if test "$curl" = "yes" ; then
   echo "CONFIG_CURL=y" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 1766b2d..d87dfa4 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -117,8 +117,7 @@ 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__)
+#ifdef CONFIG_CLOCK_MONOTONIC
     if (use_rt_clock) {
         struct timespec ts;
         clock_gettime(CLOCK_MONOTONIC, &ts);
diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c
index 16f5e75..1506942 100644
--- a/util/qemu-timer-common.c
+++ b/util/qemu-timer-common.c
@@ -49,9 +49,7 @@ int use_rt_clock;
 static void __attribute__((constructor)) init_get_clock(void)
 {
     use_rt_clock = 0;
-#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 
500000) \
-    || defined(__DragonFly__) || defined(__FreeBSD_kernel__) \
-    || defined(__OpenBSD__)
+#ifdef CONFIG_CLOCK_MONOTONIC
     {
         struct timespec ts;
         if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]