Add configure clock_gettime() monotonic time test
PATCH 1/1 Add configure clock_gettime() monotonic time test
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().
configure +18 -0
@@ -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
include/qemu/timer.h +1 -2
@@ -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);
util/qemu-timer-common.c +1 -3
@@ -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 ) {
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().
I thought the list of OSes was supposed to filter out those that somehow had a broken CLOCK_MONOTONIC.
Otherwise, you might as well use "#ifdef CLOCK_MONOTONIC" and skip the configure test completely.
Paolo
Quoted 69 lines
Signed-off-by Brad Smith <[email protected]>configure +18
-0@@ -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_makinclude/qemu/timer.h +1
-2@@ -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);util/qemu-timer-common.c +1
-3@@ -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 ) {
Quoted 11 lines · Paolo Bonzini
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.
I only wrote the test as that was what was suggested and even if there are OS's that have broken monotonic support it is better to put any exclusion logic in the configure script over having more hardcoded lists of OS's directly in the code. What OS's have broken monotonic support?
I would have no problem going in that direction if no one can actually come up with an OS (or more) that have monotonic support but it is somehow broken; as in having clock_gettime() and the CLOCK_MONOTONIC define but not functioning properly.
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Quoted 8 lines · Paolo Bonzini
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.
Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef __linux__ which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.
Google does suggest that some OSes do provide a CLOCK_MONOTONIC but clock_gettime(CLOCK_MONOTONIC) always fails, eg Centos 3.
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.
Tempting.
-- PMM
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.
Quoted 7 lines
Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.
It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 8 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.Tempting.
-- PMM
Quoted 16 lines · Paolo Bonzini
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 15 lines · Paolo Bonzini
Quoted 8 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.
Quoted 15 lines
Quoted 2 lines
Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 6 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.Tempting.
-- PMM
Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris.
include/qemu/timer.h +1 -2
@@ -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 CLOCK_MONOTONIC if (use_rt_clock) {struct timespec ts;clock_gettime (CLOCK_MONOTONIC , &ts);
util/qemu-timer-common.c +1 -3
@@ -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 CLOCK_MONOTONIC {struct timespec ts;if (clock_gettime (CLOCK_MONOTONIC , &ts) ==0 ) {
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Paolo Bonzini
Reviewed-byQuoted 70 lines · Paolo Bonzini
Quoted 18 lines
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 17 lines · Paolo Bonzini
Quoted 10 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 6 lines
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
utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.Quoted 15 lines
Quoted 2 lines
Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 6 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.Tempting.
-- PMM
Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris.
include/qemu/timer.h +1
-2@@ -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 CLOCK_MONOTONIC if (use_rt_clock) {struct timespec ts;clock_gettime(CLOCK_MONOTONIC, &ts);util/qemu-timer-common.c +1
-3@@ -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 CLOCK_MONOTONIC {struct timespec ts;
Quoted 2 lines
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {Paolo
Quoted 29 lines · Brad Smith
Quoted 28 lines · Paolo Bonzini
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Quoted 7 lines
Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 3 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Tempting.
-- PMM
Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris.
Quoted 29 lines
include/qemu/timer.h +1
-2@@ -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 CLOCK_MONOTONIC if (use_rt_clock) {struct timespec ts;clock_gettime (CLOCK_MONOTONIC , &ts);util/qemu-timer-common.c +1
-3@@ -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 CLOCK_MONOTONIC {struct timespec ts;if (clock_gettime (CLOCK_MONOTONIC , &ts) ==0 ) {
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Quoted 29 lines · Brad Smith
Quoted 28 lines · Paolo Bonzini
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Quoted 7 lines
Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 3 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Tempting.
-- PMM
Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris.
Any further comments?
Quoted 36 lines
include/qemu/timer.h +1
-2@@ -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 CLOCK_MONOTONIC if (use_rt_clock) {struct timespec ts;clock_gettime (CLOCK_MONOTONIC , &ts);util/qemu-timer-common.c +1
-3@@ -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 CLOCK_MONOTONIC {struct timespec ts;if (clock_gettime (CLOCK_MONOTONIC , &ts) ==0 ) {Signature · 4 lines
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Quoted 30 lines · Brad Smith
Quoted 29 lines · Brad Smith
Quoted 28 lines · Paolo Bonzini
Il 03/04/2013 00:52, Peter Maydell ha scritto:
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines
Il 02/04/2013 17:42, Brad Smith ha scritto:
Quoted 4 lines
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 utilizeclock_gettime().I thought the list of OSes was supposed to filter out those that somehow had a broken
CLOCK_MONOTONIC.Quoted 7 lines
Judging from wading through git history, it's mostly just historic accretion from an initial #ifdef
__linux__which was put in by Fabrice way back when configure was barely doing compile-this-code checks at all.Google does suggest that some OSes do provide a
CLOCK_MONOTONICbutclock_gettime(CLOCK_MONOTONIC)always fails, eg Centos 3.It would already fail, and no one reported it.
CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU.
Paolo
Quoted 3 lines
Quoted 2 lines
Otherwise, you might as well use "#ifdef
CLOCK_MONOTONIC" and skip the configure test completely.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Tempting.
-- PMM
Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris.
Any further comments?
Please submit a top-level patch and I'll apply it.
Regards,
Anthony Liguori
Quoted 42 lines
Quoted 37 lines
include/qemu/timer.h +1
-2@@ -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 CLOCK_MONOTONIC if (use_rt_clock) {struct timespec ts;clock_gettime (CLOCK_MONOTONIC , &ts);util/qemu-timer-common.c +1
-3@@ -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 CLOCK_MONOTONIC {struct timespec ts;if (clock_gettime (CLOCK_MONOTONIC , &ts) ==0 ) {Signature · 4 lines
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Signature · 3 lines
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.