qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Remove support for CLOCK_MONOTONIC not being defined
@ 2020-02-01 17:22 Peter Maydell
  2020-02-04 13:17 ` Paolo Bonzini
  2020-02-04 13:30 ` Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2020-02-01 17:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini

Some older parts of QEMU's codebase assume that CLOCK_MONOTONIC
might not be defined by the host OS, and have workarounds to
deal with this. However, more recently (notably in commit
50290c002c045280f8d for qemu-img in mid-2019, but also much
earlier in 2011 in commit 22795174a37e0 for ui/spice-display.c)
we've written code that assumes CLOCK_MONOTONIC is always
defined. The only host OS anybody's ever noticed this on
is OSX 10.11 and earlier, which we don't support.

So we can assume that all our host OSes have the #define,
and we can remove some now-unnecessary ifdefs.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
I've left in the runtime-check in init_get_clock(), as it's
less easy to see if the fallback there is ever used.
---
 include/qemu/timer.h     |  5 +----
 util/qemu-timer-common.c | 11 ++++-------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 85bc6eb00b2..6a8b48b5a9d 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -838,14 +838,11 @@ extern int use_rt_clock;
 
 static inline int64_t get_clock(void)
 {
-#ifdef CLOCK_MONOTONIC
     if (use_rt_clock) {
         struct timespec ts;
         clock_gettime(CLOCK_MONOTONIC, &ts);
         return ts.tv_sec * 1000000000LL + ts.tv_nsec;
-    } else
-#endif
-    {
+    } else {
         /* XXX: using gettimeofday leads to problems if the date
            changes, so it should be avoided. */
         return get_clock_realtime();
diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c
index 06d084d3646..baf3317f745 100644
--- a/util/qemu-timer-common.c
+++ b/util/qemu-timer-common.c
@@ -49,14 +49,11 @@ int use_rt_clock;
 
 static void __attribute__((constructor)) init_get_clock(void)
 {
+    struct timespec ts;
+
     use_rt_clock = 0;
-#ifdef CLOCK_MONOTONIC
-    {
-        struct timespec ts;
-        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
-            use_rt_clock = 1;
-        }
+    if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
+        use_rt_clock = 1;
     }
-#endif
 }
 #endif
-- 
2.20.1



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

* Re: [PATCH] Remove support for CLOCK_MONOTONIC not being defined
  2020-02-01 17:22 [PATCH] Remove support for CLOCK_MONOTONIC not being defined Peter Maydell
@ 2020-02-04 13:17 ` Paolo Bonzini
  2020-02-04 13:30 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-02-04 13:17 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel

On 01/02/20 18:22, Peter Maydell wrote:
> Some older parts of QEMU's codebase assume that CLOCK_MONOTONIC
> might not be defined by the host OS, and have workarounds to
> deal with this. However, more recently (notably in commit
> 50290c002c045280f8d for qemu-img in mid-2019, but also much
> earlier in 2011 in commit 22795174a37e0 for ui/spice-display.c)
> we've written code that assumes CLOCK_MONOTONIC is always
> defined. The only host OS anybody's ever noticed this on
> is OSX 10.11 and earlier, which we don't support.
> 
> So we can assume that all our host OSes have the #define,
> and we can remove some now-unnecessary ifdefs.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I've left in the runtime-check in init_get_clock(), as it's
> less easy to see if the fallback there is ever used.
> ---
>  include/qemu/timer.h     |  5 +----
>  util/qemu-timer-common.c | 11 ++++-------
>  2 files changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> index 85bc6eb00b2..6a8b48b5a9d 100644
> --- a/include/qemu/timer.h
> +++ b/include/qemu/timer.h
> @@ -838,14 +838,11 @@ extern int use_rt_clock;
>  
>  static inline int64_t get_clock(void)
>  {
> -#ifdef CLOCK_MONOTONIC
>      if (use_rt_clock) {
>          struct timespec ts;
>          clock_gettime(CLOCK_MONOTONIC, &ts);
>          return ts.tv_sec * 1000000000LL + ts.tv_nsec;
> -    } else
> -#endif
> -    {
> +    } else {
>          /* XXX: using gettimeofday leads to problems if the date
>             changes, so it should be avoided. */
>          return get_clock_realtime();
> diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c
> index 06d084d3646..baf3317f745 100644
> --- a/util/qemu-timer-common.c
> +++ b/util/qemu-timer-common.c
> @@ -49,14 +49,11 @@ int use_rt_clock;
>  
>  static void __attribute__((constructor)) init_get_clock(void)
>  {
> +    struct timespec ts;
> +
>      use_rt_clock = 0;
> -#ifdef CLOCK_MONOTONIC
> -    {
> -        struct timespec ts;
> -        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
> -            use_rt_clock = 1;
> -        }
> +    if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
> +        use_rt_clock = 1;
>      }
> -#endif
>  }
>  #endif
> 

Queued, thanks.

Paolo



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

* Re: [PATCH] Remove support for CLOCK_MONOTONIC not being defined
  2020-02-01 17:22 [PATCH] Remove support for CLOCK_MONOTONIC not being defined Peter Maydell
  2020-02-04 13:17 ` Paolo Bonzini
@ 2020-02-04 13:30 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2020-02-04 13:30 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Paolo Bonzini

On Sat, 1 Feb 2020 at 17:22, Peter Maydell <peter.maydell@linaro.org> wrote:
> I've left in the runtime-check in init_get_clock(), as it's
> less easy to see if the fallback there is ever used.

That code was first added in 1dce7c3c2244 in 2006, so
it seems at least plausible that we could remove the
runtime-check too at some point. Somebody would need
to go through all our supported hosts and check that
CLOCK_MONOTONIC really did always work rather
than returning 0...

thanks
-- PMM


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

end of thread, other threads:[~2020-02-04 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-01 17:22 [PATCH] Remove support for CLOCK_MONOTONIC not being defined Peter Maydell
2020-02-04 13:17 ` Paolo Bonzini
2020-02-04 13:30 ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).