From 3636085f77c7fec384297a79fea15447a7d74fc0 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 24 Feb 2020 14:50:20 -0500 Subject: [PATCH] fix: use timespec64 on kernels that have it This fixes v5.6 which has hidden 'struct timespec' from kernel code and makes 32bit archs y2038 compliant on v3.17 and newer. Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Change-Id: I1daedc4a93cbbebb8f5a1d99c4619cb27f6a9e07 --- lttng-events.c | 14 +++++++++++++- wrapper/time.h | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 wrapper/time.h diff --git a/lttng-events.c b/lttng-events.c index a4160f1c..cc932bf6 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -43,6 +43,7 @@ #include #include #include +#include #define METADATA_CACHE_DEFAULT_SIZE 4096 @@ -2483,6 +2484,9 @@ int _lttng_event_header_declare(struct lttng_session *session) * 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. */ static int64_t measure_clock_offset(void) @@ -2490,13 +2494,21 @@ int64_t measure_clock_offset(void) uint64_t monotonic_avg, monotonic[2], realtime; uint64_t tcf = trace_clock_freq(); int64_t offset; - struct timespec rts = { 0, 0 }; 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); diff --git a/wrapper/time.h b/wrapper/time.h new file mode 100644 index 00000000..362f314a --- /dev/null +++ b/wrapper/time.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) + * + * wrapper/time.h + * + * Copyright (C) 2020 Michael Jeanson + * Copyright (C) 2020 Mathieu Desnoyers + */ + +#ifndef _LTTNG_WRAPPER_TIME_H +#define _LTTNG_WRAPPER_TIME_H + +#include + +/* + * Use 64bit timespec on kernels that have it, this makes 32bit arch + * y2038 compliant. + */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)) +# define LTTNG_KERNEL_HAS_TIMESPEC64 +#endif + +#endif /* _LTTNG_WRAPPER_TIME_H */ -- 2.34.1