Skip to content

Commit

Permalink
workqueue: better define synchronization rule around rescuer->pool up…
Browse files Browse the repository at this point in the history
…dates

Rescuers visit different worker_pools to process work items from pools
under pressure.  Currently, rescuer->pool is updated outside any
locking and when an outsider looks at a rescuer, there's no way to
tell when and whether rescuer->pool is gonna change.  While this
doesn't currently cause any problem, it is nasty.

With recent worker_maybe_bind_and_lock() changes, we can move
rescuer->pool updates inside pool locks such that if rescuer->pool
equals a locked pool, it's guaranteed to stay that way until the pool
is unlocked.

Move rescuer->pool inside pool->lock.

This patch doesn't introduce any visible behavior difference.

tj: Updated the description.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Lai Jiangshan authored and Tejun Heo committed Mar 4, 2013
1 parent f36dc67 commit b310410
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2357,8 +2357,8 @@ static int rescuer_thread(void *__rescuer)
mayday_clear_cpu(cpu, wq->mayday_mask);

/* migrate to the target cpu if possible */
rescuer->pool = pool;
worker_maybe_bind_and_lock(pool);
rescuer->pool = pool;

/*
* Slurp in all works issued via this workqueue and
Expand All @@ -2379,6 +2379,7 @@ static int rescuer_thread(void *__rescuer)
if (keep_working(pool))
wake_up_worker(pool);

rescuer->pool = NULL;
spin_unlock_irq(&pool->lock);
}

Expand Down
1 change: 1 addition & 0 deletions kernel/workqueue_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct worker {
struct list_head scheduled; /* L: scheduled works */
struct task_struct *task; /* I: worker task */
struct worker_pool *pool; /* I: the associated pool */
/* L: for rescuers */
/* 64 bytes boundary on 64bit, 32 on 32bit */
unsigned long last_active; /* L: last active timestamp */
unsigned int flags; /* X: flags */
Expand Down

0 comments on commit b310410

Please sign in to comment.