Skip to contentSkip to conversation

oprofile: i386 support for stack trace sampling

PATCH In review Greg Banks 2 participants 3 messages Nov 9, 2004 – Nov 11, 2004

lore
Share & tools
lore

Greg Banks

author
#0 lore raw

PATCH 3/11 oprofile: i386 support for stack trace sampling

Signature · 3 lines
-- 
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.

oprofile i386 arch updates, including some internal API changes and support for stack trace sampling.

---

 arch/i386/oprofile/Makefile          |    2 
 arch/i386/oprofile/backtrace.c       |  118 +++++++++++++++++++++++++++++++++++
 arch/i386/oprofile/init.c            |   12 ++-
 arch/i386/oprofile/nmi_int.c         |   47 ++++++-------
 arch/i386/oprofile/nmi_timer_int.c   |   16 +---
 arch/i386/oprofile/op_model_athlon.c |    9 --
 arch/i386/oprofile/op_model_p4.c     |    9 --
 arch/i386/oprofile/op_model_ppro.c   |    9 --
 arch/i386/oprofile/op_x86_model.h    |    5 -
 9 files changed, 164 insertions(+), 63 deletions(-)
arch/i386/oprofile/op_model_ppro.c +3 -6
Index: linux/arch/i386/oprofile/op_model_ppro.c
===================================================================
@@ -85,19 +85,16 @@ static void ppro_setup_ctrs(struct op_ms
 }
 
  
-static int ppro_check_ctrs(unsigned int const cpu, 
-			    struct op_msrs const * const msrs,
-			    struct pt_regs * const regs)
+static int ppro_check_ctrs(struct pt_regs * const regs,
+			   struct op_msrs const * const msrs)
 {
 	unsigned int low, high;
 	int i;
-	unsigned long eip = profile_pc(regs);
-	int is_kernel = !user_mode(regs);
  
 	for (i = 0 ; i < NUM_COUNTERS; ++i) {
 		CTR_READ(low, high, msrs, i);
 		if (CTR_OVERFLOWED(low)) {
-			oprofile_add_sample(eip, is_kernel, i, cpu);
+			oprofile_add_sample(regs, i);
 			CTR_WRITE(reset_value[i], msrs, i);
 		}
 	}
arch/i386/oprofile/op_model_p4.c +3 -6
Index: linux/arch/i386/oprofile/op_model_p4.c
===================================================================
@@ -619,14 +619,11 @@ static void p4_setup_ctrs(struct op_msrs
 }
 
 
-static int p4_check_ctrs(unsigned int const cpu, 
-			  struct op_msrs const * const msrs,
-			  struct pt_regs * const regs)
+static int p4_check_ctrs(struct pt_regs * const regs,
+			 struct op_msrs const * const msrs)
 {
 	unsigned long ctr, low, high, stag, real;
 	int i;
-	unsigned long eip = profile_pc(regs);
-	int is_kernel = !user_mode(regs);
 
 	stag = get_stagger();
 
@@ -657,7 +654,7 @@ static int p4_check_ctrs(unsigned int co
 		CCCR_READ(low, high, real);
  		CTR_READ(ctr, high, real);
 		if (CCCR_OVF_P(low) || CTR_OVERFLOW_P(ctr)) {
-			oprofile_add_sample(eip, is_kernel, i, cpu);
+			oprofile_add_sample(regs, i);
  			CTR_WRITE(reset_value[i], real);
 			CCCR_CLEAR_OVF(low);
 			CCCR_WRITE(low, high, real);
arch/i386/oprofile/nmi_int.c +22 -25

126 lines not on this page · raw message

arch/i386/oprofile/nmi_timer_int.c +5 -11
Index: linux/arch/i386/oprofile/nmi_timer_int.c
===================================================================
@@ -20,9 +20,7 @@
  
 static int nmi_timer_callback(struct pt_regs * regs, int cpu)
 {
-	unsigned long eip = instruction_pointer(regs);
- 
-	oprofile_add_sample(eip, !user_mode(regs), 0, cpu);
+	oprofile_add_sample(regs, 0);
 	return 1;
 }
 
@@ -42,20 +40,16 @@ static void timer_stop(void)
 }
 
 
-static struct oprofile_operations nmi_timer_ops = {
-	.start	= timer_start,
-	.stop	= timer_stop,
-	.cpu_type = "timer"
-};
-
-int __init nmi_timer_init(struct oprofile_operations ** ops)
+int __init nmi_timer_init(struct oprofile_operations * ops)
 {
 	extern int nmi_active;
 
 	if (nmi_active <= 0)
 		return -ENODEV;
 
-	*ops = &nmi_timer_ops;
+	ops->start = timer_start;
+	ops->stop = timer_stop;
+	ops->cpu_type = "timer";
 	printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
 	return 0;
 }
arch/i386/oprofile/init.c +7 -5
Index: linux/arch/i386/oprofile/init.c
===================================================================
@@ -15,22 +15,24 @@
  * with the NMI mode driver.
  */
  
-extern int nmi_init(struct oprofile_operations ** ops);
-extern int nmi_timer_init(struct oprofile_operations **ops);
+extern int nmi_init(struct oprofile_operations * ops);
+extern int nmi_timer_init(struct oprofile_operations * ops);
 extern void nmi_exit(void);
+extern void x86_backtrace(struct pt_regs * const regs, unsigned int depth);
 
-int __init oprofile_arch_init(struct oprofile_operations ** ops)
+
+void __init oprofile_arch_init(struct oprofile_operations * ops)
 {
 	int ret = -ENODEV;
+
 #ifdef CONFIG_X86_LOCAL_APIC
 	ret = nmi_init(ops);
 #endif
-
 #ifdef CONFIG_X86_IO_APIC
 	if (ret < 0)
 		ret = nmi_timer_init(ops);
 #endif
-	return ret;
+	ops->backtrace = x86_backtrace;
 }
 
 
arch/i386/oprofile/op_x86_model.h +2 -3
Index: linux/arch/i386/oprofile/op_x86_model.h
===================================================================
@@ -36,9 +36,8 @@ struct op_x86_model_spec {
 	unsigned int const num_controls;
 	void (*fill_in_addresses)(struct op_msrs * const msrs);
 	void (*setup_ctrs)(struct op_msrs const * const msrs);
-	int (*check_ctrs)(unsigned int const cpu, 
-		struct op_msrs const * const msrs,
-		struct pt_regs * const regs);
+	int (*check_ctrs)(struct pt_regs * const regs,
+		struct op_msrs const * const msrs);
 	void (*start)(struct op_msrs const * const msrs);
 	void (*stop)(struct op_msrs const * const msrs);
 };
arch/i386/oprofile/Makefile +1 -1
Index: linux/arch/i386/oprofile/Makefile
===================================================================
@@ -6,7 +6,7 @@ DRIVER_OBJS = $(addprefix ../../../drive
 		oprofilefs.o oprofile_stats.o  \
 		timer_int.o )
 
-oprofile-y				:= $(DRIVER_OBJS) init.o
+oprofile-y				:= $(DRIVER_OBJS) init.o backtrace.o
 oprofile-$(CONFIG_X86_LOCAL_APIC) 	+= nmi_int.o op_model_athlon.o \
 					   op_model_ppro.o op_model_p4.o
 oprofile-$(CONFIG_X86_IO_APIC)		+= nmi_timer_int.o
arch/i386/oprofile/op_model_athlon.c +3 -6
Index: linux/arch/i386/oprofile/op_model_athlon.c
===================================================================
@@ -90,19 +90,16 @@ static void athlon_setup_ctrs(struct op_
 }
 
  
-static int athlon_check_ctrs(unsigned int const cpu, 
-			      struct op_msrs const * const msrs, 
-			      struct pt_regs * const regs)
+static int athlon_check_ctrs(struct pt_regs * const regs,
+			     struct op_msrs const * const msrs)
 {
 	unsigned int low, high;
 	int i;
-	unsigned long eip = profile_pc(regs);
-	int is_kernel = !user_mode(regs);
 
 	for (i = 0 ; i < NUM_COUNTERS; ++i) {
 		CTR_READ(low, high, msrs, i);
 		if (CTR_OVERFLOWED(low)) {
-			oprofile_add_sample(eip, is_kernel, i, cpu);
+			oprofile_add_sample(regs, i);
 			CTR_WRITE(reset_value[i], msrs, i);
 		}
 	}
arch/i386/oprofile/backtrace.c new file +118 -0

118 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Greg Banks

oprofile i386 arch updates, including some internal API changes and support for stack trace sampling.

It needs this to compile and link on x86_64. No idea if it works...

---

 25-akpm/arch/i386/oprofile/backtrace.c |    8 +++++++-
 25-akpm/arch/x86_64/oprofile/Makefile  |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
arch/x86_64/oprofile/Makefile renamed from arch/x86_64/oprofile/Makefile~oprofile-i386-support-for-stack-trace-sampling-fix +1 -1
diff -puN arch/x86_64/oprofile/Makefile~oprofile-i386-support-for-stack-trace-sampling-fix arch/x86_64/oprofile/Makefile
@@ -11,7 +11,7 @@ DRIVER_OBJS = $(addprefix ../../../drive
 	oprofilefs.o oprofile_stats.o \
 	timer_int.o )
 
-OPROFILE-y := init.o
+OPROFILE-y := init.o backtrace.o
 OPROFILE-$(CONFIG_X86_LOCAL_APIC) += nmi_int.o op_model_athlon.o op_model_p4.o \
 				     op_model_ppro.o
 OPROFILE-$(CONFIG_X86_IO_APIC)    += nmi_timer_int.o 
arch/i386/oprofile/backtrace.c renamed from arch/i386/oprofile/backtrace.c~oprofile-i386-support-for-stack-trace-sampling-fix +7 -1
diff -puN arch/i386/oprofile/backtrace.c~oprofile-i386-support-for-stack-trace-sampling-fix arch/i386/oprofile/backtrace.c
@@ -96,7 +96,13 @@ static int valid_kernel_stack(struct fra
 void
 x86_backtrace(struct pt_regs * const regs, unsigned int depth)
 {
-	struct frame_head * head = (struct frame_head *)regs->ebp;
+	struct frame_head *head;
+
+#ifdef CONFIG_X86_64
+	head = (struct frame_head *)regs->rbp;
+#else
+	head = (struct frame_head *)regs->ebp;
+#endif
 
 	if (!user_mode(regs)) {
 		while (depth-- && valid_kernel_stack(head, regs))

_

author
#2 lore raw
Quoted 6 lines · Andrew Morton
Quoted 3 lines · Greg Banks

oprofile i386 arch updates, including some internal API changes and support for stack trace sampling.

It needs this to compile and link on x86_64. No idea if it works...

Clearly, there has been zero testing on x86_64. How about we just disable the backtrace code on that platform until it's been tested?

Greg.

Signature · 2 lines
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.

Disable the oprofile backtrace feature pulled into x86_64 from i386 code, until it has been tested on x86_64.

---
 arch/i386/oprofile/init.c     |    4 ++++
 arch/x86_64/oprofile/Makefile |    1 +
 2 files changed, 5 insertions(+)
arch/x86_64/oprofile/Makefile +1 -0
Index: linux/arch/x86_64/oprofile/Makefile
===================================================================
@@ -1,6 +1,7 @@
 #
 # oprofile for x86-64.
 # Just reuse the one from i386. 
+# Except for the backtrace code, which is not yet tested
 #
 
 obj-$(CONFIG_OPROFILE) += oprofile.o
arch/i386/oprofile/init.c +4 -0
Index: linux/arch/i386/oprofile/init.c
===================================================================
@@ -18,8 +18,10 @@
 extern int nmi_init(struct oprofile_operations * ops);
 extern int nmi_timer_init(struct oprofile_operations * ops);
 extern void nmi_exit(void);
+#ifndef CONFIG_X86_64
 extern void x86_backtrace(struct pt_regs * const regs, struct task_struct *,
     	    	    	  unsigned int depth);
+#endif
 
 
 void __init oprofile_arch_init(struct oprofile_operations * ops)
@@ -33,7 +35,9 @@ void __init oprofile_arch_init(struct op
 	if (ret < 0)
 		ret = nmi_timer_init(ops);
 #endif
+#ifndef CONFIG_X86_64
 	ops->backtrace = x86_backtrace;
+#endif
 }