perf: Optimize perf_output_begin() -- address calculation
authorPeter Zijlstra <[email protected]>
Thu, 31 Oct 2013 16:36:25 +0000 (17:36 +0100)
committerIngo Molnar <[email protected]>
Wed, 6 Nov 2013 11:34:22 +0000 (12:34 +0100)
Rewrite the handle address calculation code to be clearer.

Saves 8 bytes on x86_64-defconfig.

Signed-off-by: Peter Zijlstra <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Michael Neuling <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: [email protected]
Cc: Vince Weaver <[email protected]>
Cc: Victor Kaplansky <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Anton Blanchard <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
kernel/events/ring_buffer.c

index e4d70f33792f136ead7736bd102c3c0f51c82729..c52a32fa5592c60ba8ebd26c58a73c2fe7e2e69e 100644 (file)
@@ -105,7 +105,7 @@ int perf_output_begin(struct perf_output_handle *handle,
 {
        struct ring_buffer *rb;
        unsigned long tail, offset, head;
-       int have_lost;
+       int have_lost, page_shift;
        struct {
                struct perf_event_header header;
                u64                      id;
@@ -159,12 +159,12 @@ int perf_output_begin(struct perf_output_handle *handle,
        if (unlikely(head - local_read(&rb->wakeup) > rb->watermark))
                local_add(rb->watermark, &rb->wakeup);
 
-       handle->page = offset >> (PAGE_SHIFT + page_order(rb));
-       handle->page &= rb->nr_pages - 1;
-       handle->size = offset & ((PAGE_SIZE << page_order(rb)) - 1);
-       handle->addr = rb->data_pages[handle->page];
-       handle->addr += handle->size;
-       handle->size = (PAGE_SIZE << page_order(rb)) - handle->size;
+       page_shift = PAGE_SHIFT + page_order(rb);
+
+       handle->page = (offset >> page_shift) & (rb->nr_pages - 1);
+       offset &= (1UL << page_shift) - 1;
+       handle->addr = rb->data_pages[handle->page] + offset;
+       handle->size = (1UL << page_shift) - offset;
 
        if (unlikely(have_lost)) {
                struct perf_sample_data sample_data;