kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.
To help with this maintenance let's start by moving sysctls to places
where they actually belong. The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we
just care about the core logic.
All filesystem syctls now get reviewed by fs folks. This commit
follows the commit of fs, move the stack_tracer_enabled sysctl to its
own file, kernel/trace/trace_stack.c.
Signed-off-by: tangmeng <[email protected]>
---
include/linux/ftrace.h | 6 ------
kernel/sysctl.c | 9 ---------
kernel/trace/trace_stack.c | 26 ++++++++++++++++++++++++--
3 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 9999e29187de..cc6f7532e038 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -392,12 +392,6 @@ static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
#ifdef CONFIG_STACK_TRACER
-
-extern int stack_tracer_enabled;
-
-int stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
- size_t *lenp, loff_t *ppos);
-
/* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
DECLARE_PER_CPU(int, disable_stack_tracer);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index d11390634321..b41138d64e5e 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1755,15 +1755,6 @@ static struct ctl_table kern_table[] = {
.proc_handler = ftrace_enable_sysctl,
},
#endif
-#ifdef CONFIG_STACK_TRACER
- {
- .procname = "stack_tracer_enabled",
- .data = &stack_tracer_enabled,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = stack_trace_sysctl,
- },
-#endif
#ifdef CONFIG_TRACING
{
.procname = "ftrace_dump_on_oops",
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 5a48dba912ea..b871499cf7e6 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -32,7 +32,7 @@ static arch_spinlock_t stack_trace_max_lock =
DEFINE_PER_CPU(int, disable_stack_tracer);
static DEFINE_MUTEX(stack_sysctl_mutex);
-int stack_tracer_enabled;
+static int stack_tracer_enabled;
static void print_max_stack(void)
{
@@ -513,7 +513,8 @@ static const struct file_operations stack_trace_filter_fops = {
#endif /* CONFIG_DYNAMIC_FTRACE */
-int
+#ifdef CONFIG_SYSCTL
+static int
stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos)
{
@@ -537,6 +538,25 @@ stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
return ret;
}
+static struct ctl_table kern_trace_stack_table[] = {
+ {
+ .procname = "stack_tracer_enabled",
+ .data = &stack_tracer_enabled,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = stack_trace_sysctl,
+ },
+ { }
+};
+
+static void __init kernel_trace_stack_sysctls_init(void)
+{
+ register_sysctl_init("kernel", kern_trace_stack_table);
+}
+#else
+#define kernel_trace_stack_sysctls_init() do { } while (0)
+#endif /* CONFIG_SYSCTL */
+
static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
static __init int enable_stacktrace(char *str)
@@ -576,6 +596,8 @@ static __init int stack_trace_init(void)
if (stack_tracer_enabled)
register_ftrace_function(&trace_ops);
+ kernel_trace_stack_sysctls_init();
+
return 0;
}
--
2.20.1
On Sun, 20 Feb 2022 14:00:17 +0800
tangmeng <[email protected]> wrote:
> kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
> dishes, this makes it very difficult to maintain.
>
> To help with this maintenance let's start by moving sysctls to places
> where they actually belong. The proc sysctl maintainers do not want to
> know what sysctl knobs you wish to add for your own piece of code, we
> just care about the core logic.
>
> All filesystem syctls now get reviewed by fs folks. This commit
> follows the commit of fs, move the stack_tracer_enabled sysctl to its
> own file, kernel/trace/trace_stack.c.
>
> Signed-off-by: tangmeng <[email protected]>
Acked-by: Steven Rostedt (Google) <[email protected]>
-- Steve