net: Make sure BHs are disabled in sock_prot_inuse_add()
[safe/jmp/linux-2.6] / kernel / trace / trace_sysprof.c
index ebcb66d..9587d3b 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * trace stack traces
  *
+ * Copyright (C) 2004-2008, Soeren Sandmann
  * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
  * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
- * Copyright (C) 2004, 2005, Soeren Sandmann
  */
 #include <linux/kallsyms.h>
 #include <linux/debugfs.h>
@@ -95,13 +95,12 @@ const static struct stacktrace_ops backtrace_ops = {
        .address                = backtrace_address,
 };
 
-static struct pt_regs *
+static int
 trace_kernel(struct pt_regs *regs, struct trace_array *tr,
             struct trace_array_cpu *data)
 {
        struct backtrace_info info;
        unsigned long bp;
-       char *user_stack;
        char *stack;
 
        info.tr = tr;
@@ -119,10 +118,7 @@ trace_kernel(struct pt_regs *regs, struct trace_array *tr,
 
        dump_trace(NULL, regs, (void *)stack, bp, &backtrace_ops, &info);
 
-       /* Now trace the user stack */
-       user_stack = ((char *)current->thread.sp0 - sizeof(struct pt_regs));
-
-       return (struct pt_regs *)user_stack;
+       return info.pos;
 }
 
 static void timer_notify(struct pt_regs *regs, int cpu)
@@ -150,32 +146,44 @@ static void timer_notify(struct pt_regs *regs, int cpu)
        __trace_special(tr, data, 0, 0, current->pid);
 
        if (!is_user)
-               regs = trace_kernel(regs, tr, data);
+               i = trace_kernel(regs, tr, data);
+       else
+               i = 0;
 
-       fp = (void __user *)regs->bp;
+       /*
+        * Trace user stack if we are not a kernel thread
+        */
+       if (current->mm && i < sample_max_depth) {
+               regs = (struct pt_regs *)current->thread.sp0 - 1;
 
-       __trace_special(tr, data, 2, regs->ip, 0);
+               fp = (void __user *)regs->bp;
 
-       for (i = 0; i < sample_max_depth; i++) {
-               frame.next_fp = 0;
-               frame.return_address = 0;
-               if (!copy_stack_frame(fp, &frame))
-                       break;
-               if ((unsigned long)fp < regs->sp)
-                       break;
+               __trace_special(tr, data, 2, regs->ip, 0);
 
-               __trace_special(tr, data, 2, frame.return_address,
-                             (unsigned long)fp);
-               fp = frame.next_fp;
-       }
+               while (i < sample_max_depth) {
+                       frame.next_fp = NULL;
+                       frame.return_address = 0;
+                       if (!copy_stack_frame(fp, &frame))
+                               break;
+                       if ((unsigned long)fp < regs->sp)
+                               break;
 
-       __trace_special(tr, data, 3, current->pid, i);
+                       __trace_special(tr, data, 2, frame.return_address,
+                                       (unsigned long)fp);
+                       fp = frame.next_fp;
+
+                       i++;
+               }
+
+       }
 
        /*
         * Special trace entry if we overflow the max depth:
         */
        if (i == sample_max_depth)
                __trace_special(tr, data, -1, -1, -1);
+
+       __trace_special(tr, data, 3, current->pid, i);
 }
 
 static enum hrtimer_restart stack_trace_timer_fn(struct hrtimer *hrtimer)
@@ -194,7 +202,7 @@ static void start_stack_timer(int cpu)
 
        hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        hrtimer->function = stack_trace_timer_fn;
-       hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
+       hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_PERCPU;
 
        hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL);
 }
@@ -233,7 +241,7 @@ static void stack_reset(struct trace_array *tr)
        tr->time_start = ftrace_now(tr->cpu);
 
        for_each_online_cpu(cpu)
-               tracing_reset(tr->data[cpu]);
+               tracing_reset(tr, cpu);
 }
 
 static void start_stack_trace(struct trace_array *tr)