]> err.no Git - linux-2.6/commitdiff
[PATCH] powerpc: Add oprofile calltrace support
authorBrian Rogan <bcr6@cornell.edu>
Mon, 27 Mar 2006 00:57:01 +0000 (11:57 +1100)
committerPaul Mackerras <paulus@samba.org>
Wed, 29 Mar 2006 02:44:16 +0000 (13:44 +1100)
Add oprofile calltrace support to powerpc. Disable spinlock backtracing
now we can use calltrace info.

(Updated to work on both 32bit and 64bit by me).

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/oprofile/Makefile
arch/powerpc/oprofile/backtrace.c [new file with mode: 0644]
arch/powerpc/oprofile/common.c
arch/powerpc/oprofile/op_model_power4.c
include/asm-powerpc/oprofile_impl.h

index 554cd7c75321b0be99bfb53d44f363ebefb9e691..f5f9859a833886c1cfe3ba71426aa5e9cbf8dee8 100644 (file)
@@ -6,7 +6,7 @@ DRIVER_OBJS := $(addprefix ../../../drivers/oprofile/, \
                oprofilefs.o oprofile_stats.o \
                timer_int.o )
 
-oprofile-y := $(DRIVER_OBJS) common.o
+oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
 oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o
 oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o
 oprofile-$(CONFIG_PPC32) += op_model_7450.o
diff --git a/arch/powerpc/oprofile/backtrace.c b/arch/powerpc/oprofile/backtrace.c
new file mode 100644 (file)
index 0000000..75f57bc
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * Copyright (C) 2005 Brian Rogan <bcr6@cornell.edu>, IBM
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+**/
+
+#include <linux/oprofile.h>
+#include <linux/sched.h>
+#include <asm/processor.h>
+#include <asm/uaccess.h>
+
+#define STACK_SP(STACK)                *(STACK)
+
+#define STACK_LR64(STACK)      *((unsigned long *)(STACK) + 2)
+#define STACK_LR32(STACK)      *((unsigned int *)(STACK) + 1)
+
+#ifdef CONFIG_PPC64
+#define STACK_LR(STACK)                STACK_LR64(STACK)
+#else
+#define STACK_LR(STACK)                STACK_LR32(STACK)
+#endif
+
+static unsigned int user_getsp32(unsigned int sp, int is_first)
+{
+       unsigned int stack_frame[2];
+
+       if (!access_ok(VERIFY_READ, sp, sizeof(stack_frame)))
+               return 0;
+
+       /*
+        * The most likely reason for this is that we returned -EFAULT,
+        * which means that we've done all that we can do from
+        * interrupt context.
+        */
+       if (__copy_from_user_inatomic(stack_frame, (void *)(long)sp,
+                                       sizeof(stack_frame)))
+               return 0;
+
+       if (!is_first)
+               oprofile_add_trace(STACK_LR32(stack_frame));
+
+       /*
+        * We do not enforce increasing stack addresses here because
+        * we may transition to a different stack, eg a signal handler.
+        */
+       return STACK_SP(stack_frame);
+}
+
+#ifdef CONFIG_PPC64
+static unsigned long user_getsp64(unsigned long sp, int is_first)
+{
+       unsigned long stack_frame[3];
+
+       if (!access_ok(VERIFY_READ, sp, sizeof(stack_frame)))
+               return 0;
+
+       if (__copy_from_user_inatomic(stack_frame, (void *)sp,
+                                       sizeof(stack_frame)))
+               return 0;
+
+       if (!is_first)
+               oprofile_add_trace(STACK_LR64(stack_frame));
+
+       return STACK_SP(stack_frame);
+}
+#endif
+
+static unsigned long kernel_getsp(unsigned long sp, int is_first)
+{
+       unsigned long *stack_frame = (unsigned long *)sp;
+
+       if (!validate_sp(sp, current, STACK_FRAME_OVERHEAD))
+               return 0;
+
+       if (!is_first)
+               oprofile_add_trace(STACK_LR(stack_frame));
+
+       /*
+        * We do not enforce increasing stack addresses here because
+        * we might be transitioning from an interrupt stack to a kernel
+        * stack. validate_sp() is designed to understand this, so just
+        * use it.
+        */
+       return STACK_SP(stack_frame);
+}
+
+void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth)
+{
+       unsigned long sp = regs->gpr[1];
+       int first_frame = 1;
+
+       /* We ditch the top stackframe so need to loop through an extra time */
+       depth += 1;
+
+       if (!user_mode(regs)) {
+               while (depth--) {
+                       sp = kernel_getsp(sp, first_frame);
+                       if (!sp)
+                               break;
+                       first_frame = 0;
+               }
+       } else {
+#ifdef CONFIG_PPC64
+               if (!test_thread_flag(TIF_32BIT)) {
+                       while (depth--) {
+                               sp = user_getsp64(sp, first_frame);
+                               if (!sp)
+                                       break;
+                               first_frame = 0;
+                       }
+
+                       return;
+               }
+#endif
+
+               while (depth--) {
+                       sp = user_getsp32(sp, first_frame);
+                       if (!sp)
+                               break;
+                       first_frame = 0;
+               }
+       }
+}
index cc2535be3a73641326f49c4bb73233729ce7d314..2b9143b0f6bafcfc6179b86c1d23d7773c31a53f 100644 (file)
@@ -126,8 +126,7 @@ static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
        sys.enable_kernel = 1;
        sys.enable_user = 1;
 #ifdef CONFIG_PPC64
-       /* Turn on backtracing through spinlocks by default */
-       sys.backtrace_spinlocks = 1;
+       sys.backtrace_spinlocks = 0;
 #endif
 
        return 0;
@@ -168,6 +167,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
        ops->shutdown = op_powerpc_shutdown;
        ops->start = op_powerpc_start;
        ops->stop = op_powerpc_stop;
+       ops->backtrace = op_powerpc_backtrace;
 
        printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
               ops->cpu_type);
index 4b06e53eb9b4bb0d4b7c521cc2fa0fdd97abb62b..38db2efef3bc53223dac08a5455b44f338772f76 100644 (file)
@@ -293,7 +293,7 @@ static void power4_handle_interrupt(struct pt_regs *regs,
                val = ctr_read(i);
                if (val < 0) {
                        if (oprofile_running && ctr[i].enabled) {
-                               oprofile_add_pc(pc, is_kernel, i);
+                               oprofile_add_ext_sample(pc, regs, i, is_kernel);
                                ctr_write(i, reset_value[i]);
                        } else {
                                ctr_write(i, 0);
index df4defc6321c190a621a38a40e3288d98bc65e69..aa180e907a675762fc1fd2ebdad14471b20fcbe4 100644 (file)
@@ -126,5 +126,7 @@ static inline void ctr_write(unsigned int i, unsigned int val)
 }
 #endif /* !CONFIG_FSL_BOOKE */
 
+extern void op_powerpc_backtrace(struct pt_regs * const regs, unsigned int depth);
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_OPROFILE_IMPL_H */