Re: [PATCH] irq_work: Improve CPU Responsiveness in irq_work_sync with cond_resched()
From: Thomas Gleixner
Date: Thu Sep 19 2024 - 09:54:36 EST
On Wed, Sep 18 2024 at 11:23, Steven Davis wrote:
> Add cond_resched() to the busy-wait loop in irq_work_sync to improve
> CPU responsiveness and prevent starvation of other tasks.
>
> Previously, the busy-wait loop used cpu_relax() alone, which, while
> reducing power consumption, could still lead to excessive CPU
> monopolization in scenarios where IRQ work remains busy for extended
> periods. By incorporating cond_resched(), the CPU is periodically yielded
> to the scheduler, allowing other tasks to execute and enhancing overall
> system responsiveness.
>
> - while (irq_work_is_busy(work))
> + int retry_count = 0;
> +
> + while (irq_work_is_busy(work)) {
> cpu_relax();
> +
> + if (retry_count++ > 1000) {
> + cond_resched();
> + retry_count = 0;
> + }
Did you verify that all callers are actually calling from preemptible
context?
If so, then we should just get rid of the loop waiting completely and
use the rcu_wait mechanism which RT uses.
Thanks,
tglx