From nobody Sun Feb 8 23:18:15 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 4D00E165EE3 for ; Fri, 2 Aug 2024 17:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722621480; cv=none; b=Eai9w40ILiSPQdRZUXInqZkk4kAiaf1lVY5xK32I7D0b9bkpDH9e7DUocwGujteJBPx+oYcXCHLW1qTUtOtkD3mPY2p64cNmuwpqcPZzLPTUkklgM2JWReY+8nrqGtYcSQ4b6VjBpXJHrZW/pELjLhtXnLnXrx6C2yHBFotIbOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722621480; c=relaxed/simple; bh=A25sOSf9Ut7mez9xnn+T+0+X5nv/K8nyWcx9x+Ff6DE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u0e+PKyqmHLGaTQaX0R3wuhsXvgbxTlNd1Vw8FjtUyXXaGkTVQmNyDL28IzpQWQjLQejAYMvo+4Db0M2yEs0fHIWeiFxuUzHBeLD9HDRHzx2Oks53xeLaCESTeAlvnRC8PIB68hmiBewi+/5qtB/g3FxqhQhHNKgxIEbC5gTowg= 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=N6o0xiiv; arc=none smtp.client-ip=209.85.214.177 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="N6o0xiiv" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fd78c165eeso73545235ad.2 for ; Fri, 02 Aug 2024 10:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722621478; x=1723226278; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rjf+dmfza711nUeLAJtttS0CyCy0EfsvdXDNrYog4E0=; b=N6o0xiivXHezWmy98QEdDLbm0EIent06ILJ6qKb8fwlPWvIQ5bV54SwLjborsBFs9l PH5DP4Y371xQ32lF9dX+jcJU6rQze343+DD3lFDbe85CnzWn50SBguAKN0fTZqcgOY9B BzKBZlFz8IaJC2Xh0DatH3RcMGT3rEl16+ZDgmW5FZWjPRUyVpwYprrAdXlEIw0EYD0/ o0cmWPs0VtTH2lT51b/UooVwukJ2KgjtsTktMCPsaxl9vmy/BaYFH3KblhAYZa8Eo6/C MntSPujw0ZGsnpOXX4UmzdurslMwO7S5D0WZk8xCTvU4L3yprraiCvu+08/eGJaTrMVh hkiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722621478; x=1723226278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rjf+dmfza711nUeLAJtttS0CyCy0EfsvdXDNrYog4E0=; b=SwHTDD78NQ1Jd+U90sAF1Xd8zTEMgTS9a1nImRUkxdx+exBizuXccK46eqL69hDKhV xGD4C5gxKh624gdt27fcByYZlnfrnpI1Kl3jxRJEj7BTY9JNTn6LBu83WaojmXf91Hnb cnl9+5Z1byvSzsiPppHxg7LENsJFlK+frGphnn1mbf3D2D2tlM607bqFzRV5MWsLJPyP lyPv8LcHxOox0NrxVnPAEd1KMFbf2qbO1i4D1S2keGsvagC3xA463EeAuYy5P65JAJhm tgI60tyFp5hzvvCpopZJckh1vrw6F7AvCvgbMUNoTjv/9spVGp1tvKzRXTr8T4+c/JXz D+Xw== X-Gm-Message-State: AOJu0Yxp8iFCthfS3R4qUYiPQaR2yRw/A5PAlr4FpsIDScY4xDdp5DOg Yv4+wrSk0a7ENBvgtydR3w3nG7iDCyPTGaxEWLyo+Bv7ixgC8OQxTbC0o2uE X-Google-Smtp-Source: AGHT+IFxuUlBjulA+PWW7UeuVnL3etLCTmTioP9phNM2OM0WIXqGTPKS/u7d1/+Kvsk2Dp+5ySRjfA== X-Received: by 2002:a17:902:bb96:b0:1fd:a5a2:5838 with SMTP id d9443c01a7336-1ff5725228fmr44718475ad.6.1722621478382; Fri, 02 Aug 2024 10:57:58 -0700 (PDT) Received: from localhost ([216.228.127.131]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f19efdsm20072605ad.31.2024.08.02.10.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 10:57:58 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Christophe JAILLET , Leonardo Bras , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH 1/2] sched/topology: pre-compute topology_span_sane() loop params Date: Fri, 2 Aug 2024 10:57:42 -0700 Message-ID: <20240802175750.1152788-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240802175750.1152788-1-yury.norov@gmail.com> References: <20240802175750.1152788-1-yury.norov@gmail.com> 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" tl->mask(cpu) is used unchanged in the loop, and tl->mask(i) in worst case may be calculated twice as parameters for cpumask_equal() and cpumask_intersects(). So, precalculate both. Suggested-by: Christophe JAILLET Suggested-by: Leonardo Bras Signed-off-by: Yury Norov Reviewed-by: Chen Yu --- kernel/sched/topology.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 76504b776d03..754ad5fa3c99 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2353,6 +2353,7 @@ static struct sched_domain *build_sched_domain(struct= sched_domain_topology_leve static bool topology_span_sane(struct sched_domain_topology_level *tl, const struct cpumask *cpu_map, int cpu) { + const struct cpumask *mi, *mc =3D tl->mask(cpu); int i =3D cpu + 1; =20 /* NUMA levels are allowed to overlap */ @@ -2366,14 +2367,15 @@ static bool topology_span_sane(struct sched_domain_= topology_level *tl, * breaks the linking done for an earlier span. */ for_each_cpu_from(i, cpu_map) { + mi =3D tl->mask(i); + /* * We should 'and' all those masks with 'cpu_map' to exactly * match the topology we're about to build, but that can only * remove CPUs, which only lessens our ability to detect * overlaps */ - if (!cpumask_equal(tl->mask(cpu), tl->mask(i)) && - cpumask_intersects(tl->mask(cpu), tl->mask(i))) + if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi)) return false; } =20 --=20 2.43.0 From nobody Sun Feb 8 23:18:15 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 4DAB9165EF3 for ; Fri, 2 Aug 2024 17:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722621483; cv=none; b=hplGIw3mxXDnbHdbzg13xFFAe9/ZCnIXG3iMi65IDQBBr8ZwTs92s+O1bWZjI9F8fIw6F+V0+hlKSY7qspA1TF21szYsunz4RTIghegxCWIDipJVgOPUS07J7PYztLuiVF3E+MS19d9o2U+SqVvvzASEdeS+yggTG+uOfRUlElc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722621483; c=relaxed/simple; bh=xsZIBRfdsZwDqoPiwS7SDtWvcLSCMiwnHEu6ibn+8V4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OCS4KHyPZs+QHBgM7lmkIOdc+TdmngIBIOhhq/ajQdQhzSDeyEnwzZpRkVHiAmv/bQVXQZhXStcleXxPVHQ+bcXuqEAiDnkt6NvfVPhgp65b5lNOalW0/yV0WkV9MglfhLLkr1g6FsBUVZ/R6jtUytbE+QenV7wsGdrzhRYj/Fs= 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=PCxLJ50q; arc=none smtp.client-ip=209.85.214.177 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="PCxLJ50q" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fc692abba4so64571745ad.2 for ; Fri, 02 Aug 2024 10:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722621481; x=1723226281; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Sz3mcqbqEF89T2wEr0EL29fSOL/K4I+O/30wFmlGKkw=; b=PCxLJ50q09DedYMR0TALS8gu56WUUFFh0fUdwyR8Pb4iEbDoFo1sBJWjN3dNJ55/4h BO6JU3K5LRXipXdEqO7a4Wjzkv7MfnNzpuwJZVpqHmOiesDCkIP/6MXb5VRWzT+s+sjm 2DJayLx0W633nO3XSy5v3wSJXAbLqvirYCS2ZNBbdw8K0DFzuYKAo2gvxX5pwKkqEUuZ m7cZIP78mfEFCtHtC//K5OG365GReHo5RUZBoctVbDSA8+NiwAqqa2P0hfZXABqCOF+D ZUfEsZ9LMGiHwFMHW9aSDWVEVUsC8sEw6EFfLLHN4V23y4++iuL6ZWV6/0IKiYcSBx1B bDsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722621481; x=1723226281; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sz3mcqbqEF89T2wEr0EL29fSOL/K4I+O/30wFmlGKkw=; b=Y3BGvsE7rXiCfG6kAkEdDqF9sOtegbMQbgrw86n2/Lp5y/YR6Ccon/4k7PY3j8aLNW bnCzEfPZLurGYihp099SyoyuGrM3BvbEspLq1Rkpeyy1TBwivY8MmTdmjsfreHUFMCqj tOdjBpgHmv3QyVVWgMACG34ot0mkJkH9VTFt+1ScoEyASqD8viN4aABiwh+6xulVfbwx MByjJ13O+4uielupHbwN+8sZoAVjOb2r5Zo5mHzazLtSqvYLku/G6zfls8SSmXAcNkKq nLUNX0z68jmGdPphd8a1qTTiJx3qQcnvbkn4hLWDTpoUEt+PHyUehmcDRbmkihiHZwCV dn4A== X-Gm-Message-State: AOJu0YzWaBUw2slrF0KBvpPdKJFofPgBvlOBckNkMmkEnfv+v54sYE7L sAEdAfdIOLGHCFyO58enMNhPi3D5PkMXE0/bQztCRtdf0/bnpfphYfQzfFVg X-Google-Smtp-Source: AGHT+IHKdC6LauYcl8QZrVe4wBPVqUBNUSNn4meiFx20A9CAPS09TbVGsmONzm5xMU5wHvWmdHTKZQ== X-Received: by 2002:a17:902:ecc9:b0:1fd:a769:fcaf with SMTP id d9443c01a7336-1ff574dfdcbmr65575795ad.61.1722621481422; Fri, 02 Aug 2024 10:58:01 -0700 (PDT) Received: from localhost ([216.228.127.131]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f5713fsm20113945ad.95.2024.08.02.10.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 10:58:01 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Christophe JAILLET , Leonardo Bras , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH 2/2] sched/topology: optimize topology_span_sane() Date: Fri, 2 Aug 2024 10:57:43 -0700 Message-ID: <20240802175750.1152788-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240802175750.1152788-1-yury.norov@gmail.com> References: <20240802175750.1152788-1-yury.norov@gmail.com> 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 function may call cpumask_equal with tl->mask(cpu) =3D=3D tl->mask(i), even when cpu !=3D i. In such case, cpumask_equal() would always return true, and we can proceed to the next iteration immediately. Signed-off-by: Yury Norov Reviewed-by: Valentin Schneider --- kernel/sched/topology.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 754ad5fa3c99..571759606954 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2368,6 +2368,8 @@ static bool topology_span_sane(struct sched_domain_to= pology_level *tl, */ for_each_cpu_from(i, cpu_map) { mi =3D tl->mask(i); + if (mi =3D=3D mc) + continue; =20 /* * We should 'and' all those masks with 'cpu_map' to exactly --=20 2.43.0