]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/fair: Fix inaccurate tally of ttwu_move_affine
authorLibo Chen <libo.chen@oracle.com>
Wed, 10 Aug 2022 22:33:13 +0000 (15:33 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 5 Apr 2023 07:58:48 +0000 (09:58 +0200)
There are scenarios where non-affine wakeups are incorrectly counted as
affine wakeups by schedstats.

When wake_affine_idle() returns prev_cpu which doesn't equal to
nr_cpumask_bits, it will slip through the check: target == nr_cpumask_bits
in wake_affine() and be counted as if target == this_cpu in schedstats.

Replace target == nr_cpumask_bits with target != this_cpu to make sure
affine wakeups are accurately tallied.

Fixes: 806486c377e33 (sched/fair: Do not migrate if the prev_cpu is idle)
Suggested-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: Libo Chen <libo.chen@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Link: https://lore.kernel.org/r/20220810223313.386614-1-libo.chen@oracle.com
kernel/sched/fair.c

index bc358dc4faeb3f164de1700598c71e1d6e951ceb..f5da01a6b35a71ff8bb46af28ce6a9dc4e6b2783 100644 (file)
@@ -6582,7 +6582,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p,
                target = wake_affine_weight(sd, p, this_cpu, prev_cpu, sync);
 
        schedstat_inc(p->stats.nr_wakeups_affine_attempts);
-       if (target == nr_cpumask_bits)
+       if (target != this_cpu)
                return prev_cpu;
 
        schedstat_inc(sd->ttwu_move_affine);