From: Valentin Schneider <vschneid@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <frederic@kernel.org>,
Juri Lelli <juri.lelli@redhat.com>, Phil Auld <pauld@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: [RFC PATCH v3 3/3] DEBUG-DO-NOT-MERGE: workqueue: kworker spawner
Date: Tue, 2 Aug 2022 09:41:46 +0100 [thread overview]
Message-ID: <20220802084146.3922640-4-vschneid@redhat.com> (raw)
In-Reply-To: <20220802084146.3922640-1-vschneid@redhat.com>
---
kernel/Makefile | 2 +-
kernel/workqueue.c | 9 +++++-
kernel/wqstress.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 2 deletions(-)
create mode 100644 kernel/wqstress.c
diff --git a/kernel/Makefile b/kernel/Makefile
index a7e1f49ab2b3..860133f7bca5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \
extable.o params.o platform-feature.o \
kthread.o sys_ni.o nsproxy.o \
notifier.o ksysfs.o cred.o reboot.o \
- async.o range.o smpboot.o ucount.o regset.o
+ async.o range.o smpboot.o ucount.o regset.o wqstress.o
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o
obj-$(CONFIG_MODULES) += kmod.o
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 28cd58c684ee..4ffd50a3db46 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -91,7 +91,7 @@ enum {
BUSY_WORKER_HASH_ORDER = 6, /* 64 pointers */
MAX_IDLE_WORKERS_RATIO = 4, /* 1/4 of busy can be idle */
- IDLE_WORKER_TIMEOUT = 300 * HZ, /* keep idle ones for 5 mins */
+ IDLE_WORKER_TIMEOUT = 3 * HZ, /* keep idle ones for 5 mins */
MAYDAY_INITIAL_TIMEOUT = HZ / 100 >= 2 ? HZ / 100 : 2,
/* call for help after 10ms
@@ -1996,6 +1996,10 @@ static void reap_workers(struct list_head *reaplist)
struct worker *worker, *tmp;
list_for_each_entry_safe(worker, tmp, reaplist, entry) {
+ pr_info("WORKER_REAP: task=%s cpu=%d this_task=%s this_cpu=%d\n",
+ worker->task->comm, task_cpu(worker->task),
+ current->comm, raw_smp_processor_id());
+
list_del_init(&worker->entry);
unbind_worker(worker);
@@ -2489,6 +2493,9 @@ static int worker_thread(void *__worker)
WARN_ON_ONCE(!list_empty(&worker->entry));
set_pf_worker(false);
+ pr_info("WORKER_DIE: task=%s this_cpu=%d\n",
+ current->comm, raw_smp_processor_id());
+
set_task_comm(worker->task, "kworker/dying");
ida_free(&pool->worker_ida, worker->id);
worker_detach_from_pool(worker);
diff --git a/kernel/wqstress.c b/kernel/wqstress.c
new file mode 100644
index 000000000000..16a3771027cd
--- /dev/null
+++ b/kernel/wqstress.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+
+MODULE_AUTHOR("Valentin Schneider <vschneid@redhat.com>");
+MODULE_LICENSE("GPL");
+
+#define TARGET_CPU 3
+
+static void wqstress_workfn(struct work_struct *work)
+{
+ schedule_timeout_interruptible(10 * HZ);
+}
+
+#define DECL_WORK(n) static DECLARE_WORK(wqstress_work_##n, wqstress_workfn)
+#define KICK_WORK(n) do { \
+ schedule_work_on(TARGET_CPU, &wqstress_work_##n); \
+ } while (0);
+#define FLUSH_WORK(n) do { \
+ flush_work(&wqstress_work_##n); \
+ } while (0);
+
+DECL_WORK(0);
+DECL_WORK(1);
+DECL_WORK(2);
+DECL_WORK(3);
+DECL_WORK(4);
+DECL_WORK(5);
+DECL_WORK(6);
+DECL_WORK(7);
+DECL_WORK(8);
+DECL_WORK(9);
+
+/*
+ * This should create ≈(N-1) extra kworkers for N kicked work
+ */
+static int __init wqstress_init(void)
+{
+ pr_info("WQSTRESS START\n");
+
+ sched_set_fifo_low(current);
+
+ KICK_WORK(0);
+ KICK_WORK(1);
+ KICK_WORK(2);
+ KICK_WORK(3);
+ KICK_WORK(4);
+ KICK_WORK(5);
+ KICK_WORK(6);
+ KICK_WORK(7);
+ KICK_WORK(8);
+ KICK_WORK(9);
+
+ FLUSH_WORK(0);
+ FLUSH_WORK(1);
+ FLUSH_WORK(2);
+ FLUSH_WORK(3);
+ FLUSH_WORK(4);
+ FLUSH_WORK(5);
+ FLUSH_WORK(6);
+ FLUSH_WORK(7);
+ FLUSH_WORK(8);
+ FLUSH_WORK(9);
+
+ return 0;
+}
+
+late_initcall_sync(wqstress_init);
--
2.31.1
prev parent reply other threads:[~2022-08-02 8:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 8:41 [RFC PATCH v3 0/3] workqueue: destroy_worker() vs isolated CPUs Valentin Schneider
2022-08-02 8:41 ` [RFC PATCH v3 1/3] workqueue: Hold wq_pool_mutex while affining tasks to wq_unbound_cpumask Valentin Schneider
2022-08-03 3:40 ` Lai Jiangshan
2022-08-04 11:40 ` Valentin Schneider
2022-08-05 2:43 ` Lai Jiangshan
2022-08-15 23:50 ` Tejun Heo
2022-08-18 14:33 ` [PATCH] workqueue: Protects wq_unbound_cpumask with wq_pool_attach_mutex Lai Jiangshan
2022-08-27 0:33 ` Tejun Heo
2022-08-30 9:32 ` Lai Jiangshan
2022-09-04 20:23 ` Tejun Heo
2022-08-30 14:16 ` [RFC PATCH v3 1/3] workqueue: Hold wq_pool_mutex while affining tasks to wq_unbound_cpumask Lai Jiangshan
2022-08-02 8:41 ` [RFC PATCH v3 2/3] workqueue: Unbind workers before sending them to exit() Valentin Schneider
2022-08-05 3:16 ` Lai Jiangshan
2022-08-05 16:47 ` Valentin Schneider
2022-08-02 8:41 ` Valentin Schneider [this message]
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=20220802084146.3922640-4-vschneid@redhat.com \
--to=vschneid@redhat.com \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pauld@redhat.com \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
/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®