Re: [PATCH v3 2/2] sched/uclamp: Protect uclamp fast path code with static key

From: Qais Yousef
Date: Thu Jun 25 2020 - 07:34:14 EST


On 06/25/20 12:26, Valentin Schneider wrote:
>
> On 25/06/20 12:00, Qais Yousef wrote:
> > Hi Valentin
> >
> > On 06/25/20 01:16, Valentin Schneider wrote:
> >> In schedutil_cpu_util(), when uclamp isn't compiled it, we have an explicit
> >> 'goto max'. When uclamp *is* compiled in, that's taken care of by the
> >> "natural" RT uclamp aggregation... Which doesn't happen until we flip the
> >> static key.
> >>
> >> It's yucky, but if you declare the key in the internal sched header, you
> >> could reuse it in the existing 'goto max' (or sysctl value, when we make
> >> that tweakable) path.
> >
> > Not sure if this is the best way forward. I need to think about it.
> > While I am not keen on enabling in kernel users of util clamp, but there was
> > already an attempt to do so. This approach will not allow us to implement
> > something in the future for that. Which maybe is what we want..
> >
>
> Just to be clear, I'm not suggesting to add any in-kernel toggling of
> uclamp outside of the scheduler: by keeping that to the internal sched
> header & schedutil, we're keeping it contained to internal scheduler land.
>
> Since a diff is worth a thousand words, here's what I was thinking of (not
> even compiled):

Yeah I understood and already thought about this. But this approach could
prevent potential in kernel-users. Whether we care or not about this now,
I don't know. But it seems the simplest thing to do.

>
> >> > - if (update_root_tg)
> >> > + if (update_root_tg) {
> >> > uclamp_update_root_tg();
> >> > + static_branch_enable(&sched_uclamp_used);
> >>
> >> I don't think it matters ATM, but shouldn't we flip that *before* updating
> >> the TG's to avoid any future surprises?
> >
> > What sort of surprises are you thinking of?
> >
>
> Say if we end up adding static key checks in some other uclamp functions
> (which are called in the TG update) and don't change this here, someone
> will have to scratch their heads to figure out the key enablement needs to
> be moved one line higher. It's harmless future-proofing, I think.

Hehe okay, I'll change that.

Thanks

--
Qais Yousef