diff options
author | Alexander Shishkin <alexander.shishkin@linux.intel.com> | 2017-09-06 12:08:11 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-09-29 04:06:45 -0400 |
commit | 441430eb54a00586f95f1aefc48e0801bbd6a923 (patch) | |
tree | 9e9bfffb3625e73466e63120ad9014980c97be46 | |
parent | 770b782f555d663d133fcd4dc1632023f79357b9 (diff) |
perf/aux: Only update ->aux_wakeup in non-overwrite mode
The following commit:
d9a50b0256 ("perf/aux: Ensure aux_wakeup represents most recent wakeup index")
changed the AUX wakeup position calculation to rounddown(), which causes
a division-by-zero in AUX overwrite mode (aka "snapshot mode").
The zero denominator results from the fact that perf record doesn't set
aux_watermark to anything, in which case the kernel will set it to half
the AUX buffer size, but only for non-overwrite mode. In the overwrite
mode aux_watermark stays zero.
The good news is that, AUX overwrite mode, wakeups don't happen and
related bookkeeping is not relevant, so we can simply forego the whole
wakeup updates.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/20170906160811.16510-1-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/events/ring_buffer.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index af71a84e12ee..f684d8e5fa2b 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c | |||
@@ -412,6 +412,19 @@ err: | |||
412 | return NULL; | 412 | return NULL; |
413 | } | 413 | } |
414 | 414 | ||
415 | static bool __always_inline rb_need_aux_wakeup(struct ring_buffer *rb) | ||
416 | { | ||
417 | if (rb->aux_overwrite) | ||
418 | return false; | ||
419 | |||
420 | if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) { | ||
421 | rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark); | ||
422 | return true; | ||
423 | } | ||
424 | |||
425 | return false; | ||
426 | } | ||
427 | |||
415 | /* | 428 | /* |
416 | * Commit the data written by hardware into the ring buffer by adjusting | 429 | * Commit the data written by hardware into the ring buffer by adjusting |
417 | * aux_head and posting a PERF_RECORD_AUX into the perf buffer. It is the | 430 | * aux_head and posting a PERF_RECORD_AUX into the perf buffer. It is the |
@@ -451,10 +464,8 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size) | |||
451 | } | 464 | } |
452 | 465 | ||
453 | rb->user_page->aux_head = rb->aux_head; | 466 | rb->user_page->aux_head = rb->aux_head; |
454 | if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) { | 467 | if (rb_need_aux_wakeup(rb)) |
455 | wakeup = true; | 468 | wakeup = true; |
456 | rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark); | ||
457 | } | ||
458 | 469 | ||
459 | if (wakeup) { | 470 | if (wakeup) { |
460 | if (handle->aux_flags & PERF_AUX_FLAG_TRUNCATED) | 471 | if (handle->aux_flags & PERF_AUX_FLAG_TRUNCATED) |
@@ -484,9 +495,8 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size) | |||
484 | rb->aux_head += size; | 495 | rb->aux_head += size; |
485 | 496 | ||
486 | rb->user_page->aux_head = rb->aux_head; | 497 | rb->user_page->aux_head = rb->aux_head; |
487 | if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) { | 498 | if (rb_need_aux_wakeup(rb)) { |
488 | perf_output_wakeup(handle); | 499 | perf_output_wakeup(handle); |
489 | rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark); | ||
490 | handle->wakeup = rb->aux_wakeup + rb->aux_watermark; | 500 | handle->wakeup = rb->aux_wakeup + rb->aux_watermark; |
491 | } | 501 | } |
492 | 502 | ||