Skip to content

Commit 6f7f4ba

Browse files
author
Leonardo Bras
committed
workqueue: Avoid using isolated cpus' timers on queue_delayed_work
JIRA: https://issues.redhat.com/browse/RHEL-20254 Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git/ commit aae17eb Author: Leonardo Bras <leobras@redhat.com> Date: Mon Jan 29 22:00:46 2024 -0300 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 <leobras@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Leonardo Bras <leobras@redhat.com>
1 parent 45955d3 commit 6f7f4ba

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
@@ -1677,10 +1677,18 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
16771677
dwork->cpu = cpu;
16781678
timer->expires = jiffies + delay;
16791679

1680-
if (unlikely(cpu != WORK_CPU_UNBOUND))
1680+
if (housekeeping_enabled(HK_TYPE_TIMER)) {
1681+
/* If the current cpu is a housekeeping cpu, use it. */
1682+
cpu = smp_processor_id();
1683+
if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER))
1684+
cpu = housekeeping_any_cpu(HK_TYPE_TIMER);
16811685
add_timer_on(timer, cpu);
1682-
else
1683-
add_timer(timer);
1686+
} else {
1687+
if (likely(cpu == WORK_CPU_UNBOUND))
1688+
add_timer(timer);
1689+
else
1690+
add_timer_on(timer, cpu);
1691+
}
16841692
}
16851693

16861694
/**

0 commit comments

Comments
 (0)