Re: [PATCH] kernel/sched/fair: Fix to not require calculation for the weight nice0

From: Hongyan Xia

Date: Fri May 29 2026 - 03:43:51 EST


On 5/29/2026 10:34 AM, Li kunyu wrote:
> Typically, the default priority for client tasks is nice0, and reducing
> the conversion of virtual runtime to real time for nice0 tasks can
> significantly reduce unnecessary computations.
>
> Signed-off-by: Li kunyu <likunyu10@xxxxxxx>
> ---
> kernel/sched/fair.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 69361c63353a..74d1c77a8bcf 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7033,7 +7033,10 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
> resched_curr(rq);
> return;
> }
> - delta = (se->load.weight * vdelta) / NICE_0_LOAD;
> + if (unlikely(se->load.weight != NICE_0_LOAD))
> + delta = (se->load.weight * vdelta) / NICE_0_LOAD;
> + else
> + delta = vdelta;
>
> /*
> * Correct for instantaneous load of other classes.

Given NICE_0_LOAD is a nice power-of-two which compiles down to just a
bit shift, it seems interesting that you would find the multiplication
to be 'significant unnecessary computations'. Do you have any data to
support this?

Also, unless my eyes are failing, it looks like you had a patch just a
couple of days ago at the exact same location

https://lore.kernel.org/all/20260527072113.359604-1-likunyu10@xxxxxxx/

in which Peter pointed out you might had a mistake. Is this somehow
connected to that one?

Hongyan