Re: [PATCH v7] perf: Sharing PMU counters across compatible events

From: Jiri Olsa
Date: Thu Nov 28 2019 - 03:30:55 EST


On Fri, Nov 15, 2019 at 03:55:04PM -0800, Song Liu wrote:

SNIP

> add_event_to_ctx(event, ctx);
> }
> @@ -2745,21 +2998,26 @@ static void __perf_event_enable(struct perf_event *event,
> {
> struct perf_event *leader = event->group_leader;
> struct perf_event_context *task_ctx;
> + int was_active;
> + int event_type;
>
> if (event->state >= PERF_EVENT_STATE_INACTIVE ||
> event->state <= PERF_EVENT_STATE_ERROR)
> return;
>
> + event_type = perf_event_can_share(event) ? EVENT_ALL : EVENT_TIME;
> + was_active = ctx->is_active;
> if (ctx->is_active)
> - ctx_sched_out(ctx, cpuctx, EVENT_TIME);
> + ctx_sched_out(ctx, cpuctx, event_type);

you're scheduling everything out in here, so cpuctx->task_ctx
will become NULL and trigger the check below

I dont think you need to do it here, ctx_resched will do that
for you later, this here is just to keep the time updated

jirka

>
> perf_event_set_state(event, PERF_EVENT_STATE_INACTIVE);
> + perf_event_setup_dup(event, ctx);
>
> - if (!ctx->is_active)
> + if (!was_active)
> return;
>
> if (!event_filter_match(event)) {
> - ctx_sched_in(ctx, cpuctx, EVENT_TIME, current);
> + ctx_sched_in(ctx, cpuctx, event_type, current);
> return;
> }
>
> @@ -2767,8 +3025,8 @@ static void __perf_event_enable(struct perf_event *event,
> * If the event is in a group and isn't the group leader,
> * then don't put it on unless the group is on.
> */
> - if (leader != event && leader->state != PERF_EVENT_STATE_ACTIVE) {
> - ctx_sched_in(ctx, cpuctx, EVENT_TIME, current);
> + if (leader != event && leader->state <= PERF_EVENT_STATE_INACTIVE) {
> + ctx_sched_in(ctx, cpuctx, event_type, current);
> return;
> }
>
> @@ -2776,7 +3034,8 @@ static void __perf_event_enable(struct perf_event *event,
> if (ctx->task)
> WARN_ON_ONCE(task_ctx != ctx);
>
> - ctx_resched(cpuctx, task_ctx, get_event_type(event));
> + /* if perf_event_can_share() resched EVENT_ALL */
> + ctx_resched(cpuctx, task_ctx, get_event_type(event) | event_type);
> }

SNIP