Commit | Line | Data |
---|---|---|
152fe7fc MJ |
1 | #ifndef _LTTNG_WRAPPER_TIMER_H |
2 | #define _LTTNG_WRAPPER_TIMER_H | |
3 | ||
4 | /* | |
5 | * wrapper/timer.h | |
6 | * | |
7 | * wrapper around linux/timer.h. | |
8 | * | |
9 | * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com> | |
10 | * | |
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. | |
15 | * | |
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. | |
20 | * | |
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 | |
24 | */ | |
25 | ||
26 | #include <linux/version.h> | |
27 | #include <linux/timer.h> | |
28 | #include <lttng-kernel-version.h> | |
29 | ||
9ee5fb4a MJ |
30 | /* |
31 | * In the olden days, pinned timers were initialized normaly with init_timer() | |
32 | * and then modified with mod_timer_pinned(). | |
33 | * | |
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(). | |
36 | * | |
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. | |
39 | */ | |
40 | ||
41 | ||
42 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)) | |
43 | ||
44 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
45 | #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list * | |
46 | ||
47 | #define lttng_mod_timer_pinned(timer, expires) \ | |
48 | mod_timer(timer, expires) | |
49 | ||
50 | #define lttng_from_timer(var, callback_timer, timer_fieldname) \ | |
51 | from_timer(var, callback_timer, timer_fieldname) | |
52 | ||
53 | #define lttng_timer_setup(timer, callback, flags, unused) \ | |
54 | timer_setup(timer, callback, flags) | |
55 | ||
152fe7fc | 56 | |
9ee5fb4a MJ |
57 | #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */ |
58 | ||
59 | ||
60 | # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \ | |
e9f828cc | 61 | || LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) |
152fe7fc | 62 | |
9ee5fb4a | 63 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
64 | init_timer_pinned(timer) |
65 | ||
9ee5fb4a MJ |
66 | #define lttng_mod_timer_pinned(timer, expires) \ |
67 | mod_timer(timer, expires) | |
152fe7fc | 68 | |
9ee5fb4a | 69 | # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ |
152fe7fc | 70 | |
9ee5fb4a | 71 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
72 | init_timer(timer) |
73 | ||
9ee5fb4a MJ |
74 | #define lttng_mod_timer_pinned(timer, expires) \ |
75 | mod_timer_pinned(timer, expires) | |
76 | ||
77 | # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ | |
78 | ||
79 | ||
80 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
81 | #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long | |
82 | ||
83 | /* timer_fieldname is unused prior to 4.15. */ | |
84 | #define lttng_from_timer(var, timer_data, timer_fieldname) \ | |
85 | ((typeof(var))timer_data) | |
86 | ||
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) | |
152fe7fc | 90 | { |
9ee5fb4a MJ |
91 | if (flags & LTTNG_TIMER_PINNED) |
92 | lttng_init_timer_pinned(timer); | |
93 | else | |
94 | init_timer(timer); | |
95 | ||
96 | timer->function = function; | |
97 | timer->data = (unsigned long)data; | |
152fe7fc MJ |
98 | } |
99 | ||
9ee5fb4a | 100 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */ |
152fe7fc MJ |
101 | |
102 | #endif /* _LTTNG_WRAPPER_TIMER_H */ |