]> sourceware.org Git - systemtap.git/commitdiff
Eliminate use of kernel's flush_scheduled_work() in systemtap modules
authorWilliam Cohen <wcohen@redhat.com>
Wed, 27 Sep 2023 14:09:11 +0000 (10:09 -0400)
committerWilliam Cohen <wcohen@redhat.com>
Wed, 27 Sep 2023 20:00:34 +0000 (16:00 -0400)
Kernel git commit 20bdedafd2f63e0ba70991127f9b5c0826ebdb32 turns use
of flush_scheduled_work() into a warning which causes builds of
anything using it to fail because warnings are treated as errors.
Previous users of flush_scheduled_work() in the kernel have been
converted over to use individual workqueues.  Systemtap runtime now
does the same.  It creates and uses its own workqueue to eliminate the
use of flush_scheduled_work().

runtime/linux/runtime.h
translate.cxx

index be02b9b5adad754ee6006f32a4169b33b887fdac..a5840794a99e6e391b4a397082c3b1523ed9af5e 100644 (file)
@@ -401,10 +401,12 @@ static struct kernel_param_ops param_ops_int64_t = {
 #endif
 #undef _STP_KERNEL_PARAM_ARG
 
+#include <linux/workqueue.h>
+struct workqueue_struct *systemtap_wq;
 
 static inline void stp_synchronize_sched(void)
 {
-  flush_scheduled_work();
+  flush_workqueue(systemtap_wq);
 #if defined(STAPCONF_SYNCHRONIZE_SCHED)
   synchronize_sched();
 #elif defined(STAPCONF_SYNCHRONIZE_RCU)
@@ -431,6 +433,10 @@ static int stap_init_module (void)
      stap, it is beneficial to add some runtime-random value to the
      map hash. */
   get_random_bytes(&stap_hash_seed, sizeof (stap_hash_seed));
+  systemtap_wq = alloc_workqueue("systemtap-wq",
+               WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
+  if (!systemtap_wq)
+    return !systemtap_wq;
   rc = systemtap_kernel_module_init();
   if (rc)
     return rc;
@@ -449,6 +455,8 @@ void stap_cleanup_module(void)
      due to tapset-procfs.cxx cleaning up after procfs probes (such
      as in --monitor mode).  */
   systemtap_kernel_module_exit();
+  if (systemtap_wq)
+    destroy_workqueue(systemtap_wq);
 }
 
 module_exit(stap_cleanup_module);
index 76fa056390ca2b36dc4bc6e2f5cfc18b596a9472..f77a4bed68620363f9bfeb99984e49745015dc3b 100644 (file)
@@ -1198,7 +1198,6 @@ c_unparser::emit_common_header ()
 
       // We will use a workqueue to schedule module_refresh work when we need
       // to enable/disable probes.
-      o->newline( 0)  << "#include <linux/workqueue.h>";
       o->newline( 0)  << "static struct work_struct module_refresher_work;";
       o->newline( 0)  << "static void module_refresher(struct work_struct *work) {";
       o->newline( 1)  <<    "systemtap_module_refresh(NULL);";
@@ -1216,7 +1215,7 @@ c_unparser::emit_common_header ()
       o->newline(+1)  <<   "if (atomic_cmpxchg(&need_module_refresh, 1, 0) == 1)";
       // NB: one might like to invoke systemtap_module_refresh(NULL) directly from
       // here ... however hrtimers are called from an unsleepable context, so no can do.
-      o->newline(+1)  <<     "schedule_work(&module_refresher_work);";
+      o->newline(+1)  <<     "queue_work(systemtap_wq, &module_refresher_work);";
       o->newline(-1)  <<   "hrtimer_set_expires(timer,";
       o->newline( 0)  <<   "  ktime_add(hrtimer_get_expires(timer),";
       o->newline( 0)  <<   "            ktime_set(0, STP_ON_THE_FLY_INTERVAL))); ";
This page took 0.038681 seconds and 5 git commands to generate.