OSDN Git Service

workqueue: Not all work insertion needs to wake up a worker
authorTejun Heo <tj@kernel.org>
Tue, 8 Aug 2023 01:57:22 +0000 (15:57 -1000)
committerTejun Heo <tj@kernel.org>
Tue, 8 Aug 2023 01:57:22 +0000 (15:57 -1000)
commitfe089f87cccb066e8ad20f49ddf05e95adc1fa8d
tree3c9023aef9f9ef46ae3825c0c1f1c3b8124d3941
parentc0ab017d43f4c4147f7ecf3ca3cb872a416e17c7
workqueue: Not all work insertion needs to wake up a worker

insert_work() always tried to wake up a worker; however, the only time it
needs to try to wake up a worker is when a new active work item is queued.
When a work item goes on the inactive list or queueing a flush work item,
there's no reason to try to wake up a worker.

This patch moves the worker wakeup logic out of insert_work() and places it
in the active new work item queueing path in __queue_work().

While at it:

* __queue_work() is dereferencing pwq->pool repeatedly. Add local variable
  pool.

* Every caller of insert_work() calls debug_work_activate(). Consolidate the
  invocations into insert_work().

* In __queue_work() pool->watchdog_ts update is relocated slightly. This is
  to better accommodate future changes.

This makes wakeups more precise and will help the planned change to assign
work items to workers before waking them up. No behavior changes intended.

v2: WARN_ON_ONCE(pool != last_pool) added in __queue_work() to clarify as
    suggested by Lai.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
kernel/workqueue.c