Skip to content

Commit 228f1d0

Browse files
Lai Jiangshanhtejun
authored andcommitted
workqueue: remove @wakeup from worker_set_flags()
worker_set_flags() has only two callers, each specifying %true and %false for @wakeup. Let's push the wake up to the caller and remove @wakeup from worker_set_flags(). The caller can use the following instead if wakeup is necessary: worker_set_flags(); if (need_more_worker(pool)) wake_up_worker(pool); This makes the code simpler. This patch doesn't introduce behavior changes. tj: Updated description and comments. Signed-off-by: Lai Jiangshan <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent a489a03 commit 228f1d0

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

kernel/workqueue.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -867,35 +867,22 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
867867
* worker_set_flags - set worker flags and adjust nr_running accordingly
868868
* @worker: self
869869
* @flags: flags to set
870-
* @wakeup: wakeup an idle worker if necessary
871870
*
872-
* Set @flags in @worker->flags and adjust nr_running accordingly. If
873-
* nr_running becomes zero and @wakeup is %true, an idle worker is
874-
* woken up.
871+
* Set @flags in @worker->flags and adjust nr_running accordingly.
875872
*
876873
* CONTEXT:
877874
* spin_lock_irq(pool->lock)
878875
*/
879-
static inline void worker_set_flags(struct worker *worker, unsigned int flags,
880-
bool wakeup)
876+
static inline void worker_set_flags(struct worker *worker, unsigned int flags)
881877
{
882878
struct worker_pool *pool = worker->pool;
883879

884880
WARN_ON_ONCE(worker->task != current);
885881

886-
/*
887-
* If transitioning into NOT_RUNNING, adjust nr_running and
888-
* wake up an idle worker as necessary if requested by
889-
* @wakeup.
890-
*/
882+
/* If transitioning into NOT_RUNNING, adjust nr_running. */
891883
if ((flags & WORKER_NOT_RUNNING) &&
892884
!(worker->flags & WORKER_NOT_RUNNING)) {
893-
if (wakeup) {
894-
if (atomic_dec_and_test(&pool->nr_running) &&
895-
!list_empty(&pool->worklist))
896-
wake_up_worker(pool);
897-
} else
898-
atomic_dec(&pool->nr_running);
885+
atomic_dec(&pool->nr_running);
899886
}
900887

901888
worker->flags |= flags;
@@ -2041,18 +2028,20 @@ __acquires(&pool->lock)
20412028
list_del_init(&work->entry);
20422029

20432030
/*
2044-
* CPU intensive works don't participate in concurrency
2045-
* management. They're the scheduler's responsibility.
2031+
* CPU intensive works don't participate in concurrency management.
2032+
* They're the scheduler's responsibility. This takes @worker out
2033+
* of concurrency management and the next code block will chain
2034+
* execution of the pending work items.
20462035
*/
20472036
if (unlikely(cpu_intensive))
2048-
worker_set_flags(worker, WORKER_CPU_INTENSIVE, true);
2037+
worker_set_flags(worker, WORKER_CPU_INTENSIVE);
20492038

20502039
/*
20512040
* Wake up another worker if necessary. The condition is always
20522041
* false for normal per-cpu workers since nr_running would always
20532042
* be >= 1 at this point. This is used to chain execution of the
20542043
* pending work items for WORKER_NOT_RUNNING workers such as the
2055-
* UNBOUND ones.
2044+
* UNBOUND and CPU_INTENSIVE ones.
20562045
*/
20572046
if (need_more_worker(pool))
20582047
wake_up_worker(pool);
@@ -2210,7 +2199,7 @@ static int worker_thread(void *__worker)
22102199
}
22112200
} while (keep_working(pool));
22122201

2213-
worker_set_flags(worker, WORKER_PREP, false);
2202+
worker_set_flags(worker, WORKER_PREP);
22142203
sleep:
22152204
/*
22162205
* pool->lock is held and there's no work to process and no need to

0 commit comments

Comments
 (0)