Update to SPDX v3.0 identifiers
[lttng-modules.git] / wrapper / timer.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * wrapper/timer.h
4 *
5 * wrapper around linux/timer.h.
6 *
7 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
8 */
9
10#ifndef _LTTNG_WRAPPER_TIMER_H
11#define _LTTNG_WRAPPER_TIMER_H
12
13#include <linux/version.h>
14#include <linux/timer.h>
15#include <lttng-kernel-version.h>
16
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
43
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) \
48 || LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0))
49
50#define lttng_init_timer_pinned(timer) \
51 init_timer_pinned(timer)
52
53#define lttng_mod_timer_pinned(timer, expires) \
54 mod_timer(timer, expires)
55
56# else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */
57
58#define lttng_init_timer_pinned(timer) \
59 init_timer(timer)
60
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
74static inline void lttng_timer_setup(struct timer_list *timer,
75 void (*function)(LTTNG_TIMER_FUNC_ARG_TYPE),
76 unsigned int flags, void *data)
77{
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;
85}
86
87#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) */
88
89#endif /* _LTTNG_WRAPPER_TIMER_H */
This page took 0.022447 seconds and 4 git commands to generate.