Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log.c | 4 ++--
lib/util.c | 20 +++++++++++++++++---
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index 8879cfd..0101bc6 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -125,7 +125,7 @@ qb_log_real_va_(struct qb_log_callsite *cs, va_list ap)
{
int32_t found_threaded;
struct qb_log_target *t;
- struct timeval tv;
+ struct timespec tv;
int32_t pos;
int len;
int32_t formatted = QB_FALSE;
@@ -152,7 +152,7 @@ qb_log_real_va_(struct qb_log_callsite *cs, va_list ap)
}
}
- gettimeofday(&tv, NULL);
+ qb_util_timespec_from_epoch_get(&tv);
/*
* 1 if we can find a threaded target that needs this log then post it
diff --git a/lib/util.c b/lib/util.c
index b261f47..b5dcafe 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -142,8 +142,11 @@ qb_util_nano_current_get(void)
uint64_t nano_monotonic;
struct timespec ts;
+#ifdef CLOCK_MONOTONIC_COARSE
+ clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
+#else
clock_gettime(CLOCK_MONOTONIC, &ts);
-
+#endif
nano_monotonic =
(ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t) ts.tv_nsec;
return (nano_monotonic);
@@ -154,9 +157,11 @@ qb_util_nano_from_epoch_get(void)
{
uint64_t nano_monotonic;
struct timespec ts;
-
+#ifdef CLOCK_REALTIME_COARSE
+ clock_gettime(CLOCK_REALTIME_COARSE, &ts);
+#else
clock_gettime(CLOCK_REALTIME, &ts);
-
+#endif
nano_monotonic =
(ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t) ts.tv_nsec;
return (nano_monotonic);
@@ -168,7 +173,11 @@ qb_util_nano_monotonic_hz(void)
uint64_t nano_monotonic_hz;
struct timespec ts;
+#ifdef CLOCK_MONOTONIC_COARSE
+ clock_getres(CLOCK_MONOTONIC_COARSE, &ts);
+#else
clock_getres(CLOCK_MONOTONIC, &ts);
+#endif
nano_monotonic_hz =
QB_TIME_NS_IN_SEC / ((ts.tv_sec * QB_TIME_NS_IN_SEC) + ts.tv_nsec);
@@ -179,8 +188,13 @@ qb_util_nano_monotonic_hz(void)
void
qb_util_timespec_from_epoch_get(struct timespec *ts)
{
+#ifdef CLOCK_REALTIME_COARSE
+ clock_gettime(CLOCK_REALTIME_COARSE, ts);
+#else
clock_gettime(CLOCK_REALTIME, ts);
+#endif
}
+
#else
uint64_t
qb_util_nano_current_get(void)
--
1.7.7.6