[PATCH] Use timer_setup and mod_timer

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Use timer_setup and mod_timer

Lu Fengqi
With kernel 4.15, the old timer interface init_timer has been removed. Use
setup_timer and mod_timer functions instead of initializing timer with the
function init_timer and data fields.

Signed-off-by: Lu Fengqi <[hidden email]>
---
 runtime/linux/timer.h           | 12 ++++++++++++
 runtime/runtime_defines.h       |  2 +-
 runtime/time.c                  |  9 +++------
 runtime/transport/relay_v2.c    | 11 ++++-------
 runtime/transport/ring_buffer.c |  9 +++------
 runtime/transport/transport.c   | 11 ++++-------
 6 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/runtime/linux/timer.h b/runtime/linux/timer.h
index e7e0bb6f0055..6ab2452ec9ea 100644
--- a/runtime/linux/timer.h
+++ b/runtime/linux/timer.h
@@ -46,6 +46,18 @@ typedef enum hrtimer_restart hrtimer_return_t;
 #define HRTIMER_MODE_REL HRTIMER_REL
 #endif
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)) && !defined(timer_setup)
+
+#define timer_setup(timer, callback, _flags) \
+do { \
+ init_timer((timer)); \
+ (timer)->function = (void (*)(unsigned long))(callback); \
+ (timer)->data = 0; \
+ (timer)->flags = _flags; \
+} while (0)
+
+#endif /* kernel version >= 4.15.0 */
+
 #endif /* kernel version >= 2.6.17 */
 
 #endif /* _LINUX_TIMER_H_ */
diff --git a/runtime/runtime_defines.h b/runtime/runtime_defines.h
index ed668b8461e2..77d6a206b00e 100644
--- a/runtime/runtime_defines.h
+++ b/runtime/runtime_defines.h
@@ -86,7 +86,7 @@ enum stp_probe_type {
 /* read or write of stap module proc file. Triggers on manipulation of
    the /proc/systemtap/MODNAME created through a procfs probe. */
  stp_probe_type_procfs,
-/* timer probe, triggered by standard kernel init_timer interface. */
+/* timer probe, triggered by standard kernel timer_setup interface. */
  stp_probe_type_timer,
 /* high resolution timer probes, triggered by hrtimer firing. */
  stp_probe_type_hrtimer,
diff --git a/runtime/time.c b/runtime/time.c
index 2e666d54ccac..640178d556a9 100644
--- a/runtime/time.c
+++ b/runtime/time.c
@@ -168,10 +168,9 @@ __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(struct timer_list *unused)
 {
     stp_time_t *time =__stp_time_local_update();
-    (void) val;
 
     /* PR6481: make sure IRQs are enabled before resetting the timer
        (IRQs are disabled and then reenabled in
@@ -200,12 +199,10 @@ __stp_init_time(void *info)
     time->freq = __stp_get_freq();
     __stp_time_local_update();
 
-    init_timer(&time->timer);
-    time->timer.expires = jiffies + STP_TIME_SYNC_INTERVAL;
-    time->timer.function = __stp_time_timer_callback;
+    timer_setup(&time->timer, __stp_time_timer_callback, 0);
 
 #ifndef STAPCONF_ADD_TIMER_ON
-    add_timer(&time->timer);
+    mod_timer(&time->timer, jiffies + STP_TIME_SYNC_INTERVAL);
 #endif
 }
 
diff --git a/runtime/transport/relay_v2.c b/runtime/transport/relay_v2.c
index f81d75dfa25c..7523af268c8e 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 "timer.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(struct timer_list *unused)
 {
 #ifdef STP_BULKMODE
  int i;
@@ -151,11 +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);
- _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);
+ timer_setup(&_stp_relay_data.timer, __stp_relay_wakeup_timer, 0);
+ mod_timer(&_stp_relay_data.timer, jiffies + STP_RELAY_TIMER_INTERVAL);
  smp_mb();
 }
 
diff --git a/runtime/transport/ring_buffer.c b/runtime/transport/ring_buffer.c
index 43e014baedb0..e10b8d47aec9 100644
--- a/runtime/transport/ring_buffer.c
+++ b/runtime/transport/ring_buffer.c
@@ -691,7 +691,7 @@ static int _stp_data_write_commit(void *entry)
 #endif
 }
 
-static void __stp_relay_wakeup_timer(unsigned long val)
+static void __stp_relay_wakeup_timer(struct timer_list *unused)
 {
  if (waitqueue_active(&_stp_poll_wait) && ! _stp_ring_buffer_empty())
  wake_up_interruptible(&_stp_poll_wait);
@@ -703,11 +703,8 @@ static void __stp_relay_wakeup_timer(unsigned long val)
 
 static void __stp_relay_timer_start(void)
 {
- init_timer(&_stp_relay_data.timer);
- _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);
+ timer_setup(&_stp_relay_data.timer, __stp_relay_wakeup_timer, 0);
+ mod_timer(&_stp_relay_data.timer, jiffies + STP_RELAY_TIMER_INTERVAL);
  smp_mb();
 }
 
diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
index 3400f220acb9..f9fd552dbc67 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(struct timer_list *unused);
 
 /*
  * Called when stapio opens the control channel.
@@ -323,11 +323,8 @@ static void _stp_attach(void)
   if (_stp_namespaces_pid < 1)
     _stp_namespaces_pid = _stp_pid;
  _stp_transport_data_fs_overwrite(0);
- init_timer(&_stp_ctl_work_timer);
- _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);
+ timer_setup(&_stp_ctl_work_timer, _stp_ctl_work_callback, 0);
+ mod_timer(&_stp_ctl_work_timer, jiffies + STP_CTL_TIMER_INTERVAL);
 }
 
 /*
@@ -341,7 +338,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(struct timer_list *unused)
 {
  int do_io = 0;
  unsigned long flags;
--
2.15.1