Re: [PATCH 01/14] perf/x86: Introduce PERF_RECORD_OVERHEAD

From: Peter Zijlstra
Date: Wed Nov 23 2016 - 15:12:10 EST


On Wed, Nov 23, 2016 at 04:44:39AM -0500, kan.liang@xxxxxxxxx wrote:
> +struct perf_overhead_entry {
> + __u32 cpu;
> + __u64 nr;
> + __u64 time;
> +};

> +void perf_log_overhead(struct perf_event *event, u32 type,
> + struct perf_overhead_entry *entry)
> +{
> + struct perf_output_handle handle;
> + struct perf_sample_data sample;
> + int ret;
> +
> + struct {
> + struct perf_event_header header;
> + u32 type;

There's two u32 sized holes here.

> + struct perf_overhead_entry overhead;
> + } overhead_event = {
> + .header = {
> + .type = PERF_RECORD_OVERHEAD,
> + .misc = 0,
> + .size = sizeof(overhead_event),
> + },
.type = type,
.overhead = *event,
> + };

> + overhead_event.type = type;
> + memcpy(&overhead_event.overhead, entry, sizeof(overhead_event.overhead));

Do the above named initialization instead.

> +
> + perf_event_header__init_id(&overhead_event.header, &sample, event);
> + ret = perf_output_begin(&handle, event, overhead_event.header.size);
> +
> + if (ret)
> + return;
> +
> + perf_output_put(&handle, overhead_event);
> + perf_event__output_id_sample(event, &handle, &sample);
> +
> + perf_output_end(&handle);
> + memset(entry, 0, sizeof(*entry));
> +}