Skip to contentSkip to conversation

perf events updates

GIT PULL New Frederic Weisbecker 2 participants 7 messages Jan 29, 2010

Subsystems (6)
x86 PowerPC perf events Tracing +2 more subsystems
lore
Share & tools
lore
#0 lore raw

Ingo,

Please pull the perf/core branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core

Thanks,
Frederic
---

K.Prasad (2):
x86/debug: Clear reserved bits of DR6 in do_debug() x86/hw-breakpoints: Optimize return code from notifier chain in hw_breakpoint_handler

Xiao Guangrong (2):
perf: Factorize trace events raw sample buffer operations tracing/kprobe: Cleanup unused return value of tracing functions

Anton Blanchard (1):
perf: Fix inconsistency between IP and callchain sampling

 arch/powerpc/kernel/perf_callchain.c |    3 -
 arch/sh/kernel/perf_callchain.c      |    3 -
 arch/x86/include/asm/debugreg.h      |    3 +
 arch/x86/kernel/cpu/perf_event.c     |    3 -
 arch/x86/kernel/hw_breakpoint.c      |   10 ++-
 arch/x86/kernel/traps.c              |    3 +
 include/linux/ftrace_event.h         |   18 +++++-
 include/trace/ftrace.h               |   48 ++-------------
 kernel/trace/trace_event_profile.c   |   52 +++++++++++++++--
 kernel/trace/trace_kprobe.c          |  109 ++++++----------------------------
 kernel/trace/trace_syscalls.c        |   71 +++-------------------
 11 files changed, 109 insertions(+), 214 deletions(-)
#1 lore raw

PATCH 1/5 perf: Fix inconsistency between IP and callchain sampling

From: Anton Blanchard <[email protected]>

When running perf across all cpus with backtracing (-a -g), sometimes we get samples without associated backtraces:

    23.44%         init  [kernel]                     [k] restore
    11.46%         init                       eeba0c  [k] 0x00000000eeba0c
     6.77%      swapper  [kernel]                     [k] .perf_ctx_adjust_freq
     5.73%         init  [kernel]                     [k] .__trace_hcall_entry
     4.69%         perf  libc-2.9.so                  [.] 0x0000000006bb8c
                       |
                       |--11.11%-- 0xfffa941bbbc

It turns out the backtrace code has a check for the idle task and the IP sampling does not. This creates problems when profiling an interrupt heavy workload (in my case 10Gbit ethernet) since we get no backtraces for interrupts received while idle (ie most of the workload).

Right now x86 and sh check that current is not NULL, which should never happen so remove that too.

Idle task's exclusion must be performed from the core code, on top of perf_event_attr:exclude_idle.

Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mundt <[email protected]>

LKML-Reference: <20100118054707.GT12666@kryten>

---
 arch/powerpc/kernel/perf_callchain.c |    3 ---
 arch/sh/kernel/perf_callchain.c      |    3 ---
 arch/x86/kernel/cpu/perf_event.c     |    3 ---
 3 files changed, 0 insertions(+), 9 deletions(-)
arch/powerpc/kernel/perf_callchain.c +0 -3
index a3c11ca..95ad9da 100644
@@ -495,9 +495,6 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
 
 	entry->nr = 0;
 
-	if (current->pid == 0)		/* idle task? */
-		return entry;
-
 	if (!user_mode(regs)) {
 		perf_callchain_kernel(regs, entry);
 		if (current->mm)
arch/sh/kernel/perf_callchain.c +0 -3
index 24ea837..a9dd3ab 100644
@@ -68,9 +68,6 @@ perf_do_callchain(struct pt_regs *regs, struct perf_callchain_entry *entry)
 
 	is_user = user_mode(regs);
 
-	if (!current || current->pid == 0)
-		return;
-
 	if (is_user && current->state != TASK_RUNNING)
 		return;
 
arch/x86/kernel/cpu/perf_event.c +0 -3
index b1bb8c5..ed1998b 100644
@@ -2425,9 +2425,6 @@ perf_do_callchain(struct pt_regs *regs, struct perf_callchain_entry *entry)
 
 	is_user = user_mode(regs);
 
-	if (!current || current->pid == 0)
-		return;
-
 	if (is_user && current->state != TASK_RUNNING)
 		return;
 
Signature · 1 line
1.6.2.3
#2 lore raw

PATCH 2/5 perf: Factorize trace events raw sample buffer operations

In reply to Frederic Weisbecker

From: Xiao Guangrong <[email protected]>

Introduce ftrace_perf_buf_prepare() and ftrace_perf_buf_submit() to gather the common code that operates on raw events sampling buffer. This cleans up redundant code between regular trace events, syscall events and kprobe events.

Changelog v1->v2:
- Rename function name as per Masami and Frederic's suggestion
- Add __kprobes for ftrace_perf_buf_prepare() and make ftrace_perf_buf_submit() inline as per Masami's suggestion
- Export ftrace_perf_buf_prepare since modules will use it

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Jason Baron <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 include/linux/ftrace_event.h       |   18 ++++++-
 include/trace/ftrace.h             |   48 +++-----------------
 kernel/trace/trace_event_profile.c |   52 +++++++++++++++++++--
 kernel/trace/trace_kprobe.c        |   86 ++++-------------------------------
 kernel/trace/trace_syscalls.c      |   71 ++++-------------------------
 5 files changed, 88 insertions(+), 187 deletions(-)
include/linux/ftrace_event.h +15 -3
index 0a09e75..cd95919 100644
@@ -5,6 +5,7 @@
 #include <linux/trace_seq.h>
 #include <linux/percpu.h>
 #include <linux/hardirq.h>
+#include <linux/perf_event.h>
 
 struct trace_array;
 struct tracer;
@@ -138,9 +139,6 @@ struct ftrace_event_call {
 
 #define FTRACE_MAX_PROFILE_SIZE	2048
 
-extern char *perf_trace_buf;
-extern char *perf_trace_buf_nmi;
-
 #define MAX_FILTER_PRED		32
 #define MAX_FILTER_STR_VAL	256	/* Should handle KSYM_SYMBOL_LEN */
 
@@ -195,6 +193,20 @@ extern void ftrace_profile_disable(int event_id);
 extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 				     char *filter_str);
 extern void ftrace_profile_free_filter(struct perf_event *event);
+extern void *
+ftrace_perf_buf_prepare(int size, unsigned short type, int *rctxp,
+			 unsigned long *irq_flags);
+
+static inline void
+ftrace_perf_buf_submit(void *raw_data, int size, int rctx, u64 addr,
+		       u64 count, unsigned long irq_flags)
+{
+	struct trace_entry *entry = raw_data;
+
+	perf_tp_event(entry->type, addr, count, raw_data, size);
+	perf_swevent_put_recursion_context(rctx);
+	local_irq_restore(irq_flags);
+}
 #endif
 
 #endif /* _LINUX_FTRACE_EVENT_H */
include/trace/ftrace.h +6 -42

70 lines not on this page · raw message

kernel/trace/trace_event_profile.c +47 -5

64 lines not on this page · raw message

kernel/trace/trace_kprobe.c +10 -76

129 lines not on this page · raw message

kernel/trace/trace_syscalls.c +10 -61

108 lines not on this page · raw message

Signature · 1 line
1.6.2.3
#3 lore raw

PATCH 3/5 tracing/kprobe: Cleanup unused return value of tracing functions

In reply to Frederic Weisbecker

From: Xiao Guangrong <[email protected]>

The return values of the kprobe's tracing functions are meaningless, lets remove these.

Cc Steven Rostedt <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Jason Baron <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]> [fweisbec@gmail: whitespace fixes, drop useless void returns in end of functions]

---
 kernel/trace/trace_kprobe.c |   27 ++++++++++-----------------
 1 files changed, 10 insertions(+), 17 deletions(-)
kernel/trace/trace_kprobe.c +10 -17
index 2e28ee3..6178abf 100644
@@ -942,7 +942,7 @@ static const struct file_operations kprobe_profile_ops = {
 };
 
 /* Kprobe handler */
-static __kprobes int kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
+static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
 	struct kprobe_trace_entry *entry;
@@ -962,7 +962,7 @@ static __kprobes int kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
 	event = trace_current_buffer_lock_reserve(&buffer, call->id, size,
 						  irq_flags, pc);
 	if (!event)
-		return 0;
+		return;
 
 	entry = ring_buffer_event_data(event);
 	entry->nargs = tp->nr_args;
@@ -972,11 +972,10 @@ static __kprobes int kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
 
 	if (!filter_current_check_discard(buffer, call, entry, event))
 		trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc);
-	return 0;
 }
 
 /* Kretprobe handler */
-static __kprobes int kretprobe_trace_func(struct kretprobe_instance *ri,
+static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
 					  struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
@@ -995,7 +994,7 @@ static __kprobes int kretprobe_trace_func(struct kretprobe_instance *ri,
 	event = trace_current_buffer_lock_reserve(&buffer, call->id, size,
 						  irq_flags, pc);
 	if (!event)
-		return 0;
+		return;
 
 	entry = ring_buffer_event_data(event);
 	entry->nargs = tp->nr_args;
@@ -1006,8 +1005,6 @@ static __kprobes int kretprobe_trace_func(struct kretprobe_instance *ri,
 
 	if (!filter_current_check_discard(buffer, call, entry, event))
 		trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc);
-
-	return 0;
 }
 
 /* Event entry printers */
@@ -1237,7 +1234,7 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 #ifdef CONFIG_PERF_EVENTS
 
 /* Kprobe profile handler */
-static __kprobes int kprobe_profile_func(struct kprobe *kp,
+static __kprobes void kprobe_profile_func(struct kprobe *kp,
 					 struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
@@ -1252,11 +1249,11 @@ static __kprobes int kprobe_profile_func(struct kprobe *kp,
 	size -= sizeof(u32);
 	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
 		     "profile buffer not large enough"))
-		return 0;
+		return;
 
 	entry = ftrace_perf_buf_prepare(size, call->id, &rctx, &irq_flags);
 	if (!entry)
-		return 0;
+		return;
 
 	entry->nargs = tp->nr_args;
 	entry->ip = (unsigned long)kp->addr;
@@ -1264,12 +1261,10 @@ static __kprobes int kprobe_profile_func(struct kprobe *kp,
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
 	ftrace_perf_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags);
-
-	return 0;
 }
 
 /* Kretprobe profile handler */
-static __kprobes int kretprobe_profile_func(struct kretprobe_instance *ri,
+static __kprobes void kretprobe_profile_func(struct kretprobe_instance *ri,
 					    struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
@@ -1284,11 +1279,11 @@ static __kprobes int kretprobe_profile_func(struct kretprobe_instance *ri,
 	size -= sizeof(u32);
 	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
 		     "profile buffer not large enough"))
-		return 0;
+		return;
 
 	entry = ftrace_perf_buf_prepare(size, call->id, &rctx, &irq_flags);
 	if (!entry)
-		return 0;
+		return;
 
 	entry->nargs = tp->nr_args;
 	entry->func = (unsigned long)tp->rp.kp.addr;
@@ -1297,8 +1292,6 @@ static __kprobes int kretprobe_profile_func(struct kretprobe_instance *ri,
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
 	ftrace_perf_buf_submit(entry, size, rctx, entry->ret_ip, 1, irq_flags);
-
-	return 0;
 }
 
 static int probe_profile_enable(struct ftrace_event_call *call)
Signature · 1 line
1.6.2.3
#4 lore raw

PATCH 4/5 x86/debug: Clear reserved bits of DR6 in do_debug()

In reply to Frederic Weisbecker

From: K.Prasad <[email protected]>

Clear the reserved bits from the stored copy of debug status register (DR6).
This will help easy bitwise operations such as quick testing of a debug event origin.

Cc Roland McGrath <[email protected]>
Cc Jan Kiszka <[email protected]>
Cc Alan Stern <[email protected]>
Cc Ingo Molnar <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/debugreg.h |    3 +++
 arch/x86/kernel/traps.c         |    3 +++
 2 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/include/asm/debugreg.h +3 -0
index 8240f76..b81002f 100644
@@ -14,6 +14,9 @@
    which debugging register was responsible for the trap.  The other bits
    are either reserved or not of interest to us. */
 
+/* Define reserved bits in DR6 which are always set to 1 */
+#define DR6_RESERVED	(0xFFFF0FF0)
+
 #define DR_TRAP0	(0x1)		/* db0 */
 #define DR_TRAP1	(0x2)		/* db1 */
 #define DR_TRAP2	(0x4)		/* db2 */
arch/x86/kernel/traps.c +3 -0
index 3339917..1168e44 100644
@@ -534,6 +534,9 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 
 	get_debugreg(dr6, 6);
 
+	/* Filter out all the reserved bits which are preset to 1 */
+	dr6 &= ~DR6_RESERVED;
+
 	/* Catch kmemcheck conditions first of all! */
 	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
 		return;
Signature · 1 line
1.6.2.3
#5 lore raw

PATCH 5/5 x86/hw-breakpoints: Optimize return code from notifier chain in hw_breakpoint_handler

In reply to Frederic Weisbecker

From: K.Prasad <[email protected]>

Processing of debug exceptions in do_debug() can stop if it originated from a hw-breakpoint exception by returning NOTIFY_STOP in most cases.

But for certain cases such as:

a) user-space breakpoints with pending SIGTRAP signal delivery (as in the case of ptrace induced breakpoints).

b) exceptions due to other causes than breakpoints

We will continue to process the exception by returning NOTIFY_DONE.

Cc Ingo Molnar <[email protected]>
Cc Roland McGrath <[email protected]>
Cc Alan Stern <[email protected]>
Cc Jan Kiszka <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/hw_breakpoint.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/hw_breakpoint.c +7 -3
index 05d5fec..ae90b47 100644
@@ -502,8 +502,6 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
 		rcu_read_lock();
 
 		bp = per_cpu(bp_per_reg[i], cpu);
-		if (bp)
-			rc = NOTIFY_DONE;
 		/*
 		 * Reset the 'i'th TRAP bit in dr6 to denote completion of
 		 * exception handling
@@ -522,7 +520,13 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
 
 		rcu_read_unlock();
 	}
-	if (dr6 & (~DR_TRAP_BITS))
+	/*
+	 * Further processing in do_debug() is needed for a) user-space
+	 * breakpoints (to generate signals) and b) when the system has
+	 * taken exception due to multiple causes
+	 */
+	if ((current->thread.debugreg6 & DR_TRAP_BITS) ||
+	    (dr6 & (~DR_TRAP_BITS)))
 		rc = NOTIFY_DONE;
 
 	set_debugreg(dr7, 7);
Signature · 1 line
1.6.2.3
#6 lore raw
In reply to Frederic Weisbecker
Quoted 23 lines · Frederic Weisbecker

Ingo,

Please pull the perf/core branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core

Thanks,
Frederic
---

K.Prasad (2):
x86/debug: Clear reserved bits of DR6 in do_debug() x86/hw-breakpoints: Optimize return code from notifier chain in hw_breakpoint_handler

Xiao Guangrong (2):
perf: Factorize trace events raw sample buffer operations tracing/kprobe: Cleanup unused return value of tracing functions

Anton Blanchard (1):
perf: Fix inconsistency between IP and callchain sampling

Quoted 12 lines
 arch/powerpc/kernel/perf_callchain.c |    3 -
 arch/sh/kernel/perf_callchain.c      |    3 -
 arch/x86/include/asm/debugreg.h      |    3 +
 arch/x86/kernel/cpu/perf_event.c     |    3 -
 arch/x86/kernel/hw_breakpoint.c      |   10 ++-
 arch/x86/kernel/traps.c              |    3 +
 include/linux/ftrace_event.h         |   18 +++++-
 include/trace/ftrace.h               |   48 ++-------------
 kernel/trace/trace_event_profile.c   |   52 +++++++++++++++--
 kernel/trace/trace_kprobe.c          |  109 ++++++----------------------------
 kernel/trace/trace_syscalls.c        |   71 +++-------------------
 11 files changed, 109 insertions(+), 214 deletions(-)

Pulled, thanks a lot Frederic!

Ingo