Commit 2023a0d2 authored by Alexander Shishkin's avatar Alexander Shishkin Committed by Ingo Molnar

perf: Support overwrite mode for the AUX area

This adds support for overwrite mode in the AUX area, which means "keep
collecting data till you're stopped", turning AUX area into a circular
buffer, where new data overwrites old data. 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.

Overwrite mode is enabled at mapping AUX area read only. Even though
aux_tail in the buffer's user page might be user writable, it will be
ignored in this mode.

A PERF_RECORD_AUX with PERF_AUX_FLAG_OVERWRITE set is written to the perf
data stream every time an event writes new data to the AUX area. The pmu
driver might not be able to infer the exact beginning of the new data in
each snapshot, some drivers will only provide the tail, which is
aux_offset + aux_size in the AUX record. Consumer has to be able to tell
the new data from the old one, for example, by means of time stamps if
such are provided in the trace.

Consumer is also responsible for disabling any events that might write
to the AUX area (thus potentially racing with the consumer) before
collecting the data.
Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kaixu Xia <kaixu.xia@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Robert Richter <rric@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: acme@infradead.org
Cc: adrian.hunter@intel.com
Cc: kan.liang@intel.com
Cc: markus.t.metzger@intel.com
Cc: mathieu.poirier@linaro.org
Link: http://lkml.kernel.org/r/1421237903-181015-9-git-send-email-alexander.shishkin@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent fdc26706
...@@ -803,6 +803,7 @@ enum perf_callchain_context { ...@@ -803,6 +803,7 @@ enum perf_callchain_context {
* PERF_RECORD_AUX::flags bits * PERF_RECORD_AUX::flags bits
*/ */
#define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */ #define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */
#define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */
#define PERF_FLAG_FD_NO_GROUP (1UL << 0) #define PERF_FLAG_FD_NO_GROUP (1UL << 0)
#define PERF_FLAG_FD_OUTPUT (1UL << 1) #define PERF_FLAG_FD_OUTPUT (1UL << 1)
......
...@@ -40,6 +40,7 @@ struct ring_buffer { ...@@ -40,6 +40,7 @@ struct ring_buffer {
local_t aux_nest; local_t aux_nest;
unsigned long aux_pgoff; unsigned long aux_pgoff;
int aux_nr_pages; int aux_nr_pages;
int aux_overwrite;
atomic_t aux_mmap_count; atomic_t aux_mmap_count;
unsigned long aux_mmap_locked; unsigned long aux_mmap_locked;
void (*free_aux)(void *); void (*free_aux)(void *);
......
...@@ -283,26 +283,33 @@ void *perf_aux_output_begin(struct perf_output_handle *handle, ...@@ -283,26 +283,33 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,
goto err_put; goto err_put;
aux_head = local_read(&rb->aux_head); aux_head = local_read(&rb->aux_head);
aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
handle->rb = rb; handle->rb = rb;
handle->event = event; handle->event = event;
handle->head = aux_head; handle->head = aux_head;
if (aux_head - aux_tail < perf_aux_size(rb)) handle->size = 0;
handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
else
handle->size = 0;
/* /*
* handle->size computation depends on aux_tail load; this forms a * In overwrite mode, AUX data stores do not depend on aux_tail,
* control dependency barrier separating aux_tail load from aux data * therefore (A) control dependency barrier does not exist. The
* store that will be enabled on successful return * (B) <-> (C) ordering is still observed by the pmu driver.
*/ */
if (!handle->size) { /* A, matches D */ if (!rb->aux_overwrite) {
event->pending_disable = 1; aux_tail = ACCESS_ONCE(rb->user_page->aux_tail);
perf_output_wakeup(handle); if (aux_head - aux_tail < perf_aux_size(rb))
local_set(&rb->aux_nest, 0); handle->size = CIRC_SPACE(aux_head, aux_tail, perf_aux_size(rb));
goto err_put;
/*
* handle->size computation depends on aux_tail load; this forms a
* control dependency barrier separating aux_tail load from aux data
* store that will be enabled on successful return
*/
if (!handle->size) { /* A, matches D */
event->pending_disable = 1;
perf_output_wakeup(handle);
local_set(&rb->aux_nest, 0);
goto err_put;
}
} }
return handle->rb->aux_priv; return handle->rb->aux_priv;
...@@ -327,13 +334,22 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, ...@@ -327,13 +334,22 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
bool truncated) bool truncated)
{ {
struct ring_buffer *rb = handle->rb; struct ring_buffer *rb = handle->rb;
unsigned long aux_head = local_read(&rb->aux_head); unsigned long aux_head;
u64 flags = 0; u64 flags = 0;
if (truncated) if (truncated)
flags |= PERF_AUX_FLAG_TRUNCATED; flags |= PERF_AUX_FLAG_TRUNCATED;
local_add(size, &rb->aux_head); /* in overwrite mode, driver provides aux_head via handle */
if (rb->aux_overwrite) {
flags |= PERF_AUX_FLAG_OVERWRITE;
aux_head = handle->head;
local_set(&rb->aux_head, aux_head);
} else {
aux_head = local_read(&rb->aux_head);
local_add(size, &rb->aux_head);
}
if (size || flags) { if (size || flags) {
/* /*
...@@ -480,6 +496,8 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event, ...@@ -480,6 +496,8 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event *event,
*/ */
atomic_set(&rb->aux_refcount, 1); atomic_set(&rb->aux_refcount, 1);
rb->aux_overwrite = overwrite;
out: out:
if (!ret) if (!ret)
rb->aux_pgoff = pgoff; rb->aux_pgoff = pgoff;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment