Skip to contentSkip to conversation

workqueue: make sysfs of unbound kworker cpumask more clever

PATCH Applied [email protected] 2 participants 2 messages Oct 17, 2021 – Oct 19, 2021 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 workqueue: make sysfs of unbound kworker cpumask more clever

From: Menglong Dong <[email protected]>

Some unfriendly component, such as dpdk, write the same mask to unbound kworker cpumask again and again. Every time it write to this interface some work is queue to cpu, even though the mask is same with the original mask.

So, fix it by return success and do nothing if the cpumask is equal with the old one.

---
v2:
- reorganize the code to avoid unnecessary saved_cpumask alloc

---
 kernel/workqueue.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
kernel/workqueue.c +11 -4
index 1b3eb1e9531f..76988f39ed5a 100644
@@ -5384,9 +5384,6 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
 	int ret = -EINVAL;
 	cpumask_var_t saved_cpumask;
 
-	if (!zalloc_cpumask_var(&saved_cpumask, GFP_KERNEL))
-		return -ENOMEM;
-
 	/*
 	 * Not excluding isolated cpus on purpose.
 	 * If the user wishes to include them, we allow that.
@@ -5394,6 +5391,15 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
 	cpumask_and(cpumask, cpumask, cpu_possible_mask);
 	if (!cpumask_empty(cpumask)) {
 		apply_wqattrs_lock();
+		if (cpumask_equal(cpumask, wq_unbound_cpumask)) {
+			ret = 0;
+			goto out_unlock;
+		}
+
+		if (!zalloc_cpumask_var(&saved_cpumask, GFP_KERNEL)) {
+			ret = -ENOMEM;
+			goto out_unlock;
+		}
 
 		/* save the old wq_unbound_cpumask. */
 		cpumask_copy(saved_cpumask, wq_unbound_cpumask);
@@ -5406,10 +5412,11 @@ int workqueue_set_unbound_cpumask(cpumask_var_t cpumask)
 		if (ret < 0)
 			cpumask_copy(wq_unbound_cpumask, saved_cpumask);
 
+		free_cpumask_var(saved_cpumask);
+out_unlock:
 		apply_wqattrs_unlock();
 	}
 
-	free_cpumask_var(saved_cpumask);
 	return ret;
 }
 
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw
Quoted 7 lines · On Sun, Oct 17, 2021 at 08:04:02PM +0800, [email protected] wrote:

From: Menglong Dong <[email protected]>

Some unfriendly component, such as dpdk, write the same mask to unbound kworker cpumask again and again. Every time it write to this interface some work is queue to cpu, even though the mask is same with the original mask.

Quoted 5 lines

So, fix it by return success and do nothing if the cpumask is equal with the old one.

Applied to wq/for-5.16.

Thanks.

Signature · 1 line
tejun