Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched/fair: Do not even the number of busy CPUs via asym_packing

Now that find_busiest_group() triggers load balancing between a fully_
busy SMT2 core and an idle non-SMT core, it is no longer needed to force
balancing via asym_packing. Use asym_packing only as intended: when there
is high-priority CPU that is idle.

After this change, the same logic apply to SMT and non-SMT local groups.
It makes less sense having a separate function to deal specifically with
SMT. Fold the logic in asym_smt_can_pull_tasks() into sched_asym().

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Link: https://lore.kernel.org/r/20230406203148.19182-8-ricardo.neri-calderon@linux.intel.com

authored by

Ricardo Neri and committed by
Peter Zijlstra
c9ca0788 43726bde

+21 -65
+21 -65
kernel/sched/fair.c
··· 9350 9350 } 9351 9351 9352 9352 /** 9353 - * asym_smt_can_pull_tasks - Check whether the load balancing CPU can pull tasks 9354 - * @dst_cpu: Destination CPU of the load balancing 9353 + * sched_asym - Check if the destination CPU can do asym_packing load balance 9354 + * @env: The load balancing environment 9355 9355 * @sds: Load-balancing data with statistics of the local group 9356 9356 * @sgs: Load-balancing statistics of the candidate busiest group 9357 - * @sg: The candidate busiest group 9357 + * @group: The candidate busiest group 9358 9358 * 9359 - * Check the state of the SMT siblings of both @sds::local and @sg and decide 9360 - * if @dst_cpu can pull tasks. 9359 + * @env::dst_cpu can do asym_packing if it has higher priority than the 9360 + * preferred CPU of @group. 9361 9361 * 9362 - * This function must be called only if all the SMT siblings of @dst_cpu are 9363 - * idle, if any. 9362 + * SMT is a special case. If we are balancing load between cores, @env::dst_cpu 9363 + * can do asym_packing balance only if all its SMT siblings are idle. Also, it 9364 + * can only do it if @group is an SMT group and has exactly on busy CPU. Larger 9365 + * imbalances in the number of CPUS are dealt with in find_busiest_group(). 9364 9366 * 9365 - * If @dst_cpu does not have SMT siblings, it can pull tasks if two or more of 9366 - * the SMT siblings of @sg are busy. If only one CPU in @sg is busy, pull tasks 9367 - * only if @dst_cpu has higher priority. 9367 + * If we are balancing load within an SMT core, or at DIE domain level, always 9368 + * proceed. 9368 9369 * 9369 - * When dealing with SMT cores, only use priorities if the SMT core has exactly 9370 - * one busy sibling. find_busiest_group() will handle bigger imbalances in the 9371 - * number of busy CPUs. 9372 - * 9373 - * Return: true if @dst_cpu can pull tasks, false otherwise. 9370 + * Return: true if @env::dst_cpu can do with asym_packing load balance. False 9371 + * otherwise. 9374 9372 */ 9375 - static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds, 9376 - struct sg_lb_stats *sgs, 9377 - struct sched_group *sg) 9378 - { 9379 - #ifdef CONFIG_SCHED_SMT 9380 - bool local_is_smt; 9381 - int sg_busy_cpus; 9382 - 9383 - local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY; 9384 - sg_busy_cpus = sgs->group_weight - sgs->idle_cpus; 9385 - 9386 - if (!local_is_smt) { 9387 - /* 9388 - * If we are here, @dst_cpu is idle and does not have SMT 9389 - * siblings. Pull tasks if candidate group has two or more 9390 - * busy CPUs. 9391 - */ 9392 - if (sg_busy_cpus >= 2) /* implies sg_is_smt */ 9393 - return true; 9394 - 9395 - /* 9396 - * @dst_cpu does not have SMT siblings. @sg may have SMT 9397 - * siblings and only one is busy. In such case, @dst_cpu 9398 - * can help if it has higher priority and is idle (i.e., 9399 - * it has no running tasks). 9400 - */ 9401 - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu); 9402 - } 9403 - 9404 - /* 9405 - * If we are here @dst_cpu has SMT siblings and are also idle. 9406 - * 9407 - * CPU priorities does not make sense for SMT cores with more than one 9408 - * busy sibling. 9409 - */ 9410 - if (group->flags & SD_SHARE_CPUCAPACITY && sg_busy_cpus != 1) 9411 - return false; 9412 - 9413 - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu); 9414 - 9415 - #else 9416 - /* Always return false so that callers deal with non-SMT cases. */ 9417 - return false; 9418 - #endif 9419 - } 9420 - 9421 9373 static inline bool 9422 9374 sched_asym(struct lb_env *env, struct sd_lb_stats *sds, struct sg_lb_stats *sgs, 9423 9375 struct sched_group *group) ··· 9378 9426 if (!sched_use_asym_prio(env->sd, env->dst_cpu)) 9379 9427 return false; 9380 9428 9381 - /* Only do SMT checks if either local or candidate have SMT siblings. */ 9382 - if ((sds->local->flags & SD_SHARE_CPUCAPACITY) || 9383 - (group->flags & SD_SHARE_CPUCAPACITY)) 9384 - return asym_smt_can_pull_tasks(env->dst_cpu, sds, sgs, group); 9429 + /* 9430 + * CPU priorities does not make sense for SMT cores with more than one 9431 + * busy sibling. 9432 + */ 9433 + if (group->flags & SD_SHARE_CPUCAPACITY) { 9434 + if (sgs->group_weight - sgs->idle_cpus != 1) 9435 + return false; 9436 + } 9385 9437 9386 9438 return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu); 9387 9439 }