perf core: Add a 'nr' field to perf_event_callchain_context

We will use it to count how many addresses are in the entry->ip[] array,
excluding PERF_CONTEXT_{KERNEL,USER,etc} entries, so that we can really
return the number of entries specified by the user via the relevant
sysctl, kernel.perf_event_max_contexts, or via the per event
perf_event_attr.sample_max_stack knob.

This way we keep the perf_sample->ip_callchain->nr meaning, that is the
number of entries, be it real addresses or PERF_CONTEXT_ entries, while
honouring the max_stack knobs, i.e. the end result will be max_stack
entries if we have at least that many entries in a given stack trace.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-s8teto51tdqvlfhefndtat9r@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cfbcf468
...@@ -75,7 +75,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs ...@@ -75,7 +75,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
tail = (struct frame_tail __user *)regs->ARM_fp - 1; tail = (struct frame_tail __user *)regs->ARM_fp - 1;
while ((entry->entry->nr < entry->max_stack) && while ((entry->nr < entry->max_stack) &&
tail && !((unsigned long)tail & 0x3)) tail && !((unsigned long)tail & 0x3))
tail = user_backtrace(tail, entry); tail = user_backtrace(tail, entry);
} }
......
...@@ -122,7 +122,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry, ...@@ -122,7 +122,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
tail = (struct frame_tail __user *)regs->regs[29]; tail = (struct frame_tail __user *)regs->regs[29];
while (entry->entry->nr < entry->max_stack && while (entry->nr < entry->max_stack &&
tail && !((unsigned long)tail & 0xf)) tail && !((unsigned long)tail & 0xf))
tail = user_backtrace(tail, entry); tail = user_backtrace(tail, entry);
} else { } else {
...@@ -132,7 +132,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry, ...@@ -132,7 +132,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
tail = (struct compat_frame_tail __user *)regs->compat_fp - 1; tail = (struct compat_frame_tail __user *)regs->compat_fp - 1;
while ((entry->entry->nr < entry->max_stack) && while ((entry->nr < entry->max_stack) &&
tail && !((unsigned long)tail & 0x3)) tail && !((unsigned long)tail & 0x3))
tail = compat_user_backtrace(tail, entry); tail = compat_user_backtrace(tail, entry);
#endif #endif
......
...@@ -65,7 +65,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs ...@@ -65,7 +65,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
--frame; --frame;
while ((entry->entry->nr < entry->max_stack) && frame) while ((entry->nr < entry->max_stack) && frame)
frame = user_backtrace(frame, entry); frame = user_backtrace(frame, entry);
} }
......
...@@ -35,7 +35,7 @@ static void save_raw_perf_callchain(struct perf_callchain_entry_ctx *entry, ...@@ -35,7 +35,7 @@ static void save_raw_perf_callchain(struct perf_callchain_entry_ctx *entry,
addr = *sp++; addr = *sp++;
if (__kernel_text_address(addr)) { if (__kernel_text_address(addr)) {
perf_callchain_store(entry, addr); perf_callchain_store(entry, addr);
if (entry->entry->nr >= entry->max_stack) if (entry->nr >= entry->max_stack)
break; break;
} }
} }
...@@ -59,7 +59,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, ...@@ -59,7 +59,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
} }
do { do {
perf_callchain_store(entry, pc); perf_callchain_store(entry, pc);
if (entry->entry->nr >= entry->max_stack) if (entry->nr >= entry->max_stack)
break; break;
pc = unwind_stack(current, &sp, pc, &ra); pc = unwind_stack(current, &sp, pc, &ra);
} while (pc); } while (pc);
......
...@@ -247,7 +247,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, ...@@ -247,7 +247,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
sp = regs->gpr[1]; sp = regs->gpr[1];
perf_callchain_store(entry, next_ip); perf_callchain_store(entry, next_ip);
while (entry->entry->nr < entry->max_stack) { while (entry->nr < entry->max_stack) {
fp = (unsigned long __user *) sp; fp = (unsigned long __user *) sp;
if (!valid_user_sp(sp, 1) || read_user_stack_64(fp, &next_sp)) if (!valid_user_sp(sp, 1) || read_user_stack_64(fp, &next_sp))
return; return;
...@@ -453,7 +453,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, ...@@ -453,7 +453,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
sp = regs->gpr[1]; sp = regs->gpr[1];
perf_callchain_store(entry, next_ip); perf_callchain_store(entry, next_ip);
while (entry->entry->nr < entry->max_stack) { while (entry->nr < entry->max_stack) {
fp = (unsigned int __user *) (unsigned long) sp; fp = (unsigned int __user *) (unsigned long) sp;
if (!valid_user_sp(sp, 0) || read_user_stack_32(fp, &next_sp)) if (!valid_user_sp(sp, 0) || read_user_stack_32(fp, &next_sp))
return; return;
......
...@@ -1756,7 +1756,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, ...@@ -1756,7 +1756,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
} }
} }
#endif #endif
} while (entry->entry->nr < entry->max_stack); } while (entry->nr < entry->max_stack);
} }
static inline int static inline int
...@@ -1790,7 +1790,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, ...@@ -1790,7 +1790,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
pc = sf.callers_pc; pc = sf.callers_pc;
ufp = (unsigned long)sf.fp + STACK_BIAS; ufp = (unsigned long)sf.fp + STACK_BIAS;
perf_callchain_store(entry, pc); perf_callchain_store(entry, pc);
} while (entry->entry->nr < entry->max_stack); } while (entry->nr < entry->max_stack);
} }
static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
...@@ -1822,7 +1822,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, ...@@ -1822,7 +1822,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
ufp = (unsigned long)sf.fp; ufp = (unsigned long)sf.fp;
} }
perf_callchain_store(entry, pc); perf_callchain_store(entry, pc);
} while (entry->entry->nr < entry->max_stack); } while (entry->nr < entry->max_stack);
} }
void void
......
...@@ -2283,7 +2283,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent ...@@ -2283,7 +2283,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
fp = compat_ptr(ss_base + regs->bp); fp = compat_ptr(ss_base + regs->bp);
pagefault_disable(); pagefault_disable();
while (entry->entry->nr < entry->max_stack) { while (entry->nr < entry->max_stack) {
unsigned long bytes; unsigned long bytes;
frame.next_frame = 0; frame.next_frame = 0;
frame.return_address = 0; frame.return_address = 0;
...@@ -2343,7 +2343,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs ...@@ -2343,7 +2343,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
return; return;
pagefault_disable(); pagefault_disable();
while (entry->entry->nr < entry->max_stack) { while (entry->nr < entry->max_stack) {
unsigned long bytes; unsigned long bytes;
frame.next_frame = NULL; frame.next_frame = NULL;
frame.return_address = 0; frame.return_address = 0;
......
...@@ -64,6 +64,7 @@ struct perf_callchain_entry { ...@@ -64,6 +64,7 @@ struct perf_callchain_entry {
struct perf_callchain_entry_ctx { struct perf_callchain_entry_ctx {
struct perf_callchain_entry *entry; struct perf_callchain_entry *entry;
u32 max_stack; u32 max_stack;
u32 nr;
}; };
struct perf_raw_record { struct perf_raw_record {
...@@ -1080,9 +1081,10 @@ extern int sysctl_perf_event_max_stack; ...@@ -1080,9 +1081,10 @@ extern int sysctl_perf_event_max_stack;
static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 ip) static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 ip)
{ {
struct perf_callchain_entry *entry = ctx->entry; if (ctx->nr < ctx->max_stack) {
if (entry->nr < ctx->max_stack) { struct perf_callchain_entry *entry = ctx->entry;
entry->ip[entry->nr++] = ip; entry->ip[entry->nr++] = ip;
++ctx->nr;
return 0; return 0;
} else { } else {
return -1; /* no more room, stop walking the stack */ return -1; /* no more room, stop walking the stack */
......
...@@ -196,8 +196,7 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, ...@@ -196,8 +196,7 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
ctx.entry = entry; ctx.entry = entry;
ctx.max_stack = max_stack; ctx.max_stack = max_stack;
ctx.nr = entry->nr = init_nr;
entry->nr = init_nr;
if (kernel && !user_mode(regs)) { if (kernel && !user_mode(regs)) {
if (add_mark) if (add_mark)
......
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