mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org, linux-irq@vger.kernel.org,
	Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: [PATCH v3 1/2] genirq/matrix: Clarify CPU selection logic
Date: Wed, 28 Jan 2026 11:14:05 +0800	[thread overview]
Message-ID: <20260128031406.9473-2-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260128031406.9473-1-zhanxusheng@xiaomi.com>

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


  reply	other threads:[~2026-01-28  3:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  2:41 [PATCH v2] " 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     ` Zhan Xusheng [this message]
2026-01-28 11:11       ` [PATCH v3 1/2] genirq/matrix: Clarify CPU selection logic 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260128031406.9473-2-zhanxusheng@xiaomi.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=linux-irq@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=zhanxusheng@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®