diff --git a/src-clock/mtime_clock_stubs.c b/src-clock/mtime_clock_stubs.c index 93bdfc1..5668970 100644 --- a/src-clock/mtime_clock_stubs.c +++ b/src-clock/mtime_clock_stubs.c @@ -22,6 +22,9 @@ #elif defined(__unix__) || defined(__unix) #include + #if defined(__linux__) + #define OCAML_MTIME_LINUX + #endif #if defined(_POSIX_VERSION) #define OCAML_MTIME_POSIX #endif @@ -51,14 +54,14 @@ CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) static uint64_t start = 0L; if (start == 0L) { start = mach_absolute_time (); } if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } - uint64_t now = mach_absolute_time (); + uint64_t now = mach_continuous_time (); return caml_copy_int64 (((now - start) * scale.numer) / scale.denom); } CAMLprim value ocaml_mtime_clock_now_ns (value unit) { if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } - uint64_t now = mach_absolute_time (); + uint64_t now = mach_continuous_time (); return caml_copy_int64 ((now * scale.numer) / scale.denom); } @@ -75,6 +78,13 @@ CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) { static struct timespec start = {0}; struct timespec now; + clockid_t clockid; + +#if defined(OCAML_MTIME_LINUX) + clockid = CLOCK_BOOTTIME; +#else + clockid = CLOCK_MONOTONIC; +#endif if (start.tv_sec == 0) {