Re: [PATCH] irq_work: Improve CPU Responsiveness in irq_work_sync with cond_resched()
From: Steven Davis
Date: Thu Sep 19 2024 - 11:25:57 EST
On Thu, 19 Sep 2024 at 15:54:21 +0200, Thomas Gleixner wrote:
> 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?
Yes, I reviewed the 11 calls to irq_work_sync, and they all seem to
occur in preemptible contexts.
> If so, then we should just get rid of the loop waiting completely and
> use the rcu_wait mechanism which RT uses.
Will do that soon. Thanks for the suggestion.
Steven