+extern struct lttng_ust_trace_clock *lttng_ust_trace_clock;
+
+/* Use the kernel MONOTONIC clock. */
+
+static __inline__
+uint64_t trace_clock_read64_monotonic(void)
+{
+ struct timespec ts;
+
+ if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts))) {
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ }
+ return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
+}
+
+static __inline__
+uint64_t trace_clock_read64(void)
+{
+ struct lttng_ust_trace_clock *ltc = CMM_LOAD_SHARED(lttng_ust_trace_clock);
+
+ if (caa_likely(!ltc)) {
+ return trace_clock_read64_monotonic();
+ } else {
+ cmm_read_barrier_depends(); /* load ltc before content */
+ return ltc->read64();
+ }
+}