Re: [PATCH 4/4] sched/fair: Proportional newidle balance

Adam Li
2025-11-11T09:07:55Z

On 11/8/2025 12:06 AM, Peter Zijlstra wrote:
> Add a randomized algorithm that runs newidle balancing proportional to
> its success rate.
>
> This improves schbench significantly:
>
> 6.18-rc4: 2.22 Mrps/s
> 6.18-rc4+revert: 2.04 Mrps/s
> 6.18-rc4+revert+random: 2.18 Mrps/S
>
> Conversely, per Adam Li this affects SpecJBB slightly, reducing it by 1%:
>
> 6.17: -6%
> 6.17+revert: 0%
> 6.17+revert+random: -1%
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Tested-by: Adam Li <adamli@os.amperecomputing.com>

Please see the Specjbb test result on AmpereOne server bellow:
6.18-rc5: 0% (baseline)
6.18-rc5+patchset: +5%
6.18-rc4+patchset+NO_NI_RANDOM: +6%
6.18-rc5+revert-155213a2aed4: +6%

Could you please explain a little the math behind success rate
(sd->newidle_ratio) calculation?

[...]
> @@ -12843,6 +12858,22 @@ static int sched_balance_newidle(struct
> break;
>
> if (sd->flags & SD_BALANCE_NEWIDLE) {
> + unsigned int weight = 1;
> +
> + if (sched_feat(NI_RANDOM)) {
> + /*
> + * Throw a 1k sided dice; and only run
> + * newidle_balance according to the success
> + * rate.
> + */
> + u32 d1k = sched_rng() % 1024;
> + weight = 1 + sd->newidle_ratio;
> + if (d1k > weight) {
> + update_newidle_stats(sd, 0);
> + continue;
> + }
> + weight = (1024 + weight/2) / weight;
> + }
>
e.g: Why 'weight = (1024 + weight/2) / weight'

Thanks,
-adam