Commit f9188e02 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf_counter: Make callchain samples extensible

Before exposing upstream tools to a callchain-samples ABI, tidy it
up to make it more extensible in the future:

Use markers in the IP chain to denote context, use (u64)-1..-4095 range
for these context markers because we use them for ERR_PTR(), so these
addresses are unlikely to be mapped.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent b8e6d829
...@@ -1555,9 +1555,9 @@ const struct pmu *hw_perf_counter_init(struct perf_counter *counter) ...@@ -1555,9 +1555,9 @@ const struct pmu *hw_perf_counter_init(struct perf_counter *counter)
*/ */
static inline static inline
void callchain_store(struct perf_callchain_entry *entry, unsigned long ip) void callchain_store(struct perf_callchain_entry *entry, u64 ip)
{ {
if (entry->nr < MAX_STACK_DEPTH) if (entry->nr < PERF_MAX_STACK_DEPTH)
entry->ip[entry->nr++] = ip; entry->ip[entry->nr++] = ip;
} }
...@@ -1602,22 +1602,10 @@ static const struct stacktrace_ops backtrace_ops = { ...@@ -1602,22 +1602,10 @@ static const struct stacktrace_ops backtrace_ops = {
static void static void
perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry) perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry)
{ {
unsigned long bp; callchain_store(entry, PERF_CONTEXT_KERNEL);
char *stack;
int nr = entry->nr;
callchain_store(entry, regs->ip); callchain_store(entry, regs->ip);
stack = ((char *)regs + sizeof(struct pt_regs)); dump_trace(NULL, regs, NULL, 0, &backtrace_ops, entry);
#ifdef CONFIG_FRAME_POINTER
get_bp(bp);
#else
bp = 0;
#endif
dump_trace(NULL, regs, (void *)&stack, bp, &backtrace_ops, entry);
entry->kernel = entry->nr - nr;
} }
/* /*
...@@ -1669,16 +1657,16 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) ...@@ -1669,16 +1657,16 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry)
{ {
struct stack_frame frame; struct stack_frame frame;
const void __user *fp; const void __user *fp;
int nr = entry->nr;
if (!user_mode(regs)) if (!user_mode(regs))
regs = task_pt_regs(current); regs = task_pt_regs(current);
fp = (void __user *)regs->bp; fp = (void __user *)regs->bp;
callchain_store(entry, PERF_CONTEXT_USER);
callchain_store(entry, regs->ip); callchain_store(entry, regs->ip);
while (entry->nr < MAX_STACK_DEPTH) { while (entry->nr < PERF_MAX_STACK_DEPTH) {
frame.next_frame = NULL; frame.next_frame = NULL;
frame.return_address = 0; frame.return_address = 0;
...@@ -1691,8 +1679,6 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) ...@@ -1691,8 +1679,6 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry)
callchain_store(entry, frame.return_address); callchain_store(entry, frame.return_address);
fp = frame.next_frame; fp = frame.next_frame;
} }
entry->user = entry->nr - nr;
} }
static void static void
...@@ -1728,9 +1714,6 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs) ...@@ -1728,9 +1714,6 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
entry = &__get_cpu_var(irq_entry); entry = &__get_cpu_var(irq_entry);
entry->nr = 0; entry->nr = 0;
entry->hv = 0;
entry->kernel = 0;
entry->user = 0;
perf_do_callchain(regs, entry); perf_do_callchain(regs, entry);
......
...@@ -343,23 +343,22 @@ enum perf_event_type { ...@@ -343,23 +343,22 @@ enum perf_event_type {
* { u64 nr; * { u64 nr;
* { u64 id, val; } cnt[nr]; } && PERF_SAMPLE_GROUP * { u64 id, val; } cnt[nr]; } && PERF_SAMPLE_GROUP
* *
* { u16 nr, * { u64 nr,
* hv,
* kernel,
* user;
* u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
* }; * };
*/ */
}; };
#define MAX_STACK_DEPTH 255 enum perf_callchain_context {
PERF_CONTEXT_HV = (__u64)-32,
PERF_CONTEXT_KERNEL = (__u64)-128,
PERF_CONTEXT_USER = (__u64)-512,
struct perf_callchain_entry { PERF_CONTEXT_GUEST = (__u64)-2048,
__u16 nr; PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
__u16 hv; PERF_CONTEXT_GUEST_USER = (__u64)-2560,
__u16 kernel;
__u16 user; PERF_CONTEXT_MAX = (__u64)-4095,
__u64 ip[MAX_STACK_DEPTH];
}; };
#ifdef __KERNEL__ #ifdef __KERNEL__
...@@ -381,6 +380,13 @@ struct perf_callchain_entry { ...@@ -381,6 +380,13 @@ struct perf_callchain_entry {
#include <linux/pid_namespace.h> #include <linux/pid_namespace.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#define PERF_MAX_STACK_DEPTH 255
struct perf_callchain_entry {
__u64 nr;
__u64 ip[PERF_MAX_STACK_DEPTH];
};
struct task_struct; struct task_struct;
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment