1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
5 * wrapper around linux/timer.h.
7 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
10 #ifndef _LTTNG_WRAPPER_TIMER_H
11 #define _LTTNG_WRAPPER_TIMER_H
13 #include <lttng-kernel-version.h>
14 #include <linux/timer.h>
15 #include <lttng-kernel-version.h>
18 * In the olden days, pinned timers were initialized normaly with init_timer()
19 * and then modified with mod_timer_pinned().
21 * Then came kernel 4.8.0 and they had to be initilized as pinned with
22 * init_timer_pinned() and then modified as regular timers with mod_timer().
24 * Then came kernel 4.15.0 with a new timer API where init_timer() is no more.
25 * It's replaced by timer_setup() where pinned is now part of timer flags.
29 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))
31 #define LTTNG_TIMER_PINNED TIMER_PINNED
32 #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list *
34 #define lttng_mod_timer_pinned(timer, expires) \
35 mod_timer(timer, expires)
37 #define lttng_from_timer(var, callback_timer, timer_fieldname) \
38 from_timer(var, callback_timer, timer_fieldname)
40 #define lttng_timer_setup(timer, callback, flags, unused) \
41 timer_setup(timer, callback, flags)
44 #else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */
47 # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \
48 || LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0))
50 #define lttng_init_timer_pinned(timer) \
51 init_timer_pinned(timer)
53 #define lttng_mod_timer_pinned(timer, expires) \
54 mod_timer(timer, expires)
56 # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
58 #define lttng_init_timer_pinned(timer) \
61 #define lttng_mod_timer_pinned(timer, expires) \
62 mod_timer_pinned(timer, expires)
64 # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
67 #define LTTNG_TIMER_PINNED TIMER_PINNED
68 #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long
70 /* timer_fieldname is unused prior to 4.15. */
71 #define lttng_from_timer(var, timer_data, timer_fieldname) \
72 ((typeof(var))timer_data)
74 static inline void lttng_timer_setup(struct timer_list
*timer
,
75 void (*function
)(LTTNG_TIMER_FUNC_ARG_TYPE
),
76 unsigned int flags
, void *data
)
78 if (flags
& LTTNG_TIMER_PINNED
)
79 lttng_init_timer_pinned(timer
);
83 timer
->function
= function
;
84 timer
->data
= (unsigned long)data
;
87 #endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */
89 #endif /* _LTTNG_WRAPPER_TIMER_H */