Skip to content

Commit aae17eb

Browse files
Leonardo Brashtejun
authored andcommitted
workqueue: Avoid using isolated cpus' timers on queue_delayed_work
When __queue_delayed_work() is called, it chooses a cpu for handling the timer interrupt. As of today, it will pick either the cpu passed as parameter or the last cpu used for this. This is not good if a system does use CPU isolation, because it can take away some valuable cpu time to: 1 - deal with the timer interrupt, 2 - schedule-out the desired task, 3 - queue work on a random workqueue, and 4 - schedule the desired task back to the cpu. So to fix this, during __queue_delayed_work(), if cpu isolation is in place, pick a random non-isolated cpu to handle the timer interrupt. As an optimization, if the current cpu is not isolated, use it instead of looking for another candidate. Signed-off-by: Leonardo Bras <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 07daa99 commit aae17eb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kernel/workqueue.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,10 +2362,18 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
23622362
dwork->cpu = cpu;
23632363
timer->expires = jiffies + delay;
23642364

2365-
if (unlikely(cpu != WORK_CPU_UNBOUND))
2365+
if (housekeeping_enabled(HK_TYPE_TIMER)) {
2366+
/* If the current cpu is a housekeeping cpu, use it. */
2367+
cpu = smp_processor_id();
2368+
if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER))
2369+
cpu = housekeeping_any_cpu(HK_TYPE_TIMER);
23662370
add_timer_on(timer, cpu);
2367-
else
2368-
add_timer(timer);
2371+
} else {
2372+
if (likely(cpu == WORK_CPU_UNBOUND))
2373+
add_timer(timer);
2374+
else
2375+
add_timer_on(timer, cpu);
2376+
}
23692377
}
23702378

23712379
/**

0 commit comments

Comments
 (0)