public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] genirq/matrix: Clarify CPU selection logic
@ 2026-01-27  2:41 Zhan Xusheng
  2026-01-27  8:37 ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Zhan Xusheng @ 2026-01-27  2:41 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel, mingo, zhanxusheng1024, zhanxusheng

The CPU selection logic in matrix_find_best_cpu() and
matrix_find_best_cpu_managed() mixes eligibility checks with update
conditions, making the actual selection criteria harder to reason
about during review.

Refactor both loops to separate the online check from the comparison
itself and make the selection rules explicit. In
matrix_find_best_cpu(), this is a pure readability change with no
behavioral impact.

In matrix_find_best_cpu_managed(), the refactoring also avoids updating
best_cpu when CPUs have identical managed_allocated counts, removing an
implicit tie-breaking behavior based on CPU iteration order.

The intended selection policy is unchanged, except that equal cases in
the managed path no longer trigger redundant best_cpu updates.

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] 7+ messages in thread

end of thread, other threads:[~2026-01-28 11:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27  2:41 [PATCH v2] genirq/matrix: Clarify CPU selection logic Zhan Xusheng
2026-01-27  8:37 ` Thomas Gleixner
2026-01-28  3:14   ` [PATCH v3 0/2] genirq/matrix: CPU selection cleanup and tie-breaking fix Zhan Xusheng
2026-01-28  3:14     ` [PATCH v3 1/2] genirq/matrix: Clarify CPU selection logic Zhan Xusheng
2026-01-28 11:11       ` Thomas Gleixner
2026-01-28  3:14     ` [PATCH v3 2/2] genirq/matrix: Avoid implicit tie-breaking by CPU iteration order Zhan Xusheng
2026-01-28 11:16       ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox