Messages in this thread Patch in this message | | | Subject | Re: [PATCH v5 3/4] sched: Allow sched_{get,set}attr to change latency_nice of the task | From | Parth Shah <> | Date | Wed, 13 May 2020 15:11:09 +0530 |
| |
On 5/11/20 4:43 PM, Dietmar Eggemann wrote: > On 28/02/2020 10:07, Parth Shah wrote: >> Introduce the latency_nice attribute to sched_attr and provide a >> mechanism to change the value with the use of sched_setattr/sched_getattr >> syscall. >> >> Also add new flag "SCHED_FLAG_LATENCY_NICE" to hint the change in >> latency_nice of the task on every sched_setattr syscall. >> >> Signed-off-by: Parth Shah <parth@linux.ibm.com> >> Reviewed-by: Qais Yousef <qais.yousef@arm.com> > > [...] > > ndif /* _UAPI_LINUX_SCHED_TYPES_H */ >> diff --git a/kernel/sched/core.c b/kernel/sched/core.c >> index 866ea3d2d284..cd1fb9c8be26 100644 >> --- a/kernel/sched/core.c >> +++ b/kernel/sched/core.c >> @@ -4710,6 +4710,9 @@ static void __setscheduler_params(struct task_struct *p, >> p->rt_priority = attr->sched_priority; >> p->normal_prio = normal_prio(p); >> set_load_weight(p, true); >> + >> + if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE) >> + p->latency_nice = attr->sched_latency_nice; >> } > > How do you make sure that p->latency_nice can be set independently from > p->static_prio? > > AFAICS, util_clamp achieves this by relying on SCHED_FLAG_KEEP_PARAMS, > so completely bypassing __setscheduler_params() and using it's own > __setscheduler_uclamp(). >
Right. good catch. Use of SCHED_FLAG_LATENCY_NICE/SCHED_FLAG_ALL is must to change latency_nice value, but currently setting latency_nice value also changes static_prio.
One possible solution here is to move the above code to _setscheduler():
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6031ec58c7ae..44bcbf060718 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4731,9 +4731,6 @@ static void __setscheduler_params(struct task_struct *p, p->rt_priority = attr->sched_priority; p->normal_prio = normal_prio(p); set_load_weight(p, true); - - if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE) - p->latency_nice = attr->sched_latency_nice; }
/* Actually do priority change: must hold pi & rq lock. */ @@ -4749,6 +4746,13 @@ static void __setscheduler(struct rq *rq, struct task_struct *p,
__setscheduler_params(p, attr);
+ /* + * Change latency_nice value only when SCHED_FLAG_LATENCY_NICE or + * SCHED_FLAG_ALL sched_flag is set. + */ + if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE) + p->latency_nice = attr->sched_latency_nice; +
This should allow setting value only on above flags, also restricts setting the value when SCHED_FLAG_KEEP_PARAMS/SCHED_FLAG_KEEP_ALL is passed.
Thanks, Parth
| |