lkml.org 
[lkml]   [2022]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v3 3/3] DEBUG-DO-NOT-MERGE: workqueue: kworker spawner
Date
---
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
\
 
 \ /
  Last update: 2022-08-02 10:43    [W:0.101 / U:0.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site