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 | ||
5f4c791e | 13 | #include <lttng/kernel-version.h> |
152fe7fc | 14 | #include <linux/timer.h> |
152fe7fc | 15 | |
1fd97f9f MJ |
16 | /* |
17 | * In the olden days, pinned timers were initialized normaly with init_timer() | |
18 | * and then modified with mod_timer_pinned(). | |
19 | * | |
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(). | |
22 | * | |
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. | |
25 | */ | |
26 | ||
27 | ||
5f4c791e | 28 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0)) |
1fd97f9f MJ |
29 | |
30 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
31 | #define LTTNG_TIMER_FUNC_ARG_TYPE struct timer_list * | |
32 | ||
33 | #define lttng_mod_timer_pinned(timer, expires) \ | |
34 | mod_timer(timer, expires) | |
35 | ||
36 | #define lttng_from_timer(var, callback_timer, timer_fieldname) \ | |
37 | from_timer(var, callback_timer, timer_fieldname) | |
38 | ||
39 | #define lttng_timer_setup(timer, callback, flags, unused) \ | |
40 | timer_setup(timer, callback, flags) | |
41 | ||
152fe7fc | 42 | |
5f4c791e | 43 | #else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */ |
1fd97f9f MJ |
44 | |
45 | ||
46 | # if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \ | |
5f4c791e | 47 | || LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0)) |
152fe7fc | 48 | |
1fd97f9f | 49 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
50 | init_timer_pinned(timer) |
51 | ||
1fd97f9f MJ |
52 | #define lttng_mod_timer_pinned(timer, expires) \ |
53 | mod_timer(timer, expires) | |
152fe7fc | 54 | |
1fd97f9f | 55 | # else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ |
152fe7fc | 56 | |
1fd97f9f | 57 | #define lttng_init_timer_pinned(timer) \ |
152fe7fc MJ |
58 | init_timer(timer) |
59 | ||
1fd97f9f MJ |
60 | #define lttng_mod_timer_pinned(timer, expires) \ |
61 | mod_timer_pinned(timer, expires) | |
62 | ||
63 | # endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */ | |
64 | ||
65 | ||
66 | #define LTTNG_TIMER_PINNED TIMER_PINNED | |
67 | #define LTTNG_TIMER_FUNC_ARG_TYPE unsigned long | |
68 | ||
69 | /* timer_fieldname is unused prior to 4.15. */ | |
70 | #define lttng_from_timer(var, timer_data, timer_fieldname) \ | |
71 | ((typeof(var))timer_data) | |
72 | ||
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) | |
152fe7fc | 76 | { |
1fd97f9f MJ |
77 | if (flags & LTTNG_TIMER_PINNED) |
78 | lttng_init_timer_pinned(timer); | |
79 | else | |
80 | init_timer(timer); | |
81 | ||
82 | timer->function = function; | |
83 | timer->data = (unsigned long)data; | |
152fe7fc MJ |
84 | } |
85 | ||
5f4c791e | 86 | #endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */ |
152fe7fc MJ |
87 | |
88 | #endif /* _LTTNG_WRAPPER_TIMER_H */ |