[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260127024134.6872-1-zhanxusheng@xiaomi.com>
Date: Tue, 27 Jan 2026 10:41:34 +0800
From: Zhan Xusheng <zhanxusheng1024@...il.com>
To: tglx@...nel.org
Cc: linux-kernel@...r.kernel.org,
mingo@...nel.org,
zhanxusheng1024@...il.com,
zhanxusheng@...omi.com
Subject: [PATCH v2] genirq/matrix: Clarify CPU selection logic
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@...omi.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
Powered by blists - more mailing lists