File: timer.h

package info (click to toggle)
lttng-modules 2.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,808 kB
  • sloc: ansic: 74,851; sh: 548; makefile: 62
file content (109 lines) | stat: -rw-r--r-- 2,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
 *
 * wrapper/timer.h
 *
 * wrapper around linux/timer.h.
 *
 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
 */

#ifndef _LTTNG_WRAPPER_TIMER_H
#define _LTTNG_WRAPPER_TIMER_H

#include <lttng/kernel-version.h>
#include <linux/timer.h>

/*
 * In the olden days, pinned timers were initialized normaly with init_timer()
 * and then modified with mod_timer_pinned().
 *
 * Then came kernel 4.8.0 and they had to be initilized as pinned with
 * init_timer_pinned() and then modified as regular timers with mod_timer().
 *
 * Then came kernel 4.15.0 with a new timer API where init_timer() is no more.
 * It's replaced by timer_setup() where pinned is now part of timer flags.
 */

static inline int lttng_timer_delete_sync(struct timer_list *timer)
{
#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,15,0))
	return timer_delete_sync(timer);
#else
	return del_timer_sync(timer);
#endif
}


#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,16,0))

#define lttng_timer_container_of(var, callback_timer, timer_fieldname) \
	timer_container_of(var, callback_timer, timer_fieldname)

#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))

#define lttng_timer_container_of(var, callback_timer, timer_fieldname) \
	from_timer(var, callback_timer, timer_fieldname)

#else

/* timer_fieldname is unused prior to 4.15. */
#define lttng_timer_container_of(var, timer_data, timer_fieldname) \
	((typeof(var))timer_data)

#endif


#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))

#define LTTNG_TIMER_PINNED		TIMER_PINNED
#define LTTNG_TIMER_FUNC_ARG_TYPE	struct timer_list *

#define lttng_mod_timer_pinned(timer, expires)  \
	mod_timer(timer, expires)

#define lttng_timer_setup(timer, callback, flags, unused) \
	timer_setup(timer, callback, flags)


#else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */


# if (LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) \
	|| LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0))

#define lttng_init_timer_pinned(timer) \
	init_timer_pinned(timer)

#define lttng_mod_timer_pinned(timer, expires) \
	mod_timer(timer, expires)

# else /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */

#define lttng_init_timer_pinned(timer) \
	init_timer(timer)

#define lttng_mod_timer_pinned(timer, expires) \
	mod_timer_pinned(timer, expires)

# endif /* LTTNG_RT_VERSION_CODE >= LTTNG_RT_KERNEL_VERSION(4,6,4,8) */


#define LTTNG_TIMER_PINNED		TIMER_PINNED
#define LTTNG_TIMER_FUNC_ARG_TYPE	unsigned long

static inline void lttng_timer_setup(struct timer_list *timer,
		void (*function)(LTTNG_TIMER_FUNC_ARG_TYPE),
		unsigned int flags, void *data)
{
	if (flags & LTTNG_TIMER_PINNED)
		lttng_init_timer_pinned(timer);
	else
		init_timer(timer);

	timer->function = function;
	timer->data = (unsigned long)data;
}

#endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0) */

#endif /* _LTTNG_WRAPPER_TIMER_H */