Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1731270 > unrolled thread

Re: [PATCH] perf/aux: Only update aux_wakeup in non-overwrite mode

Started byWill Deacon <will.deacon@arm.com>
First post2017-09-13 00:40 +0200
Last post2017-09-13 12:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] perf/aux: Only update aux_wakeup in non-overwrite mode Will Deacon <will.deacon@arm.com> - 2017-09-13 00:40 +0200
    Re: [PATCH] perf/aux: Only update aux_wakeup in non-overwrite mode Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2017-09-13 12:50 +0200

#1731270 — Re: [PATCH] perf/aux: Only update aux_wakeup in non-overwrite mode

FromWill Deacon <will.deacon@arm.com>
Date2017-09-13 00:40 +0200
SubjectRe: [PATCH] perf/aux: Only update aux_wakeup in non-overwrite mode
Message-ID<up20x-7jY-1@gated-at.bofh.it>
Hi Alexander,

On Wed, Sep 06, 2017 at 07:08:11PM +0300, Alexander Shishkin wrote:
> Commit d9a50b0256 ("perf/aux: Ensure aux_wakeup represents most recent
> wakeup index") changed 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>
> ---
>  kernel/events/ring_buffer.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)

Damn, sorry about that. How did you spot the problem?
Anyway, I think the code is much better with this factored out:

Acked-by: Will Deacon <will.deacon@arm.com>

Thanks,

Will

> diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
> index f4ebe42879..4dae1da4c1 100644
> --- a/kernel/events/ring_buffer.c
> +++ b/kernel/events/ring_buffer.c
> @@ -412,6 +412,19 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
>  	return NULL;
>  }
>  
> +static bool __always_inline rb_need_aux_wakeup(struct ring_buffer *rb)
> +{
> +	if (rb->aux_overwrite)
> +		return false;
> +
> +	if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
> +		rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark);
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
>  /*
>   * Commit the data written by hardware into the ring buffer by adjusting
>   * 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)
>  	}
>  
>  	rb->user_page->aux_head = rb->aux_head;
> -	if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
> +	if (rb_need_aux_wakeup(rb))
>  		wakeup = true;
> -		rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark);
> -	}
>  
>  	if (wakeup) {
>  		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)
>  	rb->aux_head += size;
>  
>  	rb->user_page->aux_head = rb->aux_head;
> -	if (rb->aux_head - rb->aux_wakeup >= rb->aux_watermark) {
> +	if (rb_need_aux_wakeup(rb)) {
>  		perf_output_wakeup(handle);
> -		rb->aux_wakeup = rounddown(rb->aux_head, rb->aux_watermark);
>  		handle->wakeup = rb->aux_wakeup + rb->aux_watermark;
>  	}
>  
> -- 
> 2.14.1
> 

[toc] | [next] | [standalone]


#1731528

FromAlexander Shishkin <alexander.shishkin@linux.intel.com>
Date2017-09-13 12:50 +0200
Message-ID<updp0-6fY-1@gated-at.bofh.it>
In reply to#1731270
Will Deacon <will.deacon@arm.com> writes:

> Hi Alexander,
>
> On Wed, Sep 06, 2017 at 07:08:11PM +0300, Alexander Shishkin wrote:
>> Commit d9a50b0256 ("perf/aux: Ensure aux_wakeup represents most recent
>> wakeup index") changed 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>
>> ---
>>  kernel/events/ring_buffer.c | 20 +++++++++++++++-----
>>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> Damn, sorry about that. How did you spot the problem?

A normal perf record with -S should trigger it, I don't remember what
exactly I was doing at that moment. But no worries, we all missed it the
first time around. :)

> Anyway, I think the code is much better with this factored out:
>
> Acked-by: Will Deacon <will.deacon@arm.com>

Thanks!

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web