]> code.ossystems Code Review - openembedded-core.git/blob
460c3b7609fbd55c271b9cd90aa443ce86f66806
[openembedded-core.git] /
1 From fbb26e17a4c026f05a497fc5d584516bad3b6950 Mon Sep 17 00:00:00 2001
2 From: David Smith <dsmith@redhat.com>
3 Date: Wed, 6 Dec 2017 14:37:42 -0600
4 Subject: [PATCH] Fix PR22551 by updating the use of timers for the 4.15
5  kernel.
6
7 * runtime/linux/timer_compatibility.h: New file.
8 * runtime/time.c: Update timer callback function parameter type. Update
9   timer initialization.
10 * runtime/transport/relay_v2.c: Ditto.
11 * runtime/transport/transport.c: Ditto.
12 * tapset-timers.cxx (timer_derived_probe_group::emit_module_decls):
13   Ditto. Handle old and new timer callback interface.
14 * runtime/linux/runtime.h: Include timer_compatibility.h instead of timer.h.
15 * tapset/linux/scsi.stp: Ditto.
16
17 Upstream-Status: Backport
18 Signed-off-by: Victor Kamensky <kamensky@cisco.com>
19
20 ---
21  runtime/linux/runtime.h             |  2 +-
22  runtime/linux/timer_compatibility.h | 76 +++++++++++++++++++++++++++++++++++++
23  runtime/time.c                      |  7 ++--
24  runtime/transport/relay_v2.c        |  8 ++--
25  runtime/transport/transport.c       | 13 +++----
26  tapset-timers.cxx                   | 14 +++++--
27  tapset/linux/scsi.stp               |  2 +-
28  7 files changed, 100 insertions(+), 22 deletions(-)
29  create mode 100644 runtime/linux/timer_compatibility.h
30
31 diff --git a/runtime/linux/runtime.h b/runtime/linux/runtime.h
32 index 9c585a2..df9b74c 100644
33 --- a/runtime/linux/runtime.h
34 +++ b/runtime/linux/runtime.h
35 @@ -34,7 +34,7 @@
36  #include <linux/compat.h>
37  #include <linux/sched.h>
38  #include <linux/mm.h>
39 -#include <linux/timer.h>
40 +#include "timer_compatibility.h"
41  #include <linux/delay.h>
42  #include <linux/profile.h>
43  #include <linux/rcupdate.h>
44 diff --git a/runtime/linux/timer_compatibility.h b/runtime/linux/timer_compatibility.h
45 new file mode 100644
46 index 0000000..ac03de9
47 --- /dev/null
48 +++ b/runtime/linux/timer_compatibility.h
49 @@ -0,0 +1,76 @@
50 +/*
51 + * linux/timer.h compatibility defines and inlines
52 + * Copyright (C) 2017 Red Hat Inc.
53 + *
54 + * This file is part of systemtap, and is free software.  You can
55 + * redistribute it and/or modify it under the terms of the GNU General
56 + * Public License (GPL); either version 2, or (at your option) any
57 + * later version.
58 + */
59 +
60 +#ifndef _TIMER_COMPATIBILITY_H_
61 +#define _TIMER_COMPATIBILITY_H_
62 +
63 +#include <linux/timer.h>
64 +
65 +/*
66 + * Starting with the 4.15 kernel, the timer interface
67 + * changed. Originally, you'd do something like:
68 + *
69 + *   static void timer_func(unsigned long val);
70 + *
71 + *   init_timer(&timer);
72 + *   timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
73 + *   timer.function = timer_func;
74 + *   timer.data = 0;
75 + *   add_timer(&timer);
76 + *
77 + * The 'data' parameter would get passed to the callback
78 + * function. Starting with 4.15, you'd do something like this:
79 + *
80 + *   static void timer_func(struct timer_list *val);
81 + *
82 + *   timer_setup(&timer, timer_func, 0);
83 + *   timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
84 + *   add_timer(&timer);
85 + *   
86 + * With the new code, the timer that caused the callback gets passed
87 + * to the timer callback function. The 'data' field has been removed.
88 + *
89 + * So, we're going to use the new interface. To hide the differences
90 + * between the callback function parameter type, we'll define a new
91 + * type, 'stp_timer_callback_parameter_t'.
92 + *
93 + * If code needs to figure out the difference between the old and new
94 + * interface, it should test the TIMER_TRACE_FLAGMASK define (which
95 + * only exists in the new interface).
96 + */
97 +
98 +#if defined(TIMER_TRACE_FLAGMASK) 
99 +/* This is the >= 4.15 kernel interface. */
100 +
101 +typedef struct timer_list * stp_timer_callback_parameter_t;
102 +
103 +#else
104 +/* This is the < 4.15 kernel interface. */
105 +
106 +typedef unsigned long stp_timer_callback_parameter_t;
107 +
108 +/**
109 + * timer_setup - prepare a timer for first use
110 + * @timer: the timer in question
111 + * @callback: the function to call when timer expires
112 + * @flags: any TIMER_* flags (note that anything other than 0 is an
113 + *        error, since this compatibility function can't support any
114 + *        of the TIMER_* flags)
115 + */
116 +#define timer_setup(timer, callback, flags)                    \
117 +       {                                                       \
118 +               init_timer((timer));                            \
119 +               (timer)->function = callback;                   \
120 +               (timer)->data = 0;                              \
121 +               BUILD_BUG_ON_ZERO((flags) != 0);                \
122 +       }
123 +#endif
124 +
125 +#endif /* _TIMER_COMPATIBILITY_H_ */
126 diff --git a/runtime/time.c b/runtime/time.c
127 index 2e666d5..91ceafa 100644
128 --- a/runtime/time.c
129 +++ b/runtime/time.c
130 @@ -168,10 +168,10 @@ __stp_time_smp_callback(void *val)
131  
132  /* The timer callback is in a softIRQ -- interrupts enabled. */
133  static void
134 -__stp_time_timer_callback(unsigned long val)
135 +__stp_time_timer_callback(stp_timer_callback_parameter_t unused)
136  {
137      stp_time_t *time =__stp_time_local_update();
138 -    (void) val;
139 +    (void) unused;
140  
141      /* PR6481: make sure IRQs are enabled before resetting the timer
142         (IRQs are disabled and then reenabled in
143 @@ -200,9 +200,8 @@ __stp_init_time(void *info)
144      time->freq = __stp_get_freq();
145      __stp_time_local_update();
146  
147 -    init_timer(&time->timer);
148 +    timer_setup(&time->timer, __stp_time_timer_callback, 0);
149      time->timer.expires = jiffies + STP_TIME_SYNC_INTERVAL;
150 -    time->timer.function = __stp_time_timer_callback;
151  
152  #ifndef STAPCONF_ADD_TIMER_ON
153      add_timer(&time->timer);
154 diff --git a/runtime/transport/relay_v2.c b/runtime/transport/relay_v2.c
155 index f81d75d..135951a 100644
156 --- a/runtime/transport/relay_v2.c
157 +++ b/runtime/transport/relay_v2.c
158 @@ -30,7 +30,7 @@
159  #include <linux/debugfs.h>
160  #include <linux/mm.h>
161  #include <linux/relay.h>
162 -#include <linux/timer.h>
163 +#include "../linux/timer_compatibility.h"
164  #include "../uidgid_compatibility.h"
165  #include "relay_compat.h"
166  
167 @@ -120,7 +120,7 @@ static void __stp_relay_wakeup_readers(struct rchan_buf *buf)
168                 wake_up_interruptible(&buf->read_wait);
169  }
170  
171 -static void __stp_relay_wakeup_timer(unsigned long val)
172 +static void __stp_relay_wakeup_timer(stp_timer_callback_parameter_t unused)
173  {
174  #ifdef STP_BULKMODE
175         int i;
176 @@ -151,10 +151,8 @@ static void __stp_relay_wakeup_timer(unsigned long val)
177  static void __stp_relay_timer_init(void)
178  {
179         atomic_set(&_stp_relay_data.wakeup, 0);
180 -       init_timer(&_stp_relay_data.timer);
181 +       timer_setup(&_stp_relay_data.timer, __stp_relay_wakeup_timer, 0);
182         _stp_relay_data.timer.expires = jiffies + STP_RELAY_TIMER_INTERVAL;
183 -       _stp_relay_data.timer.function = __stp_relay_wakeup_timer;
184 -       _stp_relay_data.timer.data = 0;
185         add_timer(&_stp_relay_data.timer);
186         smp_mb();
187  }
188 diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
189 index 3400f22..320fd18 100644
190 --- a/runtime/transport/transport.c
191 +++ b/runtime/transport/transport.c
192 @@ -311,7 +311,7 @@ static void _stp_detach(void)
193  }
194  
195  
196 -static void _stp_ctl_work_callback(unsigned long val);
197 +static void _stp_ctl_work_callback(stp_timer_callback_parameter_t unused);
198  
199  /*
200   * Called when stapio opens the control channel.
201 @@ -320,13 +320,12 @@ static void _stp_attach(void)
202  {
203         dbug_trans(1, "attach\n");
204         _stp_pid = current->pid;
205 -  if (_stp_namespaces_pid < 1)
206 -    _stp_namespaces_pid = _stp_pid;
207 +       if (_stp_namespaces_pid < 1)
208 +               _stp_namespaces_pid = _stp_pid;
209         _stp_transport_data_fs_overwrite(0);
210 -       init_timer(&_stp_ctl_work_timer);
211 +
212 +       timer_setup(&_stp_ctl_work_timer, _stp_ctl_work_callback, 0);
213         _stp_ctl_work_timer.expires = jiffies + STP_CTL_TIMER_INTERVAL;
214 -       _stp_ctl_work_timer.function = _stp_ctl_work_callback;
215 -       _stp_ctl_work_timer.data= 0;
216         add_timer(&_stp_ctl_work_timer);
217  }
218  
219 @@ -341,7 +340,7 @@ static void _stp_attach(void)
220   *     notified. Reschedules itself if someone is still attached
221   *     to the cmd channel.
222   */
223 -static void _stp_ctl_work_callback(unsigned long val)
224 +static void _stp_ctl_work_callback(stp_timer_callback_parameter_t unused)
225  {
226         int do_io = 0;
227         unsigned long flags;
228 diff --git a/tapset-timers.cxx b/tapset-timers.cxx
229 index 1a40bcd..0ab4d69 100644
230 --- a/tapset-timers.cxx
231 +++ b/tapset-timers.cxx
232 @@ -122,9 +122,13 @@ timer_derived_probe_group::emit_module_decls (systemtap_session& s)
233    s.op->newline(-1) << "};";
234    s.op->newline();
235  
236 -  s.op->newline() << "static void enter_timer_probe (unsigned long val) {";
237 +  s.op->newline() << "static void enter_timer_probe (stp_timer_callback_parameter_t val) {";
238 +  s.op->newline() << "#if defined(TIMER_TRACE_FLAGMASK)";
239 +  s.op->newline(1) << "struct stap_timer_probe* stp = container_of(val, struct stap_timer_probe, timer_list);";
240 +  s.op->newline(-1) << "#else";
241    s.op->newline(1) << "struct stap_timer_probe* stp = & stap_timer_probes [val];";
242 -  s.op->newline() << "if ((atomic_read (session_state()) == STAP_SESSION_STARTING) ||";
243 +  s.op->newline(-1) << "#endif";
244 +  s.op->newline(1) << "if ((atomic_read (session_state()) == STAP_SESSION_STARTING) ||";
245    s.op->newline() << "    (atomic_read (session_state()) == STAP_SESSION_RUNNING))";
246    s.op->newline(1) << "mod_timer (& stp->timer_list, jiffies + ";
247    emit_interval (s.op);
248 @@ -148,9 +152,11 @@ timer_derived_probe_group::emit_module_init (systemtap_session& s)
249    s.op->newline() << "for (i=0; i<" << probes.size() << "; i++) {";
250    s.op->newline(1) << "struct stap_timer_probe* stp = & stap_timer_probes [i];";
251    s.op->newline() << "probe_point = stp->probe->pp;";
252 -  s.op->newline() << "init_timer (& stp->timer_list);";
253 -  s.op->newline() << "stp->timer_list.function = & enter_timer_probe;";
254 +
255 +  s.op->newline() << "timer_setup (& stp->timer_list, enter_timer_probe, 0);";
256 +  s.op->newline() << "#if !defined(TIMER_TRACE_FLAGMASK)";
257    s.op->newline() << "stp->timer_list.data = i;"; // NB: important!
258 +  s.op->newline() << "#endif";
259    // copy timer renew calculations from above :-(
260    s.op->newline() << "stp->timer_list.expires = jiffies + ";
261    emit_interval (s.op);
262 diff --git a/tapset/linux/scsi.stp b/tapset/linux/scsi.stp
263 index 44f686c..3577942 100644
264 --- a/tapset/linux/scsi.stp
265 +++ b/tapset/linux/scsi.stp
266 @@ -14,7 +14,7 @@
267  #include <scsi/scsi_cmnd.h>
268  #include <scsi/scsi_device.h>
269  #include <scsi/scsi_host.h>
270 -#include <linux/timer.h>
271 +#include "linux/timer_compatibility.h"
272  #include <linux/blkdev.h>
273  %}
274  
275 -- 
276 2.7.4
277