From nobody Sun Feb 8 12:20:01 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3C432D7BF for ; Tue, 27 Jan 2026 02:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769481700; cv=none; b=DNmbt4sMJwvY5RdQlFG8h5n8TnA98GSHEII7+xByjCZQFjIpl5tfPOUQKT+NeYH+LYFMHvZK+CQN8LeC74kei/1SPoAvuCIAOivZqVsK1Pz2Q5h4uQpmltP2+OqnAY5xVgkDQ2cGcdYfhMX1DJcHLNM0bV/bOanGTXA4DbIeRlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769481700; c=relaxed/simple; bh=dGMl8czo5q+91uIWARfroVvW85zoD8zPIOtyuuhz2xc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Sd07luGcYyd+i9dFLD/NLupiMGOy8Zqc5ulVA0hlI4g+hh4FkEPnWjZTb+FgTBsHNYvaYmupXkqfN5K8SUmwHjP7sDTMrUbnG4ACtBjzNLzKQzKf1uBgz79TsheIQHriLGqtkUHUPQKuwnGKXTV2ae+guzSU6p6G3S+Y8z2F734= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AvuMUp75; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AvuMUp75" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-81e8a9d521dso3069562b3a.2 for ; Mon, 26 Jan 2026 18:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769481699; x=1770086499; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hQRDcRFE/81hMk/NSCU8D/Yo2nB5doqfuZiYyByUyR4=; b=AvuMUp757lyeOF8+0915qp8Rcu6Drp+xJibGbAaHTqPdJ7w76vBWQuaLUPtg3atF9t NRzaESZsFuqu4zmugBRsTI7XzeHskH4Q8YPrK/7rcKPtj80T4J5hH1jwjL3FJzqeH2W2 SnYugEUlOPs1s+vc/wdtzTk0VeTtMsjSGVe+DyuESpyVS8Q37BstO+6codLHThd7tWS+ muSq/CHZgULDEtUfmfxFIHcadkadzcqOxkEBMpqNrwn57yQA77uWIcc6CgJNCDXKtEgW yrNw+PdtP6qAEZVgEyHiO8AFQh3YCFbkW0gQFZDsODlkDsNRFyVEEEbN+Z6gQSExx2jA vgnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769481699; x=1770086499; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hQRDcRFE/81hMk/NSCU8D/Yo2nB5doqfuZiYyByUyR4=; b=Mnhc7xUndeDdtwNlyW7ZXSK7JMC8nQJ68D3kZGbWxVd6IOakdP48jp43NGzJej9D13 TL3UWClOSrYlyHDgLBPBqVVpI7Xv22Y43lJf1A3fZ14hvIHUJl+VQHNammGlz1f7M5Aq 3kkGq+55rWWvka2z8byZXx/Yg/lkYnDFbOTGQ1GeePBr1lUHyCw0/g9GpBeDy2MdNikw 94RcxXgGyTNqebXF7lL7FEFyZlRPD4XaVVhhL2S5bHjunbpohcdKgh7W/iAJbluDbdhl H0a9cg8gReHXzu2wRfgpUxFtvAf7TWaRqTeiqjSyQcOtgzo0L9Vq3DwsBcCYLK4uQi6L elLw== X-Gm-Message-State: AOJu0YyT8BW2/bn0UGojgMCGd7izRLAAzSXOTetgj/vQrgbZ7+ocmHpk xDQpTmIEonPS2jo+SLvGGnANf/XkR3tggDe0+hiEev8aWxneLW394xla X-Gm-Gg: AZuq6aIgC4xQvAAxr4VaNkjqvjsyKRweTMVskmPb+hk0VAKxX4Kshdo+756j0RC4K71 /6DZOdY+9GcDzqlUXfsDvF+horGGSq/O/mDGcf86KHPCvvhjhpPJQIDw4HSuK628J5aZvK+u5Pn SR99gR/uj1FgqF0mcuaBipB7vuzPwBn/fZKHfh+5Y4d6WgzJBBsvgrs9vpjAMRV/f7MeKt94Fl9 53NfZBwqnhNXNTbO+H6fYKIxbIGGkPyU2R92BUFw518VnBJ+6NX/ti6K37FhTIubHcXXRTIR676 Dis4tiLdrIiWYkhrH8xjs3v8QmypXgN3i8qeTga3ATzykajBcne6a6XtoPaop/IKavcZn5XTEoZ 9GK5dnT1XgGms6CiaMkUoXf1qsyeMVkaAWbVZ5FEvDAEsOBBwaUXXNtT5lm9NlcPCCI6T8SJpSA jSD2k9/Cj35CKwl3fQyQgZWyc9Fp1ERr6Vawe0Yo9wqJBVJg== X-Received: by 2002:a05:6a20:2d28:b0:35f:aa1b:bbfb with SMTP id adf61e73a8af0-38ec63e83d6mr71723637.50.1769481698986; Mon, 26 Jan 2026 18:41:38 -0800 (PST) Received: from DESKTOP-MOQC9AF.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c635a3fb56csm9297497a12.18.2026.01.26.18.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 18:41:38 -0800 (PST) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: tglx@kernel.org Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, zhanxusheng1024@gmail.com, zhanxusheng@xiaomi.com Subject: [PATCH v2] genirq/matrix: Clarify CPU selection logic Date: Tue, 27 Jan 2026 10:41:34 +0800 Message-ID: <20260127024134.6872-1-zhanxusheng@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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_m= atrix *m, =20 best_cpu =3D UINT_MAX; =20 + /* Select the online CPU with the most available vectors */ for_each_cpu(cpu, msk) { cm =3D per_cpu_ptr(m->maps, cpu); =20 - if (!cm->online || cm->available <=3D maxavl) + if (!cm->online) continue; =20 - best_cpu =3D cpu; - maxavl =3D cm->available; + if (cm->available > maxavl) { + best_cpu =3D cpu; + maxavl =3D cm->available; + } } return best_cpu; } @@ -161,14 +164,17 @@ static unsigned int matrix_find_best_cpu_managed(stru= ct irq_matrix *m, =20 best_cpu =3D UINT_MAX; =20 + /* Select the online CPU with the fewest managed allocated vectors */ for_each_cpu(cpu, msk) { cm =3D per_cpu_ptr(m->maps, cpu); =20 - if (!cm->online || cm->managed_allocated > allocated) + if (!cm->online) continue; =20 - best_cpu =3D cpu; - allocated =3D cm->managed_allocated; + if (cm->managed_allocated < allocated) { + best_cpu =3D cpu; + allocated =3D cm->managed_allocated; + } } return best_cpu; } --=20 2.43.0