Skip to content

Conversation

@lrh2000
Copy link

@lrh2000 lrh2000 commented Jan 11, 2026

__ndelay() spins until the timeout occurs. If interrupts come concurrently from another host thread, an irq_status bit will be set, but the handler will not be called during the spin. This behavior is unreasonable. At least, it differs from that of real Linux running on a bare-mental machine.

A driver may expect the device to raise an IRQ within a few microseconds, so it tries to spin and wait for it. This does not work without the commit.

Calling cpu_relax() explicitly can cause the handlers to fire. This is also a valid use of cpu_relax() because the CPU is spinning.


static inline void cpu_relax(void)
{
unsigned long flags;
/* since this is usually called in a tight loop waiting for some
* external condition (e.g. jiffies) lets run interrupts now to allow
* the external condition to propagate */
local_irq_save(flags);
local_irq_restore(flags);
}

__ndelay() spins until the timeout occurs. If interrupts come
concurrently from another host thread, an irq_status bit will be set,
but the handler will not be called during the spin. This behavior is
unreasonable. At least, it differs from that of real Linux running on a
bare-mental machine.

A driver may expect the device to raise an IRQ within a few
microseconds, so it tries to spin and wait for it. This does not work
without the commit.

Calling cpu_relax() explicitly can cause the handlers to fire. This is
also a valid use of cpu_relax() because the CPU is spinning.

Signed-off-by: Ruihan Li <[email protected]>
Copy link
Member

@tavip tavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @lrh2000!

Copy link

@ddiss ddiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Curious to see how this affects benchmarks.

@lrh2000
Copy link
Author

lrh2000 commented Jan 13, 2026

Curious to see how this affects benchmarks.

Does any benchmark have spinning sleep as its hot path? I think that's unusual. A driver sometimes spins to wait for interrupts, but that shouldn't be common. It especially shouldn't occur on a hot path.


Meanwhile, thanks for your quick reviews @tavip @ddiss!

@tavip
Copy link
Member

tavip commented Jan 13, 2026

Curious to see how this affects benchmarks.

Does any benchmark have spinning sleep as its hot path? I think that's unusual. A driver sometimes spins to wait for interrupts, but that shouldn't be common. It especially shouldn't occur on a hot path.

I agree. @ddiss do you something specific in mind?

@ddiss
Copy link

ddiss commented Jan 13, 2026

Curious to see how this affects benchmarks.

Does any benchmark have spinning sleep as its hot path? I think that's unusual. A driver sometimes spins to wait for interrupts, but that shouldn't be common. It especially shouldn't occur on a hot path.

I agree. @ddiss do you something specific in mind?

Nothing specific. I was vaguely thinking of network and storage throttling / back-off, but I don't see any such callers.

@thehajime
Copy link
Member

LGTM, thanks !

@tavip tavip merged commit f6d6f7d into lkl:master Jan 15, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants