summarylogtreecommitdiffstats
path: root/fix-timers-for-4.15-kernel.patch
blob: 3ca7c401e4ca6bb7d669de71848522ac00f1d5b6 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
diff --git a/runtime/linux/runtime.h b/runtime/linux/runtime.h
index 9c585a20d..df9b74c5c 100644
--- a/runtime/linux/runtime.h
+++ b/runtime/linux/runtime.h
@@ -34,7 +34,7 @@
 #include <linux/compat.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
-#include <linux/timer.h>
+#include "timer_compatibility.h"
 #include <linux/delay.h>
 #include <linux/profile.h>
 #include <linux/rcupdate.h>
diff --git a/runtime/linux/timer_compatibility.h b/runtime/linux/timer_compatibility.h
new file mode 100644
index 000000000..ac03de998
--- /dev/null
+++ b/runtime/linux/timer_compatibility.h
@@ -0,0 +1,76 @@
+/*
+ * linux/timer.h compatibility defines and inlines
+ * Copyright (C) 2017 Red Hat Inc.
+ *
+ * This file is part of systemtap, and is free software.  You can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License (GPL); either version 2, or (at your option) any
+ * later version.
+ */
+
+#ifndef _TIMER_COMPATIBILITY_H_
+#define _TIMER_COMPATIBILITY_H_
+
+#include <linux/timer.h>
+
+/*
+ * Starting with the 4.15 kernel, the timer interface
+ * changed. Originally, you'd do something like:
+ *
+ *   static void timer_func(unsigned long val);
+ *
+ *   init_timer(&timer);
+ *   timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
+ *   timer.function = timer_func;
+ *   timer.data = 0;
+ *   add_timer(&timer);
+ *
+ * The 'data' parameter would get passed to the callback
+ * function. Starting with 4.15, you'd do something like this:
+ *
+ *   static void timer_func(struct timer_list *val);
+ *
+ *   timer_setup(&timer, timer_func, 0);
+ *   timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
+ *   add_timer(&timer);
+ *   
+ * With the new code, the timer that caused the callback gets passed
+ * to the timer callback function. The 'data' field has been removed.
+ *
+ * So, we're going to use the new interface. To hide the differences
+ * between the callback function parameter type, we'll define a new
+ * type, 'stp_timer_callback_parameter_t'.
+ *
+ * If code needs to figure out the difference between the old and new
+ * interface, it should test the TIMER_TRACE_FLAGMASK define (which
+ * only exists in the new interface).
+ */
+
+#if defined(TIMER_TRACE_FLAGMASK) 
+/* This is the >= 4.15 kernel interface. */
+
+typedef struct timer_list * stp_timer_callback_parameter_t;
+
+#else
+/* This is the < 4.15 kernel interface. */
+
+typedef unsigned long stp_timer_callback_parameter_t;
+
+/**
+ * timer_setup - prepare a timer for first use
+ * @timer: the timer in question
+ * @callback: the function to call when timer expires
+ * @flags: any TIMER_* flags (note that anything other than 0 is an
+ * 	   error, since this compatibility function can't support any
+ *	   of the TIMER_* flags)
+ */
+#define timer_setup(timer, callback, flags)			\
+	{							\
+		init_timer((timer));				\
+		(timer)->function = callback;			\
+		(timer)->data = 0;				\
+		BUILD_BUG_ON_ZERO((flags) != 0);		\
+	}
+#endif
+
+#endif /* _TIMER_COMPATIBILITY_H_ */
diff --git a/runtime/time.c b/runtime/time.c
index 2e666d54c..91ceafa6a 100644
--- a/runtime/time.c
+++ b/runtime/time.c
@@ -168,10 +168,10 @@ __stp_time_smp_callback(void *val)
 
 /* The timer callback is in a softIRQ -- interrupts enabled. */
 static void
-__stp_time_timer_callback(unsigned long val)
+__stp_time_timer_callback(stp_timer_callback_parameter_t unused)
 {
     stp_time_t *time =__stp_time_local_update();
-    (void) val;
+    (void) unused;
 
     /* PR6481: make sure IRQs are enabled before resetting the timer
        (IRQs are disabled and then reenabled in
@@ -200,9 +200,8 @@ __stp_init_time(void *info)
     time->freq = __stp_get_freq();
     __stp_time_local_update();
 
-    init_timer(&time->timer);
+    timer_setup(&time->timer, __stp_time_timer_callback, 0);
     time->timer.expires = jiffies + STP_TIME_SYNC_INTERVAL;
-    time->timer.function = __stp_time_timer_callback;
 
 #ifndef STAPCONF_ADD_TIMER_ON
     add_timer(&time->timer);
diff --git a/runtime/transport/relay_v2.c b/runtime/transport/relay_v2.c
index f81d75dfa..135951a8e 100644
--- a/runtime/transport/relay_v2.c
+++ b/runtime/transport/relay_v2.c
@@ -30,7 +30,7 @@
 #include <linux/debugfs.h>
 #include <linux/mm.h>
 #include <linux/relay.h>
-#include <linux/timer.h>
+#include "../linux/timer_compatibility.h"
 #include "../uidgid_compatibility.h"
 #include "relay_compat.h"
 
@@ -120,7 +120,7 @@ static void __stp_relay_wakeup_readers(struct rchan_buf *buf)
 		wake_up_interruptible(&buf->read_wait);
 }
 
-static void __stp_relay_wakeup_timer(unsigned long val)
+static void __stp_relay_wakeup_timer(stp_timer_callback_parameter_t unused)
 {
 #ifdef STP_BULKMODE
 	int i;
@@ -151,10 +151,8 @@ static void __stp_relay_wakeup_timer(unsigned long val)
 static void __stp_relay_timer_init(void)
 {
 	atomic_set(&_stp_relay_data.wakeup, 0);
-	init_timer(&_stp_relay_data.timer);
+	timer_setup(&_stp_relay_data.timer, __stp_relay_wakeup_timer, 0);
 	_stp_relay_data.timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
-	_stp_relay_data.timer.function = __stp_relay_wakeup_timer;
-	_stp_relay_data.timer.data = 0;
 	add_timer(&_stp_relay_data.timer);
 	smp_mb();
 }
diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
index 3400f220a..320fd187e 100644
--- a/runtime/transport/transport.c
+++ b/runtime/transport/transport.c
@@ -311,7 +311,7 @@ static void _stp_detach(void)
 }
 
 
-static void _stp_ctl_work_callback(unsigned long val);
+static void _stp_ctl_work_callback(stp_timer_callback_parameter_t unused);
 
 /*
  * Called when stapio opens the control channel.
@@ -320,13 +320,12 @@ static void _stp_attach(void)
 {
 	dbug_trans(1, "attach\n");
 	_stp_pid = current->pid;
-  if (_stp_namespaces_pid < 1)
-    _stp_namespaces_pid = _stp_pid;
+	if (_stp_namespaces_pid < 1)
+		_stp_namespaces_pid = _stp_pid;
 	_stp_transport_data_fs_overwrite(0);
-	init_timer(&_stp_ctl_work_timer);
+
+	timer_setup(&_stp_ctl_work_timer, _stp_ctl_work_callback, 0);
 	_stp_ctl_work_timer.expires = jiffies + STP_CTL_TIMER_INTERVAL;
-	_stp_ctl_work_timer.function = _stp_ctl_work_callback;
-	_stp_ctl_work_timer.data= 0;
 	add_timer(&_stp_ctl_work_timer);
 }
 
@@ -341,7 +340,7 @@ static void _stp_attach(void)
  *	notified. Reschedules itself if someone is still attached
  *	to the cmd channel.
  */
-static void _stp_ctl_work_callback(unsigned long val)
+static void _stp_ctl_work_callback(stp_timer_callback_parameter_t unused)
 {
 	int do_io = 0;
 	unsigned long flags;
diff --git a/tapset-timers.cxx b/tapset-timers.cxx
index 1a40bcda0..0ab4d69cd 100644
--- a/tapset-timers.cxx
+++ b/tapset-timers.cxx
@@ -122,9 +122,13 @@ timer_derived_probe_group::emit_module_decls (systemtap_session& s)
   s.op->newline(-1) << "};";
   s.op->newline();
 
-  s.op->newline() << "static void enter_timer_probe (unsigned long val) {";
+  s.op->newline() << "static void enter_timer_probe (stp_timer_callback_parameter_t val) {";
+  s.op->newline() << "#if defined(TIMER_TRACE_FLAGMASK)";
+  s.op->newline(1) << "struct stap_timer_probe* stp = container_of(val, struct stap_timer_probe, timer_list);";
+  s.op->newline(-1) << "#else";
   s.op->newline(1) << "struct stap_timer_probe* stp = & stap_timer_probes [val];";
-  s.op->newline() << "if ((atomic_read (session_state()) == STAP_SESSION_STARTING) ||";
+  s.op->newline(-1) << "#endif";
+  s.op->newline(1) << "if ((atomic_read (session_state()) == STAP_SESSION_STARTING) ||";
   s.op->newline() << "    (atomic_read (session_state()) == STAP_SESSION_RUNNING))";
   s.op->newline(1) << "mod_timer (& stp->timer_list, jiffies + ";
   emit_interval (s.op);
@@ -148,9 +152,11 @@ timer_derived_probe_group::emit_module_init (systemtap_session& s)
   s.op->newline() << "for (i=0; i<" << probes.size() << "; i++) {";
   s.op->newline(1) << "struct stap_timer_probe* stp = & stap_timer_probes [i];";
   s.op->newline() << "probe_point = stp->probe->pp;";
-  s.op->newline() << "init_timer (& stp->timer_list);";
-  s.op->newline() << "stp->timer_list.function = & enter_timer_probe;";
+
+  s.op->newline() << "timer_setup (& stp->timer_list, enter_timer_probe, 0);";
+  s.op->newline() << "#if !defined(TIMER_TRACE_FLAGMASK)";
   s.op->newline() << "stp->timer_list.data = i;"; // NB: important!
+  s.op->newline() << "#endif";
   // copy timer renew calculations from above :-(
   s.op->newline() << "stp->timer_list.expires = jiffies + ";
   emit_interval (s.op);
diff --git a/tapset/linux/scsi.stp b/tapset/linux/scsi.stp
index 44f686c2a..35779421b 100644
--- a/tapset/linux/scsi.stp
+++ b/tapset/linux/scsi.stp
@@ -14,7 +14,7 @@
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
-#include <linux/timer.h>
+#include "linux/timer_compatibility.h"
 #include <linux/blkdev.h>
 %}