[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230226160259.18354-2-ammarfaizi2@gnuweeb.org>
Date: Sun, 26 Feb 2023 23:02:54 +0700
From: Ammar Faizi <ammarfaizi2@...weeb.org>
To: Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
David Sterba <dsterba@...e.com>, Tejun Heo <tj@...nel.org>
Cc: Ammar Faizi <ammarfaizi2@...weeb.org>,
Lai Jiangshan <jiangshanlai@...il.com>,
Filipe Manana <fdmanana@...e.com>,
Linux Btrfs Mailing List <linux-btrfs@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux Fsdevel Mailing List <linux-fsdevel@...r.kernel.org>,
GNU/Weeb Mailing List <gwml@...r.gnuweeb.org>
Subject: [RFC PATCH v1 1/6] workqueue: Add set_workqueue_cpumask() helper function
Allow users to specify a CPU set for the workqueue. The first use case
of this helper function is to set the CPU affinity of Btrfs workqueues.
Signed-off-by: Ammar Faizi <ammarfaizi2@...weeb.org>
---
include/linux/workqueue.h | 3 +++
kernel/workqueue.c | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index ac551b8ee7d9f2f4..e3bd6f47e74ecd66 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -710,6 +710,9 @@ int workqueue_online_cpu(unsigned int cpu);
int workqueue_offline_cpu(unsigned int cpu);
#endif
+int set_workqueue_cpumask(struct workqueue_struct *wq,
+ const cpumask_var_t mask);
+
void __init workqueue_init_early(void);
void __init workqueue_init(void);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index b8b541caed4854a4..adc1478fafb1811c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4398,6 +4398,25 @@ static int init_rescuer(struct workqueue_struct *wq)
return 0;
}
+int set_workqueue_cpumask(struct workqueue_struct *wq, const cpumask_var_t mask)
+{
+ struct workqueue_attrs *tmp_attrs;
+ int ret;
+
+ tmp_attrs = alloc_workqueue_attrs();
+ if (!tmp_attrs)
+ return -ENOMEM;
+
+ apply_wqattrs_lock();
+ copy_workqueue_attrs(tmp_attrs, wq->unbound_attrs);
+ cpumask_copy(tmp_attrs->cpumask, mask);
+ ret = apply_workqueue_attrs_locked(wq, tmp_attrs);
+ apply_wqattrs_unlock();
+ free_workqueue_attrs(tmp_attrs);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(set_workqueue_cpumask);
+
__printf(1, 4)
struct workqueue_struct *alloc_workqueue(const char *fmt,
unsigned int flags,
--
Ammar Faizi
Powered by blists - more mailing lists