* [PATCH] irq/matrix: simplify CPU selection logic
@ 2026-01-21 3:05 Zhan Xusheng
2026-01-26 8:03 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Zhan Xusheng @ 2026-01-21 3:05 UTC (permalink / raw)
To: linux-kernel; +Cc: mingo, tglx, Zhan Xusheng
The functions matrix_find_best_cpu() and matrix_find_best_cpu_managed()
were refactored to simplify the CPU selection logic and improve
readability.
- In matrix_find_best_cpu(), the selection logic was clarified by ensuring
that the `best_cpu` is only updated when a CPU has more available IRQ
vectors than the previously selected CPU.
- In matrix_find_best_cpu_managed(), the logic was modified to select the
CPU with the fewest `managed_allocated` IRQ vectors, ensuring that the
`best_cpu` is only updated when a CPU has a strictly fewer number of
allocated vectors. Previously, the `best_cpu` was updated even when the
`managed_allocated` values were equal, which was unnecessary and
inconsistent.
This change improves code clarity and ensures that CPU selection is more
predictable, especially in high-load or resource-constrained scenarios.
Impact:
- The change improves the readability of both functions and makes the CPU
selection behavior more explicit and predictable.
- There is no functional change under normal operating conditions. The
behavior change only affects scenarios where the `managed_allocated`
value is equal between CPUs, which is rare and would have previously led
to unnecessary updates to `best_cpu`.
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..ed4b1e44dc1e 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-26 8:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21 3:05 [PATCH] irq/matrix: simplify CPU selection logic Zhan Xusheng
2026-01-26 8:03 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox