1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
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>
17 * In the olden days, pinned timers were initialized normaly with init_timer()
18 * and then modified with mod_timer_pinned().
20 * Then came kernel 4.8.0 and they had to be initilized as pinned with
21 * init_timer_pinned() and then modified as regular timers with mod_timer().
23 * Then came kernel 4.15.0 with a new timer API where init_timer() is no more.
24 * It's replaced by timer_setup() where pinned is now part of timer flags.
28 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))
30 #define LTTNG_TIMER_PINNED TIMER_PINNED
31 #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list *
33 #define lttng_mod_timer_pinned(timer, expires) \
34 mod_timer(timer, expires)
36 #define lttng_from_timer(var, callback_timer, timer_fieldname) \
37 from_timer(var, callback_timer, timer_fieldname)
39 #define lttng_timer_setup(timer, callback, flags, unused) \
40 timer_setup(timer, callback, flags)
43 #else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */
46 # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \
47 || LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0))
49 #define lttng_init_timer_pinned(timer) \
50 init_timer_pinned(timer)
52 #define lttng_mod_timer_pinned(timer, expires) \
53 mod_timer(timer, expires)
55 # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
57 #define lttng_init_timer_pinned(timer) \
60 #define lttng_mod_timer_pinned(timer, expires) \
61 mod_timer_pinned(timer, expires)
63 # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
66 #define LTTNG_TIMER_PINNED TIMER_PINNED
67 #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long
69 /* timer_fieldname is unused prior to 4.15. */
70 #define lttng_from_timer(var, timer_data, timer_fieldname) \
71 ((typeof(var))timer_data)
73 static inline void lttng_timer_setup(struct timer_list
*timer
,
74 void (*function
)(LTTNG_TIMER_FUNC_ARG_TYPE
),
75 unsigned int flags
, void *data
)
77 if (flags
& LTTNG_TIMER_PINNED
)
78 lttng_init_timer_pinned(timer
);
82 timer
->function
= function
;
83 timer
->data
= (unsigned long)data
;
86 #endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */
88 #endif /* _LTTNG_WRAPPER_TIMER_H */