Skip to content

Commit 917d468

Browse files
Yicong Yangopsiff
authored andcommitted
sched/fair: Use candidate prev/recent_used CPU if scanning failed for cluster wakeup
ANBZ: #8001 commit 22165f6 upstream. Chen Yu reports a hackbench regression of cluster wakeup when hackbench threads equal to the CPU number [1]. Analysis shows it's because we wake up more on the target CPU even if the prev_cpu is a good wakeup candidate and leads to the decrease of the CPU utilization. Generally if the task's prev_cpu is idle we'll wake up the task on it without scanning. On cluster machines we'll try to wake up the task in the same cluster of the target for better cache affinity, so if the prev_cpu is idle but not sharing the same cluster with the target we'll still try to find an idle CPU within the cluster. This will improve the performance at low loads on cluster machines. But in the issue above, if the prev_cpu is idle but not in the cluster with the target CPU, we'll try to scan an idle one in the cluster. But since the system is busy, we're likely to fail the scanning and use target instead, even if the prev_cpu is idle. Then leads to the regression. This patch solves this in 2 steps: o record the prev_cpu/recent_used_cpu if they're good wakeup candidates but not sharing the cluster with the target. o on scanning failure use the prev_cpu/recent_used_cpu if they're recorded as idle [1] https://lore.kernel.org/all/ZGzDLuVaHR1PAYDt@chenyu5-mobl1/ Intel-SIG: commit 22165f6 Use candidate prev/recent_used CPU if scanning failed for cluster wakeup. Cluster based task wakeup optimization backport Closes: https://lore.kernel.org/all/ZGsLy83wPIpamy6x@chenyu5-mobl1/ Reported-by: Chen Yu <yu.c.chen@intel.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Tested-and-reviewed-by: Chen Yu <yu.c.chen@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lkml.kernel.org/r/20231019033323.54147-4-yangyicong@huawei.com [ Aubrey Li: amend commit log ] Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
1 parent 661225b commit 917d468

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

kernel/sched/fair.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7570,7 +7570,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
75707570
bool has_idle_core = false;
75717571
struct sched_domain *sd;
75727572
unsigned long task_util, util_min, util_max;
7573-
int i, recent_used_cpu;
7573+
int i, recent_used_cpu, prev_aff = -1;
75747574

75757575
/*
75767576
* On asymmetric system, update task utilization because we will check
@@ -7602,6 +7602,8 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
76027602
if (!static_branch_unlikely(&sched_cluster_active) ||
76037603
cpus_share_resources(prev, target))
76047604
return prev;
7605+
7606+
prev_aff = prev;
76057607
}
76067608

76077609
/*
@@ -7634,6 +7636,8 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
76347636
cpus_share_resources(recent_used_cpu, target))
76357637
return recent_used_cpu;
76367638

7639+
} else {
7640+
recent_used_cpu = -1;
76377641
}
76387642

76397643
/*
@@ -7674,6 +7678,17 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
76747678
if ((unsigned)i < nr_cpumask_bits)
76757679
return i;
76767680

7681+
/*
7682+
* For cluster machines which have lower sharing cache like L2 or
7683+
* LLC Tag, we tend to find an idle CPU in the target's cluster
7684+
* first. But prev_cpu or recent_used_cpu may also be a good candidate,
7685+
* use them if possible when no idle CPU found in select_idle_cpu().
7686+
*/
7687+
if ((unsigned int)prev_aff < nr_cpumask_bits)
7688+
return prev_aff;
7689+
if ((unsigned int)recent_used_cpu < nr_cpumask_bits)
7690+
return recent_used_cpu;
7691+
76777692
return target;
76787693
}
76797694

0 commit comments

Comments
 (0)