Skip to content

Commit

Permalink
perf: Optimize perf_output_*() by avoiding local_xchg()
Browse files Browse the repository at this point in the history
Since the x86 XCHG ins implies LOCK, avoid the use by
using a sequence count instead.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed May 18, 2010
1 parent fa58815 commit 6d1acfd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ struct perf_output_handle {
struct perf_mmap_data *data;
unsigned long head;
unsigned long offset;
unsigned long wakeup;
int nmi;
int sample;
};
Expand Down
3 changes: 2 additions & 1 deletion kernel/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,7 @@ static void perf_output_get_handle(struct perf_output_handle *handle)

preempt_disable();
local_inc(&data->nest);
handle->wakeup = local_read(&data->wakeup);
}

static void perf_output_put_handle(struct perf_output_handle *handle)
Expand Down Expand Up @@ -2950,7 +2951,7 @@ static void perf_output_put_handle(struct perf_output_handle *handle)
goto again;
}

if (local_xchg(&data->wakeup, 0))
if (handle->wakeup != local_read(&data->wakeup))
perf_output_wakeup(handle);

preempt_enable();
Expand Down

0 comments on commit 6d1acfd

Please sign in to comment.