Re: [PATCH v2 03/14] perf: Add persistent event facilities

From: Namhyung Kim
Date: Thu Jun 13 2013 - 22:15:22 EST


Hi Robert and Boris,

On Tue, 11 Jun 2013 18:42:29 +0200, Robert Richter wrote:
> From: Borislav Petkov <bp@xxxxxxxxx>
>
> Add a barebones implementation for registering persistent events with
> perf. For that, we don't destroy the buffers when they're unmapped;
> also, we map them read-only so that multiple agents can access them.
>
> Also, we allocate the event buffers at event init time and not at mmap
> time so that we can log samples into them regardless of whether there
> are readers in userspace or not.
>
> Changes made by Robert Richter <robert.richter@xxxxxxxxxx>:
>
> * Fixing wrongly determined attribute size.
>
> * The default buffer size used to setup event buffers with perf tools
> is 512k. Using the same buffer size for persistent events. This also
> avoids failed mmap calls due to different buffer sizes.
>
> * Improve error reporting.
>
> * Returning -ENODEV if no file descriptor is found. An error code of
> -1 (-EPERM) is misleading in this case.
>
> * Adding cpu check to perf_get_persistent_event_fd()
>
> [ make percpu variable static ]
> Reported-by: Fengguang Wu <fengguang.wu@xxxxxxxxx>
> Signed-off-by: Borislav Petkov <bp@xxxxxxx>
> [ Fix attr size ]
> [ Setting default buffer size to 512k as in perf tools ]
> [ Print error code on failure when adding events ]
> [ Return resonable error code ]
> [ Adding cpu check to perf_get_persistent_event_fd() ]
> Reported-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> Signed-off-by: Robert Richter <robert.richter@xxxxxxxxxx>
> Signed-off-by: Robert Richter <rric@xxxxxxxxxx>
[SNIP]
> +int perf_add_persistent_event_by_id(int id)
> +{
> + struct perf_event_attr *attr;
> +
> + attr = kzalloc(sizeof(*attr), GFP_KERNEL);
> + if (!attr)
> + return -ENOMEM;
> +
> + attr->sample_period = 1;
> + attr->wakeup_events = 1;
> + attr->sample_type = PERF_SAMPLE_RAW;
> + attr->persistent = 1;
> + attr->config = id;
> + attr->type = PERF_TYPE_TRACEPOINT;
> + attr->size = sizeof(*attr);
> +
> + return perf_add_persistent_event(attr, CPU_BUFFER_NR_PAGES);
> +}
> +
> +int perf_get_persistent_event_fd(unsigned cpu, struct perf_event_attr *attr)
> +{
> + struct pers_event_desc *desc;
> +
> + if (cpu >= (unsigned)nr_cpu_ids)
> + return -EINVAL;
> +
> + list_for_each_entry(desc, &per_cpu(pers_events, cpu), plist)
> + if (desc->attr->config == attr->config)
> + return __alloc_persistent_event_fd(desc);
> +

So it only supports tracepoint events. Don't we need to add other types
of event?

Thanks,
Namhyung


> + return -ENODEV;
> +}
> +
> +
> +void __init persistent_events_init(void)
> +{
> + int i;
> +
> + for_each_possible_cpu(i)
> + INIT_LIST_HEAD(&per_cpu(pers_events, i));
> +}
--
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/