sched/topology: Balance cluster static-key updates
PATCH 1/1 sched/topology: Balance cluster static-key updates
build_sched_domains() increments sched_cluster_active once per newly built partition that contains an SD_CLUSTER domain. detach_destroy_domains() instead tested the global static key before decrementing it, so destroying a cluster-less partition could drop a reference owned by another partition and disable cluster-aware scheduling while SD_CLUSTER domains remained installed.
Check the installed domains before detaching them and decrement only when the removed partition contains an SD_CLUSTER domain.
With two cluster-bearing partitions installed, removing a singleton partition left the baseline count at 1 where 2 partitions still carried SD_CLUSTER; the fixed kernel correctly reports 2. On an asymmetric cluster topology where the parent partition gains no cluster domain, the baseline count drops to 0 while a cluster partition remains installed; the fixed kernel keeps it at 1.
--- kernel/sched/topology.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
kernel/sched/topology.c +11 -1
@@ -3314,12 +3314,22 @@ int __init sched_init_domains(const struct cpumask *cpu_map)static void detach_destroy_domains (const struct cpumask *cpu_map) {unsigned int cpu =cpumask_any (cpu_map); +bool has_cluster = false;int i;if (rcu_access_pointer (per_cpu (sd_asym_cpucapacity, cpu)))static_branch_dec_cpuslocked (&sched_asym_cpucapacity); -if (static_branch_unlikely (&sched_cluster_active)) +rcu_read_lock (); +for_each_cpu (i, cpu_map) { +if (lowest_flag_domain (i,SD_CLUSTER )) { + has_cluster = true; +break ; + } + } +rcu_read_unlock (); + +if (has_cluster)static_branch_dec_cpuslocked (&sched_cluster_active);rcu_read_lock ();
Signature · 1 line
2.55.0
Hello Hui,
Quoted 13 lines · Hui Su
kernel/sched/topology.c +1
-0@@ -3314,12 +3314,22 @@ int __init sched_init_domains(const struct cpumask *cpu_map)static void detach_destroy_domains (const struct cpumask *cpu_map) {unsigned int cpu =cpumask_any (cpu_map); +bool has_cluster = false;int i;if (rcu_access_pointer (per_cpu (sd_asym_cpucapacity, cpu)))static_branch_dec_cpuslocked (&sched_asym_cpucapacity);
kernel/sched/topology.c int __init sched_init_domains(const struct cpumask *cpu_map) · line 3330
Quoted 10 lines
kernel/sched/topology.c +8
-1-if (static_branch_unlikely (&sched_cluster_active)) +rcu_read_lock (); +for_each_cpu (i, cpu_map) { +if (lowest_flag_domain (i,SD_CLUSTER )) { + has_cluster = true; +break ; + } + } +rcu_read_unlock ();
nit.
This should be done only when sched_cluster_active is enabled to avoid the extra loop on systems that don't have any cluster domain.
Apart from that, feel free to include:
Quoted 5 lines
kernel/sched/topology.c +2
-0+ +if (has_cluster)static_branch_dec_cpuslocked (&sched_cluster_active);rcu_read_lock ();
Signature · 2 lines
Thanks and Regards, Prateek
Quoted 4 lines
nit.
This should be done only when
sched_cluster_activeis enabled to avoid the extra loop on systems that don't have any cluster domain.
Agreed. v2 guards the SD_CLUSTER scan with static_branch_unlikely(&sched_cluster_active), so systems without cluster domains skip the loop entirely.
Thanks for the review!
Hui