From nobody Sun Feb 8 11:16:54 2026 Received: from baidu.com (mx22.baidu.com [220.181.50.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3223C18FDDF for ; Fri, 7 Mar 2025 06:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.181.50.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741330020; cv=none; b=U07yOhm0VDeFzuaLohyQftISR81BPOW7oM6uM9G9nqnPmfmn6t4FeYmDV3znVh9ZF7pIKbYjjNcdw+eOvjTKy4DDOuXKmCpatY/ydkg6kPtweaCledEH4xz8tzaO88s9+G1i3EptQYxYDYb+zdLsFF5G5KudFhSOta8JrR3GfCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741330020; c=relaxed/simple; bh=tqN7YV2/K/pq6371MddAZ5p6Dol0Hg7j/y85drm3Qhg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lMjGKYD9X/T+xn2Q0MjOT7lvT+E8hmT/Jy6TtB+5VjTJMc0IiQQJ6Vh3mUfbvoFtUYFYyL9WPcnktsoUpLlj5KHmj2PHJEbTCPQaSr5O1VzBGRyytEinK0hXYTUB3t5UXnQEjFAH2kRRXBKCsR0jOBCQBfqKg9jm+p+EDW2Vzdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; arc=none smtp.client-ip=220.181.50.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com From: lirongqing To: , , , , , , , , , , , , , CC: Li RongQing Subject: [PATCH] sched_ext: Simplify cpumask computation in balance_scx Date: Fri, 7 Mar 2025 14:45:33 +0800 Message-ID: <20250307064533.2663-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: BJHW-Mail-Ex08.internal.baidu.com (10.127.64.18) To BJHW-Mail-Ex15.internal.baidu.com (10.127.64.38) X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex15_2025-03-07 14:45:40:751 X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex15_2025-03-07 14:45:40:766 X-FEAS-Client-IP: 10.127.64.38 X-FE-Policy-ID: 52:10:53:SYSTEM Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing Compare SMT CPU against RQ CPU and skip balance it, to avoid calling for_each_cpu_andnot() and cpumask_of(), they are relatively expensive Signed-off-by: Li RongQing --- kernel/sched/ext.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 0f1da19..7e40ede 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -2920,11 +2920,19 @@ static int balance_scx(struct rq *rq, struct task_s= truct *prev, */ if (sched_core_enabled(rq)) { const struct cpumask *smt_mask =3D cpu_smt_mask(cpu_of(rq)); - int scpu; + int scpu, cpu; =20 - for_each_cpu_andnot(scpu, smt_mask, cpumask_of(cpu_of(rq))) { - struct rq *srq =3D cpu_rq(scpu); - struct task_struct *sprev =3D srq->curr; + cpu =3D cpu_of(rq); + + for_each_cpu(scpu, smt_mask) { + struct rq *srq; + struct task_struct *sprev; + + if (scpu =3D=3D cpu) + continue; + + srq =3D cpu_rq(scpu); + sprev =3D srq->curr; =20 WARN_ON_ONCE(__rq_lockp(rq) !=3D __rq_lockp(srq)); update_rq_clock(srq); --=20 2.9.4