[PATCH v3 09/23] perf: Support overwrite mode for AUX area
From: Alexander Shishkin
Date: Mon Aug 11 2014 - 01:29:34 EST
This adds support for overwrite mode in the AUX area, which means "keep
collecting data till you're stopped". It does not depend on data buffer's
overwrite mode, so that it doesn't lose sideband data that is instrumental
for processing AUX data.
Signed-off-by: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
---
kernel/events/internal.h | 1 +
kernel/events/ring_buffer.c | 40 +++++++++++++++++++++++++++++-----------
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index c6b2987afe..4607742be8 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -40,6 +40,7 @@ struct ring_buffer {
local_t aux_nest;
unsigned long aux_pgoff;
int aux_nr_pages;
+ int aux_overwrite;
atomic_t aux_mmap_count;
unsigned long aux_mmap_locked;
void **aux_pages;
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 598c02a555..4ee7723d87 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -263,19 +263,23 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
goto err;
aux_head = local_read(&rb->aux_head);
- aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
handle->rb = rb;
handle->event = event;
handle->head = aux_head;
- handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
-
- if (!handle->size) {
- event->pending_disable = 1;
- event->hw.state = PERF_HES_STOPPED;
- perf_output_wakeup(handle);
- local_set(&rb->aux_nest, 0);
- goto err;
+ if (!rb->aux_overwrite) {
+ aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
+ handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
+
+ if (!handle->size) {
+ event->pending_disable = 1;
+ event->hw.state = PERF_HES_STOPPED;
+ perf_output_wakeup(handle);
+ local_set(&rb->aux_nest, 0);
+ goto err;
+ }
+ } else {
+ handle->size = 0;
}
return handle->rb->aux_priv;
@@ -291,9 +295,22 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
bool truncated)
{
struct ring_buffer *rb = handle->rb;
+ unsigned long aux_head;
- local_add(size, &rb->aux_head);
- perf_event_aux_event(handle->event, aux_head, size, truncated);
+ aux_head = local_read(&rb->aux_head);
+
+ if (rb->aux_overwrite) {
+ local_set(&rb->aux_head, size);
+
+ /*
+ * Send a RECORD_AUX with size==0 to communicate aux_head
+ * of this snapshot to userspace
+ */
+ perf_event_aux_event(handle->event, size, 0, truncated);
+ } else {
+ local_add(size, &rb->aux_head);
+ perf_event_aux_event(handle->event, aux_head, size, truncated);
+ }
smp_wmb();
rb->user_page->aux_head = local_read(&rb->aux_head);
@@ -405,6 +422,7 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,
overwrite);
if (rb->aux_priv)
ret = 0;
+ rb->aux_overwrite = overwrite;
out:
if (!ret)
--
2.1.0.rc1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/