diff options
author | Peter Zijlstra <peterz@infradead.org> | 2013-10-31 12:20:25 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-11-06 06:34:19 -0500 |
commit | c72b42a3dde487132da80202756c101b371b2add (patch) | |
tree | 5e6771876f565957aae8caab8e6abddba707f5be /kernel/events/ring_buffer.c | |
parent | 26c86da8821f7b64fced498674990318bc34c8de (diff) |
perf: Add unlikely() to the ring-buffer code
Add unlikely() annotations to 'slow' paths:
When having a sampling event but no output buffer; you have bigger
issues -- also the bail is still faster than actually doing the work.
When having a sampling event but a control page only buffer, you have
bigger issues -- again the bail is still faster than actually doing
work.
Optimize for the case where you're not loosing events -- again, not
doing the work is still faster but make sure that when you have to
actually do work its as fast as possible.
The typical watermark is 1/2 the buffer size, so most events will not
take this path.
Shrinks perf_output_begin() by 16 bytes on x86_64-defconfig.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Michael Neuling <mikey@neuling.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: james.hogan@imgtec.com
Cc: Vince Weaver <vince@deater.net>
Cc: Victor Kaplansky <VICTORK@il.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Anton Blanchard <anton@samba.org>
Link: http://lkml.kernel.org/n/tip-wlg3jew3qnutm8opd0hyeuwn@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events/ring_buffer.c')
-rw-r--r-- | kernel/events/ring_buffer.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 6929c5848d4f..383cde476176 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c | |||
@@ -121,17 +121,17 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
121 | event = event->parent; | 121 | event = event->parent; |
122 | 122 | ||
123 | rb = rcu_dereference(event->rb); | 123 | rb = rcu_dereference(event->rb); |
124 | if (!rb) | 124 | if (unlikely(!rb)) |
125 | goto out; | 125 | goto out; |
126 | 126 | ||
127 | handle->rb = rb; | 127 | if (unlikely(!rb->nr_pages)) |
128 | handle->event = event; | ||
129 | |||
130 | if (!rb->nr_pages) | ||
131 | goto out; | 128 | goto out; |
132 | 129 | ||
130 | handle->rb = rb; | ||
131 | handle->event = event; | ||
132 | |||
133 | have_lost = local_read(&rb->lost); | 133 | have_lost = local_read(&rb->lost); |
134 | if (have_lost) { | 134 | if (unlikely(have_lost)) { |
135 | lost_event.header.size = sizeof(lost_event); | 135 | lost_event.header.size = sizeof(lost_event); |
136 | perf_event_header__init_id(&lost_event.header, &sample_data, | 136 | perf_event_header__init_id(&lost_event.header, &sample_data, |
137 | event); | 137 | event); |
@@ -157,7 +157,7 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
157 | head += size; | 157 | head += size; |
158 | } while (local_cmpxchg(&rb->head, offset, head) != offset); | 158 | } while (local_cmpxchg(&rb->head, offset, head) != offset); |
159 | 159 | ||
160 | if (head - local_read(&rb->wakeup) > rb->watermark) | 160 | if (unlikely(head - local_read(&rb->wakeup) > rb->watermark)) |
161 | local_add(rb->watermark, &rb->wakeup); | 161 | local_add(rb->watermark, &rb->wakeup); |
162 | 162 | ||
163 | handle->page = offset >> (PAGE_SHIFT + page_order(rb)); | 163 | handle->page = offset >> (PAGE_SHIFT + page_order(rb)); |
@@ -167,7 +167,7 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
167 | handle->addr += handle->size; | 167 | handle->addr += handle->size; |
168 | handle->size = (PAGE_SIZE << page_order(rb)) - handle->size; | 168 | handle->size = (PAGE_SIZE << page_order(rb)) - handle->size; |
169 | 169 | ||
170 | if (have_lost) { | 170 | if (unlikely(have_lost)) { |
171 | lost_event.header.type = PERF_RECORD_LOST; | 171 | lost_event.header.type = PERF_RECORD_LOST; |
172 | lost_event.header.misc = 0; | 172 | lost_event.header.misc = 0; |
173 | lost_event.id = event->id; | 173 | lost_event.id = event->id; |