1 #ifndef _LTTNG_WRAPPER_TIMER_H
2 #define _LTTNG_WRAPPER_TIMER_H
7 * wrapper around linux/timer.h.
9 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/version.h>
27 #include <linux/timer.h>
28 #include <lttng-kernel-version.h>
31 * In the olden days, pinned timers were initialized normaly with init_timer()
32 * and then modified with mod_timer_pinned().
34 * Then came kernel 4.8.0 and they had to be initilized as pinned with
35 * init_timer_pinned() and then modified as regular timers with mod_timer().
37 * Then came kernel 4.15.0 with a new timer API where init_timer() is no more.
38 * It's replaced by timer_setup() where pinned is now part of timer flags.
42 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
44 #define LTTNG_TIMER_PINNED TIMER_PINNED
45 #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list *
47 #define lttng_mod_timer_pinned(timer, expires) \
48 mod_timer(timer, expires)
50 #define lttng_from_timer(var, callback_timer, timer_fieldname) \
51 from_timer(var, callback_timer, timer_fieldname)
53 #define lttng_timer_setup(timer, callback, flags, unused) \
54 timer_setup(timer, callback, flags)
57 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */
60 # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \
61 || LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0))
63 #define lttng_init_timer_pinned(timer) \
64 init_timer_pinned(timer)
66 #define lttng_mod_timer_pinned(timer, expires) \
67 mod_timer(timer, expires)
69 # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
71 #define lttng_init_timer_pinned(timer) \
74 #define lttng_mod_timer_pinned(timer, expires) \
75 mod_timer_pinned(timer, expires)
77 # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
80 #define LTTNG_TIMER_PINNED TIMER_PINNED
81 #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long
83 /* timer_fieldname is unused prior to 4.15. */
84 #define lttng_from_timer(var, timer_data, timer_fieldname) \
85 ((typeof(var))timer_data)
87 static inline void lttng_timer_setup(struct timer_list
*timer
,
88 void (*function
)(LTTNG_TIMER_FUNC_ARG_TYPE
),
89 unsigned int flags
, void *data
)
91 if (flags
& LTTNG_TIMER_PINNED
)
92 lttng_init_timer_pinned(timer
);
96 timer
->function
= function
;
97 timer
->data
= (unsigned long)data
;
100 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */
102 #endif /* _LTTNG_WRAPPER_TIMER_H */