提交 7fc23a53 编写于 作者: P Peter Zijlstra 提交者: Ingo Molnar

perf_counter: optimize perf_counter_task_tick()

perf_counter_task_tick() does way too much work to find out
there's nothing to do. Provide an easy short-circuit for the
normal case where there are no counters on the system.

[ Impact: micro-optimization ]
Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090508170028.750619201@chello.nl>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 3611dfb8
...@@ -39,6 +39,7 @@ int perf_max_counters __read_mostly = 1; ...@@ -39,6 +39,7 @@ int perf_max_counters __read_mostly = 1;
static int perf_reserved_percpu __read_mostly; static int perf_reserved_percpu __read_mostly;
static int perf_overcommit __read_mostly = 1; static int perf_overcommit __read_mostly = 1;
static atomic_t nr_counters __read_mostly;
static atomic_t nr_mmap_tracking __read_mostly; static atomic_t nr_mmap_tracking __read_mostly;
static atomic_t nr_munmap_tracking __read_mostly; static atomic_t nr_munmap_tracking __read_mostly;
static atomic_t nr_comm_tracking __read_mostly; static atomic_t nr_comm_tracking __read_mostly;
...@@ -1076,8 +1077,14 @@ static void rotate_ctx(struct perf_counter_context *ctx) ...@@ -1076,8 +1077,14 @@ static void rotate_ctx(struct perf_counter_context *ctx)
void perf_counter_task_tick(struct task_struct *curr, int cpu) void perf_counter_task_tick(struct task_struct *curr, int cpu)
{ {
struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu); struct perf_cpu_context *cpuctx;
struct perf_counter_context *ctx = &curr->perf_counter_ctx; struct perf_counter_context *ctx;
if (!atomic_read(&nr_counters))
return;
cpuctx = &per_cpu(perf_cpu_context, cpu);
ctx = &curr->perf_counter_ctx;
perf_counter_cpu_sched_out(cpuctx); perf_counter_cpu_sched_out(cpuctx);
perf_counter_task_sched_out(curr, cpu); perf_counter_task_sched_out(curr, cpu);
...@@ -1197,6 +1204,7 @@ static void free_counter(struct perf_counter *counter) ...@@ -1197,6 +1204,7 @@ static void free_counter(struct perf_counter *counter)
{ {
perf_pending_sync(counter); perf_pending_sync(counter);
atomic_dec(&nr_counters);
if (counter->hw_event.mmap) if (counter->hw_event.mmap)
atomic_dec(&nr_mmap_tracking); atomic_dec(&nr_mmap_tracking);
if (counter->hw_event.munmap) if (counter->hw_event.munmap)
...@@ -2861,6 +2869,7 @@ perf_counter_alloc(struct perf_counter_hw_event *hw_event, ...@@ -2861,6 +2869,7 @@ perf_counter_alloc(struct perf_counter_hw_event *hw_event,
counter->pmu = pmu; counter->pmu = pmu;
atomic_inc(&nr_counters);
if (counter->hw_event.mmap) if (counter->hw_event.mmap)
atomic_inc(&nr_mmap_tracking); atomic_inc(&nr_mmap_tracking);
if (counter->hw_event.munmap) if (counter->hw_event.munmap)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册