Re: [PATCH v2 1/1] perf: Sharing PMU counters across compatible events

From: Jiri Olsa
Date: Thu Aug 30 2018 - 11:14:01 EST


On Wed, Aug 15, 2018 at 10:03:13AM -0700, Song Liu wrote:

SNIP

>
> + perf_event_remove_dup(event, ctx);
> /*
> * We can have double detach due to exit/hot-unplug + close.
> */
> @@ -1982,6 +2123,92 @@ event_filter_match(struct perf_event *event)
> perf_cgroup_match(event) && pmu_filter_match(event);
> }
>
> +/* PMU sharing aware version of event->pmu->add() */
> +static int event_pmu_add(struct perf_event *event,
> + struct perf_event_context *ctx)
> +{
> + struct perf_event_dup *dup;
> + int ret;
> +
> + /* no sharing, just do event->pmu->add() */
> + if (event->dup_id == -1)
> + return event->pmu->add(event, PERF_EF_START);
> +
> + dup = &ctx->dup_events[event->dup_id];
> +
> + if (dup->active_event_count) {
> + /* already enabled */
> + dup->active_event_count++;
> + dup->master->pmu->read(dup->master);
> + event->dup_base_count = dup_read_count(dup);
> + event->dup_base_child_count = dup_read_child_count(dup);
> + return 0;
> + }
> +
> + /* try add master */
> + ret = event->pmu->add(dup->master, PERF_EF_START);
> +
> + if (!ret) {
> + dup->active_event_count = 1;
> + event->pmu->read(dup->master);
> + event->dup_base_count = dup_read_count(dup);
> + event->dup_base_child_count = dup_read_child_count(dup);

should you read the base before calling pmu->add ?
should be same for any dup event not just master

jirka