From ca71442b93af61cbd9a1386e24e967373f928eae Mon Sep 17 00:00:00 2001 From: William Cohen Date: Wed, 27 Sep 2023 10:09:11 -0400 Subject: [PATCH] Eliminate use of kernel's flush_scheduled_work() in systemtap modules 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 | 10 +++++++++- translate.cxx | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/runtime/linux/runtime.h b/runtime/linux/runtime.h index be02b9b5a..a5840794a 100644 --- a/runtime/linux/runtime.h +++ b/runtime/linux/runtime.h @@ -401,10 +401,12 @@ static struct kernel_param_ops param_ops_int64_t = { #endif #undef _STP_KERNEL_PARAM_ARG +#include +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); diff --git a/translate.cxx b/translate.cxx index 76fa05639..f77a4bed6 100644 --- a/translate.cxx +++ b/translate.cxx @@ -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 "; 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))); "; -- 2.43.5