History

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.

Leonardo Bras committed 2 years ago

Commit aae17eb1 parent 07daa991 file · +11 −3Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+11−3
@@ -2362,10 +2362,18 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, · 2361 unmodified lines
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 /**