The CPU selection loops in matrix_find_best_cpu() and
matrix_find_best_cpu_managed() mix the online check with the
comparison that determines whether a CPU becomes the current
best candidate.
Restructure the loops to filter out offline CPUs first and then
perform the comparison separately. This makes the selection
criteria easier to read and reason about.
No functional change intended.
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
kernel/irq/matrix.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
index a50f2305a8dc..c363e918087c 100644
--- a/kernel/irq/matrix.c
+++ b/kernel/irq/matrix.c
@@ -140,14 +140,17 @@ static unsigned int matrix_find_best_cpu(struct irq_matrix *m,
best_cpu = UINT_MAX;
+ /* Select the online CPU with the most available vectors */
for_each_cpu(cpu, msk) {
cm = per_cpu_ptr(m->maps, cpu);
- if (!cm->online || cm->available <= maxavl)
+ if (!cm->online)
continue;
- best_cpu = cpu;
- maxavl = cm->available;
+ if (cm->available > maxavl) {
+ best_cpu = cpu;
+ maxavl = cm->available;
+ }
}
return best_cpu;
}
@@ -161,14 +164,17 @@ static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m,
best_cpu = UINT_MAX;
+ /* Select the online CPU with the fewest managed allocated vectors */
for_each_cpu(cpu, msk) {
cm = per_cpu_ptr(m->maps, cpu);
- if (!cm->online || cm->managed_allocated > allocated)
+ if (!cm->online)
continue;
- best_cpu = cpu;
- allocated = cm->managed_allocated;
+ if (cm->managed_allocated <= allocated) {
+ best_cpu = cpu;
+ allocated = cm->managed_allocated;
+ }
}
return best_cpu;
}
--
2.43.0
On Wed, Jan 28 2026 at 11:14, Zhan Xusheng wrote:
> The CPU selection loops in matrix_find_best_cpu() and
> matrix_find_best_cpu_managed() mix the online check with the
> comparison that determines whether a CPU becomes the current
> best candidate.
What's wrong about that?
> Restructure the loops to filter out offline CPUs first and then
> perform the comparison separately. This makes the selection
> criteria easier to read and reason about.
It's just different and not any better. We are not reshuffling perfectly
correct code just to accomodate with personal taste of someone.
Thanks,
tglx
© 2016 - 2026 Red Hat, Inc.