Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
152fe7fc MJ |
3 | * wrapper/timer.h |
4 | * | |
5 | * wrapper around linux/timer.h. | |
6 | * | |
7 | * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com> | |
152fe7fc MJ |
8 | */ |
9 | ||
9f36eaed MJ |
10 | #ifndef _LTTNG_WRAPPER_TIMER_H |
11 | #define _LTTNG_WRAPPER_TIMER_H | |
12 | ||
152fe7fc MJ |
13 | #include <linux/version.h> |
14 | #include <linux/timer.h> | |
15 | #include <lttng-kernel-version.h> | |
16 | ||
1fd97f9f MJ |
17 | /* |
18 | * In the olden days, pinned timers were initialized normaly with init_timer() | |
19 | * and then modified with mod_timer_pinned(). | |
20 | * | |
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(). | |
23 | * | |
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. | |
26 | */ | |
27 | ||
28 | ||
29 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)) | |
30 | ||
31 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
32 | #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list * | |
33 | ||
34 | #define lttng_mod_timer_pinned(timer, expires) \ | |
35 | mod_timer(timer, expires) | |
36 | ||
37 | #define lttng_from_timer(var, callback_timer, timer_fieldname) \ | |
38 | from_timer(var, callback_timer, timer_fieldname) | |
39 | ||
40 | #define lttng_timer_setup(timer, callback, flags, unused) \ | |
41 | timer_setup(timer, callback, flags) | |
42 | ||
152fe7fc | 43 | |
1fd97f9f MJ |
44 | #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */ |
45 | ||
46 | ||
47 | # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \ | |
e9f828cc | 48 | || LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) |
152fe7fc | 49 | |
1fd97f9f | 50 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
51 | init_timer_pinned(timer) |
52 | ||
1fd97f9f MJ |
53 | #define lttng_mod_timer_pinned(timer, expires) \ |
54 | mod_timer(timer, expires) | |
152fe7fc | 55 | |
1fd97f9f | 56 | # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ |
152fe7fc | 57 | |
1fd97f9f | 58 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
59 | init_timer(timer) |
60 | ||
1fd97f9f MJ |
61 | #define lttng_mod_timer_pinned(timer, expires) \ |
62 | mod_timer_pinned(timer, expires) | |
63 | ||
64 | # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ | |
65 | ||
66 | ||
67 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
68 | #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long | |
69 | ||
70 | /* timer_fieldname is unused prior to 4.15. */ | |
71 | #define lttng_from_timer(var, timer_data, timer_fieldname) \ | |
72 | ((typeof(var))timer_data) | |
73 | ||
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) | |
152fe7fc | 77 | { |
1fd97f9f MJ |
78 | if (flags & LTTNG_TIMER_PINNED) |
79 | lttng_init_timer_pinned(timer); | |
80 | else | |
81 | init_timer(timer); | |
82 | ||
83 | timer->function = function; | |
84 | timer->data = (unsigned long)data; | |
152fe7fc MJ |
85 | } |
86 | ||
1fd97f9f | 87 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */ |
152fe7fc MJ |
88 | |
89 | #endif /* _LTTNG_WRAPPER_TIMER_H */ |