- Remove the extra array member of stack_dump_trace[] along with the
  ARRAY_SIZE - 1 initialization for struct stack_trace :: max_entries.

  Both are historical leftovers of no value. The stack tracer never exceeds
  the array and there is no extra storage requirement either.

- Make variables which are only used in trace_stack.c static.

- Simplify the enable/disable logic.

- Rename stack_trace_print() as it's using the stack_trace_ namespace. Free
  the name up for stack trace related functions.

Signed-off-by: Thomas Gleixner <t...@linutronix.de>
Reviewed-by: Steven Rostedt <rost...@goodmis.org>
---
V3: Remove the -1 init and split the variable declaration as requested by 
Steven.
V2: Add more cleanups and use print_max_stack() as requested by Steven.
---
 include/linux/ftrace.h     |   18 ++++--------------
 kernel/trace/trace_stack.c |   42 +++++++++++++-----------------------------
 2 files changed, 17 insertions(+), 43 deletions(-)

--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -241,21 +241,11 @@ static inline void ftrace_free_mem(struc
 
 #ifdef CONFIG_STACK_TRACER
 
-#define STACK_TRACE_ENTRIES 500
-
-struct stack_trace;
-
-extern unsigned stack_trace_index[];
-extern struct stack_trace stack_trace_max;
-extern unsigned long stack_trace_max_size;
-extern arch_spinlock_t stack_trace_max_lock;
-
 extern int stack_tracer_enabled;
-void stack_trace_print(void);
-int
-stack_trace_sysctl(struct ctl_table *table, int write,
-                  void __user *buffer, size_t *lenp,
-                  loff_t *ppos);
+
+int stack_trace_sysctl(struct ctl_table *table, int write,
+                      void __user *buffer, size_t *lenp,
+                      loff_t *ppos);
 
 /* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
 DECLARE_PER_CPU(int, disable_stack_tracer);
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -18,30 +18,26 @@
 
 #include "trace.h"
 
-static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES + 1];
-unsigned stack_trace_index[STACK_TRACE_ENTRIES];
+#define STACK_TRACE_ENTRIES 500
+
+static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES];
+static unsigned stack_trace_index[STACK_TRACE_ENTRIES];
 
-/*
- * Reserve one entry for the passed in ip. This will allow
- * us to remove most or all of the stack size overhead
- * added by the stack tracer itself.
- */
 struct stack_trace stack_trace_max = {
-       .max_entries            = STACK_TRACE_ENTRIES - 1,
+       .max_entries            = STACK_TRACE_ENTRIES,
        .entries                = &stack_dump_trace[0],
 };
 
-unsigned long stack_trace_max_size;
-arch_spinlock_t stack_trace_max_lock =
+static unsigned long stack_trace_max_size;
+static arch_spinlock_t stack_trace_max_lock =
        (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
 
 DEFINE_PER_CPU(int, disable_stack_tracer);
 static DEFINE_MUTEX(stack_sysctl_mutex);
 
 int stack_tracer_enabled;
-static int last_stack_tracer_enabled;
 
-void stack_trace_print(void)
+static void print_max_stack(void)
 {
        long i;
        int size;
@@ -61,16 +57,7 @@ void stack_trace_print(void)
        }
 }
 
-/*
- * When arch-specific code overrides this function, the following
- * data should be filled up, assuming stack_trace_max_lock is held to
- * prevent concurrent updates.
- *     stack_trace_index[]
- *     stack_trace_max
- *     stack_trace_max_size
- */
-void __weak
-check_stack(unsigned long ip, unsigned long *stack)
+static void check_stack(unsigned long ip, unsigned long *stack)
 {
        unsigned long this_size, flags; unsigned long *p, *top, *start;
        static int tracer_frame;
@@ -179,7 +166,7 @@ check_stack(unsigned long ip, unsigned l
        stack_trace_max.nr_entries = x;
 
        if (task_stack_end_corrupted(current)) {
-               stack_trace_print();
+               print_max_stack();
                BUG();
        }
 
@@ -412,23 +399,21 @@ stack_trace_sysctl(struct ctl_table *tab
                   void __user *buffer, size_t *lenp,
                   loff_t *ppos)
 {
+       int was_enabled;
        int ret;
 
        mutex_lock(&stack_sysctl_mutex);
+       was_enabled = !!stack_tracer_enabled;
 
        ret = proc_dointvec(table, write, buffer, lenp, ppos);
 
-       if (ret || !write ||
-           (last_stack_tracer_enabled == !!stack_tracer_enabled))
+       if (ret || !write || (was_enabled == !!stack_tracer_enabled))
                goto out;
 
-       last_stack_tracer_enabled = !!stack_tracer_enabled;
-
        if (stack_tracer_enabled)
                register_ftrace_function(&trace_ops);
        else
                unregister_ftrace_function(&trace_ops);
-
  out:
        mutex_unlock(&stack_sysctl_mutex);
        return ret;
@@ -444,7 +429,6 @@ static __init int enable_stacktrace(char
                strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
 
        stack_tracer_enabled = 1;
-       last_stack_tracer_enabled = 1;
        return 1;
 }
 __setup("stacktrace", enable_stacktrace);


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to