Skip to content

Commit c0ab017

Browse files
committed
workqueue: Cleanups around process_scheduled_works()
* Drop the trivial optimization in worker_thread() where it bypasses calling process_scheduled_works() if the first work item isn't linked. This is a mostly pointless micro optimization and gets in the way of improving the work processing path. * Consolidate pool->watchdog_ts updates in the two callers into process_scheduled_works(). Signed-off-by: Tejun Heo <[email protected]>
1 parent bc8b50c commit c0ab017

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

kernel/workqueue.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,9 +2652,15 @@ __acquires(&pool->lock)
26522652
*/
26532653
static void process_scheduled_works(struct worker *worker)
26542654
{
2655-
while (!list_empty(&worker->scheduled)) {
2656-
struct work_struct *work = list_first_entry(&worker->scheduled,
2657-
struct work_struct, entry);
2655+
struct work_struct *work;
2656+
bool first = true;
2657+
2658+
while ((work = list_first_entry_or_null(&worker->scheduled,
2659+
struct work_struct, entry))) {
2660+
if (first) {
2661+
worker->pool->watchdog_ts = jiffies;
2662+
first = false;
2663+
}
26582664
process_one_work(worker, work);
26592665
}
26602666
}
@@ -2735,17 +2741,8 @@ static int worker_thread(void *__worker)
27352741
list_first_entry(&pool->worklist,
27362742
struct work_struct, entry);
27372743

2738-
pool->watchdog_ts = jiffies;
2739-
2740-
if (likely(!(*work_data_bits(work) & WORK_STRUCT_LINKED))) {
2741-
/* optimization path, not strictly necessary */
2742-
process_one_work(worker, work);
2743-
if (unlikely(!list_empty(&worker->scheduled)))
2744-
process_scheduled_works(worker);
2745-
} else {
2746-
move_linked_works(work, &worker->scheduled, NULL);
2747-
process_scheduled_works(worker);
2748-
}
2744+
move_linked_works(work, &worker->scheduled, NULL);
2745+
process_scheduled_works(worker);
27492746
} while (keep_working(pool));
27502747

27512748
worker_set_flags(worker, WORKER_PREP);
@@ -2820,7 +2817,6 @@ static int rescuer_thread(void *__rescuer)
28202817
struct pool_workqueue, mayday_node);
28212818
struct worker_pool *pool = pwq->pool;
28222819
struct work_struct *work, *n;
2823-
bool first = true;
28242820

28252821
__set_current_state(TASK_RUNNING);
28262822
list_del_init(&pwq->mayday_node);
@@ -2838,12 +2834,9 @@ static int rescuer_thread(void *__rescuer)
28382834
WARN_ON_ONCE(!list_empty(scheduled));
28392835
list_for_each_entry_safe(work, n, &pool->worklist, entry) {
28402836
if (get_work_pwq(work) == pwq) {
2841-
if (first)
2842-
pool->watchdog_ts = jiffies;
28432837
move_linked_works(work, scheduled, &n);
28442838
pwq->stats[PWQ_STAT_RESCUED]++;
28452839
}
2846-
first = false;
28472840
}
28482841

28492842
if (!list_empty(scheduled)) {

0 commit comments

Comments
 (0)