mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Yury Norov <yury.norov@gmail.com>, Chen Yu <yu.c.chen@intel.com>,
	Leonardo Bras <leobras@redhat.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>
Subject: [PATCH v3 3/3] sched/topology: reorganize topology_span_sane() checking order
Date: Mon,  2 Sep 2024 11:36:07 -0700	[thread overview]
Message-ID: <20240902183609.1683756-4-yury.norov@gmail.com> (raw)
In-Reply-To: <20240902183609.1683756-1-yury.norov@gmail.com>

The function currently makes 3 checks:

1. mc == mi;
2. cpumask_equal(mc, mi);
3. cpumask_intersects(mc, mi).

Historically, 2 last checks build a single condition for if() statement.

Logically, #1 and #2 should be tested together, because for the topology
sanity checking purposes, they do the same thing. In contrast, #3 tests
for intersection, which is a different logical unit.

This patch creates a helper for #1 and #2 and puts the corresponding
comment on top of the helper; unloading the main topology_span_sane().

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 kernel/sched/topology.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 04a3b3d7b6f4..bbbe7955d37c 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2346,6 +2346,22 @@ static struct sched_domain *build_sched_domain(struct sched_domain_topology_leve
 	return sd;
 }
 
+/*
+ * Some topology levels (e.g. PKG in default_topology[]) have a
+ * sched_domain_mask_f implementation that reuses the same mask for
+ * several CPUs (in PKG's case, one mask * for all CPUs in the same
+ * NUMA node).
+ *
+ * For such topology levels, repeating cpumask_equal() checks is
+ * wasteful. Instead, we first check that the tl->mask(i) pointers
+ * aren't the same.
+ */
+static inline bool topology_cpumask_equal(const struct cpumask *m1,
+					  const struct cpumask *m2)
+{
+	return m1 == m2 || cpumask_equal(m1, m2);
+}
+
 /*
  * Ensure topology masks are sane, i.e. there are no conflicts (overlaps) for
  * any two given CPUs at this (non-NUMA) topology level.
@@ -2369,18 +2385,7 @@ static bool topology_span_sane(struct sched_domain_topology_level *tl,
 	 */
 	for_each_cpu_from(cpu, cpu_map) {
 		mi = tl->mask(cpu);
-
-		/*
-		 * Some topology levels (e.g. PKG in default_topology[])
-		 * have a sched_domain_mask_f implementation that reuses
-		 * the same mask for several CPUs (in PKG's case, one mask
-		 * for all CPUs in the same NUMA node).
-		 *
-		 * For such topology levels, repeating cpumask_equal()
-		 * checks is wasteful. Instead, we first check that the
-		 * tl->mask(i) pointers aren't the same.
-		 */
-		if (mi == mc)
+		if (topology_cpumask_equal(mc, mi))
 			continue;
 
 		/*
@@ -2389,7 +2394,7 @@ static bool topology_span_sane(struct sched_domain_topology_level *tl,
 		 * remove CPUs, which only lessens our ability to detect
 		 * overlaps
 		 */
-		if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi))
+		if (cpumask_intersects(mc, mi))
 			return false;
 	}
 
-- 
2.43.0


  parent reply	other threads:[~2024-09-02 18:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-02 18:36 [PATCH v3 0/3] sched/topology: optimize topology_span_sane() Yury Norov
2024-09-02 18:36 ` [PATCH v3 1/3] sched/topology: pre-compute topology_span_sane() loop params Yury Norov
2024-09-02 18:36 ` [PATCH v3 2/3] sched/topology: optimize topology_span_sane() Yury Norov
2024-09-02 18:36 ` Yury Norov [this message]
2024-09-14 16:54 ` [PATCH v3 0/3] " Yury Norov
2024-09-30 19:14   ` Yury Norov
2024-11-06 16:28     ` Yury Norov
2024-11-06 17:58       ` Christophe JAILLET
2024-11-06 18:03         ` Yury Norov
2024-11-06 18:06 ` Peter Zijlstra
2024-11-07 15:22   ` Yury Norov

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=20240902183609.1683756-4-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=bsegall@google.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=leobras@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=yu.c.chen@intel.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®