Skip to content

Commit

Permalink
perf: Expose get/put_callchain_entry()
Browse files Browse the repository at this point in the history
Sanitize and expose get/put_callchain_entry(). This would be used by bpf
stack map.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200630062846.664389-2-songliubraving@fb.com
  • Loading branch information
Song Liu authored and Alexei Starovoitov committed Jul 1, 2020
1 parent bba1dc0 commit d141b8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/linux/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
extern struct perf_callchain_entry *perf_callchain(struct perf_event *event, struct pt_regs *regs);
extern int get_callchain_buffers(int max_stack);
extern void put_callchain_buffers(void);
extern struct perf_callchain_entry *get_callchain_entry(int *rctx);
extern void put_callchain_entry(int rctx);

extern int sysctl_perf_event_max_stack;
extern int sysctl_perf_event_max_contexts_per_stack;
Expand Down
13 changes: 6 additions & 7 deletions kernel/events/callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void put_callchain_buffers(void)
}
}

static struct perf_callchain_entry *get_callchain_entry(int *rctx)
struct perf_callchain_entry *get_callchain_entry(int *rctx)
{
int cpu;
struct callchain_cpus_entries *entries;
Expand All @@ -159,16 +159,18 @@ static struct perf_callchain_entry *get_callchain_entry(int *rctx)
return NULL;

entries = rcu_dereference(callchain_cpus_entries);
if (!entries)
if (!entries) {
put_recursion_context(this_cpu_ptr(callchain_recursion), *rctx);
return NULL;
}

cpu = smp_processor_id();

return (((void *)entries->cpu_entries[cpu]) +
(*rctx * perf_callchain_entry__sizeof()));
}

static void
void
put_callchain_entry(int rctx)
{
put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
Expand All @@ -183,11 +185,8 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
int rctx;

entry = get_callchain_entry(&rctx);
if (rctx == -1)
return NULL;

if (!entry)
goto exit_put;
return NULL;

ctx.entry = entry;
ctx.max_stack = max_stack;
Expand Down

0 comments on commit d141b8b

Please sign in to comment.