Skip to content

Commit

Permalink
perf_counter: Optimize perf_counter_alloc()'s inherit case
Browse files Browse the repository at this point in the history
We don't need to add usage counts for swcounter and attr usage
models for inherited counters since the parent counter will
always have one, which suffices to generate the needed output.

This avoids up to 3 global atomic increments per inherited
counter.

LKML-Reference: <new-submission>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jun 23, 2009
1 parent b84fbc9 commit f344011
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,11 +1508,13 @@ static void free_counter(struct perf_counter *counter)
{
perf_pending_sync(counter);

atomic_dec(&nr_counters);
if (counter->attr.mmap)
atomic_dec(&nr_mmap_counters);
if (counter->attr.comm)
atomic_dec(&nr_comm_counters);
if (!counter->parent) {
atomic_dec(&nr_counters);
if (counter->attr.mmap)
atomic_dec(&nr_mmap_counters);
if (counter->attr.comm)
atomic_dec(&nr_comm_counters);
}

if (counter->destroy)
counter->destroy(counter);
Expand Down Expand Up @@ -3515,6 +3517,8 @@ static void sw_perf_counter_destroy(struct perf_counter *counter)
{
u64 event = counter->attr.config;

WARN_ON(counter->parent);

atomic_dec(&perf_swcounter_enabled[event]);
}

Expand Down Expand Up @@ -3551,8 +3555,10 @@ static const struct pmu *sw_perf_counter_init(struct perf_counter *counter)
case PERF_COUNT_SW_PAGE_FAULTS_MAJ:
case PERF_COUNT_SW_CONTEXT_SWITCHES:
case PERF_COUNT_SW_CPU_MIGRATIONS:
atomic_inc(&perf_swcounter_enabled[event]);
counter->destroy = sw_perf_counter_destroy;
if (!counter->parent) {
atomic_inc(&perf_swcounter_enabled[event]);
counter->destroy = sw_perf_counter_destroy;
}
pmu = &perf_ops_generic;
break;
}
Expand Down Expand Up @@ -3663,11 +3669,13 @@ perf_counter_alloc(struct perf_counter_attr *attr,

counter->pmu = pmu;

atomic_inc(&nr_counters);
if (counter->attr.mmap)
atomic_inc(&nr_mmap_counters);
if (counter->attr.comm)
atomic_inc(&nr_comm_counters);
if (!counter->parent) {
atomic_inc(&nr_counters);
if (counter->attr.mmap)
atomic_inc(&nr_mmap_counters);
if (counter->attr.comm)
atomic_inc(&nr_comm_counters);
}

return counter;
}
Expand Down

0 comments on commit f344011

Please sign in to comment.