All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
@ 2013-04-02 15:42 Brad Smith
  2013-04-02 16:45 ` Paolo Bonzini
  0 siblings, 1 reply; 10+ messages in thread
From: Brad Smith @ 2013-04-02 15:42 UTC (permalink / raw)
  To: qemu-devel

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 <brad@comstyle.com>

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.

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-02 15:42 [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test Brad Smith
@ 2013-04-02 16:45 ` Paolo Bonzini
  2013-04-02 22:28   ` Brad Smith
  2013-04-02 22:52   ` Peter Maydell
  0 siblings, 2 replies; 10+ messages in thread
From: Paolo Bonzini @ 2013-04-02 16:45 UTC (permalink / raw)
  To: Brad Smith; +Cc: qemu-devel

Il 02/04/2013 17:42, Brad Smith ha scritto:
> 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().

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

> 
> Signed-off-by: Brad Smith <brad@comstyle.com>
> 
> 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) {
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-02 16:45 ` Paolo Bonzini
@ 2013-04-02 22:28   ` Brad Smith
  2013-04-02 22:52   ` Peter Maydell
  1 sibling, 0 replies; 10+ messages in thread
From: Brad Smith @ 2013-04-02 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini

On Tue, Apr 02, 2013 at 06:45:17PM +0200, Paolo Bonzini wrote:
> Il 02/04/2013 17:42, Brad Smith ha scritto:
> > 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().
> 
> 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.

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-02 16:45 ` Paolo Bonzini
  2013-04-02 22:28   ` Brad Smith
@ 2013-04-02 22:52   ` Peter Maydell
  2013-04-03  8:18     ` Paolo Bonzini
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2013-04-02 22:52 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Brad Smith

On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 02/04/2013 17:42, Brad Smith ha scritto:
>> 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().
>
> 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.

> Otherwise, you might as well use "#ifdef CLOCK_MONOTONIC" and skip the
> configure test completely.

Tempting.

-- PMM

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-02 22:52   ` Peter Maydell
@ 2013-04-03  8:18     ` Paolo Bonzini
  2013-04-03 19:22       ` Brad Smith
  0 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2013-04-03  8:18 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Brad Smith

Il 03/04/2013 00:52, Peter Maydell ha scritto:
> On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Il 02/04/2013 17:42, Brad Smith ha scritto:
>>> 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().
>>
>> 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.

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

>> Otherwise, you might as well use "#ifdef CLOCK_MONOTONIC" and skip the
>> configure test completely.
> 
> Tempting.
> 
> -- PMM
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-03  8:18     ` Paolo Bonzini
@ 2013-04-03 19:22       ` Brad Smith
  2013-04-03 20:00         ` Paolo Bonzini
                           ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Brad Smith @ 2013-04-03 19:22 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote:
> Il 03/04/2013 00:52, Peter Maydell ha scritto:
> > On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
> >> Il 02/04/2013 17:42, Brad Smith ha scritto:
> >>> 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().
> >>
> >> 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.
> 
> 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
> 
> >> 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.


diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 1766b2d..c363190 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 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..95e0847 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 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.

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-03 19:22       ` Brad Smith
@ 2013-04-03 20:00         ` Paolo Bonzini
  2013-04-03 20:07         ` Brad Smith
  2013-04-04 17:21         ` Brad Smith
  2 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2013-04-03 20:00 UTC (permalink / raw)
  To: Brad Smith; +Cc: Peter Maydell, qemu-devel


> On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote:
> > Il 03/04/2013 00:52, Peter Maydell ha scritto:
> > > On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
> > >> Il 02/04/2013 17:42, Brad Smith ha scritto:
> > >>> 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().
> > >>
> > >> 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.
> > 
> > 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
> > 
> > >> 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.
> 
> 
> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 1766b2d..c363190 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 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..95e0847 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 CLOCK_MONOTONIC
>      {
>          struct timespec ts;
>          if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-03 19:22       ` Brad Smith
  2013-04-03 20:00         ` Paolo Bonzini
@ 2013-04-03 20:07         ` Brad Smith
  2013-04-04 17:21         ` Brad Smith
  2 siblings, 0 replies; 10+ messages in thread
From: Brad Smith @ 2013-04-03 20:07 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

On Wed, Apr 03, 2013 at 03:22:24PM -0400, Brad Smith wrote:
> On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote:
> > Il 03/04/2013 00:52, Peter Maydell ha scritto:
> > > On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
> > >> Il 02/04/2013 17:42, Brad Smith ha scritto:
> > >>> 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().
> > >>
> > >> 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.
> > 
> > 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
> > 
> > >> 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.


Signed-off-by: Brad Smith <brad@comstyle.com>

> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 1766b2d..c363190 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 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..95e0847 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 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-03 19:22       ` Brad Smith
  2013-04-03 20:00         ` Paolo Bonzini
  2013-04-03 20:07         ` Brad Smith
@ 2013-04-04 17:21         ` Brad Smith
  2013-04-05  0:22           ` Anthony Liguori
  2 siblings, 1 reply; 10+ messages in thread
From: Brad Smith @ 2013-04-04 17:21 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

On Wed, Apr 03, 2013 at 03:22:24PM -0400, Brad Smith wrote:
> On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote:
> > Il 03/04/2013 00:52, Peter Maydell ha scritto:
> > > On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
> > >> Il 02/04/2013 17:42, Brad Smith ha scritto:
> > >>> 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().
> > >>
> > >> 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.
> > 
> > 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
> > 
> > >> 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.

Any further comments?

> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 1766b2d..c363190 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 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..95e0847 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 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.
> 
> 

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test
  2013-04-04 17:21         ` Brad Smith
@ 2013-04-05  0:22           ` Anthony Liguori
  0 siblings, 0 replies; 10+ messages in thread
From: Anthony Liguori @ 2013-04-05  0:22 UTC (permalink / raw)
  To: Brad Smith, Paolo Bonzini; +Cc: Peter Maydell, qemu-devel

Brad Smith <brad@comstyle.com> writes:

> On Wed, Apr 03, 2013 at 03:22:24PM -0400, Brad Smith wrote:
>> On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote:
>> > Il 03/04/2013 00:52, Peter Maydell ha scritto:
>> > > On 2 April 2013 17:45, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> > >> Il 02/04/2013 17:42, Brad Smith ha scritto:
>> > >>> 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().
>> > >>
>> > >> 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.
>> > 
>> > 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
>> > 
>> > >> 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.
>
> Any further comments?

Please submit a top-level patch and I'll apply it.

Regards,

Anthony Liguori

>
>> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
>> index 1766b2d..c363190 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 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..95e0847 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 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.
>> 
>> 
>
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-04-05  0:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-02 15:42 [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test Brad Smith
2013-04-02 16:45 ` Paolo Bonzini
2013-04-02 22:28   ` Brad Smith
2013-04-02 22:52   ` Peter Maydell
2013-04-03  8:18     ` Paolo Bonzini
2013-04-03 19:22       ` Brad Smith
2013-04-03 20:00         ` Paolo Bonzini
2013-04-03 20:07         ` Brad Smith
2013-04-04 17:21         ` Brad Smith
2013-04-05  0:22           ` Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.