Re: [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified

From: Stephane Eranian
Date: Fri Apr 05 2019 - 20:49:39 EST


On Fri, Apr 5, 2019 at 1:26 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Fri, Apr 05, 2019 at 10:00:03AM -0700, Stephane Eranian wrote:
>
> > > > +static void update_tfa_sched(void *ignored)
> > > > +{
> > > > + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
> > > > + struct pmu *pmu = x86_get_pmu();
> > > > + struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context);
> > > > + struct perf_event_context *task_ctx = cpuctx->task_ctx;
> > > > +
> > > > + /* prevent any changes to the two contexts */
> > > > + perf_ctx_lock(cpuctx, task_ctx);
> > > > +
> > > > + /*
> > > > + * check if PMC3 is used
> > > > + * and if so force schedule out for all event types all contexts
> > > > + */
> > > > + if (test_bit(3, cpuc->active_mask))
> > > > + perf_ctx_resched(cpuctx, task_ctx, EVENT_ALL|EVENT_CPU);
> > > > +
> > > > + perf_ctx_unlock(cpuctx, task_ctx);
> > >
> > > I'm not particularly happy with exporting all that. Can't we create this
> > > new perf_ctx_resched() to include the locking and everything. Then the
> > > above reduces to:
> > >
> > > if (test_bit(3, cpuc->active_mask))
> > > perf_ctx_resched(cpuctx);
> > >
> > > And we don't get to export the tricky bits.
> > >
> > The only reason I exported the locking is to protect
> > cpuc->active_mask. But if you
> > think there is no race, then sure, we can just export a new
> > perf_ctx_resched() that
> > does the locking and invokes the ctx_resched() function.
>
> It doesn't matter if it races, if it was used and isn't anymore, it's
> a pointless reschedule, if it isn't used and we don't reschedule, it
> cannot be used because we've already set the flag.

True. I will post V2 shortly.