lttng-events.o lttng-abi.o lttng-string-utils.o \
lttng-probes.o lttng-context.o \
metadata-printer.o \
+ clock-utils.o \
ctf1-8.o \
lttng-context-pid.o lttng-context-procname.o \
lttng-context-prio.o lttng-context-nice.o \
--- /dev/null
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * src/clock-utils.h
+ *
+ * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
+ */
+
+/*
+ * Approximation of NTP time of day to clock monotonic correlation,
+ * taken at start of trace.
+ * Yes, this is only an approximation. Yes, we can (and will) do better
+ * in future versions.
+ * This function may return a negative offset. It may happen if the
+ * system sets the REALTIME clock to 0 after boot.
+ *
+ * Use 64bit timespec on kernels that have it, this makes 32bit arch
+ * y2038 compliant.
+ */
+
+#include <linux/types.h>
+
+#include <wrapper/time.h>
+#include <wrapper/trace-clock.h>
+
+int64_t trace_clock_measure_offset(void)
+{
+ uint64_t monotonic_avg, monotonic[2], realtime;
+ uint64_t tcf = trace_clock_freq();
+ int64_t offset;
+ unsigned long flags;
+#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
+ struct timespec64 rts = { 0, 0 };
+#else
+ struct timespec rts = { 0, 0 };
+#endif
+
+ /* Disable interrupts to increase correlation precision. */
+ local_irq_save(flags);
+ monotonic[0] = trace_clock_read64();
+#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
+ ktime_get_real_ts64(&rts);
+#else
+ getnstimeofday(&rts);
+#endif
+ monotonic[1] = trace_clock_read64();
+ local_irq_restore(flags);
+
+ monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
+ realtime = (uint64_t)rts.tv_sec * tcf;
+ if (tcf == NSEC_PER_SEC) {
+ realtime += rts.tv_nsec;
+ } else {
+ uint64_t n = rts.tv_nsec * tcf;
+
+ do_div(n, NSEC_PER_SEC);
+ realtime += n;
+ }
+ offset = (int64_t)realtime - monotonic_avg;
+ return offset;
+}
--- /dev/null
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * src/clock-utils.h
+ *
+ * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
+ */
+
+#ifndef LTTNG_CLOCK_UTILS_H
+#define LTTNG_CLOCK_UTILS_H
+
+#include <linux/types.h>
+
+int64_t trace_clock_measure_offset(void);
+
+#endif /* LTTNG_CLOCK_UTILS_H */
#include <lttng/events.h>
#include <lttng/events-internal.h>
-#include <wrapper/time.h>
#include "metadata-printer.h"
+#include "clock-utils.h"
static
int _lttng_field_statedump(struct lttng_kernel_session *session,
);
}
- /*
- * Approximation of NTP time of day to clock monotonic correlation,
- * taken at start of trace.
- * Yes, this is only an approximation. Yes, we can (and will) do better
- * in future versions.
- * This function may return a negative offset. It may happen if the
- * system sets the REALTIME clock to 0 after boot.
- *
- * Use 64bit timespec on kernels that have it, this makes 32bit arch
- * y2038 compliant.
- */
-int64_t measure_clock_offset(void)
-{
- uint64_t monotonic_avg, monotonic[2], realtime;
- uint64_t tcf = trace_clock_freq();
- int64_t offset;
- unsigned long flags;
-#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
- struct timespec64 rts = { 0, 0 };
-#else
- struct timespec rts = { 0, 0 };
-#endif
-
- /* Disable interrupts to increase correlation precision. */
- local_irq_save(flags);
- monotonic[0] = trace_clock_read64();
-#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
- ktime_get_real_ts64(&rts);
-#else
- getnstimeofday(&rts);
-#endif
- monotonic[1] = trace_clock_read64();
- local_irq_restore(flags);
-
- monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
- realtime = (uint64_t) rts.tv_sec * tcf;
- if (tcf == NSEC_PER_SEC) {
- realtime += rts.tv_nsec;
- } else {
- uint64_t n = rts.tv_nsec * tcf;
-
- do_div(n, NSEC_PER_SEC);
- realtime += n;
- }
- offset = (int64_t) realtime - monotonic_avg;
- return offset;
-}
-
static
int print_escaped_ctf_string(struct lttng_kernel_session *session, const char *string)
{
"};\n\n",
trace_clock_description(),
(unsigned long long) trace_clock_freq(),
- (long long) measure_clock_offset()
+ (long long) trace_clock_measure_offset()
);
if (ret)
goto end;