From cf4893eb9563703e691118e6ed6d4eb7cb9bbbd0 Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Fri, 23 Feb 2024 15:57:48 +0000 Subject: [PATCH] BACKPORT: sched: Add a new function to compare if two cpus have the same capacity The new helper function is needed to help blk-mq check if it needs to dispatch the softirq on another CPU to match the performance level the IO requester is running at. This is important on HMP systems where not all CPUs have the same compute capacity. Bug: 341551538 Signed-off-by: Qais Yousef Reviewed-by: Bart Van Assche Link: https://lore.kernel.org/r/20240223155749.2958009-2-qyousef@layalina.io Signed-off-by: Jens Axboe (cherry picked from commit b361c9027b4e4159e7bcca4eb64fd26507c19994) [Trivial clash due to some code shuffling between versions] Signed-off-by: Qais Yousef (cherry picked from https://android-review.googlesource.com/q/commit:ee8168e00c6e4fb04bea953bacb61ff017a39f63) Merged-In: I58f3f3e3560f4800b5c73b3c85bbfdf628e9764e Change-Id: I58f3f3e3560f4800b5c73b3c85bbfdf628e9764e --- include/linux/sched/topology.h | 6 ++++++ kernel/sched/core.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index d51e2645bc47..f5e5e045ed72 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -186,6 +186,7 @@ extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], cpumask_var_t *alloc_sched_domains(unsigned int ndoms); void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms); +bool cpus_equal_capacity(int this_cpu, int that_cpu); bool cpus_share_cache(int this_cpu, int that_cpu); typedef const struct cpumask *(*sched_domain_mask_f)(int cpu); @@ -235,6 +236,11 @@ partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], { } +static inline bool cpus_equal_capacity(int this_cpu, int that_cpu) +{ + return true; +} + static inline bool cpus_share_cache(int this_cpu, int that_cpu) { return true; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1e5dc0964c7b..6f1d576c28bd 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3959,6 +3959,17 @@ out: } EXPORT_SYMBOL_GPL(wake_up_if_idle); +bool cpus_equal_capacity(int this_cpu, int that_cpu) +{ + if (!sched_asym_cpucap_active()) + return true; + + if (this_cpu == that_cpu) + return true; + + return arch_scale_cpu_capacity(this_cpu) == arch_scale_cpu_capacity(that_cpu); +} + bool cpus_share_cache(int this_cpu, int that_cpu) { if (this_cpu == that_cpu)