perf: add AUX space to ring_buffer
Alexander Shishkin
reviewercover perf: add AUX space to ring_buffer
Hi Peter,
I tried to bend my head around the AUX space and this is where I am at the moment. Not posting the whole itrace/PT bulk yet, to make sure this part is ok and to save bandwidth.
Alexander Shishkin (1):
perf: add data_{offset,size} to user_page
Peter Zijlstra (1):
perf: add AUX area to ring buffer for raw data streams
include/linux/perf_event.h | 13 ++++ include/uapi/linux/perf_event.h | 33 ++++++++++ kernel/events/core.c | 132 ++++++++++++++++++++++++++++++++-------- kernel/events/internal.h | 16 +++++ kernel/events/ring_buffer.c | 53 ++++++++++++++-- 5 files changed, 217 insertions(+), 30 deletions(-)
Signature · 1 line
2.0.0.rc2
Alexander Shishkin
reviewerRFC 1/2 perf: add data_{offset,size} to user_page
Currently, the actual perf ring buffer is one page into the mmap area, following the user page and the userspace follows this convention. This patch adds data_{offset,size} fields to user_page that can be used by userspace instead for locating perf data in the mmap area.
Right now, it is made to follow the existing convention that
data_offset == PAGE_SIZE and data_offset + data_size == mmap_size.
--- include/uapi/linux/perf_event.h | 5 +++++ kernel/events/core.c | 2 ++ 2 files changed, 7 insertions(+)
include/uapi/linux/perf_event.h +5 -0
@@ -488,9 +488,14 @@ struct perf_event_mmap_page {* In this case the kernel will not over-write unread data. * * See perf_output_put_handle() for the data ordering. +* +* data_{offset,size} indicate the location and size of the perf record +* buffer within the mmapped area. */ __u64 data_head;/* head in the data section */ __u64 data_tail;/* user-space written tail */ +__u64 data_offset;/* where the buffer starts */ +__u64 data_size;/* data buffer size */ };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
kernel/events/core.c +2 -0
@@ -3768,6 +3768,8 @@ static void perf_event_init_userpage(struct perf_event *event)/* Allow new userspace to detect that bit 0 is deprecated */ userpg->cap_bit0_is_deprecated =1 ; userpg->size = offsetof(struct perf_event_mmap_page , __reserved); + userpg->data_offset =PAGE_SIZE ; + userpg->data_size =perf_data_size (rb); unlock:rcu_read_unlock ();
Signature · 1 line
2.0.0.rc2
Re: [RFC 1/2] perf: add data_{offset,size} to user_page
include/uapi/linux/perf_event.h struct perf_event_mmap_page { · line 499
Quoted 13 lines · Alexander Shishkin
include/uapi/linux/perf_event.h +5
-0@@ -488,9 +488,14 @@ struct perf_event_mmap_page {* In this case the kernel will not over-write unread data. * * See perf_output_put_handle() for the data ordering. +* +* data_{offset,size} indicate the location and size of the perf record +* buffer within the mmapped area. */ __u64 data_head;/* head in the data section */ __u64 data_tail;/* user-space written tail */ +__u64 data_offset;/* where the buffer starts */ +__u64 data_size;/* data buffer size */ };
Yeah, we need something like this also for other reasons. For persistent events we don't know the buffer size when mmaping existing/shared buffers. To determine the buffer size we could map the first page only, read the size and then mremap() to the actual size.
Please keep this use case in mind too, also for the aux buffer. The best would be if data_size is the mmap size.
Thanks,
-Robert
Alexander Shishkin
reviewerRFC 2/2 perf: add AUX area to ring buffer for raw data streams
In reply to Alexander ShishkinFrom: Peter Zijlstra <[email protected]>
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. The latter is not forced to be a power of 2 number of pages, so that PMU drivers have to take care of this if necessary in their implementations of ->alloc_aux(). 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.
--- include/linux/perf_event.h | 13 ++++ include/uapi/linux/perf_event.h | 28 +++++++++ kernel/events/core.c | 130 ++++++++++++++++++++++++++++++++-------- kernel/events/internal.h | 16 +++++ kernel/events/ring_buffer.c | 53 ++++++++++++++-- 5 files changed, 210 insertions(+), 30 deletions(-)
include/linux/perf_event.h +13 -0
@@ -252,6 +252,19 @@ struct pmu {* flush branch stack on context-switches (needed in cpu-wide mode) */ void (*flush_branch_stack) (void ); + +/* +* Allocate AUX space buffer: return an array of @nr_pages pages to be +* mapped to userspace that will also be passed to ->free_aux. +*/ +void *(*alloc_aux) (int cpu,int nr_pages,bool overwrite, +struct perf_event_mmap_page *user_page); +/* optional */ + +/* +* Free AUX buffer +*/ +void (*free_aux) (void *aux);/* optional */ };/**
include/uapi/linux/perf_event.h +28 -0
@@ -496,6 +496,22 @@ struct perf_event_mmap_page {__u64 data_tail;/* user-space written tail */ __u64 data_offset;/* where the buffer starts */ __u64 data_size;/* data buffer size */ + +/* +* AUX area is defined by aux_{offset,size} fields that should be set +* by the userspace, so that +* +* aux_offset >= data_offset + data_size +* +* prior to mmap()ing it. Size of the mmap()ed area should be aux_size. +* +* Ring buffer pointers aux_{head,tail} have the same semantics as +* data_{head,tail} and same ordering rules apply. +*/ +__u64 aux_head; +__u64 aux_tail; +__u64 aux_offset; +__u64 aux_size; };#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
@@ -710,6 +726,18 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 =10 , +/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };
kernel/events/core.c +104 -26
192 lines not on this page · raw message
kernel/events/internal.h +16 -0
@@ -35,6 +35,14 @@ struct ring_buffer {unsigned long mmap_locked;struct user_struct *mmap_user; +/* AUX area */ +unsigned long aux_pgoff; +int aux_nr_pages; +atomic_t aux_mmap_count; +unsigned long aux_mmap_locked; +void **aux_pages; +void (*free_aux)(void *aux); +struct perf_event_mmap_page *user_page;void *data_pages[0 ]; };
@@ -43,6 +51,14 @@ extern void rb_free(struct ring_buffer *rb);extern struct ring_buffer *rb_alloc (int nr_pages,long watermark,int cpu,int flags);extern void perf_event_wakeup (struct perf_event *event); +extern int rb_alloc_aux (struct ring_buffer *rb,struct perf_event *event, +pgoff_t pgoff,int nr_pages,int flags); +extern void rb_free_aux (struct ring_buffer *rb); + +static inline bool rb_has_aux (struct ring_buffer *rb) +{ +return !!rb->aux_nr_pages; +} extern void perf_event_header__init_id(struct perf_event_header *header,
kernel/events/ring_buffer.c +49 -4
74 lines not on this page · raw message
Signature · 1 line
2.0.0.rc2
Re: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
Quoted 10 lines · Alexander Shishkin
From: Peter Zijlstra <[email protected]>
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_pagestructure, and read/write pointers aux_{head,tail}, which abide by the same rules as data_* counterparts of the main perf buffer.
Quoted 8 lines
In order to allocate/mmap AUX, userspace needs to set up
aux_offsetto such an offset that will be greater than data_offset+data_size andaux_sizeto be the desired buffer size. Both need to be page aligned. The latter is not forced to be a power of 2 number of pages, so that PMU drivers have to take care of this if necessary in their implementations of ->alloc_aux(). Then, sameaux_offsetandaux_sizeshould be passed tommap()call and if everything adds up, you should have an AUX buffer as a result.
Raw data sample (PERF_SAMPLE_RAW) already allow to pass data to userspace. What is the reason for a separate buffer? I see the following:
* the buffer accessed from userspace should have a customized format unrelated to perf,
* zero copying (not sure if this is really possible),
* data size and alignment requirements that can not be handled by raw data samples.
If possible, raw data samples should be a first option.
On the other side there might the need of an aux buffer (I would better call it raw buffer analog to raw data). So here some comments on the implementation and the user i/f.
Instead of extending the current ringbuffer I would better add a 2nd ring buffer. The mmap and ringbuffer handling and esp. the access from userspace looks much more complex now and it was already complex before. So with a 2nd buffer there would be less changes in the implementation and handling. Access from userland would remain as it currently is, there is no need to modify the header page layout. To setup a 2nd buffer, you just need to modify the mmap call in a way (maybe by prot, flags or offset argument) to let the kernel know an aux buffer should be attached to the event.
Then, instead of introducing a new PERF_RECORD_AUX, just reuse PERF_RECORD_SAMPLE. If an aux/raw buffer is connected to the event, then the data is not part of the sample but passed to the raw buffer.
Tools, interfaces and helper functions would work already with such raw samples, just the raw buffer handling need to be added.
How about this?
-Robert
Alexander Shishkin
reviewerRe: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
Quoted 24 lines · Robert Richter
Quoted 10 lines · Alexander Shishkin
From: Peter Zijlstra <[email protected]>
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_pagestructure, and read/write pointers aux_{head,tail}, which abide by the same rules as data_* counterparts of the main perf buffer.Quoted 8 lines
In order to allocate/mmap AUX, userspace needs to set up
aux_offsetto such an offset that will be greater than data_offset+data_size andaux_sizeto be the desired buffer size. Both need to be page aligned. The latter is not forced to be a power of 2 number of pages, so that PMU drivers have to take care of this if necessary in their implementations of ->alloc_aux(). Then, sameaux_offsetandaux_sizeshould be passed tommap()call and if everything adds up, you should have an AUX buffer as a result.Raw data sample (
PERF_SAMPLE_RAW) already allow to pass data to userspace. What is the reason for a separate buffer? I see the following:
Quoted 7 lines
* the buffer accessed from userspace should have a customized format unrelated to perf,
* zero copying (not sure if this is really possible),
* data size and alignment requirements that can not be handled by raw data samples.
It is all three. What we're dealing with at the moment is a unit that generates instruction traces at rates like hhundreds of megabytes per second. So the only sensible thing to do is zero copy the data.
Quoted 6 lines
If possible, raw data samples should be a first option.
On the other side there might the need of an aux buffer (I would better call it raw buffer analog to raw data). So here some comments on the implementation and the user i/f.
Quoted 9 lines
Instead of extending the current ringbuffer I would better add a 2nd ring buffer. The mmap and ringbuffer handling and esp. the access from userspace looks much more complex now and it was already complex before. So with a 2nd buffer there would be less changes in the implementation and handling. Access from userland would remain as it currently is, there is no need to modify the header page layout. To setup a 2nd buffer, you just need to modify the mmap call in a way (maybe by prot, flags or offset argument) to let the kernel know an aux buffer should be attached to the event.
Tried that, didn't fly. See the full story here [1]. Though splicing arbitrary pages into perf buffer is less than trivial, especially so with hardware that doesn't do scatter-gather. So all in all, AUX area seems to be a sensible compromise.
[1] http://marc.info/?l=linux-kernel&m=139264764530809&w=2
Regards,
--
Alex
Peter Zijlstra
maintainerRe: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
In reply to Alexander ShishkinQuoted 10 lines · Alexander Shishkin
include/linux/perf_event.h +4
-0@@ -252,6 +252,19 @@ struct pmu {* flush branch stack on context-switches (needed in cpu-wide mode) */ void (*flush_branch_stack) (void ); + +/* +* Allocate AUX space buffer: return an array of @nr_pages pages to be +* mapped to userspace that will also be passed to ->free_aux.
include/linux/perf_event.h struct pmu { · line 268
Quoted 10 lines
include/linux/perf_event.h +9
-0+*/ +void *(*alloc_aux) (int cpu,int nr_pages,bool overwrite, +struct perf_event_mmap_page *user_page); +/* optional */ + +/* +* Free AUX buffer +*/ +void (*free_aux) (void *aux);/* optional */ };
I'm not entirely thrilled to expose it to the PMU like this.. I realize you want this in order to get physically contiguous pages.
Are you aware of allocation constraints for other architectures?
Quoted 9 lines
include/linux/perf_event.h +4
-0#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)@@ -710,6 +726,18 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 = 10, +/* +* Records that new data landed in the AUX buffer part. +* +* struct {
include/linux/perf_event.h enum perf_event_type { · line 742
Quoted 10 lines
include/linux/perf_event.h +8
-0+* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* }; +*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };
Ideally the patch introducing this would also introduce code to generate these records.
Quoted 52 lines
include/linux/perf_event.h +47
-1@@ -4076,7 +4090,63 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ; vma_size = vma->vm_end - vma->vm_start; - nr_pages = (vma_size /PAGE_SIZE ) -1 ; + +if (vma->vm_pgoff ==0 ) { + nr_pages = (vma_size /PAGE_SIZE ) -1 ; + }else { +/* +* AUX area mapping: if rb->aux_nr_pages != 0, it's already +* mapped, all subsequent mappings should have the same size +* and offset. Must be above the normal perf buffer. +*/ +u64 aux_offset, aux_size; + +if (!event->rb) +return -EINVAL ; + + nr_pages = vma_size /PAGE_SIZE ; + +mutex_lock (&event->mmap_mutex); + ret = -EINVAL ; + + rb = event->rb; +if (!rb) + goto aux_unlock; + + aux_offset =ACCESS_ONCE (rb->user_page->aux_offset); + aux_size =ACCESS_ONCE (rb->user_page->aux_size); + +if (aux_offset <perf_data_size (rb) +PAGE_SIZE ) + goto aux_unlock; + +if (aux_offset != vma->vm_pgoff <<PAGE_SHIFT ) + goto aux_unlock; + +/* already mapped with a different offset */ +if (rb_has_aux (rb) && rb->aux_pgoff != vma->vm_pgoff) + goto aux_unlock; + +if (aux_size != vma_size || aux_size != nr_pages *PAGE_SIZE ) + goto aux_unlock; + +/* already mapped with a different size */ +if (rb_has_aux (rb) && rb->aux_nr_pages != nr_pages) + goto aux_unlock; + +if (!atomic_inc_not_zero (&rb->mmap_count)) + goto aux_unlock; + +if (rb_has_aux (rb)) {
include/linux/perf_event.h static int perf_mmap(struct file *file, struct vm_area_struct *vma) · line 4149
Quoted 10 lines
include/linux/perf_event.h +10
-0+atomic_inc (&rb->aux_mmap_count); + ret =0 ; + goto unlock; + } + +atomic_set (&rb->aux_mmap_count,1 ); + user_extra = nr_pages; + + goto accounting; + }
That appears to be missing a is_power_of_2(aux_size) check.
The problem with not having that is that since perf_event_mmap_page::aux_{head,tail} are of Z mod 2^64 but your actual {head,tail} are of Z mod aux_size, you need aux_size to be a full divider of 2^64 or otherwise you get wrapping issues at the overflow.
Having it them all 2^n makes the divider trivial.
Alexander Shishkin
reviewerRe: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Alexander Shishkin
include/linux/perf_event.h +9
-0@@ -252,6 +252,19 @@ struct pmu {* flush branch stack on context-switches (needed in cpu-wide mode) */ void (*flush_branch_stack) (void ); + +/* +* Allocate AUX space buffer: return an array of @nr_pages pages to be +* mapped to userspace that will also be passed to ->free_aux. +*/ +void *(*alloc_aux) (int cpu,int nr_pages,bool overwrite, +struct perf_event_mmap_page *user_page); +/* optional */ +
Quoted 8 lines
include/linux/perf_event.h struct pmu { · line 268
Quoted 5 lines
include/linux/perf_event.h +4
-0+/* +* Free AUX buffer +*/ +void (*free_aux) (void *aux);/* optional */ };I'm not entirely thrilled to expose it to the PMU like this.. I realize you want this in order to get physically contiguous pages.
Hmm, I guess we can have code in perf core to carry out the allocation according to, say, contstraint flags and pass the page array down to the PMU if that sounds like a cleaner thing to do?
Quoted 1 line
Are you aware of allocation constraints for other architectures?
Somewhat. ARM's trace memory controller supports both scatter-gather and a plain contiguous buffer, I haven't found evidence of one being available while the other one isn't, so I'm inclined to assume that if it can write to system memory, it supports SG.
Quoted 14 lines
Quoted 14 lines
include/linux/perf_event.h +9
-0#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)@@ -710,6 +726,18 @@ enum perf_event_type {*/ PERF_RECORD_MMAP2 = 10, +/* +* Records that new data landed in the AUX buffer part. +* +* struct { +* struct perf_event_header header; +* +* u64 aux_offset; +* u64 aux_size; +* };
Quoted 8 lines
include/linux/perf_event.h enum perf_event_type { · line 742
Quoted 5 lines
include/linux/perf_event.h +3
-0+*/ +PERF_RECORD_AUX =11 , + PERF_RECORD_MAX, /* non-ABI */ };Ideally the patch introducing this would also introduce code to generate these records.
Fair enough.
Quoted 65 lines
Quoted 52 lines
include/linux/perf_event.h +47
-1@@ -4076,7 +4090,63 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ; vma_size = vma->vm_end - vma->vm_start; - nr_pages = (vma_size /PAGE_SIZE ) -1 ; + +if (vma->vm_pgoff ==0 ) { + nr_pages = (vma_size /PAGE_SIZE ) -1 ; + }else { +/* +* AUX area mapping: if rb->aux_nr_pages != 0, it's already +* mapped, all subsequent mappings should have the same size +* and offset. Must be above the normal perf buffer. +*/ +u64 aux_offset, aux_size; + +if (!event->rb) +return -EINVAL ; + + nr_pages = vma_size /PAGE_SIZE ; + +mutex_lock (&event->mmap_mutex); + ret = -EINVAL ; + + rb = event->rb; +if (!rb) + goto aux_unlock; + + aux_offset =ACCESS_ONCE (rb->user_page->aux_offset); + aux_size =ACCESS_ONCE (rb->user_page->aux_size); + +if (aux_offset <perf_data_size (rb) +PAGE_SIZE ) + goto aux_unlock; + +if (aux_offset != vma->vm_pgoff <<PAGE_SHIFT ) + goto aux_unlock; + +/* already mapped with a different offset */ +if (rb_has_aux (rb) && rb->aux_pgoff != vma->vm_pgoff) + goto aux_unlock; + +if (aux_size != vma_size || aux_size != nr_pages *PAGE_SIZE ) + goto aux_unlock; + +/* already mapped with a different size */ +if (rb_has_aux (rb) && rb->aux_nr_pages != nr_pages) + goto aux_unlock; + +if (!atomic_inc_not_zero (&rb->mmap_count)) + goto aux_unlock; + +if (rb_has_aux (rb)) {include/linux/perf_event.h static int perf_mmap(struct file *file, struct vm_area_struct *vma) · line 4149
Quoted 10 lines
include/linux/perf_event.h +10
-0+atomic_inc (&rb->aux_mmap_count); + ret =0 ; + goto unlock; + } + +atomic_set (&rb->aux_mmap_count,1 ); + user_extra = nr_pages; + + goto accounting; + }That appears to be missing a
is_power_of_2(aux_size)check.
Quoted 6 lines
The problem with not having that is that since perf_event_mmap_page::aux_{head,tail} are of Z mod 2^64 but your actual {head,tail} are of Z mod
aux_size, you needaux_sizeto be a full divider of 2^64 or otherwise you get wrapping issues at the overflow.Having it them all 2^n makes the divider trivial.
I left it out so that the PMU callback could decide if it wants to do the math or not. Maybe it can also be a constraint flag or is it not worth it at all?
Regards,
--
Alex
Peter Zijlstra
maintainerRe: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
Quoted 9 lines · Alexander Shishkin
Quoted 2 lines · Peter Zijlstra
I'm not entirely thrilled to expose it to the PMU like this.. I realize you want this in order to get physically contiguous pages.
Hmm, I guess we can have code in perf core to carry out the allocation according to, say, contstraint flags and pass the page array down to the PMU if that sounds like a cleaner thing to do?
Quoted 6 lines
Quoted 1 line
Are you aware of allocation constraints for other architectures?
Somewhat. ARM's trace memory controller supports both scatter-gather and a plain contiguous buffer, I haven't found evidence of one being available while the other one isn't, so I'm inclined to assume that if it can write to system memory, it supports SG.
I've just added a patch from Vince Weaver:
http://lkml.kernel.org/r/alpine.DEB.2.10.1405161708060.11099@vincent-weaver-1.umelst.maine.edu
That adds pmu::capabilities, I suppose we could start with something like:
PERF_PMU_CAP_AUX_BROKEN_SG
which would make the allocator attempt to fill the AUX buffer with as big a chunks of contiguous memory as is available.
Quoted 7 lines
Quoted 7 lines
That appears to be missing a
is_power_of_2(aux_size)check.The problem with not having that is that since perf_event_mmap_page::aux_{head,tail} are of Z mod 2^64 but your actual {head,tail} are of Z mod
aux_size, you needaux_sizeto be a full divider of 2^64 or otherwise you get wrapping issues at the overflow.
Quoted 5 lines
Quoted 1 line
Having it them all 2^n makes the divider trivial.
I left it out so that the PMU callback could decide if it wants to do the math or not. Maybe it can also be a constraint flag or is it not worth it at all?
I'd start with the most constrained model -- that is add the power of two test -- and worry about relaxing it if it turns out its really needed.
Alexander Shishkin
reviewerRe: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
Quoted 21 lines · Peter Zijlstra
Quoted 9 lines · Alexander Shishkin
Quoted 2 lines · Peter Zijlstra
I'm not entirely thrilled to expose it to the PMU like this.. I realize you want this in order to get physically contiguous pages.
Hmm, I guess we can have code in perf core to carry out the allocation according to, say, contstraint flags and pass the page array down to the PMU if that sounds like a cleaner thing to do?
Quoted 6 lines
Quoted 1 line
Are you aware of allocation constraints for other architectures?
Somewhat. ARM's trace memory controller supports both scatter-gather and a plain contiguous buffer, I haven't found evidence of one being available while the other one isn't, so I'm inclined to assume that if it can write to system memory, it supports SG.
I've just added a patch from Vince Weaver:
http://lkml.kernel.org/r/alpine.DEB.2.10.1405161708060.11099@vincent-weaver-1.umelst.maine.edu
Quoted 7 lines
That adds
pmu::capabilities, I suppose we could start with something like:
PERF_PMU_CAP_AUX_BROKEN_SGwhich would make the allocator attempt to fill the AUX buffer with as big a chunks of contiguous memory as is available.
Ok, how about this (on top of the previous patch):
include/linux/perf_event.h +5 -4
@@ -278,15 +278,15 @@ struct pmu {void (*flush_branch_stack) (void );/* -* Allocate AUX space buffer: return an array of @nr_pages pages to be -* mapped to userspace that will also be passed to ->free_aux. +* Set up pmu-private data structures for an AUX area */ -void *(*alloc_aux) (int cpu,int nr_pages,bool overwrite, +void *(*setup_aux) (int cpu,void **pages, +int nr_pages,bool overwrite,struct perf_event_mmap_page *user_page);/* optional */ /* -* Free AUX buffer +* Free pmu-private AUX data structures */ void (*free_aux) (void *aux);/* optional */
@@ -300,6 +300,7 @@ struct pmu {* struct pmu::capabilities flags */ #define PERF_PMU_CAP_NO_INTERRUPT 1 +#define PERF_PMU_CAP_AUX_BROKEN_SG 2/** * enum perf_event_active_state - the states of a event
kernel/events/internal.h +1 -0
@@ -41,6 +41,7 @@ struct ring_buffer {atomic_t aux_mmap_count;unsigned long aux_mmap_locked;void **aux_pages; +void *aux_priv;void (*free_aux)(void *aux);struct perf_event_mmap_page *user_page;
kernel/events/ring_buffer.c +70 -6
102 lines not on this page · raw message
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
That appears to be missing a
is_power_of_2(aux_size)check.The problem with not having that is that since perf_event_mmap_page::aux_{head,tail} are of Z mod 2^64 but your actual {head,tail} are of Z mod
aux_size, you needaux_sizeto be a full divider of 2^64 or otherwise you get wrapping issues at the overflow.Having it them all 2^n makes the divider trivial.
Quoted 7 lines
Quoted 3 lines
I left it out so that the PMU callback could decide if it wants to do the math or not. Maybe it can also be a constraint flag or is it not worth it at all?
I'd start with the most constrained model -- that is add the power of two test -- and worry about relaxing it if it turns out its really needed.
Makes sense, I'll put it back.
Regards,
--
Alex
Re: [RFC 2/2] perf: add AUX area to ring buffer for raw data streams
include/linux/perf_event.h struct pmu { · line 303
Quoted 5 lines · Alexander Shishkin
include/linux/perf_event.h +1
-0@@ -300,6 +300,7 @@ struct pmu {* struct pmu::capabilities flags */ #define PERF_PMU_CAP_NO_INTERRUPT 1 +#define PERF_PMU_CAP_AUX_BROKEN_SG 2
Btw., I'd name it PERF_PMU_AUX_PHYSICAL_SG or so, and add a comment before it that explains that such hardware interfaces are restrictive, or so.
Thanks,
Ingo