Skip to contentSkip to conversation

qemu-timer: fix get_clock() gettimeofday() fallback #ifdef

PATCH In review Stefan Hajnoczi 4 participants 5 messages Aug 6, 2013 – Sep 24, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-timer: fix get_clock() gettimeofday() fallback #ifdef

If CLOCK_MONOTONIC is not defined by system headers we use gettimeofday(2). Apparently this is not used very often since no one noticed the #ifdef was actually broken and left the function definition unterminated.

---
 include/qemu/timer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/timer.h +1 -1
index 9dd206c..e3299b8 100644
@@ -125,8 +125,8 @@ static inline int64_t get_clock(void)
            changes, so it should be avoided. */
         return get_clock_realtime();
     }
-}
 #endif
+}
 
 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 4 lines · Stefan Hajnoczi

If CLOCK_MONOTONIC is not defined by system headers we use gettimeofday(2). Apparently this is not used very often since no one noticed the #ifdef was actually broken and left the function definition unterminated.

Can you show what this supposedly fixes? This code built just fine on OpenBSD before d05ef160453e98546a4197496dc8a3cb2defac53.

Quoted 20 lines
---
  include/qemu/timer.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/timer.h +1 -1
index 9dd206c..e3299b8 100644
@@ -125,8 +125,8 @@ static inline int64_t get_clock(void)
             changes, so it should be avoided. */
          return get_clock_realtime();
      }
-}
  #endif
+}
 
  void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
  void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
#2 lore raw
Quoted 8 lines · Brad Smith
Quoted 4 lines · Stefan Hajnoczi

If CLOCK_MONOTONIC is not defined by system headers we use gettimeofday(2). Apparently this is not used very often since no one noticed the #ifdef was actually broken and left the function definition unterminated.

Can you show what this supposedly fixes? This code built just fine on OpenBSD before d05ef160453e98546a4197496dc8a3cb2defac53.

Hi Brad, thanks for pointing this out. I misread the code:

  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      <--- thought this was #else
      {
          /* XXX: using gettimeofday leads to problems if the date
             changes, so it should be avoided. */
          return get_clock_realtime();
      }
  }
  #endif      <--- this is actually for #ifdef _WIN32

So I thought the function definition would not be terminated properly. But after you mentioned it, my change makes no sense.

Dropping this patch.

Thanks,
Stefan

#3 lore raw
In reply to Stefan Hajnoczi

Quoting Stefan Hajnoczi (2013-08-06 06:48:58)

Quoted 6 lines

If CLOCK_MONOTONIC is not defined by system headers we use gettimeofday(2). Apparently this is not used very often since no one noticed the #ifdef was actually broken and left the function definition unterminated.

Ping, looking to pull this in for stable.

Quoted 20 lines
---
 include/qemu/timer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/timer.h +1 -1
index 9dd206c..e3299b8 100644
@@ -125,8 +125,8 @@ static inline int64_t get_clock(void)
            changes, so it should be avoided. */
         return get_clock_realtime();
     }
-}
 #endif
+}
 
 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
Signature · 1 line
1.8.1.4
#4 lore raw

Quoting Michael Roth (2013-09-24 16:58:22)

Quoted 9 lines

Quoting Stefan Hajnoczi (2013-08-06 06:48:58)

Quoted 6 lines

If CLOCK_MONOTONIC is not defined by system headers we use gettimeofday(2). Apparently this is not used very often since no one noticed the #ifdef was actually broken and left the function definition unterminated.

Ping, looking to pull this in for stable.

Bah, ignore this. Didn't see previous discussion.

Quoted 21 lines
Quoted 21 lines
---
 include/qemu/timer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/timer.h +1 -1
index 9dd206c..e3299b8 100644
@@ -125,8 +125,8 @@ static inline int64_t get_clock(void)
            changes, so it should be avoided. */
         return get_clock_realtime();
     }
-}
 #endif
+}
 
 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
Signature · 1 line
1.8.1.4