* [PATCHSET wq/for-3.10] workqueue: misc cleanups
@ 2013-03-13 23:58 Tejun Heo
2013-03-13 23:58 ` [PATCH 1/6] workqueue: relocate pwq_set_max_active() Tejun Heo
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs
Hello,
This patchset contains mostly cleanups and a fix for a bug in the new
unbound pools w/ attrs.
This patchset contains the following six patches.
0001-workqueue-relocate-pwq_set_max_active.patch
0002-workqueue-implement-and-use-pwq_adjust_max_active.patch
0003-workqueue-fix-max_active-handling-in-init_and_link_p.patch
0004-workqueue-update-comments-and-a-warning-message.patch
0005-workqueue-rename-id-to-pi-in-for_each_each_pool.patch
0006-workqueue-inline-trivial-wrappers.patch
0001-0002 clean up pwq->max_active handling.
0003 fixes a race condition around max_active handling for the new
unbound pools w/ attrs.
0004-0006 are cleanups which make no functional differences other than
inlining of some trivial wrappers.
This patch is on top of wq/for-3.10 e626761691 ("workqueue: implement
current_is_workqueue_rescuer()").
diffstat follows. Thanks.
include/linux/workqueue.h | 123 +++++++++++++++--
kernel/workqueue.c | 324 +++++++++++++++-------------------------------
2 files changed, 218 insertions(+), 229 deletions(-)
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/6] workqueue: relocate pwq_set_max_active()
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-13 23:58 ` [PATCH 2/6] workqueue: implement and use pwq_adjust_max_active() Tejun Heo
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
pwq_set_max_active() is gonna be modified and used during
pool_workqueue init. Move it above init_and_link_pwq().
This patch is pure code reorganization and doesn't introduce any
functional changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f5c8bbb..d519289 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3725,6 +3725,26 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
kfree(wq);
}
+/**
+ * pwq_set_max_active - adjust max_active of a pwq
+ * @pwq: target pool_workqueue
+ * @max_active: new max_active value.
+ *
+ * Set @pwq->max_active to @max_active and activate delayed works if
+ * increased.
+ *
+ * CONTEXT:
+ * spin_lock_irq(pool->lock).
+ */
+static void pwq_set_max_active(struct pool_workqueue *pwq, int max_active)
+{
+ pwq->max_active = max_active;
+
+ while (!list_empty(&pwq->delayed_works) &&
+ pwq->nr_active < pwq->max_active)
+ pwq_activate_first_delayed(pwq);
+}
+
static void init_and_link_pwq(struct pool_workqueue *pwq,
struct workqueue_struct *wq,
struct worker_pool *pool,
@@ -4012,26 +4032,6 @@ void destroy_workqueue(struct workqueue_struct *wq)
EXPORT_SYMBOL_GPL(destroy_workqueue);
/**
- * pwq_set_max_active - adjust max_active of a pwq
- * @pwq: target pool_workqueue
- * @max_active: new max_active value.
- *
- * Set @pwq->max_active to @max_active and activate delayed works if
- * increased.
- *
- * CONTEXT:
- * spin_lock_irq(pool->lock).
- */
-static void pwq_set_max_active(struct pool_workqueue *pwq, int max_active)
-{
- pwq->max_active = max_active;
-
- while (!list_empty(&pwq->delayed_works) &&
- pwq->nr_active < pwq->max_active)
- pwq_activate_first_delayed(pwq);
-}
-
-/**
* workqueue_set_max_active - adjust max_active of a workqueue
* @wq: target workqueue
* @max_active: new max_active value.
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/6] workqueue: implement and use pwq_adjust_max_active()
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
2013-03-13 23:58 ` [PATCH 1/6] workqueue: relocate pwq_set_max_active() Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-13 23:58 ` [PATCH 3/6] workqueue: fix max_active handling in init_and_link_pwq() Tejun Heo
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
Rename pwq_set_max_active() to pwq_adjust_max_active() and move
pool_workqueue->max_active synchronization and max_active
determination logic into it.
The new function should be called with workqueue_lock held for stable
workqueue->saved_max_active, determines the current max_active value
the target pool_workqueue should be using from @wq->saved_max_active
and the state of the associated pool, and applies it with proper
synchronization.
The current two users - workqueue_set_max_active() and
thaw_workqueues() - are updated accordingly. In addition, the manual
freezing handling in __alloc_workqueue_key() and
freeze_workqueues_begin() are replaced with calls to
pwq_adjust_max_active().
This centralizes max_active handling so that it's less error-prone.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 83 +++++++++++++++++++++++++-----------------------------
1 file changed, 38 insertions(+), 45 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index d519289..9e2ec4c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3726,23 +3726,38 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
}
/**
- * pwq_set_max_active - adjust max_active of a pwq
+ * pwq_adjust_max_active - update a pwq's max_active to the current setting
* @pwq: target pool_workqueue
- * @max_active: new max_active value.
- *
- * Set @pwq->max_active to @max_active and activate delayed works if
- * increased.
*
- * CONTEXT:
- * spin_lock_irq(pool->lock).
+ * If @pwq isn't freezing, set @pwq->max_active to the associated
+ * workqueue's saved_max_active and activate delayed work items
+ * accordingly. If @pwq is freezing, clear @pwq->max_active to zero.
*/
-static void pwq_set_max_active(struct pool_workqueue *pwq, int max_active)
+static void pwq_adjust_max_active(struct pool_workqueue *pwq)
{
- pwq->max_active = max_active;
+ struct workqueue_struct *wq = pwq->wq;
+ bool freezable = wq->flags & WQ_FREEZABLE;
+
+ /* for @wq->saved_max_active */
+ lockdep_assert_held(&workqueue_lock);
+
+ /* fast exit for non-freezable wqs */
+ if (!freezable && pwq->max_active == wq->saved_max_active)
+ return;
+
+ spin_lock(&pwq->pool->lock);
+
+ if (!freezable || !(pwq->pool->flags & POOL_FREEZING)) {
+ pwq->max_active = wq->saved_max_active;
- while (!list_empty(&pwq->delayed_works) &&
- pwq->nr_active < pwq->max_active)
- pwq_activate_first_delayed(pwq);
+ while (!list_empty(&pwq->delayed_works) &&
+ pwq->nr_active < pwq->max_active)
+ pwq_activate_first_delayed(pwq);
+ } else {
+ pwq->max_active = 0;
+ }
+
+ spin_unlock(&pwq->pool->lock);
}
static void init_and_link_pwq(struct pool_workqueue *pwq,
@@ -3932,15 +3947,14 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
goto err_destroy;
/*
- * workqueue_lock protects global freeze state and workqueues
- * list. Grab it, set max_active accordingly and add the new
- * workqueue to workqueues list.
+ * workqueue_lock protects global freeze state and workqueues list.
+ * Grab it, adjust max_active and add the new workqueue to
+ * workqueues list.
*/
spin_lock_irq(&workqueue_lock);
- if (workqueue_freezing && wq->flags & WQ_FREEZABLE)
- for_each_pwq(pwq, wq)
- pwq->max_active = 0;
+ for_each_pwq(pwq, wq)
+ pwq_adjust_max_active(pwq);
list_add(&wq->list, &workqueues);
@@ -4055,17 +4069,8 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
wq->saved_max_active = max_active;
- for_each_pwq(pwq, wq) {
- struct worker_pool *pool = pwq->pool;
-
- spin_lock(&pool->lock);
-
- if (!(wq->flags & WQ_FREEZABLE) ||
- !(pool->flags & POOL_FREEZING))
- pwq_set_max_active(pwq, max_active);
-
- spin_unlock(&pool->lock);
- }
+ for_each_pwq(pwq, wq)
+ pwq_adjust_max_active(pwq);
spin_unlock_irq(&workqueue_lock);
}
@@ -4358,14 +4363,8 @@ void freeze_workqueues_begin(void)
/* suppress further executions by setting max_active to zero */
list_for_each_entry(wq, &workqueues, list) {
- if (!(wq->flags & WQ_FREEZABLE))
- continue;
-
- for_each_pwq(pwq, wq) {
- spin_lock(&pwq->pool->lock);
- pwq->max_active = 0;
- spin_unlock(&pwq->pool->lock);
- }
+ for_each_pwq(pwq, wq)
+ pwq_adjust_max_active(pwq);
}
spin_unlock_irq(&workqueue_lock);
@@ -4445,14 +4444,8 @@ void thaw_workqueues(void)
/* restore max_active and repopulate worklist */
list_for_each_entry(wq, &workqueues, list) {
- if (!(wq->flags & WQ_FREEZABLE))
- continue;
-
- for_each_pwq(pwq, wq) {
- spin_lock(&pwq->pool->lock);
- pwq_set_max_active(pwq, wq->saved_max_active);
- spin_unlock(&pwq->pool->lock);
- }
+ for_each_pwq(pwq, wq)
+ pwq_adjust_max_active(pwq);
}
/* kick workers */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/6] workqueue: fix max_active handling in init_and_link_pwq()
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
2013-03-13 23:58 ` [PATCH 1/6] workqueue: relocate pwq_set_max_active() Tejun Heo
2013-03-13 23:58 ` [PATCH 2/6] workqueue: implement and use pwq_adjust_max_active() Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-13 23:58 ` [PATCH 4/6] workqueue: update comments and a warning message Tejun Heo
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
Since 9e8cd2f589 ("workqueue: implement apply_workqueue_attrs()"),
init_and_link_pwq() may be called to initialize a new pool_workqueue
for a workqueue which is already online, but the function was setting
pwq->max_active to wq->saved_max_active without proper
synchronization.
Fix it by calling pwq_adjust_max_active() under proper locking instead
of manually setting max_active.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 9e2ec4c..7567614 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3771,21 +3771,25 @@ static void init_and_link_pwq(struct pool_workqueue *pwq,
pwq->wq = wq;
pwq->flush_color = -1;
pwq->refcnt = 1;
- pwq->max_active = wq->saved_max_active;
INIT_LIST_HEAD(&pwq->delayed_works);
INIT_LIST_HEAD(&pwq->mayday_node);
INIT_WORK(&pwq->unbound_release_work, pwq_unbound_release_workfn);
- /*
- * Link @pwq and set the matching work_color. This is synchronized
- * with flush_mutex to avoid confusing flush_workqueue().
- */
mutex_lock(&wq->flush_mutex);
spin_lock_irq(&workqueue_lock);
+ /*
+ * Set the matching work_color. This is synchronized with
+ * flush_mutex to avoid confusing flush_workqueue().
+ */
if (p_last_pwq)
*p_last_pwq = first_pwq(wq);
pwq->work_color = wq->work_color;
+
+ /* sync max_active to the current setting */
+ pwq_adjust_max_active(pwq);
+
+ /* link in @pwq */
list_add_rcu(&pwq->pwqs_node, &wq->pwqs);
spin_unlock_irq(&workqueue_lock);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/6] workqueue: update comments and a warning message
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
` (2 preceding siblings ...)
2013-03-13 23:58 ` [PATCH 3/6] workqueue: fix max_active handling in init_and_link_pwq() Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-13 23:58 ` [PATCH 5/6] workqueue: rename @id to @pi in for_each_each_pool() Tejun Heo
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
* Update incorrect and add missing synchronization labels.
* Update incorrect or misleading comments. Add new comments where
clarification is necessary. Reformat / rephrase some comments.
* drain_workqueue() can be used separately from destroy_workqueue()
but its warning message was incorrectly referring to destruction.
Other than the warning message change, this patch doesn't make any
functional changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 84 ++++++++++++++++++++++++++++--------------------------
1 file changed, 44 insertions(+), 40 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7567614..248a1e9 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -145,7 +145,7 @@ struct worker_pool {
struct timer_list idle_timer; /* L: worker idle timeout */
struct timer_list mayday_timer; /* L: SOS timer for workers */
- /* workers are chained either in busy_hash or idle_list */
+ /* a workers is either on busy_hash or idle_list, or the manager */
DECLARE_HASHTABLE(busy_hash, BUSY_WORKER_HASH_ORDER);
/* L: hash of busy workers */
@@ -154,8 +154,8 @@ struct worker_pool {
struct ida worker_ida; /* L: for worker IDs */
struct workqueue_attrs *attrs; /* I: worker attributes */
- struct hlist_node hash_node; /* R: unbound_pool_hash node */
- int refcnt; /* refcnt for unbound pools */
+ struct hlist_node hash_node; /* W: unbound_pool_hash node */
+ int refcnt; /* W: refcnt for unbound pools */
/*
* The current concurrency level. As it's likely to be accessed
@@ -213,8 +213,8 @@ struct wq_flusher {
struct wq_device;
/*
- * The externally visible workqueue abstraction is an array of
- * per-CPU workqueues:
+ * The externally visible workqueue. It relays the issued work items to
+ * the appropriate worker_pool through its pool_workqueues.
*/
struct workqueue_struct {
unsigned int flags; /* W: WQ_* flags */
@@ -247,9 +247,10 @@ struct workqueue_struct {
static struct kmem_cache *pwq_cache;
-/* hash of all unbound pools keyed by pool->attrs */
+/* W: hash of all unbound pools keyed by pool->attrs */
static DEFINE_HASHTABLE(unbound_pool_hash, UNBOUND_POOL_HASH_ORDER);
+/* I: attributes used when instantiating standard unbound pools on demand */
static struct workqueue_attrs *unbound_std_wq_attrs[NR_STD_WORKER_POOLS];
struct workqueue_struct *system_wq __read_mostly;
@@ -434,16 +435,13 @@ static DEFINE_SPINLOCK(workqueue_lock);
static LIST_HEAD(workqueues);
static bool workqueue_freezing; /* W: have wqs started freezing? */
-/*
- * The CPU and unbound standard worker pools. The unbound ones have
- * POOL_DISASSOCIATED set, and their workers have WORKER_UNBOUND set.
- */
+/* the per-cpu worker pools */
static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
cpu_worker_pools);
/*
- * idr of all pools. Modifications are protected by workqueue_lock. Read
- * accesses are protected by sched-RCU protected.
+ * R: idr of all pools. Modifications are protected by workqueue_lock.
+ * Read accesses are protected by sched-RCU protected.
*/
static DEFINE_IDR(worker_pool_idr);
@@ -890,13 +888,12 @@ static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
* recycled work item as currently executing and make it wait until the
* current execution finishes, introducing an unwanted dependency.
*
- * This function checks the work item address, work function and workqueue
- * to avoid false positives. Note that this isn't complete as one may
- * construct a work function which can introduce dependency onto itself
- * through a recycled work item. Well, if somebody wants to shoot oneself
- * in the foot that badly, there's only so much we can do, and if such
- * deadlock actually occurs, it should be easy to locate the culprit work
- * function.
+ * This function checks the work item address and work function to avoid
+ * false positives. Note that this isn't complete as one may construct a
+ * work function which can introduce dependency onto itself through a
+ * recycled work item. Well, if somebody wants to shoot oneself in the
+ * foot that badly, there's only so much we can do, and if such deadlock
+ * actually occurs, it should be easy to locate the culprit work function.
*
* CONTEXT:
* spin_lock_irq(pool->lock).
@@ -1187,9 +1184,9 @@ static void insert_work(struct pool_workqueue *pwq, struct work_struct *work,
get_pwq(pwq);
/*
- * Ensure either worker_sched_deactivated() sees the above
- * list_add_tail() or we see zero nr_running to avoid workers
- * lying around lazily while there are works to be processed.
+ * Ensure either wq_worker_sleeping() sees the above
+ * list_add_tail() or we see zero nr_running to avoid workers lying
+ * around lazily while there are works to be processed.
*/
smp_mb();
@@ -1790,6 +1787,10 @@ static struct worker *create_worker(struct worker_pool *pool)
if (IS_ERR(worker->task))
goto fail;
+ /*
+ * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any
+ * online CPUs. It'll be re-applied when any of the CPUs come up.
+ */
set_user_nice(worker->task, pool->attrs->nice);
set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask);
@@ -1950,8 +1951,8 @@ static void pool_mayday_timeout(unsigned long __pool)
* sent to all rescuers with works scheduled on @pool to resolve
* possible allocation deadlock.
*
- * On return, need_to_create_worker() is guaranteed to be false and
- * may_start_working() true.
+ * On return, need_to_create_worker() is guaranteed to be %false and
+ * may_start_working() %true.
*
* LOCKING:
* spin_lock_irq(pool->lock) which may be released and regrabbed
@@ -1959,7 +1960,7 @@ static void pool_mayday_timeout(unsigned long __pool)
* manager.
*
* RETURNS:
- * false if no action was taken and pool->lock stayed locked, true
+ * %false if no action was taken and pool->lock stayed locked, %true
* otherwise.
*/
static bool maybe_create_worker(struct worker_pool *pool)
@@ -2016,7 +2017,7 @@ restart:
* multiple times. Called only from manager.
*
* RETURNS:
- * false if no action was taken and pool->lock stayed locked, true
+ * %false if no action was taken and pool->lock stayed locked, %true
* otherwise.
*/
static bool maybe_destroy_workers(struct worker_pool *pool)
@@ -2268,11 +2269,11 @@ static void process_scheduled_works(struct worker *worker)
* worker_thread - the worker thread function
* @__worker: self
*
- * The worker thread function. There are NR_CPU_WORKER_POOLS dynamic pools
- * of these per each cpu. These workers process all works regardless of
- * their specific target workqueue. The only exception is works which
- * belong to workqueues with a rescuer which will be explained in
- * rescuer_thread().
+ * The worker thread function. All workers belong to a worker_pool -
+ * either a per-cpu one or dynamic unbound one. These workers process all
+ * work items regardless of their specific target workqueue. The only
+ * exception is work items which belong to workqueues with a rescuer which
+ * will be explained in rescuer_thread().
*/
static int worker_thread(void *__worker)
{
@@ -2600,11 +2601,8 @@ static bool flush_workqueue_prep_pwqs(struct workqueue_struct *wq,
* flush_workqueue - ensure that any scheduled work has run to completion.
* @wq: workqueue to flush
*
- * Forces execution of the workqueue and blocks until its completion.
- * This is typically used in driver shutdown handlers.
- *
- * We sleep until all works which were queued on entry have been handled,
- * but we are not livelocked by new incoming ones.
+ * This function sleeps until all work items which were queued on entry
+ * have finished execution, but it is not livelocked by new incoming ones.
*/
void flush_workqueue(struct workqueue_struct *wq)
{
@@ -2794,7 +2792,7 @@ reflush:
if (++flush_cnt == 10 ||
(flush_cnt % 100 == 0 && flush_cnt <= 1000))
- pr_warn("workqueue %s: flush on destruction isn't complete after %u tries\n",
+ pr_warn("workqueue %s: drain_workqueue() isn't complete after %u tries\n",
wq->name, flush_cnt);
local_irq_enable();
@@ -3576,7 +3574,9 @@ static void rcu_free_pool(struct rcu_head *rcu)
* @pool: worker_pool to put
*
* Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
- * safe manner.
+ * safe manner. get_unbound_pool() calls this function on its failure path
+ * and this function should be able to release pools which went through,
+ * successfully or not, init_worker_pool().
*/
static void put_unbound_pool(struct worker_pool *pool)
{
@@ -3602,7 +3602,11 @@ static void put_unbound_pool(struct worker_pool *pool)
spin_unlock_irq(&workqueue_lock);
- /* lock out manager and destroy all workers */
+ /*
+ * Become the manager and destroy all workers. Grabbing
+ * manager_arb prevents @pool's workers from blocking on
+ * manager_mutex.
+ */
mutex_lock(&pool->manager_arb);
spin_lock_irq(&pool->lock);
@@ -4339,7 +4343,7 @@ EXPORT_SYMBOL_GPL(work_on_cpu);
* freeze_workqueues_begin - begin freezing workqueues
*
* Start freezing workqueues. After this function returns, all freezable
- * workqueues will queue new works to their frozen_works list instead of
+ * workqueues will queue new works to their delayed_works list instead of
* pool->worklist.
*
* CONTEXT:
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/6] workqueue: rename @id to @pi in for_each_each_pool()
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
` (3 preceding siblings ...)
2013-03-13 23:58 ` [PATCH 4/6] workqueue: update comments and a warning message Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-13 23:58 ` [PATCH 6/6] workqueue: inline trivial wrappers Tejun Heo
2013-03-14 2:54 ` [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
Rename @id argument of for_each_pool() to @pi so that it doesn't get
reused accidentally when for_each_pool() is used in combination with
other iterators.
This patch is purely cosmetic.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/workqueue.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 248a1e9..147fc5a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -283,7 +283,7 @@ EXPORT_SYMBOL_GPL(system_freezable_wq);
/**
* for_each_pool - iterate through all worker_pools in the system
* @pool: iteration cursor
- * @id: integer used for iteration
+ * @pi: integer used for iteration
*
* This must be called either with workqueue_lock held or sched RCU read
* locked. If the pool needs to be used beyond the locking in effect, the
@@ -292,8 +292,8 @@ EXPORT_SYMBOL_GPL(system_freezable_wq);
* The if/else clause exists only for the lockdep assertion and can be
* ignored.
*/
-#define for_each_pool(pool, id) \
- idr_for_each_entry(&worker_pool_idr, pool, id) \
+#define for_each_pool(pool, pi) \
+ idr_for_each_entry(&worker_pool_idr, pool, pi) \
if (({ assert_rcu_or_wq_lock(); false; })) { } \
else
@@ -4354,7 +4354,7 @@ void freeze_workqueues_begin(void)
struct worker_pool *pool;
struct workqueue_struct *wq;
struct pool_workqueue *pwq;
- int id;
+ int pi;
spin_lock_irq(&workqueue_lock);
@@ -4362,7 +4362,7 @@ void freeze_workqueues_begin(void)
workqueue_freezing = true;
/* set FREEZING */
- for_each_pool(pool, id) {
+ for_each_pool(pool, pi) {
spin_lock(&pool->lock);
WARN_ON_ONCE(pool->flags & POOL_FREEZING);
pool->flags |= POOL_FREEZING;
@@ -4435,7 +4435,7 @@ void thaw_workqueues(void)
struct workqueue_struct *wq;
struct pool_workqueue *pwq;
struct worker_pool *pool;
- int id;
+ int pi;
spin_lock_irq(&workqueue_lock);
@@ -4443,7 +4443,7 @@ void thaw_workqueues(void)
goto out_unlock;
/* clear FREEZING */
- for_each_pool(pool, id) {
+ for_each_pool(pool, pi) {
spin_lock(&pool->lock);
WARN_ON_ONCE(!(pool->flags & POOL_FREEZING));
pool->flags &= ~POOL_FREEZING;
@@ -4457,7 +4457,7 @@ void thaw_workqueues(void)
}
/* kick workers */
- for_each_pool(pool, id) {
+ for_each_pool(pool, pi) {
spin_lock(&pool->lock);
wake_up_worker(pool);
spin_unlock(&pool->lock);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/6] workqueue: inline trivial wrappers
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
` (4 preceding siblings ...)
2013-03-13 23:58 ` [PATCH 5/6] workqueue: rename @id to @pi in for_each_each_pool() Tejun Heo
@ 2013-03-13 23:58 ` Tejun Heo
2013-03-14 2:54 ` [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
6 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-13 23:58 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs, Tejun Heo
There's no reason to make these trivial wrappers full (exported)
functions. Inline the followings.
queue_work()
queue_delayed_work()
mod_delayed_work()
schedule_work_on()
schedule_work()
schedule_delayed_work_on()
schedule_delayed_work()
keventd_up()
Signed-off-by: Tejun Heo <tj@kernel.org>
---
include/linux/workqueue.h | 123 +++++++++++++++++++++++++++++++++++++++++-----
kernel/workqueue.c | 111 -----------------------------------------
2 files changed, 111 insertions(+), 123 deletions(-)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index df30763..835d12b 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -417,28 +417,16 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
extern bool queue_work_on(int cpu, struct workqueue_struct *wq,
struct work_struct *work);
-extern bool queue_work(struct workqueue_struct *wq, struct work_struct *work);
extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
struct delayed_work *work, unsigned long delay);
-extern bool queue_delayed_work(struct workqueue_struct *wq,
- struct delayed_work *work, unsigned long delay);
extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
struct delayed_work *dwork, unsigned long delay);
-extern bool mod_delayed_work(struct workqueue_struct *wq,
- struct delayed_work *dwork, unsigned long delay);
extern void flush_workqueue(struct workqueue_struct *wq);
extern void drain_workqueue(struct workqueue_struct *wq);
extern void flush_scheduled_work(void);
-extern bool schedule_work_on(int cpu, struct work_struct *work);
-extern bool schedule_work(struct work_struct *work);
-extern bool schedule_delayed_work_on(int cpu, struct delayed_work *work,
- unsigned long delay);
-extern bool schedule_delayed_work(struct delayed_work *work,
- unsigned long delay);
extern int schedule_on_each_cpu(work_func_t func);
-extern int keventd_up(void);
int execute_in_process_context(work_func_t fn, struct execute_work *);
@@ -455,6 +443,117 @@ extern bool current_is_workqueue_rescuer(void);
extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
extern unsigned int work_busy(struct work_struct *work);
+/**
+ * queue_work - queue work on a workqueue
+ * @wq: workqueue to use
+ * @work: work to queue
+ *
+ * Returns %false if @work was already on a queue, %true otherwise.
+ *
+ * We queue the work to the CPU on which it was submitted, but if the CPU dies
+ * it can be processed by another CPU.
+ */
+static inline bool queue_work(struct workqueue_struct *wq,
+ struct work_struct *work)
+{
+ return queue_work_on(WORK_CPU_UNBOUND, wq, work);
+}
+
+/**
+ * queue_delayed_work - queue work on a workqueue after delay
+ * @wq: workqueue to use
+ * @dwork: delayable work to queue
+ * @delay: number of jiffies to wait before queueing
+ *
+ * Equivalent to queue_delayed_work_on() but tries to use the local CPU.
+ */
+static inline bool queue_delayed_work(struct workqueue_struct *wq,
+ struct delayed_work *dwork,
+ unsigned long delay)
+{
+ return queue_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
+}
+
+/**
+ * mod_delayed_work - modify delay of or queue a delayed work
+ * @wq: workqueue to use
+ * @dwork: work to queue
+ * @delay: number of jiffies to wait before queueing
+ *
+ * mod_delayed_work_on() on local CPU.
+ */
+static inline bool mod_delayed_work(struct workqueue_struct *wq,
+ struct delayed_work *dwork,
+ unsigned long delay)
+{
+ return mod_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
+}
+
+/**
+ * schedule_work_on - put work task on a specific cpu
+ * @cpu: cpu to put the work task on
+ * @work: job to be done
+ *
+ * This puts a job on a specific cpu
+ */
+static inline bool schedule_work_on(int cpu, struct work_struct *work)
+{
+ return queue_work_on(cpu, system_wq, work);
+}
+
+/**
+ * schedule_work - put work task in global workqueue
+ * @work: job to be done
+ *
+ * Returns %false if @work was already on the kernel-global workqueue and
+ * %true otherwise.
+ *
+ * This puts a job in the kernel-global workqueue if it was not already
+ * queued and leaves it in the same position on the kernel-global
+ * workqueue otherwise.
+ */
+static inline bool schedule_work(struct work_struct *work)
+{
+ return queue_work(system_wq, work);
+}
+
+/**
+ * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
+ * @cpu: cpu to use
+ * @dwork: job to be done
+ * @delay: number of jiffies to wait
+ *
+ * After waiting for a given time this puts a job in the kernel-global
+ * workqueue on the specified CPU.
+ */
+static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
+ unsigned long delay)
+{
+ return queue_delayed_work_on(cpu, system_wq, dwork, delay);
+}
+
+/**
+ * schedule_delayed_work - put work task in global workqueue after delay
+ * @dwork: job to be done
+ * @delay: number of jiffies to wait or 0 for immediate execution
+ *
+ * After waiting for a given time this puts a job in the kernel-global
+ * workqueue.
+ */
+static inline bool schedule_delayed_work(struct delayed_work *dwork,
+ unsigned long delay)
+{
+ return queue_delayed_work(system_wq, dwork, delay);
+}
+
+/**
+ * keventd_up - is workqueue initialized yet?
+ */
+static inline bool keventd_up(void)
+{
+ return system_wq != NULL;
+}
+
/*
* Like above, but uses del_timer() instead of del_timer_sync(). This means,
* if it returns 0 the timer function may be running and the queueing is in
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 147fc5a..f37421f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1340,22 +1340,6 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
}
EXPORT_SYMBOL_GPL(queue_work_on);
-/**
- * queue_work - queue work on a workqueue
- * @wq: workqueue to use
- * @work: work to queue
- *
- * Returns %false if @work was already on a queue, %true otherwise.
- *
- * We queue the work to the CPU on which it was submitted, but if the CPU dies
- * it can be processed by another CPU.
- */
-bool queue_work(struct workqueue_struct *wq, struct work_struct *work)
-{
- return queue_work_on(WORK_CPU_UNBOUND, wq, work);
-}
-EXPORT_SYMBOL_GPL(queue_work);
-
void delayed_work_timer_fn(unsigned long __data)
{
struct delayed_work *dwork = (struct delayed_work *)__data;
@@ -1431,21 +1415,6 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
EXPORT_SYMBOL_GPL(queue_delayed_work_on);
/**
- * queue_delayed_work - queue work on a workqueue after delay
- * @wq: workqueue to use
- * @dwork: delayable work to queue
- * @delay: number of jiffies to wait before queueing
- *
- * Equivalent to queue_delayed_work_on() but tries to use the local CPU.
- */
-bool queue_delayed_work(struct workqueue_struct *wq,
- struct delayed_work *dwork, unsigned long delay)
-{
- return queue_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
-}
-EXPORT_SYMBOL_GPL(queue_delayed_work);
-
-/**
* mod_delayed_work_on - modify delay of or queue a delayed work on specific CPU
* @cpu: CPU number to execute work on
* @wq: workqueue to use
@@ -1484,21 +1453,6 @@ bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
EXPORT_SYMBOL_GPL(mod_delayed_work_on);
/**
- * mod_delayed_work - modify delay of or queue a delayed work
- * @wq: workqueue to use
- * @dwork: work to queue
- * @delay: number of jiffies to wait before queueing
- *
- * mod_delayed_work_on() on local CPU.
- */
-bool mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
- unsigned long delay)
-{
- return mod_delayed_work_on(WORK_CPU_UNBOUND, wq, dwork, delay);
-}
-EXPORT_SYMBOL_GPL(mod_delayed_work);
-
-/**
* worker_enter_idle - enter idle state
* @worker: worker which is entering idle state
*
@@ -3002,66 +2956,6 @@ bool cancel_delayed_work_sync(struct delayed_work *dwork)
EXPORT_SYMBOL(cancel_delayed_work_sync);
/**
- * schedule_work_on - put work task on a specific cpu
- * @cpu: cpu to put the work task on
- * @work: job to be done
- *
- * This puts a job on a specific cpu
- */
-bool schedule_work_on(int cpu, struct work_struct *work)
-{
- return queue_work_on(cpu, system_wq, work);
-}
-EXPORT_SYMBOL(schedule_work_on);
-
-/**
- * schedule_work - put work task in global workqueue
- * @work: job to be done
- *
- * Returns %false if @work was already on the kernel-global workqueue and
- * %true otherwise.
- *
- * This puts a job in the kernel-global workqueue if it was not already
- * queued and leaves it in the same position on the kernel-global
- * workqueue otherwise.
- */
-bool schedule_work(struct work_struct *work)
-{
- return queue_work(system_wq, work);
-}
-EXPORT_SYMBOL(schedule_work);
-
-/**
- * schedule_delayed_work_on - queue work in global workqueue on CPU after delay
- * @cpu: cpu to use
- * @dwork: job to be done
- * @delay: number of jiffies to wait
- *
- * After waiting for a given time this puts a job in the kernel-global
- * workqueue on the specified CPU.
- */
-bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
- unsigned long delay)
-{
- return queue_delayed_work_on(cpu, system_wq, dwork, delay);
-}
-EXPORT_SYMBOL(schedule_delayed_work_on);
-
-/**
- * schedule_delayed_work - put work task in global workqueue after delay
- * @dwork: job to be done
- * @delay: number of jiffies to wait or 0 for immediate execution
- *
- * After waiting for a given time this puts a job in the kernel-global
- * workqueue.
- */
-bool schedule_delayed_work(struct delayed_work *dwork, unsigned long delay)
-{
- return queue_delayed_work(system_wq, dwork, delay);
-}
-EXPORT_SYMBOL(schedule_delayed_work);
-
-/**
* schedule_on_each_cpu - execute a function synchronously on each online CPU
* @func: the function to call
*
@@ -3154,11 +3048,6 @@ int execute_in_process_context(work_func_t fn, struct execute_work *ew)
}
EXPORT_SYMBOL_GPL(execute_in_process_context);
-int keventd_up(void)
-{
- return system_wq != NULL;
-}
-
#ifdef CONFIG_SYSFS
/*
* Workqueues with WQ_SYSFS flag set is visible to userland via
--
1.8.1.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCHSET wq/for-3.10] workqueue: misc cleanups
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
` (5 preceding siblings ...)
2013-03-13 23:58 ` [PATCH 6/6] workqueue: inline trivial wrappers Tejun Heo
@ 2013-03-14 2:54 ` Tejun Heo
2013-03-18 19:50 ` Tejun Heo
6 siblings, 1 reply; 9+ messages in thread
From: Tejun Heo @ 2013-03-14 2:54 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs
On Wed, Mar 13, 2013 at 04:58:12PM -0700, Tejun Heo wrote:
> This patch is on top of wq/for-3.10 e626761691 ("workqueue: implement
> current_is_workqueue_rescuer()").
Oops, forgot the git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git review-misc-cleanups
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHSET wq/for-3.10] workqueue: misc cleanups
2013-03-14 2:54 ` [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
@ 2013-03-18 19:50 ` Tejun Heo
0 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2013-03-18 19:50 UTC (permalink / raw)
To: linux-kernel; +Cc: laijs
On Wed, Mar 13, 2013 at 07:54:01PM -0700, Tejun Heo wrote:
> On Wed, Mar 13, 2013 at 04:58:12PM -0700, Tejun Heo wrote:
> > This patch is on top of wq/for-3.10 e626761691 ("workqueue: implement
> > current_is_workqueue_rescuer()").
>
> Oops, forgot the git branch.
>
> git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git review-misc-cleanups
Applied to wq/for-3.10.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-03-18 19:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-13 23:58 [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
2013-03-13 23:58 ` [PATCH 1/6] workqueue: relocate pwq_set_max_active() Tejun Heo
2013-03-13 23:58 ` [PATCH 2/6] workqueue: implement and use pwq_adjust_max_active() Tejun Heo
2013-03-13 23:58 ` [PATCH 3/6] workqueue: fix max_active handling in init_and_link_pwq() Tejun Heo
2013-03-13 23:58 ` [PATCH 4/6] workqueue: update comments and a warning message Tejun Heo
2013-03-13 23:58 ` [PATCH 5/6] workqueue: rename @id to @pi in for_each_each_pool() Tejun Heo
2013-03-13 23:58 ` [PATCH 6/6] workqueue: inline trivial wrappers Tejun Heo
2013-03-14 2:54 ` [PATCHSET wq/for-3.10] workqueue: misc cleanups Tejun Heo
2013-03-18 19:50 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox