Messages in this thread | | | Date | Wed, 11 Nov 2020 19:04:41 +0100 | From | Peter Zijlstra <> | Subject | Re: [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp |
| |
On Wed, Nov 11, 2020 at 06:41:07PM +0100, Dietmar Eggemann wrote: > diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h > index c852153ddb0d..b9165f17dddc 100644 > --- a/include/uapi/linux/sched/types.h > +++ b/include/uapi/linux/sched/types.h > @@ -115,8 +115,8 @@ struct sched_attr { > __u64 sched_period; > > /* Utilization hints */ > - __u32 sched_util_min; > - __u32 sched_util_max; > + __s32 sched_util_min; > + __s32 sched_util_max;
So that's UAPI, not sure we can change the type here.
> }; > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 3dc415f58bd7..caaa2a8434b9 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1413,17 +1413,24 @@ int sysctl_sched_uclamp_handler(struct ctl_table *table, int write, > static int uclamp_validate(struct task_struct *p, > const struct sched_attr *attr) > { > - unsigned int lower_bound = p->uclamp_req[UCLAMP_MIN].value; > - unsigned int upper_bound = p->uclamp_req[UCLAMP_MAX].value; > + int util_min = p->uclamp_req[UCLAMP_MIN].value; > + int util_max = p->uclamp_req[UCLAMP_MAX].value; > > - if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) > - lower_bound = attr->sched_util_min; > - if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) > - upper_bound = attr->sched_util_max; > + if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { > + util_min = attr->sched_util_min; > > - if (lower_bound > upper_bound) > - return -EINVAL; > - if (upper_bound > SCHED_CAPACITY_SCALE) > + if (util_min < -1 || util_min > SCHED_CAPACITY_SCALE) > + return -EINVAL; > + } > + > + if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) { > + util_max = attr->sched_util_max; > + > + if (util_max < -1 || util_max > SCHED_CAPACITY_SCALE) > + return -EINVAL; > + }
Luckily we can write that range as a single branch like:
if (util_{min,max} + 1 > SCHED_CAPACITY_SCALE+1)
which assumes u32 :-)
> + > + if (util_min != -1 && util_max != -1 && util_min > util_max) > return -EINVAL;
I think that will compile as is, otherwise write it like ~0u, which is the same bit pattern.
| |