From b9197b0f7b69ff712f2c3aa0d5467b6aacd0eb58 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 20 Jun 2014 09:45:46 -0700 Subject: [PATCH] runtime: Add a universal stp_synchronize_sched The kernel has had synchronize_sched for a while. However, in the RHEL5 era this was merely a #define to synchronize_rcu, which our exportconf wouldn't detect. RHEL4 only had synchronize_kernel. Now stp_synchronize_sched covers all of these options, otherwise issuing an #error message. --- buildrun.cxx | 2 ++ runtime/dyninst/runtime.h | 2 ++ runtime/linux/runtime.h | 15 +++++++++++++++ runtime/linux/runtime_context.h | 6 +----- translate.cxx | 12 +++--------- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/buildrun.cxx b/buildrun.cxx index 5d434c713..6f820a819 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -323,6 +323,8 @@ compile_pass (systemtap_session& s) output_autoconf(s, o, "autoconf-uaccess.c", "STAPCONF_LINUX_UACCESS_H", NULL); output_autoconf(s, o, "autoconf-oneachcpu-retry.c", "STAPCONF_ONEACHCPU_RETRY", NULL); output_autoconf(s, o, "autoconf-dpath-path.c", "STAPCONF_DPATH_PATH", NULL); + output_exportconf(s, o, "synchronize_kernel", "STAPCONF_SYNCHRONIZE_KERNEL"); + output_exportconf(s, o, "synchronize_rcu", "STAPCONF_SYNCHRONIZE_RCU"); output_exportconf(s, o, "synchronize_sched", "STAPCONF_SYNCHRONIZE_SCHED"); output_autoconf(s, o, "autoconf-task-uid.c", "STAPCONF_TASK_UID", NULL); output_autoconf(s, o, "autoconf-from_kuid_munged.c", "STAPCONF_FROM_KUID_MUNGED", NULL); diff --git a/runtime/dyninst/runtime.h b/runtime/dyninst/runtime.h index 506cf1aba..1ae95a8a2 100644 --- a/runtime/dyninst/runtime.h +++ b/runtime/dyninst/runtime.h @@ -271,6 +271,8 @@ err_attr: return rc; } +static inline void stp_synchronize_sched(void) { } + /* * For stapdyn to work in a multiprocess environment, the module must be * prepared to be loaded multiple times in different processes. Thus, we have diff --git a/runtime/linux/runtime.h b/runtime/linux/runtime.h index 21319ff58..ec792d62d 100644 --- a/runtime/linux/runtime.h +++ b/runtime/linux/runtime.h @@ -37,6 +37,7 @@ #include #include #include +#include //#include // newer kernels only //#include #ifdef STAPCONF_GENERATED_COMPILE @@ -276,6 +277,20 @@ static struct kernel_param_ops param_ops_int64_t = { #endif #undef _STP_KERNEL_PARAM_ARG + +static inline void stp_synchronize_sched(void) +{ +#if defined(STAPCONF_SYNCHRONIZE_SCHED) + synchronize_sched(); +#elif defined(STAPCONF_SYNCHRONIZE_RCU) + synchronize_rcu(); +#elif defined(STAPCONF_SYNCHRONIZE_KERNEL) + synchronize_kernel(); +#else +#error "No implementation for stp_synchronize_sched!" +#endif +} + /************* Module Stuff ********************/ diff --git a/runtime/linux/runtime_context.h b/runtime/linux/runtime_context.h index 6729f8d4f..c9ffe180b 100644 --- a/runtime/linux/runtime_context.h +++ b/runtime/linux/runtime_context.h @@ -47,11 +47,7 @@ static void _stp_runtime_contexts_free(void) } /* Sync to make sure existing readers are done. */ -#ifdef STAPCONF_SYNCHRONIZE_SCHED - synchronize_sched(); -#else - synchronize_kernel(); -#endif + stp_synchronize_sched(); /* Now we can actually free the contexts. */ for_each_possible_cpu(cpu) { diff --git a/translate.cxx b/translate.cxx index 5d6821f39..b549cc0f1 100644 --- a/translate.cxx +++ b/translate.cxx @@ -1872,9 +1872,7 @@ c_unparser::emit_module_init () // For any partially registered/unregistered kernel facilities. o->newline() << "atomic_set (session_state(), STAP_SESSION_STOPPED);"; - o->newline() << "#ifdef STAPCONF_SYNCHRONIZE_SCHED"; - o->newline() << "synchronize_sched();"; - o->newline() << "#endif"; + o->newline() << "stp_synchronize_sched();"; // In case tracepoints were started, they need to be cleaned up o->newline() << "#ifdef STAP_NEED_TRACEPOINTS"; @@ -1958,9 +1956,7 @@ c_unparser::emit_module_exit () // Let's wait a while to make sure they're all done, done, done. // cargo cult prologue - o->newline() << "#ifdef STAPCONF_SYNCHRONIZE_SCHED"; - o->newline() << "synchronize_sched();"; - o->newline() << "#endif"; + o->newline() << "stp_synchronize_sched();"; // NB: systemtap_module_exit is assumed to be called from ordinary // user context, say during module unload. Among other things, this @@ -1969,9 +1965,7 @@ c_unparser::emit_module_exit () // cargo cult epilogue o->newline() << "atomic_set (session_state(), STAP_SESSION_STOPPED);"; - o->newline() << "#ifdef STAPCONF_SYNCHRONIZE_SCHED"; - o->newline() << "synchronize_sched();"; - o->newline() << "#endif"; + o->newline() << "stp_synchronize_sched();"; // XXX: might like to have an escape hatch, in case some probe is // genuinely stuck somehow -- 2.43.5