From nobody Sun Feb 8 11:22:16 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 49DB6320A06 for ; Wed, 21 Jan 2026 03:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768964757; cv=none; b=gWPNvjCcVkLaT9fqUc0xYW0QXrE3FuTGyG4x3PdbPSn1n7ztmMQtnodaZoQq7xpvnPAMTaXYahkU1mw1d04lUle14xXgjhZgUpvers2klMOnf6/mPv4hi/OCKjv+xWRka/u6fmL8TaJfuuyZgofAwEZa2If7PKkqbfJG4M5F5LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768964757; c=relaxed/simple; bh=Z1yBUgJ1J8iwdf6Q1+0FKF1qJFUtAFfCSo4u9hBSdiQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cgr6wk7PD5EdqwgzOmNn2gjwCZa7K5k3xxATzB89ZH1efWtf1pg7aMLsxRIlDm5X0DmIFykMyPTmq95TTV2zZE2HIaWETtHBeYSkWLAG484kQ34m1F+3DYZP9MkD1edQOBdStxCzok3DNnLDUP9CyGUmIolAOi9OoYZCdu6we9w= 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=GPDFBpPb; arc=none smtp.client-ip=209.85.215.176 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="GPDFBpPb" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-bc29d64b39dso2001770a12.3 for ; Tue, 20 Jan 2026 19:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768964755; x=1769569555; 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=KGeH07HGVcKEYwijsWEVrC+w84Cs0aQ//lL7ULo7blo=; b=GPDFBpPbJGsAfSJ1ereOd9pYqIi/v7P/M2xK2ZaNNmwQq9uWR7LYKwVTBUO2aLZiJD LfUqyY89xRG8D6DEfJVIrIuDusZcDBr3yEwgiorZ92f2nDqVHV5u3NfpEfVKdXaqL4ap nX0epNsxQWrwcGXKw5w/Dm2SrQd4eKtDAJwaKNd88RuTE+2UvHBlEeoSyU6Zi3MiKg6V 4CRx4FuQn3AMUwt/a9Xpw1XmuEyierdv6S7LBNlM53+FMEIvc7I5eM3jqORuM7YjhmwP +koVNJQEUPl/CeKk16w+5uI+ub2PWQS9IO3tCHGkZLoLNxFcv5MpyS/w52SZDx3eR9/z qTjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768964755; x=1769569555; 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=KGeH07HGVcKEYwijsWEVrC+w84Cs0aQ//lL7ULo7blo=; b=cDr7Y8BuOUtE0aVlwX9jnYvjYEuyS5Vjd0Mwul0GPr3/1E4DYNPGQBtQIdXYgzn1dg fmhAcLLuF+/gtZpIvIlQqLj3Uem66iPNY1Ah2vVfQUrin+cdmgaBA8tit5cisK3js2eD SOp0O41cabk76hM18pdoRdZ/z3eJ5Z7lQvZdQ0GfmVPL/EAkssDpztpBFY3YDe3KB5/t uYhf3U8mQLs/CfjHRfiGCqjBtqhOK9RuxV+CrpVtKJD/8c3KywSE3dXNezK7kam2Yvs2 nY1FT1+jfM3HeFCSi3IqAh2z7sXfh4mowowfsqkYnsWdSk89cPVfUxvzyAylOMdahI+N ortQ== X-Gm-Message-State: AOJu0YwdUt3Vh1NQpnTYaFtwHxQIIrv3pM/Lsv8HK6cVo6UeBk6ylYNX t0XQ3xgl0JmOz0d8+HbDawX/7bt6YwVO+z0Ub5NhTM4sjUJwqms0psAMhkixjA== X-Gm-Gg: AZuq6aJiXJgYgkEOMJoNVMhf303tAvJUHyUVvRCk3rDZ5td76+USXgrOm0vNp08L8lz BePzOm0pnQ3eP0nGdtLMps3Wdr7ZGPtIvKQpHnO9sDiu6WOrKd1lMJydgsFq9/gN625qaaiWegp RAYfbGHaDS5sMlGdgiox1RpCdDnHYSLQWt6dYRW3hpIWUd9ZXQA52id7ItJEQm/YpPXhEZhGygZ p/6zPRFXJxf7QwERAWa6jfYlELM0dIveb4q0uwlrCTU9ABfz3iutEsyLzVAb9a9r87KqPhScRWT gVMnKp6W1YyZh3BTAnFxcXFhoYJD+SIil2gagMHA7zYLdkz1Fm+RZwqKkuMHgg7qLH418j+WLFm A/Ao+Ml5mHPjcScoVUQaTiAz3lQkrKviVCTpw0y6N0AsGWbNyHOUtHtztvd5LvFfnLgfxZmmybZ j4/aI6P+30M8zS5TtCCi49CnveGvdc2R1WZFM= X-Received: by 2002:a17:902:d592:b0:2a3:bf5f:926d with SMTP id d9443c01a7336-2a718896d41mr148250055ad.24.1768964755169; Tue, 20 Jan 2026 19:05:55 -0800 (PST) Received: from DESKTOP-MOQC9AF.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a75889f594sm35395205ad.85.2026.01.20.19.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 19:05:54 -0800 (PST) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: linux-kernel@vger.kernel.org Cc: mingo@kernel.org, tglx@linutronix.de, Zhan Xusheng Subject: [PATCH] irq/matrix: simplify CPU selection logic Date: Wed, 21 Jan 2026 11:05:49 +0800 Message-ID: <20260121030549.45257-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 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 --- 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