@@ -6619,6 +6619,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
6619
6619
/* Working cpumask for: load_balance, load_balance_newidle. */
6620
6620
static DEFINE_PER_CPU (cpumask_var_t , load_balance_mask ) ;
6621
6621
static DEFINE_PER_CPU (cpumask_var_t , select_rq_mask ) ;
6622
+ static DEFINE_PER_CPU (cpumask_var_t , should_we_balance_tmpmask ) ;
6622
6623
6623
6624
#ifdef CONFIG_NO_HZ_COMMON
6624
6625
@@ -9579,7 +9580,7 @@ static inline long sibling_imbalance(struct lb_env *env,
9579
9580
imbalance /= ncores_local + ncores_busiest ;
9580
9581
9581
9582
/* Take advantage of resource in an empty sched group */
9582
- if (imbalance == 0 && local -> sum_nr_running == 0 &&
9583
+ if (imbalance <= 1 && local -> sum_nr_running == 0 &&
9583
9584
busiest -> sum_nr_running > 1 )
9584
9585
imbalance = 2 ;
9585
9586
@@ -9767,6 +9768,15 @@ static bool update_sd_pick_busiest(struct lb_env *env,
9767
9768
break ;
9768
9769
9769
9770
case group_smt_balance :
9771
+ /*
9772
+ * Check if we have spare CPUs on either SMT group to
9773
+ * choose has spare or fully busy handling.
9774
+ */
9775
+ if (sgs -> idle_cpus != 0 || busiest -> idle_cpus != 0 )
9776
+ goto has_spare ;
9777
+
9778
+ fallthrough ;
9779
+
9770
9780
case group_fully_busy :
9771
9781
/*
9772
9782
* Select the fully busy group with highest avg_load. In
@@ -9806,6 +9816,7 @@ static bool update_sd_pick_busiest(struct lb_env *env,
9806
9816
else
9807
9817
return true;
9808
9818
}
9819
+ has_spare :
9809
9820
9810
9821
/*
9811
9822
* Select not overloaded group with lowest number of idle cpus
@@ -10917,6 +10928,7 @@ static int active_load_balance_cpu_stop(void *data);
10917
10928
10918
10929
static int should_we_balance (struct lb_env * env )
10919
10930
{
10931
+ struct cpumask * swb_cpus = this_cpu_cpumask_var_ptr (should_we_balance_tmpmask );
10920
10932
struct sched_group * sg = env -> sd -> groups ;
10921
10933
int cpu , idle_smt = -1 ;
10922
10934
@@ -10940,8 +10952,9 @@ static int should_we_balance(struct lb_env *env)
10940
10952
return 1 ;
10941
10953
}
10942
10954
10955
+ cpumask_copy (swb_cpus , group_balance_mask (sg ));
10943
10956
/* Try to find first idle CPU */
10944
- for_each_cpu_and (cpu , group_balance_mask ( sg ) , env -> cpus ) {
10957
+ for_each_cpu_and (cpu , swb_cpus , env -> cpus ) {
10945
10958
if (!idle_cpu (cpu ))
10946
10959
continue ;
10947
10960
@@ -10953,6 +10966,14 @@ static int should_we_balance(struct lb_env *env)
10953
10966
if (!(env -> sd -> flags & SD_SHARE_CPUCAPACITY ) && !is_core_idle (cpu )) {
10954
10967
if (idle_smt == -1 )
10955
10968
idle_smt = cpu ;
10969
+ /*
10970
+ * If the core is not idle, and first SMT sibling which is
10971
+ * idle has been found, then its not needed to check other
10972
+ * SMT siblings for idleness:
10973
+ */
10974
+ #ifdef CONFIG_SCHED_SMT
10975
+ cpumask_andnot (swb_cpus , swb_cpus , cpu_smt_mask (cpu ));
10976
+ #endif
10956
10977
continue ;
10957
10978
}
10958
10979
@@ -12918,6 +12939,8 @@ __init void init_sched_fair_class(void)
12918
12939
for_each_possible_cpu (i ) {
12919
12940
zalloc_cpumask_var_node (& per_cpu (load_balance_mask , i ), GFP_KERNEL , cpu_to_node (i ));
12920
12941
zalloc_cpumask_var_node (& per_cpu (select_rq_mask , i ), GFP_KERNEL , cpu_to_node (i ));
12942
+ zalloc_cpumask_var_node (& per_cpu (should_we_balance_tmpmask , i ),
12943
+ GFP_KERNEL , cpu_to_node (i ));
12921
12944
12922
12945
#ifdef CONFIG_CFS_BANDWIDTH
12923
12946
INIT_CSD (& cpu_rq (i )-> cfsb_csd , __cfsb_csd_unthrottle , cpu_rq (i ));
0 commit comments