summaryrefslogtreecommitdiffstats
path: root/lib/timeutils.c
diff options
context:
space:
mode:
authorKarel Zak2014-11-18 14:35:21 +0100
committerKarel Zak2014-11-18 14:35:21 +0100
commit700031ade7cbcdcecf1205f98f50ed0da57c7493 (patch)
tree4ff850a1015129cb448577dd1c4d9ca461cbb041 /lib/timeutils.c
parentuuidd: Fixed a typo in daemon logging message (diff)
downloadkernel-qcow2-util-linux-700031ade7cbcdcecf1205f98f50ed0da57c7493.tar.gz
kernel-qcow2-util-linux-700031ade7cbcdcecf1205f98f50ed0da57c7493.tar.xz
kernel-qcow2-util-linux-700031ade7cbcdcecf1205f98f50ed0da57c7493.zip
misc: use monotonic time rater than gettimeofday
Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r--lib/timeutils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c
index b811041e4..bd3d40248 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -340,3 +340,26 @@ int parse_timestamp(const char *t, usec_t *usec)
return 0;
}
+
+
+int gettime_monotonic(struct timeval *tv)
+{
+#ifdef CLOCK_MONOTONIC
+ /* Can slew only by ntp and adjtime */
+ int ret;
+ struct timespec ts;
+
+# ifdef CLOCK_MONOTONIC_RAW
+ /* Linux specific, cant slew */
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
+# else
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
+# endif
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+ }
+ return ret;
+#else
+ return gettimeofday(tv, NULL);
+#endif
+}