From: "brookxu.cn" <brookxu.cn@gmail.com>
To: tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] lib/group_cpus: sequentially bind CPUs within node to groups.
Date: Mon, 7 Sep 2026 16:42:38 +0800 [thread overview]
Message-ID: <20260907084238.101618-1-brookxu.cn@gmail.com> (raw)
From: Chunguang Xu <chunguang.xu@shopee.com>
grp_spread_init_one() tends to bind adjacent CPUs to a queue, which may
leads to performance regresstion in some case, such as SPDK, business
often need to bind SPDK to static CPUs to poll data, such as 3,4,5,6,
this will result in some SPDK instance may only have one queue active.
So I think we should tends to spread the CPUs within node to all queue
sequentially as what we do before.
Signed-off-by: Chunguang Xu <chunguang.xu@shopee.com>
---
lib/group_cpus.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/lib/group_cpus.c b/lib/group_cpus.c
index 18d43a406114..b40e885f6fbf 100644
--- a/lib/group_cpus.c
+++ b/lib/group_cpus.c
@@ -11,19 +11,28 @@
#ifdef CONFIG_SMP
-static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,
- unsigned int cpus_per_grp)
+struct node_groups {
+ unsigned id;
+
+ union {
+ unsigned ngroups;
+ unsigned ncpus;
+ };
+};
+
+static void grp_spread_init_one(struct node_groups *nv, struct cpumask *irqmsk,
+ struct cpumask *nmsk, unsigned int cpus_per_grp)
{
const struct cpumask *siblmsk;
int cpu, sibl;
+ cpu = cpumask_first(nmsk);
+
+ /* Should not happen, but I'm too lazy to think about it */
+ if (cpu >= nr_cpu_ids)
+ return;
+
for ( ; cpus_per_grp > 0; ) {
- cpu = cpumask_first(nmsk);
-
- /* Should not happen, but I'm too lazy to think about it */
- if (cpu >= nr_cpu_ids)
- return;
-
cpumask_clear_cpu(cpu, nmsk);
cpumask_set_cpu(cpu, irqmsk);
cpus_per_grp--;
@@ -39,6 +48,10 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,
cpumask_set_cpu(sibl, irqmsk);
cpus_per_grp--;
}
+
+ cpu += nv->ngroups;
+ if (!cpumask_test_cpu(cpu, nmsk))
+ return;
}
}
@@ -97,15 +110,6 @@ static int get_nodes_in_cpumask(cpumask_var_t *node_to_cpumask,
return nodes;
}
-struct node_groups {
- unsigned id;
-
- union {
- unsigned ngroups;
- unsigned ncpus;
- };
-};
-
static int ncpus_cmp_func(const void *l, const void *r)
{
const struct node_groups *ln = l;
@@ -320,8 +324,8 @@ static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,
*/
if (curgrp >= last_grp)
curgrp = 0;
- grp_spread_init_one(&masks[curgrp], nmsk,
- cpus_per_grp);
+
+ grp_spread_init_one(nv, &masks[curgrp], nmsk, cpus_per_grp);
}
done += nv->ngroups;
}
--
2.43.0
reply other threads:[~2026-09-07 8:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260907084238.101618-1-brookxu.cn@gmail.com \
--to=brookxu.cn@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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®