Commit 7f453c24 authored by Peter Zijlstra's avatar Peter Zijlstra

perf_counter: PERF_SAMPLE_ID and inherited counters

Anton noted that for inherited counters the counter-id as provided by
PERF_SAMPLE_ID isn't mappable to the id found through PERF_RECORD_ID
because each inherited counter gets its own id.

His suggestion was to always return the parent counter id, since that
is the primary counter id as exposed. However, these inherited
counters have a unique identifier so that events like
PERF_EVENT_PERIOD and PERF_EVENT_THROTTLE can be specific about which
counter gets modified, which is important when trying to normalize the
sample streams.

This patch removes PERF_EVENT_PERIOD in favour of PERF_SAMPLE_PERIOD,
which is more useful anyway, since changing periods became a lot more
common than initially thought -- rendering PERF_EVENT_PERIOD the less
useful solution (also, PERF_SAMPLE_PERIOD reports the more accurate
value, since it reports the value used to trigger the overflow,
whereas PERF_EVENT_PERIOD simply reports the requested period changed,
which might only take effect on the next cycle).

This still leaves us PERF_EVENT_THROTTLE to consider, but since that
_should_ be a rare occurrence, and linking it to a primary id is the
most useful bit to diagnose the problem, we introduce a
PERF_SAMPLE_STREAM_ID, for those few cases where the full
reconstruction is important.

[Does change the ABI a little, but I see no other way out]
Suggested-by: default avatarAnton Blanchard <anton@samba.org>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1248095846.15751.8781.camel@twins>
parent 573402db
...@@ -120,8 +120,9 @@ enum perf_counter_sample_format { ...@@ -120,8 +120,9 @@ enum perf_counter_sample_format {
PERF_SAMPLE_ID = 1U << 6, PERF_SAMPLE_ID = 1U << 6,
PERF_SAMPLE_CPU = 1U << 7, PERF_SAMPLE_CPU = 1U << 7,
PERF_SAMPLE_PERIOD = 1U << 8, PERF_SAMPLE_PERIOD = 1U << 8,
PERF_SAMPLE_STREAM_ID = 1U << 9,
PERF_SAMPLE_MAX = 1U << 9, /* non-ABI */ PERF_SAMPLE_MAX = 1U << 10, /* non-ABI */
}; };
/* /*
...@@ -312,16 +313,7 @@ enum perf_event_type { ...@@ -312,16 +313,7 @@ enum perf_event_type {
* struct perf_event_header header; * struct perf_event_header header;
* u64 time; * u64 time;
* u64 id; * u64 id;
* u64 sample_period; * u64 stream_id;
* };
*/
PERF_EVENT_PERIOD = 4,
/*
* struct {
* struct perf_event_header header;
* u64 time;
* u64 id;
* }; * };
*/ */
PERF_EVENT_THROTTLE = 5, PERF_EVENT_THROTTLE = 5,
...@@ -356,6 +348,7 @@ enum perf_event_type { ...@@ -356,6 +348,7 @@ enum perf_event_type {
* { u64 time; } && PERF_SAMPLE_TIME * { u64 time; } && PERF_SAMPLE_TIME
* { u64 addr; } && PERF_SAMPLE_ADDR * { u64 addr; } && PERF_SAMPLE_ADDR
* { u64 id; } && PERF_SAMPLE_ID * { u64 id; } && PERF_SAMPLE_ID
* { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
* { u32 cpu, res; } && PERF_SAMPLE_CPU * { u32 cpu, res; } && PERF_SAMPLE_CPU
* { u64 period; } && PERF_SAMPLE_PERIOD * { u64 period; } && PERF_SAMPLE_PERIOD
* *
......
...@@ -154,6 +154,20 @@ static void unclone_ctx(struct perf_counter_context *ctx) ...@@ -154,6 +154,20 @@ static void unclone_ctx(struct perf_counter_context *ctx)
} }
} }
/*
* If we inherit counters we want to return the parent counter id
* to userspace.
*/
static u64 primary_counter_id(struct perf_counter *counter)
{
u64 id = counter->id;
if (counter->parent)
id = counter->parent->id;
return id;
}
/* /*
* Get the perf_counter_context for a task and lock it. * Get the perf_counter_context for a task and lock it.
* This has to cope with with the fact that until it is locked, * This has to cope with with the fact that until it is locked,
...@@ -1296,7 +1310,6 @@ static void perf_counter_cpu_sched_in(struct perf_cpu_context *cpuctx, int cpu) ...@@ -1296,7 +1310,6 @@ static void perf_counter_cpu_sched_in(struct perf_cpu_context *cpuctx, int cpu)
#define MAX_INTERRUPTS (~0ULL) #define MAX_INTERRUPTS (~0ULL)
static void perf_log_throttle(struct perf_counter *counter, int enable); static void perf_log_throttle(struct perf_counter *counter, int enable);
static void perf_log_period(struct perf_counter *counter, u64 period);
static void perf_adjust_period(struct perf_counter *counter, u64 events) static void perf_adjust_period(struct perf_counter *counter, u64 events)
{ {
...@@ -1315,8 +1328,6 @@ static void perf_adjust_period(struct perf_counter *counter, u64 events) ...@@ -1315,8 +1328,6 @@ static void perf_adjust_period(struct perf_counter *counter, u64 events)
if (!sample_period) if (!sample_period)
sample_period = 1; sample_period = 1;
perf_log_period(counter, sample_period);
hwc->sample_period = sample_period; hwc->sample_period = sample_period;
} }
...@@ -1705,7 +1716,7 @@ perf_read_hw(struct perf_counter *counter, char __user *buf, size_t count) ...@@ -1705,7 +1716,7 @@ perf_read_hw(struct perf_counter *counter, char __user *buf, size_t count)
values[n++] = counter->total_time_running + values[n++] = counter->total_time_running +
atomic64_read(&counter->child_total_time_running); atomic64_read(&counter->child_total_time_running);
if (counter->attr.read_format & PERF_FORMAT_ID) if (counter->attr.read_format & PERF_FORMAT_ID)
values[n++] = counter->id; values[n++] = primary_counter_id(counter);
mutex_unlock(&counter->child_mutex); mutex_unlock(&counter->child_mutex);
if (count < n * sizeof(u64)) if (count < n * sizeof(u64))
...@@ -1812,8 +1823,6 @@ static int perf_counter_period(struct perf_counter *counter, u64 __user *arg) ...@@ -1812,8 +1823,6 @@ static int perf_counter_period(struct perf_counter *counter, u64 __user *arg)
counter->attr.sample_freq = value; counter->attr.sample_freq = value;
} else { } else {
perf_log_period(counter, value);
counter->attr.sample_period = value; counter->attr.sample_period = value;
counter->hw.sample_period = value; counter->hw.sample_period = value;
} }
...@@ -2662,6 +2671,9 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, ...@@ -2662,6 +2671,9 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
if (sample_type & PERF_SAMPLE_ID) if (sample_type & PERF_SAMPLE_ID)
header.size += sizeof(u64); header.size += sizeof(u64);
if (sample_type & PERF_SAMPLE_STREAM_ID)
header.size += sizeof(u64);
if (sample_type & PERF_SAMPLE_CPU) { if (sample_type & PERF_SAMPLE_CPU) {
header.size += sizeof(cpu_entry); header.size += sizeof(cpu_entry);
...@@ -2705,7 +2717,13 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, ...@@ -2705,7 +2717,13 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
if (sample_type & PERF_SAMPLE_ADDR) if (sample_type & PERF_SAMPLE_ADDR)
perf_output_put(&handle, data->addr); perf_output_put(&handle, data->addr);
if (sample_type & PERF_SAMPLE_ID) if (sample_type & PERF_SAMPLE_ID) {
u64 id = primary_counter_id(counter);
perf_output_put(&handle, id);
}
if (sample_type & PERF_SAMPLE_STREAM_ID)
perf_output_put(&handle, counter->id); perf_output_put(&handle, counter->id);
if (sample_type & PERF_SAMPLE_CPU) if (sample_type & PERF_SAMPLE_CPU)
...@@ -2728,7 +2746,7 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, ...@@ -2728,7 +2746,7 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
if (sub != counter) if (sub != counter)
sub->pmu->read(sub); sub->pmu->read(sub);
group_entry.id = sub->id; group_entry.id = primary_counter_id(sub);
group_entry.counter = atomic64_read(&sub->count); group_entry.counter = atomic64_read(&sub->count);
perf_output_put(&handle, group_entry); perf_output_put(&handle, group_entry);
...@@ -2788,15 +2806,8 @@ perf_counter_read_event(struct perf_counter *counter, ...@@ -2788,15 +2806,8 @@ perf_counter_read_event(struct perf_counter *counter,
} }
if (counter->attr.read_format & PERF_FORMAT_ID) { if (counter->attr.read_format & PERF_FORMAT_ID) {
u64 id;
event.header.size += sizeof(u64); event.header.size += sizeof(u64);
if (counter->parent) event.format[i++] = primary_counter_id(counter);
id = counter->parent->id;
else
id = counter->id;
event.format[i++] = id;
} }
ret = perf_output_begin(&handle, counter, event.header.size, 0, 0); ret = perf_output_begin(&handle, counter, event.header.size, 0, 0);
...@@ -3190,49 +3201,6 @@ void __perf_counter_mmap(struct vm_area_struct *vma) ...@@ -3190,49 +3201,6 @@ void __perf_counter_mmap(struct vm_area_struct *vma)
perf_counter_mmap_event(&mmap_event); perf_counter_mmap_event(&mmap_event);
} }
/*
* Log sample_period changes so that analyzing tools can re-normalize the
* event flow.
*/
struct freq_event {
struct perf_event_header header;
u64 time;
u64 id;
u64 period;
};
static void perf_log_period(struct perf_counter *counter, u64 period)
{
struct perf_output_handle handle;
struct freq_event event;
int ret;
if (counter->hw.sample_period == period)
return;
if (counter->attr.sample_type & PERF_SAMPLE_PERIOD)
return;
event = (struct freq_event) {
.header = {
.type = PERF_EVENT_PERIOD,
.misc = 0,
.size = sizeof(event),
},
.time = sched_clock(),
.id = counter->id,
.period = period,
};
ret = perf_output_begin(&handle, counter, sizeof(event), 1, 0);
if (ret)
return;
perf_output_put(&handle, event);
perf_output_end(&handle);
}
/* /*
* IRQ throttle logging * IRQ throttle logging
*/ */
...@@ -3246,14 +3214,16 @@ static void perf_log_throttle(struct perf_counter *counter, int enable) ...@@ -3246,14 +3214,16 @@ static void perf_log_throttle(struct perf_counter *counter, int enable)
struct perf_event_header header; struct perf_event_header header;
u64 time; u64 time;
u64 id; u64 id;
u64 stream_id;
} throttle_event = { } throttle_event = {
.header = { .header = {
.type = PERF_EVENT_THROTTLE + 1, .type = PERF_EVENT_THROTTLE + 1,
.misc = 0, .misc = 0,
.size = sizeof(throttle_event), .size = sizeof(throttle_event),
}, },
.time = sched_clock(), .time = sched_clock(),
.id = counter->id, .id = primary_counter_id(counter),
.stream_id = counter->id,
}; };
ret = perf_output_begin(&handle, counter, sizeof(throttle_event), 1, 0); ret = perf_output_begin(&handle, counter, sizeof(throttle_event), 1, 0);
......
...@@ -74,20 +74,12 @@ struct fork_event { ...@@ -74,20 +74,12 @@ struct fork_event {
u32 pid, ppid; u32 pid, ppid;
}; };
struct period_event {
struct perf_event_header header;
u64 time;
u64 id;
u64 sample_period;
};
typedef union event_union { typedef union event_union {
struct perf_event_header header; struct perf_event_header header;
struct ip_event ip; struct ip_event ip;
struct mmap_event mmap; struct mmap_event mmap;
struct comm_event comm; struct comm_event comm;
struct fork_event fork; struct fork_event fork;
struct period_event period;
} event_t; } event_t;
...@@ -997,19 +989,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -997,19 +989,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head)
return 0; return 0;
} }
static int
process_period_event(event_t *event, unsigned long offset, unsigned long head)
{
dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->period.time,
event->period.id,
event->period.sample_period);
return 0;
}
static int static int
process_event(event_t *event, unsigned long offset, unsigned long head) process_event(event_t *event, unsigned long offset, unsigned long head)
{ {
...@@ -1025,9 +1004,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1025,9 +1004,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
case PERF_EVENT_FORK: case PERF_EVENT_FORK:
return process_fork_event(event, offset, head); return process_fork_event(event, offset, head);
case PERF_EVENT_PERIOD:
return process_period_event(event, offset, head);
/* /*
* We dont process them right now but they are fine: * We dont process them right now but they are fine:
*/ */
......
...@@ -101,13 +101,6 @@ struct fork_event { ...@@ -101,13 +101,6 @@ struct fork_event {
u32 pid, ppid; u32 pid, ppid;
}; };
struct period_event {
struct perf_event_header header;
u64 time;
u64 id;
u64 sample_period;
};
struct lost_event { struct lost_event {
struct perf_event_header header; struct perf_event_header header;
u64 id; u64 id;
...@@ -127,7 +120,6 @@ typedef union event_union { ...@@ -127,7 +120,6 @@ typedef union event_union {
struct mmap_event mmap; struct mmap_event mmap;
struct comm_event comm; struct comm_event comm;
struct fork_event fork; struct fork_event fork;
struct period_event period;
struct lost_event lost; struct lost_event lost;
struct read_event read; struct read_event read;
} event_t; } event_t;
...@@ -1635,19 +1627,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1635,19 +1627,6 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head)
return 0; return 0;
} }
static int
process_period_event(event_t *event, unsigned long offset, unsigned long head)
{
dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->period.time,
event->period.id,
event->period.sample_period);
return 0;
}
static int static int
process_lost_event(event_t *event, unsigned long offset, unsigned long head) process_lost_event(event_t *event, unsigned long offset, unsigned long head)
{ {
...@@ -1729,9 +1708,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head) ...@@ -1729,9 +1708,6 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
case PERF_EVENT_FORK: case PERF_EVENT_FORK:
return process_fork_event(event, offset, head); return process_fork_event(event, offset, head);
case PERF_EVENT_PERIOD:
return process_period_event(event, offset, head);
case PERF_EVENT_LOST: case PERF_EVENT_LOST:
return process_lost_event(event, offset, head); return process_lost_event(event, offset, head);
......
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