Skip to content

Commit 2ab346c

Browse files
wildea01ingomolnar
authored andcommitted
perf/aux: Make aux_{head,wakeup} ring_buffer members long
The aux_head and aux_wakeup members of struct ring_buffer are defined using the local_t type, despite the fact that they are only accessed via the perf_aux_output_*() functions, which cannot race with each other for a given ring buffer. This patch changes the type of the members to long, so we can avoid using the local_*() API where it isn't needed. Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1502900297-21839-1-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 290d9bf commit 2ab346c

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

‎kernel/events/internal.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct ring_buffer {
3838
struct user_struct *mmap_user;
3939

4040
/* AUX area */
41-
local_t aux_head;
41+
long aux_head;
4242
local_t aux_nest;
43-
local_t aux_wakeup;
43+
long aux_wakeup;
4444
unsigned long aux_pgoff;
4545
int aux_nr_pages;
4646
int aux_overwrite;

‎kernel/events/ring_buffer.c‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
367367
if (WARN_ON_ONCE(local_xchg(&rb->aux_nest, 1)))
368368
goto err_put;
369369

370-
aux_head = local_read(&rb->aux_head);
370+
aux_head = rb->aux_head;
371371

372372
handle->rb = rb;
373373
handle->event = event;
@@ -382,7 +382,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
382382
*/
383383
if (!rb->aux_overwrite) {
384384
aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
385-
handle->wakeup = local_read(&rb->aux_wakeup) + rb->aux_watermark;
385+
handle->wakeup = rb->aux_wakeup + rb->aux_watermark;
386386
if (aux_head - aux_tail < perf_aux_size(rb))
387387
handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
388388

@@ -433,12 +433,12 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
433433
handle->aux_flags |= PERF_AUX_FLAG_OVERWRITE;
434434

435435
aux_head = handle->head;
436-
local_set(&rb->aux_head, aux_head);
436+
rb->aux_head = aux_head;
437437
} else {
438438
handle->aux_flags &= ~PERF_AUX_FLAG_OVERWRITE;
439439

440-
aux_head = local_read(&rb->aux_head);
441-
local_add(size, &rb->aux_head);
440+
aux_head = rb->aux_head;
441+
rb->aux_head += size;
442442
}
443443

444444
if (size || handle->aux_flags) {
@@ -450,11 +450,10 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
450450
handle->aux_flags);
451451
}
452452

453-
aux_head = rb->user_page->aux_head = local_read(&rb->aux_head);
454-
455-
if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) {
453+
rb->user_page->aux_head = rb->aux_head;
454+
if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
456455
wakeup = true;
457-
local_add(rb->aux_watermark, &rb->aux_wakeup);
456+
rb->aux_wakeup += rb->aux_watermark;
458457
}
459458

460459
if (wakeup) {
@@ -478,22 +477,20 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
478477
int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)
479478
{
480479
struct ring_buffer *rb = handle->rb;
481-
unsigned long aux_head;
482480

483481
if (size > handle->size)
484482
return -ENOSPC;
485483

486-
local_add(size, &rb->aux_head);
484+
rb->aux_head += size;
487485

488-
aux_head = rb->user_page->aux_head = local_read(&rb->aux_head);
489-
if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) {
486+
rb->user_page->aux_head = rb->aux_head;
487+
if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
490488
perf_output_wakeup(handle);
491-
local_add(rb->aux_watermark, &rb->aux_wakeup);
492-
handle->wakeup = local_read(&rb->aux_wakeup) +
493-
rb->aux_watermark;
489+
rb->aux_wakeup += rb->aux_watermark;
490+
handle->wakeup = rb->aux_wakeup + rb->aux_watermark;
494491
}
495492

496-
handle->head = aux_head;
493+
handle->head = rb->aux_head;
497494
handle->size -= size;
498495

499496
return 0;

0 commit comments

Comments
 (0)