History

workqueue: drop apply_wqattrs_lock()/unlock() wrappers

The apply_wqattrs_lock()/unlock() helpers were introduced by commit a0111cf6710b ("workqueue: separate out and refactor the locking of applying attrs") to encapsulate the get_online_cpus() (later cpus_read_lock()) + mutex_lock(&wq_pool_mutex) acquire pair that was duplicated across the apply-attrs paths. Since commit 19af45757383 ("workqueue: Remove cpus_read_lock() from apply_wqattrs_lock()") removed the cpus_read_lock() (pwq creation and installation now operate on wq_online_cpumask, so CPU hotplug no longer needs to be excluded), the wrappers have been one-line forwarders to mutex_lock(&wq_pool_mutex)/mutex_unlock(&wq_pool_mutex). They no longer encode any non-trivial locking rule and obscure the fact that callers just take the existing wq_pool_mutex. This align with the "unnecessary" helpers that got discussed in [1] Inline the eight call sites and remove the wrappers. No functional change.

Breno Leitao committed 6 months ago

Commit dfca4631 parent 7fcb7af1 file · +14 −24Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+14−24
@@ -5300,16 +5300,6 @@ static struct pool_workqueue *alloc_unbound_pwq(struct workqueue_struct *wq, · 5299 unmodified lines
53005300 return pwq;
53015301 }
53025302
5303−static void apply_wqattrs_lock(void)
5304−{
5305− mutex_lock(&wq_pool_mutex);
5306−}
5307−
5308−static void apply_wqattrs_unlock(void)
5309−{
5310− mutex_unlock(&wq_pool_mutex);
5311−}
5312−
53135303 /**
53145304 * wq_calc_pod_cpumask - calculate a wq_attrs' cpumask for a pod
53155305 * @attrs: the wq_attrs of the default pwq of the target workqueue
@@ -5863,7 +5853,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt, · 547 unmodified lines
58635853 * wq_pool_mutex protects the workqueues list, allocations of PWQs,
58645854 * and the global freeze state.
58655855 */
5866− apply_wqattrs_lock();
5856+ mutex_lock(&wq_pool_mutex);
58675857
58685858 if (alloc_and_link_pwqs(wq) < 0)
58695859 goto err_unlock_free_node_nr_active;
@@ -5877,7 +5867,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt, · 7 unmodified lines
58775867 if (wq_online && init_rescuer(wq) < 0)
58785868 goto err_unlock_destroy;
58795869
5880− apply_wqattrs_unlock();
5870+ mutex_unlock(&wq_pool_mutex);
58815871
58825872 if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq))
58835873 goto err_destroy;
@@ -5885,7 +5875,7 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt, · 1 unmodified line
58855875 return wq;
58865876
58875877 err_unlock_free_node_nr_active:
5888− apply_wqattrs_unlock();
5878+ mutex_unlock(&wq_pool_mutex);
58895879 /*
58905880 * Failed alloc_and_link_pwqs() may leave pending pwq->release_work,
58915881 * flushing the pwq_release_worker ensures that the pwq_release_workfn()
@@ -5900,7 +5890,7 @@ err_free_wq: · 8 unmodified lines
59005890 kfree(wq);
59015891 return NULL;
59025892 err_unlock_destroy:
5903− apply_wqattrs_unlock();
5893+ mutex_unlock(&wq_pool_mutex);
59045894 err_destroy:
59055895 destroy_workqueue(wq);
59065896 return NULL;
@@ -7301,7 +7291,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr, · 1394 unmodified lines
73017291 struct workqueue_attrs *attrs;
73027292 int ret = -ENOMEM;
73037293
7304− apply_wqattrs_lock();
7294+ mutex_lock(&wq_pool_mutex);
73057295
73067296 attrs = wq_sysfs_prep_attrs(wq);
73077297 if (!attrs)
@@ -7314,7 +7304,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr, · 6 unmodified lines
73147304 ret = -EINVAL;
73157305
73167306 out_unlock:
7317− apply_wqattrs_unlock();
7307+ mutex_unlock(&wq_pool_mutex);
73187308 free_workqueue_attrs(attrs);
73197309 return ret ?: count;
73207310 }
@@ -7340,7 +7330,7 @@ static ssize_t wq_cpumask_store(struct device *dev, · 19 unmodified lines
73407330 struct workqueue_attrs *attrs;
73417331 int ret = -ENOMEM;
73427332
7343− apply_wqattrs_lock();
7333+ mutex_lock(&wq_pool_mutex);
73447334
73457335 attrs = wq_sysfs_prep_attrs(wq);
73467336 if (!attrs)
@@ -7351,7 +7341,7 @@ static ssize_t wq_cpumask_store(struct device *dev, · 4 unmodified lines
73517341 ret = apply_workqueue_attrs_locked(wq, attrs);
73527342
73537343 out_unlock:
7354− apply_wqattrs_unlock();
7344+ mutex_unlock(&wq_pool_mutex);
73557345 free_workqueue_attrs(attrs);
73567346 return ret ?: count;
73577347 }
@@ -7387,13 +7377,13 @@ static ssize_t wq_affn_scope_store(struct device *dev, · 29 unmodified lines
73877377 if (affn < 0)
73887378 return affn;
73897379
7390− apply_wqattrs_lock();
7380+ mutex_lock(&wq_pool_mutex);
73917381 attrs = wq_sysfs_prep_attrs(wq);
73927382 if (attrs) {
73937383 attrs->affn_scope = affn;
73947384 ret = apply_workqueue_attrs_locked(wq, attrs);
73957385 }
7396− apply_wqattrs_unlock();
7386+ mutex_unlock(&wq_pool_mutex);
73977387 free_workqueue_attrs(attrs);
73987388 return ret ?: count;
73997389 }
@@ -7418,13 +7408,13 @@ static ssize_t wq_affinity_strict_store(struct device *dev, · 18 unmodified lines
74187408 if (sscanf(buf, "%d", &v) != 1)
74197409 return -EINVAL;
74207410
7421− apply_wqattrs_lock();
7411+ mutex_lock(&wq_pool_mutex);
74227412 attrs = wq_sysfs_prep_attrs(wq);
74237413 if (attrs) {
74247414 attrs->affn_strict = (bool)v;
74257415 ret = apply_workqueue_attrs_locked(wq, attrs);
74267416 }
7427− apply_wqattrs_unlock();
7417+ mutex_unlock(&wq_pool_mutex);
74287418 free_workqueue_attrs(attrs);
74297419 return ret ?: count;
74307420 }
@@ -7465,12 +7455,12 @@ static int workqueue_set_unbound_cpumask(cpumask_var_t cpumask) · 34 unmodified lines
74657455 cpumask_and(cpumask, cpumask, cpu_possible_mask);
74667456 if (!cpumask_empty(cpumask)) {
74677457 ret = 0;
7468− apply_wqattrs_lock();
7458+ mutex_lock(&wq_pool_mutex);
74697459 if (!cpumask_equal(cpumask, wq_unbound_cpumask))
74707460 ret = workqueue_apply_unbound_cpumask(cpumask);
74717461 if (!ret)
74727462 cpumask_copy(wq_requested_unbound_cpumask, cpumask);
7473− apply_wqattrs_unlock();
7463+ mutex_unlock(&wq_pool_mutex);
74747464 }
74757465
74767466 return ret;