check clock resolution
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 3 Nov 2025 18:19:33 +0000 (19:19 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 3 Nov 2025 18:19:33 +0000 (19:19 +0100)
mtime.c
mtime.h

diff --git a/mtime.c b/mtime.c
index 67c6ee7f0c91d97160af589dab0468a49d11fbce..f1ca3641c7864fec7d5b68613f0186fe806c15c5 100644 (file)
--- a/mtime.c
+++ b/mtime.c
@@ -1,7 +1,20 @@
+#include <stdio.h>
 #include <time.h>
 
 #include "mtime.h"
 
+int res_timestamp (void)
+{
+    struct timespec ts;
+    int res = 0;
+    if (clock_getres (CLOCK_REALTIME, &ts) == -1) {
+        fprintf (stderr, "error: clock_getres\n");
+    } else {
+        res = ts.tv_nsec;
+    }
+    return res;
+}
+
 dts_t diff_timestamp  (ts_t *ts1, ts_t *ts2)
 {
     return  (dts_t)(ts1->tv_sec - ts2->tv_sec) * 1000000000 +
diff --git a/mtime.h b/mtime.h
index 369d046886c4391451a68337b5576cbc21de707a..69343b00a8cf071d7acccfefc1eaee07a208f629 100644 (file)
--- a/mtime.h
+++ b/mtime.h
@@ -9,6 +9,8 @@ typedef struct timespec ts_t;
 
 typedef long int dts_t;
 
+int res_timestamp (void);
+
 #define sys_timestamp(ts) clock_gettime (CLOCK_REALTIME, (ts))
 
 dts_t diff_timestamp  (ts_t *ts1, ts_t *ts2);