Commit 25432ae9 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf: Optimize perf_sched_events() usage

It doesn't make sense to take up-to _4_ references on
perf_sched_events() per event, avoid doing this.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent aee7dbc4
...@@ -3491,11 +3491,13 @@ static void unaccount_event_cpu(struct perf_event *event, int cpu) ...@@ -3491,11 +3491,13 @@ static void unaccount_event_cpu(struct perf_event *event, int cpu)
static void unaccount_event(struct perf_event *event) static void unaccount_event(struct perf_event *event)
{ {
bool dec = false;
if (event->parent) if (event->parent)
return; return;
if (event->attach_state & PERF_ATTACH_TASK) if (event->attach_state & PERF_ATTACH_TASK)
static_key_slow_dec_deferred(&perf_sched_events); dec = true;
if (event->attr.mmap || event->attr.mmap_data) if (event->attr.mmap || event->attr.mmap_data)
atomic_dec(&nr_mmap_events); atomic_dec(&nr_mmap_events);
if (event->attr.comm) if (event->attr.comm)
...@@ -3505,12 +3507,15 @@ static void unaccount_event(struct perf_event *event) ...@@ -3505,12 +3507,15 @@ static void unaccount_event(struct perf_event *event)
if (event->attr.freq) if (event->attr.freq)
atomic_dec(&nr_freq_events); atomic_dec(&nr_freq_events);
if (event->attr.context_switch) { if (event->attr.context_switch) {
static_key_slow_dec_deferred(&perf_sched_events); dec = true;
atomic_dec(&nr_switch_events); atomic_dec(&nr_switch_events);
} }
if (is_cgroup_event(event)) if (is_cgroup_event(event))
static_key_slow_dec_deferred(&perf_sched_events); dec = true;
if (has_branch_stack(event)) if (has_branch_stack(event))
dec = true;
if (dec)
static_key_slow_dec_deferred(&perf_sched_events); static_key_slow_dec_deferred(&perf_sched_events);
unaccount_event_cpu(event, event->cpu); unaccount_event_cpu(event, event->cpu);
...@@ -7723,11 +7728,13 @@ static void account_event_cpu(struct perf_event *event, int cpu) ...@@ -7723,11 +7728,13 @@ static void account_event_cpu(struct perf_event *event, int cpu)
static void account_event(struct perf_event *event) static void account_event(struct perf_event *event)
{ {
bool inc = false;
if (event->parent) if (event->parent)
return; return;
if (event->attach_state & PERF_ATTACH_TASK) if (event->attach_state & PERF_ATTACH_TASK)
static_key_slow_inc(&perf_sched_events.key); inc = true;
if (event->attr.mmap || event->attr.mmap_data) if (event->attr.mmap || event->attr.mmap_data)
atomic_inc(&nr_mmap_events); atomic_inc(&nr_mmap_events);
if (event->attr.comm) if (event->attr.comm)
...@@ -7740,11 +7747,14 @@ static void account_event(struct perf_event *event) ...@@ -7740,11 +7747,14 @@ static void account_event(struct perf_event *event)
} }
if (event->attr.context_switch) { if (event->attr.context_switch) {
atomic_inc(&nr_switch_events); atomic_inc(&nr_switch_events);
static_key_slow_inc(&perf_sched_events.key); inc = true;
} }
if (has_branch_stack(event)) if (has_branch_stack(event))
static_key_slow_inc(&perf_sched_events.key); inc = true;
if (is_cgroup_event(event)) if (is_cgroup_event(event))
inc = true;
if (inc)
static_key_slow_inc(&perf_sched_events.key); static_key_slow_inc(&perf_sched_events.key);
account_event_cpu(event, event->cpu); account_event_cpu(event, event->cpu);
......
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