@@ -4561,8 +4561,8 @@ static inline int util_fits_cpu(unsigned long util,
4561
4561
* handle the case uclamp_min > uclamp_max.
4562
4562
*/
4563
4563
uclamp_min = min (uclamp_min , uclamp_max );
4564
- if (util < uclamp_min && capacity_orig != SCHED_CAPACITY_SCALE )
4565
- fits = fits && ( uclamp_min <= capacity_orig_thermal ) ;
4564
+ if (fits && ( util < uclamp_min ) && ( uclamp_min > capacity_orig_thermal ) )
4565
+ return -1 ;
4566
4566
4567
4567
return fits ;
4568
4568
}
@@ -4572,7 +4572,11 @@ static inline int task_fits_cpu(struct task_struct *p, int cpu)
4572
4572
unsigned long uclamp_min = uclamp_eff_value (p , UCLAMP_MIN );
4573
4573
unsigned long uclamp_max = uclamp_eff_value (p , UCLAMP_MAX );
4574
4574
unsigned long util = task_util_est (p );
4575
- return util_fits_cpu (util , uclamp_min , uclamp_max , cpu );
4575
+ /*
4576
+ * Return true only if the cpu fully fits the task requirements, which
4577
+ * include the utilization but also the performance hints.
4578
+ */
4579
+ return (util_fits_cpu (util , uclamp_min , uclamp_max , cpu ) > 0 );
4576
4580
}
4577
4581
4578
4582
static inline void update_misfit_status (struct task_struct * p , struct rq * rq )
@@ -6138,6 +6142,7 @@ static inline bool cpu_overutilized(int cpu)
6138
6142
unsigned long rq_util_min = uclamp_rq_get (cpu_rq (cpu ), UCLAMP_MIN );
6139
6143
unsigned long rq_util_max = uclamp_rq_get (cpu_rq (cpu ), UCLAMP_MAX );
6140
6144
6145
+ /* Return true only if the utilization doesn't fit CPU's capacity */
6141
6146
return !util_fits_cpu (cpu_util_cfs (cpu ), rq_util_min , rq_util_max , cpu );
6142
6147
}
6143
6148
@@ -6931,6 +6936,7 @@ static int
6931
6936
select_idle_capacity (struct task_struct * p , struct sched_domain * sd , int target )
6932
6937
{
6933
6938
unsigned long task_util , util_min , util_max , best_cap = 0 ;
6939
+ int fits , best_fits = 0 ;
6934
6940
int cpu , best_cpu = -1 ;
6935
6941
struct cpumask * cpus ;
6936
6942
@@ -6946,12 +6952,28 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
6946
6952
6947
6953
if (!available_idle_cpu (cpu ) && !sched_idle_cpu (cpu ))
6948
6954
continue ;
6949
- if (util_fits_cpu (task_util , util_min , util_max , cpu ))
6955
+
6956
+ fits = util_fits_cpu (task_util , util_min , util_max , cpu );
6957
+
6958
+ /* This CPU fits with all requirements */
6959
+ if (fits > 0 )
6950
6960
return cpu ;
6961
+ /*
6962
+ * Only the min performance hint (i.e. uclamp_min) doesn't fit.
6963
+ * Look for the CPU with best capacity.
6964
+ */
6965
+ else if (fits < 0 )
6966
+ cpu_cap = capacity_orig_of (cpu ) - thermal_load_avg (cpu_rq (cpu ));
6951
6967
6952
- if (cpu_cap > best_cap ) {
6968
+ /*
6969
+ * First, select CPU which fits better (-1 being better than 0).
6970
+ * Then, select the one with best capacity at same level.
6971
+ */
6972
+ if ((fits < best_fits ) ||
6973
+ ((fits == best_fits ) && (cpu_cap > best_cap ))) {
6953
6974
best_cap = cpu_cap ;
6954
6975
best_cpu = cpu ;
6976
+ best_fits = fits ;
6955
6977
}
6956
6978
}
6957
6979
@@ -6964,7 +6986,11 @@ static inline bool asym_fits_cpu(unsigned long util,
6964
6986
int cpu )
6965
6987
{
6966
6988
if (sched_asym_cpucap_active ())
6967
- return util_fits_cpu (util , util_min , util_max , cpu );
6989
+ /*
6990
+ * Return true only if the cpu fully fits the task requirements
6991
+ * which include the utilization and the performance hints.
6992
+ */
6993
+ return (util_fits_cpu (util , util_min , util_max , cpu ) > 0 );
6968
6994
6969
6995
return true;
6970
6996
}
@@ -7331,6 +7357,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
7331
7357
unsigned long p_util_max = uclamp_is_used () ? uclamp_eff_value (p , UCLAMP_MAX ) : 1024 ;
7332
7358
struct root_domain * rd = this_rq ()-> rd ;
7333
7359
int cpu , best_energy_cpu , target = -1 ;
7360
+ int prev_fits = -1 , best_fits = -1 ;
7361
+ unsigned long best_thermal_cap = 0 ;
7362
+ unsigned long prev_thermal_cap = 0 ;
7334
7363
struct sched_domain * sd ;
7335
7364
struct perf_domain * pd ;
7336
7365
struct energy_env eenv ;
@@ -7366,6 +7395,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
7366
7395
unsigned long prev_spare_cap = 0 ;
7367
7396
int max_spare_cap_cpu = -1 ;
7368
7397
unsigned long base_energy ;
7398
+ int fits , max_fits = -1 ;
7369
7399
7370
7400
cpumask_and (cpus , perf_domain_span (pd ), cpu_online_mask );
7371
7401
@@ -7415,22 +7445,27 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
7415
7445
util_min = max (rq_util_min , p_util_min );
7416
7446
util_max = max (rq_util_max , p_util_max );
7417
7447
}
7418
- if (!util_fits_cpu (util , util_min , util_max , cpu ))
7448
+
7449
+ fits = util_fits_cpu (util , util_min , util_max , cpu );
7450
+ if (!fits )
7419
7451
continue ;
7420
7452
7421
7453
lsub_positive (& cpu_cap , util );
7422
7454
7423
7455
if (cpu == prev_cpu ) {
7424
7456
/* Always use prev_cpu as a candidate. */
7425
7457
prev_spare_cap = cpu_cap ;
7426
- } else if (cpu_cap > max_spare_cap ) {
7458
+ prev_fits = fits ;
7459
+ } else if ((fits > max_fits ) ||
7460
+ ((fits == max_fits ) && (cpu_cap > max_spare_cap ))) {
7427
7461
/*
7428
7462
* Find the CPU with the maximum spare capacity
7429
7463
* among the remaining CPUs in the performance
7430
7464
* domain.
7431
7465
*/
7432
7466
max_spare_cap = cpu_cap ;
7433
7467
max_spare_cap_cpu = cpu ;
7468
+ max_fits = fits ;
7434
7469
}
7435
7470
}
7436
7471
@@ -7449,26 +7484,50 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
7449
7484
if (prev_delta < base_energy )
7450
7485
goto unlock ;
7451
7486
prev_delta -= base_energy ;
7487
+ prev_thermal_cap = cpu_thermal_cap ;
7452
7488
best_delta = min (best_delta , prev_delta );
7453
7489
}
7454
7490
7455
7491
/* Evaluate the energy impact of using max_spare_cap_cpu. */
7456
7492
if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap ) {
7493
+ /* Current best energy cpu fits better */
7494
+ if (max_fits < best_fits )
7495
+ continue ;
7496
+
7497
+ /*
7498
+ * Both don't fit performance hint (i.e. uclamp_min)
7499
+ * but best energy cpu has better capacity.
7500
+ */
7501
+ if ((max_fits < 0 ) &&
7502
+ (cpu_thermal_cap <= best_thermal_cap ))
7503
+ continue ;
7504
+
7457
7505
cur_delta = compute_energy (& eenv , pd , cpus , p ,
7458
7506
max_spare_cap_cpu );
7459
7507
/* CPU utilization has changed */
7460
7508
if (cur_delta < base_energy )
7461
7509
goto unlock ;
7462
7510
cur_delta -= base_energy ;
7463
- if (cur_delta < best_delta ) {
7464
- best_delta = cur_delta ;
7465
- best_energy_cpu = max_spare_cap_cpu ;
7466
- }
7511
+
7512
+ /*
7513
+ * Both fit for the task but best energy cpu has lower
7514
+ * energy impact.
7515
+ */
7516
+ if ((max_fits > 0 ) && (best_fits > 0 ) &&
7517
+ (cur_delta >= best_delta ))
7518
+ continue ;
7519
+
7520
+ best_delta = cur_delta ;
7521
+ best_energy_cpu = max_spare_cap_cpu ;
7522
+ best_fits = max_fits ;
7523
+ best_thermal_cap = cpu_thermal_cap ;
7467
7524
}
7468
7525
}
7469
7526
rcu_read_unlock ();
7470
7527
7471
- if (best_delta < prev_delta )
7528
+ if ((best_fits > prev_fits ) ||
7529
+ ((best_fits > 0 ) && (best_delta < prev_delta )) ||
7530
+ ((best_fits < 0 ) && (best_thermal_cap > prev_thermal_cap )))
7472
7531
target = best_energy_cpu ;
7473
7532
7474
7533
return target ;
@@ -10271,24 +10330,23 @@ static struct sched_group *find_busiest_group(struct lb_env *env)
10271
10330
*/
10272
10331
update_sd_lb_stats (env , & sds );
10273
10332
10274
- if (sched_energy_enabled ()) {
10275
- struct root_domain * rd = env -> dst_rq -> rd ;
10276
-
10277
- if (rcu_dereference (rd -> pd ) && !READ_ONCE (rd -> overutilized ))
10278
- goto out_balanced ;
10279
- }
10280
-
10281
- local = & sds .local_stat ;
10282
- busiest = & sds .busiest_stat ;
10283
-
10284
10333
/* There is no busy sibling group to pull tasks from */
10285
10334
if (!sds .busiest )
10286
10335
goto out_balanced ;
10287
10336
10337
+ busiest = & sds .busiest_stat ;
10338
+
10288
10339
/* Misfit tasks should be dealt with regardless of the avg load */
10289
10340
if (busiest -> group_type == group_misfit_task )
10290
10341
goto force_balance ;
10291
10342
10343
+ if (sched_energy_enabled ()) {
10344
+ struct root_domain * rd = env -> dst_rq -> rd ;
10345
+
10346
+ if (rcu_dereference (rd -> pd ) && !READ_ONCE (rd -> overutilized ))
10347
+ goto out_balanced ;
10348
+ }
10349
+
10292
10350
/* ASYM feature bypasses nice load balance check */
10293
10351
if (busiest -> group_type == group_asym_packing )
10294
10352
goto force_balance ;
@@ -10301,6 +10359,7 @@ static struct sched_group *find_busiest_group(struct lb_env *env)
10301
10359
if (busiest -> group_type == group_imbalanced )
10302
10360
goto force_balance ;
10303
10361
10362
+ local = & sds .local_stat ;
10304
10363
/*
10305
10364
* If the local group is busier than the selected busiest group
10306
10365
* don't try and pull any tasks.
0 commit comments