Re: [PATCH v4 02/22] perf: Add AUX area to ring buffer for raw data streams

From: Peter Zijlstra
Date: Mon Sep 08 2014 - 03:02:58 EST


On Wed, Aug 20, 2014 at 03:35:59PM +0300, Alexander Shishkin wrote:
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>
> This patch introduces "AUX space" in the perf mmap buffer, intended for
> exporting high bandwidth data streams to userspace, such as instruction
> flow traces.
>
> AUX space is a ring buffer, defined by aux_{offset,size} fields in the
> user_page structure, and read/write pointers aux_{head,tail}, which abide
> by the same rules as data_* counterparts of the main perf buffer.
>
> In order to allocate/mmap AUX, userspace needs to set up aux_offset to
> such an offset that will be greater than data_offset+data_size and
> aux_size to be the desired buffer size. Both need to be page aligned.
> Then, same aux_offset and aux_size should be passed to mmap() call and
> if everything adds up, you should have an AUX buffer as a result.
>
> Pages that are mapped into this buffer also come out of user's mlock
> rlimit plus perf_event_mlock_kb allowance.
>
> Signed-off-by: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
> ---

> +void rb_free_aux(struct ring_buffer *rb, struct perf_event *event)
> +{
> + struct perf_event *iter;
> + int pg;
> +
> + if (rb->aux_priv) {
> + /* disable all potential writers before freeing */
> + rcu_read_lock();
> + list_for_each_entry_rcu(iter, &rb->event_list, rb_entry)
> + perf_event_disable(iter);
> + rcu_read_unlock();

Hmm, I cannot remember this from the last time; and its not explained
why this was added.

This would change semantics between munmap of a buffer with and without
AUX bits in.

> +
> + event->pmu->free_aux(rb->aux_priv);
> + rb->aux_priv = NULL;
> + }
> +
> + for (pg = 0; pg < rb->aux_nr_pages; pg++)
> + free_page((unsigned long)rb->aux_pages[pg]);
> +
> + kfree(rb->aux_pages);
> + rb->aux_nr_pages = 0;
> +}

Attachment: pgpSkGojNcnHr.pgp
Description: PGP signature