Is in_irq () reliable?

Unreliable Linux kernel hacking guide claims

You can say that you are in a hardware interrupt because in_irq () returns true.
Warning . Remember that this will lead to a false positive if interrupts are disabled (see below).

Is it really that it in_irq()can return a nonzero value not in the hardirq context in Linux kernels 2.6.32 or later on x86?

In my experiments with the kernel 2.6.32 (Debian 6) and 3.4 (OpenSUSE 12.1), I in_irq()always returned 0 when called from a process context, even if it was called between local_irq_disable()and local_irq_enable(). The results were the same when I used spinlock functions that forbid interrupts instead local_irq*.

From the kernel source, I currently do not see how it in_irq()can return a false result. Can anyone clarify this?

EDIT: I also tried using the API *_irqsave()and *_irq()spinlock API, as well as local_irq_save()/ local_irq_restore(), the results were the same, i.e. in_irq()returned 0 when interrupts were disabled. Disabling interrupts explicitly using clithe x86 machine instruction also did not force in_irq () to return a nonzero value.

+5
source share
1 answer

in_irq()is a shell that looks at some bits inpreempt_count , which is an int in the structure thread_infoand a value of 0 means that it did not get ahead of time, therefore it was not in irq.

local_irq_disable() , spin_lock_irqsave() , . , -, ? , , preempt_count.

: , , .

+3

All Articles