Re: [PATCH v5 04/15] sched/core: uclamp: add CPU's clamp groups refcounting

From: Patrick Bellasi
Date: Thu Nov 22 2018 - 09:20:54 EST


On 13-Nov 07:11, Patrick Bellasi wrote:
> On 11-Nov 17:47, Peter Zijlstra wrote:
> > On Mon, Oct 29, 2018 at 06:32:59PM +0000, Patrick Bellasi wrote:

[...]

> > > + /* Both min and max clamps are MAX aggregated */
> > > + if (max_value < rq->uclamp.group[clamp_id][group_id].value)
> > > + max_value = rq->uclamp.group[clamp_id][group_id].value;
> >
> > max_value = max(max_value, rq->uclamp.group[clamp_id][group_id].value);
>
> Right, I get used to this pattern to avoid write instructions.
> I guess that here, being just a function local variable, we don't
> really care much...

The above does not work also because we now use bitfields:

In file included from ./include/linux/list.h:9:0,
from ./include/linux/rculist.h:10,
from ./include/linux/pid.h:5,
from ./include/linux/sched.h:14,
from kernel/sched/sched.h:5,
from kernel/sched/core.c:8:
kernel/sched/core.c: In function âuclamp_cpu_updateâ:
kernel/sched/core.c:867:5: error: âtypeofâ applied to a bit-field
rq->uclamp.group[clamp_id][group_id].value);
^

[...]

> > > + if (rq->uclamp.value[clamp_id] < p->uclamp[clamp_id].value)
> > > + rq->uclamp.value[clamp_id] = p->uclamp[clamp_id].value;
> >
> > rq->uclamp.value[clamp_id] = max(rq->uclamp.value[clamp_id],
> > p->uclamp[clamp_id].value);
>
> In this case instead, since we are updating a variable visible from
> other CPUs, should not be preferred to avoid assignment when not
> required ?

And what about this ?

> Is the compiler is smart enough to optimize the code above?
> ... will check better.

Did not really checked what the compiler does in the two cases but,
given also the above, for consistency I would probably prefer to keep
both max aggregation as originally defined.

What do you think ?

--
#include <best/regards.h>

Patrick Bellasi