perf/aux: Make aux_{head,wakeup} ring_buffer members long
authorWill Deacon <will.deacon@arm.com>
Wed, 16 Aug 2017 16:18:16 +0000 (17:18 +0100)
committerIngo Molnar <mingo@kernel.org>
Fri, 25 Aug 2017 09:04:15 +0000 (11:04 +0200)
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>
kernel/events/internal.h
kernel/events/ring_buffer.c

index 486fd78eb8d5e426dcc88ee6c68e28a10601decf..2941b868353ca6e159ad4344a0e6b65d77125273 100644 (file)
@@ -38,9 +38,9 @@ struct ring_buffer {
        struct user_struct              *mmap_user;
 
        /* AUX area */
-       local_t                         aux_head;
+       long                            aux_head;
        local_t                         aux_nest;
-       local_t                         aux_wakeup;
+       long                            aux_wakeup;
        unsigned long                   aux_pgoff;
        int                             aux_nr_pages;
        int                             aux_overwrite;
index ee97196bb1510e4f95cfd6ddc039fa9700cdc828..25437fda56e31e0db028a4b4961fe3818e94f2cd 100644 (file)
@@ -367,7 +367,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
        if (WARN_ON_ONCE(local_xchg(&rb->aux_nest, 1)))
                goto err_put;
 
-       aux_head = local_read(&rb->aux_head);
+       aux_head = rb->aux_head;
 
        handle->rb = rb;
        handle->event = event;
@@ -382,7 +382,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
         */
        if (!rb->aux_overwrite) {
                aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
-               handle->wakeup = local_read(&rb->aux_wakeup) + rb->aux_watermark;
+               handle->wakeup = rb->aux_wakeup + rb->aux_watermark;
                if (aux_head - aux_tail < perf_aux_size(rb))
                        handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
 
@@ -433,12 +433,12 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
                handle->aux_flags |= PERF_AUX_FLAG_OVERWRITE;
 
                aux_head = handle->head;
-               local_set(&rb->aux_head, aux_head);
+               rb->aux_head = aux_head;
        } else {
                handle->aux_flags &= ~PERF_AUX_FLAG_OVERWRITE;
 
-               aux_head = local_read(&rb->aux_head);
-               local_add(size, &rb->aux_head);
+               aux_head = rb->aux_head;
+               rb->aux_head += size;
        }
 
        if (size || handle->aux_flags) {
@@ -450,11 +450,10 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
                                     handle->aux_flags);
        }
 
-       aux_head = rb->user_page->aux_head = local_read(&rb->aux_head);
-
-       if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) {
+       rb->user_page->aux_head = rb->aux_head;
+       if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
                wakeup = true;
-               local_add(rb->aux_watermark, &rb->aux_wakeup);
+               rb->aux_wakeup += rb->aux_watermark;
        }
 
        if (wakeup) {
@@ -478,22 +477,20 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
 int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)
 {
        struct ring_buffer *rb = handle->rb;
-       unsigned long aux_head;
 
        if (size > handle->size)
                return -ENOSPC;
 
-       local_add(size, &rb->aux_head);
+       rb->aux_head += size;
 
-       aux_head = rb->user_page->aux_head = local_read(&rb->aux_head);
-       if (aux_head - local_read(&rb->aux_wakeup) >= rb->aux_watermark) {
+       rb->user_page->aux_head = rb->aux_head;
+       if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
                perf_output_wakeup(handle);
-               local_add(rb->aux_watermark, &rb->aux_wakeup);
-               handle->wakeup = local_read(&rb->aux_wakeup) +
-                                rb->aux_watermark;
+               rb->aux_wakeup += rb->aux_watermark;
+               handle->wakeup = rb->aux_wakeup + rb->aux_watermark;
        }
 
-       handle->head = aux_head;
+       handle->head = rb->aux_head;
        handle->size -= size;
 
        return 0;