linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] irq: simplify irq_im_handle_irq()
@ 2025-07-19 21:18 Yury Norov
  2025-07-21 14:07 ` Thomas Gleixner
  2025-07-22  8:11 ` Jiri Slaby
  0 siblings, 2 replies; 6+ messages in thread
From: Yury Norov @ 2025-07-19 21:18 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel; +Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

Hi Thomas,

The function calls bitmap_empty() for potentially every bit in
work_ctx->pending, which makes a simple bitmap traverse O(N^2).
Fix it by switching to the dedicated for_each_set_bit().

While there, fix using atomic clear_bit() in a context where atomicity
cannot be guaranteed.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 kernel/irq/irq_sim.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
index ae4c9cbd1b4b..e05904da7e3d 100644
--- a/kernel/irq/irq_sim.c
+++ b/kernel/irq/irq_sim.c
@@ -128,15 +128,13 @@ static struct irq_chip irq_sim_irqchip = {
 static void irq_sim_handle_irq(struct irq_work *work)
 {
 	struct irq_sim_work_ctx *work_ctx;
-	unsigned int offset = 0;
+	unsigned int offset;
 	int irqnum;
 
 	work_ctx = container_of(work, struct irq_sim_work_ctx, work);
 
-	while (!bitmap_empty(work_ctx->pending, work_ctx->irq_count)) {
-		offset = find_next_bit(work_ctx->pending,
-				       work_ctx->irq_count, offset);
-		clear_bit(offset, work_ctx->pending);
+	for_each_set_bit(offset, work_ctx->pending, work_ctx->irq_count) {
+		__clear_bit(offset, work_ctx->pending);
 		irqnum = irq_find_mapping(work_ctx->domain, offset);
 		handle_simple_irq(irq_to_desc(irqnum));
 	}
-- 
2.43.0


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

end of thread, other threads:[~2025-07-31  8:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-19 21:18 [PATCH] irq: simplify irq_im_handle_irq() Yury Norov
2025-07-21 14:07 ` Thomas Gleixner
2025-07-21 14:27   ` Yury Norov
2025-07-21 15:44     ` Thomas Gleixner
2025-07-31  8:02       ` Jiri Slaby
2025-07-22  8:11 ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).