提交 4ec8363d 编写于 作者: V Vince Weaver 提交者: Ingo Molnar

perf_events: Fix perf buffer watermark setting

Since 2.6.36 (specifically commit d57e34fd ("perf: Simplify the
ring-buffer logic: make perf_buffer_alloc() do everything needed"),
the perf_buffer_init_code() has been mis-setting the buffer watermark
if perf_event_attr.wakeup_events has a non-zero value.

This is because perf_event_attr.wakeup_events is a union with
perf_event_attr.wakeup_watermark.

This commit re-enables the check for perf_event_attr.watermark being
set before continuing with setting a non-default watermark.

This bug is most noticable when you are trying to use PERF_IOC_REFRESH
with a value larger than one and perf_event_attr.wakeup_events is set to
one.  In this case the buffer watermark will be set to 1 and you will
get extraneous POLL_IN overflows rather than POLL_HUP as expected.

[ avoid using attr.wakeup_events when attr.watermark is set ]
Signed-off-by: NVince Weaver <vweaver1@eecs.utk.edu>
Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: <stable@kernel.org>
Link: http://lkml.kernel.org/r/alpine.DEB.2.00.1106011506390.5384@cl320.eecs.utk.eduSigned-off-by: NIngo Molnar <mingo@elte.hu>
上级 0f933625
...@@ -3569,8 +3569,10 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -3569,8 +3569,10 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
if (vma->vm_flags & VM_WRITE) if (vma->vm_flags & VM_WRITE)
flags |= RING_BUFFER_WRITABLE; flags |= RING_BUFFER_WRITABLE;
rb = rb_alloc(nr_pages, event->attr.wakeup_watermark, rb = rb_alloc(nr_pages,
event->cpu, flags); event->attr.watermark ? event->attr.wakeup_watermark : 0,
event->cpu, flags);
if (!rb) { if (!rb) {
ret = -ENOMEM; ret = -ENOMEM;
goto unlock; goto unlock;
......
...@@ -199,13 +199,15 @@ void perf_output_end(struct perf_output_handle *handle) ...@@ -199,13 +199,15 @@ void perf_output_end(struct perf_output_handle *handle)
struct perf_event *event = handle->event; struct perf_event *event = handle->event;
struct ring_buffer *rb = handle->rb; struct ring_buffer *rb = handle->rb;
int wakeup_events = event->attr.wakeup_events; if (handle->sample && !event->attr.watermark) {
int wakeup_events = event->attr.wakeup_events;
if (handle->sample && wakeup_events) {
int events = local_inc_return(&rb->events); if (wakeup_events) {
if (events >= wakeup_events) { int events = local_inc_return(&rb->events);
local_sub(wakeup_events, &rb->events); if (events >= wakeup_events) {
local_inc(&rb->wakeup); local_sub(wakeup_events, &rb->events);
local_inc(&rb->wakeup);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册