Release 4.15 kernel/events/callchain.c
/*
* Performance events callchain code, extracted from core.c:
*
* Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de>
* Copyright (C) 2008-2011 Red Hat, Inc., Ingo Molnar
* Copyright (C) 2008-2011 Red Hat, Inc., Peter Zijlstra
* Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
*
* For licensing details see kernel-base/COPYING
*/
#include <linux/perf_event.h>
#include <linux/slab.h>
#include <linux/sched/task_stack.h>
#include "internal.h"
struct callchain_cpus_entries {
struct rcu_head rcu_head;
struct perf_callchain_entry *cpu_entries[0];
};
int sysctl_perf_event_max_stack __read_mostly = PERF_MAX_STACK_DEPTH;
int sysctl_perf_event_max_contexts_per_stack __read_mostly = PERF_MAX_CONTEXTS_PER_STACK;
static inline size_t perf_callchain_entry__sizeof(void)
{
return (sizeof(struct perf_callchain_entry) +
sizeof(__u64) * (sysctl_perf_event_max_stack +
sysctl_perf_event_max_contexts_per_stack));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Arnaldo Carvalho de Melo | 29 | 100.00% | 2 | 100.00% |
Total | 29 | 100.00% | 2 | 100.00% |
static DEFINE_PER_CPU(int, callchain_recursion[PERF_NR_CONTEXTS]);
static atomic_t nr_callchain_events;
static DEFINE_MUTEX(callchain_mutex);
static struct callchain_cpus_entries *callchain_cpus_entries;
__weak void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
struct pt_regs *regs)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 14 | 93.33% | 1 | 50.00% |
Arnaldo Carvalho de Melo | 1 | 6.67% | 1 | 50.00% |
Total | 15 | 100.00% | 2 | 100.00% |
__weak void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
struct pt_regs *regs)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 14 | 93.33% | 1 | 50.00% |
Arnaldo Carvalho de Melo | 1 | 6.67% | 1 | 50.00% |
Total | 15 | 100.00% | 2 | 100.00% |
static void release_callchain_buffers_rcu(struct rcu_head *head)
{
struct callchain_cpus_entries *entries;
int cpu;
entries = container_of(head, struct callchain_cpus_entries, rcu_head);
for_each_possible_cpu(cpu)
kfree(entries->cpu_entries[cpu]);
kfree(entries);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 50 | 100.00% | 1 | 100.00% |
Total | 50 | 100.00% | 1 | 100.00% |
static void release_callchain_buffers(void)
{
struct callchain_cpus_entries *entries;
entries = callchain_cpus_entries;
RCU_INIT_POINTER(callchain_cpus_entries, NULL);
call_rcu(&entries->rcu_head, release_callchain_buffers_rcu);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 33 | 97.06% | 1 | 50.00% |
Andreea-Cristina Bernat | 1 | 2.94% | 1 | 50.00% |
Total | 34 | 100.00% | 2 | 100.00% |
static int alloc_callchain_buffers(void)
{
int cpu;
int size;
struct callchain_cpus_entries *entries;
/*
* We can't use the percpu allocation API for data that can be
* accessed from NMI. Use a temporary manual per cpu allocation
* until that gets sorted out.
*/
size = offsetof(struct callchain_cpus_entries, cpu_entries[nr_cpu_ids]);
entries = kzalloc(size, GFP_KERNEL);
if (!entries)
return -ENOMEM;
size = perf_callchain_entry__sizeof() * PERF_NR_CONTEXTS;
for_each_possible_cpu(cpu) {
entries->cpu_entries[cpu] = kmalloc_node(size, GFP_KERNEL,
cpu_to_node(cpu));
if (!entries->cpu_entries[cpu])
goto fail;
}
rcu_assign_pointer(callchain_cpus_entries, entries);
return 0;
fail:
for_each_possible_cpu(cpu)
kfree(entries->cpu_entries[cpu]);
kfree(entries);
return -ENOMEM;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 129 | 98.47% | 1 | 50.00% |
Arnaldo Carvalho de Melo | 2 | 1.53% | 1 | 50.00% |
Total | 131 | 100.00% | 2 | 100.00% |
int get_callchain_buffers(int event_max_stack)
{
int err = 0;
int count;
mutex_lock(&callchain_mutex);
count = atomic_inc_return(&nr_callchain_events);
if (WARN_ON_ONCE(count < 1)) {
err = -EINVAL;
goto exit;
}
if (count > 1) {
/* If the allocation failed, give up */
if (!callchain_cpus_entries)
err = -ENOMEM;
/*
* If requesting per event more than the global cap,
* return a different error to help userspace figure
* this out.
*
* And also do it here so that we have &callchain_mutex held.
*/
if (event_max_stack > sysctl_perf_event_max_stack)
err = -EOVERFLOW;
goto exit;
}
err = alloc_callchain_buffers();
exit:
if (err)
atomic_dec(&nr_callchain_events);
mutex_unlock(&callchain_mutex);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 79 | 72.48% | 1 | 25.00% |
Frédéric Weisbecker | 16 | 14.68% | 2 | 50.00% |
Arnaldo Carvalho de Melo | 14 | 12.84% | 1 | 25.00% |
Total | 109 | 100.00% | 4 | 100.00% |
void put_callchain_buffers(void)
{
if (atomic_dec_and_mutex_lock(&nr_callchain_events, &callchain_mutex)) {
release_callchain_buffers();
mutex_unlock(&callchain_mutex);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
static struct perf_callchain_entry *get_callchain_entry(int *rctx)
{
int cpu;
struct callchain_cpus_entries *entries;
*rctx = get_recursion_context(this_cpu_ptr(callchain_recursion));
if (*rctx == -1)
return NULL;
entries = rcu_dereference(callchain_cpus_entries);
if (!entries)
return NULL;
cpu = smp_processor_id();
return (((void *)entries->cpu_entries[cpu]) +
(*rctx * perf_callchain_entry__sizeof()));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 71 | 82.56% | 1 | 33.33% |
Arnaldo Carvalho de Melo | 14 | 16.28% | 1 | 33.33% |
Christoph Lameter | 1 | 1.16% | 1 | 33.33% |
Total | 86 | 100.00% | 3 | 100.00% |
static void
put_callchain_entry(int rctx)
{
put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 18 | 94.74% | 1 | 50.00% |
Christoph Lameter | 1 | 5.26% | 1 | 50.00% |
Total | 19 | 100.00% | 2 | 100.00% |
struct perf_callchain_entry *
perf_callchain(struct perf_event *event, struct pt_regs *regs)
{
bool kernel = !event->attr.exclude_callchain_kernel;
bool user = !event->attr.exclude_callchain_user;
/* Disallow cross-task user callchains. */
bool crosstask = event->ctx->task && event->ctx->task != current;
const u32 max_stack = event->attr.sample_max_stack;
if (!kernel && !user)
return NULL;
return get_perf_callchain(regs, 0, kernel, user, max_stack, crosstask, true);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexei Starovoitov | 37 | 39.36% | 1 | 16.67% |
Frédéric Weisbecker | 29 | 30.85% | 1 | 16.67% |
Arnaldo Carvalho de Melo | 12 | 12.77% | 2 | 33.33% |
Borislav Petkov | 11 | 11.70% | 1 | 16.67% |
Andrey Vagin | 5 | 5.32% | 1 | 16.67% |
Total | 94 | 100.00% | 6 | 100.00% |
struct perf_callchain_entry *
get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
u32 max_stack, bool crosstask, bool add_mark)
{
struct perf_callchain_entry *entry;
struct perf_callchain_entry_ctx ctx;
int rctx;
entry = get_callchain_entry(&rctx);
if (rctx == -1)
return NULL;
if (!entry)
goto exit_put;
ctx.entry = entry;
ctx.max_stack = max_stack;
ctx.nr = entry->nr = init_nr;
ctx.contexts = 0;
ctx.contexts_maxed = false;
if (kernel && !user_mode(regs)) {
if (add_mark)
perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL);
perf_callchain_kernel(&ctx, regs);
}
if (user) {
if (!user_mode(regs)) {
if (current->mm)
regs = task_pt_regs(current);
else
regs = NULL;
}
if (regs) {
mm_segment_t fs;
if (crosstask)
goto exit_put;
if (add_mark)
perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
fs = get_fs();
set_fs(USER_DS);
perf_callchain_user(&ctx, regs);
set_fs(fs);
}
}
exit_put:
put_callchain_entry(rctx);
return entry;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 98 | 42.79% | 1 | 11.11% |
Arnaldo Carvalho de Melo | 45 | 19.65% | 4 | 44.44% |
Alexei Starovoitov | 44 | 19.21% | 1 | 11.11% |
Will Deacon | 18 | 7.86% | 1 | 11.11% |
Frédéric Weisbecker | 18 | 7.86% | 1 | 11.11% |
Andrey Vagin | 6 | 2.62% | 1 | 11.11% |
Total | 229 | 100.00% | 9 | 100.00% |
/*
* Used for sysctl_perf_event_max_stack and
* sysctl_perf_event_max_contexts_per_stack.
*/
int perf_event_max_stack_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
int *value = table->data;
int new_value = *value, ret;
struct ctl_table new_table = *table;
new_table.data = &new_value;
ret = proc_dointvec_minmax(&new_table, write, buffer, lenp, ppos);
if (ret || !write)
return ret;
mutex_lock(&callchain_mutex);
if (atomic_read(&nr_callchain_events))
ret = -EBUSY;
else
*value = new_value;
mutex_unlock(&callchain_mutex);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Arnaldo Carvalho de Melo | 116 | 100.00% | 2 | 100.00% |
Total | 116 | 100.00% | 2 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Borislav Petkov | 599 | 58.38% | 1 | 5.56% |
Arnaldo Carvalho de Melo | 247 | 24.07% | 7 | 38.89% |
Alexei Starovoitov | 81 | 7.89% | 1 | 5.56% |
Frédéric Weisbecker | 63 | 6.14% | 3 | 16.67% |
Will Deacon | 18 | 1.75% | 1 | 5.56% |
Andrey Vagin | 11 | 1.07% | 1 | 5.56% |
Ingo Molnar | 3 | 0.29% | 1 | 5.56% |
Christoph Lameter | 2 | 0.19% | 1 | 5.56% |
Peter Zijlstra | 1 | 0.10% | 1 | 5.56% |
Andreea-Cristina Bernat | 1 | 0.10% | 1 | 5.56% |
Total | 1026 | 100.00% | 18 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.