public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irq_work: Improve CPU Responsiveness in irq_work_sync with cond_resched()
@ 2024-09-18 15:23 Steven Davis
  2024-09-19 13:54 ` Thomas Gleixner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Steven Davis @ 2024-09-18 15:23 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Steven Davis

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.

Signed-off-by: Steven Davis <goldside000@outlook.com>
---
 kernel/irq_work.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 2f4fb336dda1..bdc478979ee6 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -295,9 +295,17 @@ void irq_work_sync(struct irq_work *work)
 		return;
 	}
 
-	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;
+	}
 }
+
 EXPORT_SYMBOL_GPL(irq_work_sync);
 
 static void run_irq_workd(unsigned int cpu)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-21 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-18 15:23 [PATCH] irq_work: Improve CPU Responsiveness in irq_work_sync with cond_resched() Steven Davis
2024-09-19 13:54 ` Thomas Gleixner
2024-09-19 15:25   ` Steven Davis
2024-09-21 14:42 ` kernel test robot
2024-09-21 15:13 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox