mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tiozhang <tiozhang@didiglobal.com>
To: <rdunlap@infradead.org>, <tj@kernel.org>
Cc: <jiangshanlai@gmail.com>, <linux-kernel@vger.kernel.org>,
	<zyhtheonly@yeah.net>, <zwp10758@gmail.com>,
	<zyhtheonly@gmail.com>, <tiozhang@didiglobal.com>
Subject: [PATCH v2] workqueue: add cmdline parameter `workqueue_unbound_cpus` to further constrain wq_unbound_cpumask at boot time
Date: Fri, 23 Jun 2023 15:30:33 +0800	[thread overview]
Message-ID: <20230623073033.GA6584@didi-ThinkCentre-M930t-N000> (raw)
In-Reply-To: <88e569b6-69d6-90c2-8000-9dd542aaf007@infradead.org>

Motivation of doing this is to better improve boot times for devices when
we want to prevent our workqueue works from running on some specific CPUs,
e,g, some CPUs are busy with interrupts.

Signed-off-by: tiozhang <tiozhang@didiglobal.com>
---
 .../admin-guide/kernel-parameters.txt         |  8 ++++++
 kernel/workqueue.c                            | 25 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a465d5242774..7f2fe8c60d5c 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6780,6 +6780,14 @@
 			disables both lockup detectors. Default is 10
 			seconds.
 
+	workqueue_unbound_cpus=
+			[KNL,SMP]
+			Format: <cpu-list>
+			Specify to constrain one or some CPUs to use in
+			unbound workqueues.
+			By default, all online CPUs are available for
+			unbound workqueues.
+
 	workqueue.watchdog_thresh=
 			If CONFIG_WQ_WATCHDOG is configured, workqueue can
 			warn stall conditions and dump internal state to
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7cd5f5e7e0a1..1475f8f560cc 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -329,6 +329,9 @@ static bool workqueue_freezing;		/* PL: have wqs started freezing? */
 /* PL: allowable cpus for unbound wqs and work items */
 static cpumask_var_t wq_unbound_cpumask;
 
+/* for further constrain wq_unbound_cpumask by cmdline parameter*/
+static cpumask_var_t wq_cmdline_cpumask;
+
 /* CPU where unbound work was last round robin scheduled from this CPU */
 static DEFINE_PER_CPU(int, wq_rr_cpu_last);
 
@@ -6006,6 +6009,10 @@ void __init workqueue_init_early(void)
 	cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_WQ));
 	cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN));
 
+	if (!cpumask_empty(wq_cmdline_cpumask))
+		cpumask_and(wq_unbound_cpumask, wq_unbound_cpumask, wq_cmdline_cpumask);
+	free_bootmem_cpumask_var(wq_cmdline_cpumask);
+
 	pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC);
 
 	/* initialize CPU pools */
@@ -6129,3 +6136,21 @@ void __init workqueue_init(void)
  */
 void __warn_flushing_systemwide_wq(void) { }
 EXPORT_SYMBOL(__warn_flushing_systemwide_wq);
+
+
+static int __init workqueue_unbound_cpus_setup(char *str)
+{
+	cpumask_var_t cpumask;
+
+	alloc_bootmem_cpumask_var(&wq_cmdline_cpumask);
+	alloc_bootmem_cpumask_var(&cpumask);
+	if (cpulist_parse(str, cpumask) < 0)
+		pr_warn("workqueue_unbound_cpus: incorrect CPU range\n");
+	else
+		cpumask_copy(wq_cmdline_cpumask, cpumask);
+
+	free_bootmem_cpumask_var(cpumask);
+
+	return 0;
+}
+__setup("workqueue_unbound_cpus=", workqueue_unbound_cpus_setup);
-- 
2.17.1


  reply	other threads:[~2023-06-23  7:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22  3:34 [PATCH] workqueue: add cmdline parameter `unbound_workqueue_cpus` " tiozhang
2023-06-22  3:47 ` Randy Dunlap
2023-06-23  7:30   ` tiozhang [this message]
2023-06-25  3:15     ` [PATCH v3] workqueue: add cmdline parameter `workqueue_unbound_cpus` " tiozhang
2023-06-26 21:00       ` Tejun Heo
2023-06-28 11:18         ` [PATCH v4] workqueue: add cmdline parameter `workqueue.unbound_cpus` " tiozhang
2023-06-28 18:51           ` Randy Dunlap
2023-06-29  3:50             ` [PATCH v5] " tiozhang
2023-07-10 20:43               ` Tejun Heo

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=20230623073033.GA6584@didi-ThinkCentre-M930t-N000 \
    --to=tiozhang@didiglobal.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=tj@kernel.org \
    --cc=zwp10758@gmail.com \
    --cc=zyhtheonly@gmail.com \
    --cc=zyhtheonly@yeah.net \
    /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®