[PATCH v2 7/7] sched/fair: Use full weight to __calc_delta()

Peter Zijlstra posted 7 patches 1 month, 1 week ago
[PATCH v2 7/7] sched/fair: Use full weight to __calc_delta()
Posted by Peter Zijlstra 1 month, 1 week ago
Since we now use the full weight for avg_vruntime(), also make
__calc_delta() use the full value.

Since weight is effectively NICE_0_LOAD, this is 20 bits on 64bit.
This leaves 44 bits for delta_exec, which is ~16k seconds, way longer
than any one tick would ever be, so no worry about overflow.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: Shubhang Kaushik <shubhang@os.amperecomputing.com>
---
 kernel/sched/fair.c |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -225,6 +225,7 @@ void __init sched_init_granularity(void)
 	update_sysctl();
 }
 
+#ifndef CONFIG_64BIT
 #define WMULT_CONST	(~0U)
 #define WMULT_SHIFT	32
 
@@ -283,6 +284,12 @@ static u64 __calc_delta(u64 delta_exec,
 
 	return mul_u64_u32_shr(delta_exec, fact, shift);
 }
+#else
+static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight *lw)
+{
+	return (delta_exec * weight) / lw->weight;
+}
+#endif
 
 /*
  * delta /= w
Re: [PATCH v2 7/7] sched/fair: Use full weight to __calc_delta()
Posted by Vincent Guittot 1 month, 1 week ago
On Thu, 19 Feb 2026 at 09:10, Peter Zijlstra <peterz@infradead.org> wrote:
>
> Since we now use the full weight for avg_vruntime(), also make
> __calc_delta() use the full value.
>
> Since weight is effectively NICE_0_LOAD, this is 20 bits on 64bit.
> This leaves 44 bits for delta_exec, which is ~16k seconds, way longer
> than any one tick would ever be, so no worry about overflow.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Tested-by: Shubhang Kaushik <shubhang@os.amperecomputing.com>

Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>


> ---
>  kernel/sched/fair.c |    7 +++++++
>  1 file changed, 7 insertions(+)
>
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -225,6 +225,7 @@ void __init sched_init_granularity(void)
>         update_sysctl();
>  }
>
> +#ifndef CONFIG_64BIT
>  #define WMULT_CONST    (~0U)
>  #define WMULT_SHIFT    32
>
> @@ -283,6 +284,12 @@ static u64 __calc_delta(u64 delta_exec,
>
>         return mul_u64_u32_shr(delta_exec, fact, shift);
>  }
> +#else
> +static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight *lw)
> +{
> +       return (delta_exec * weight) / lw->weight;
> +}
> +#endif
>
>  /*
>   * delta /= w
>
>