Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Interrupt Handling in User Space

In Linux, what are the options for handling device interrupts in user space code rather than in kernel space?

like image 540
Brandon E Taylor Avatar asked Nov 02 '11 19:11

Brandon E Taylor


People also ask

How are interrupts handled in Linux?

An interrupt is simply a signal that the hardware can send when it wants the processor's attention. Linux handles interrupts in much the same way that it handles signals in user space. For the most part, a driver need only register a handler for its device's interrupts, and handle them properly when they arrive.

What is IRQ in Linux?

An IRQ is an interrupt request from a device. Currently they can come in over a pin, or over a packet. Several devices may be connected to the same pin thus sharing an IRQ. An IRQ number is a kernel identifier used to talk about a hardware interrupt source.

How do I disable IRQ in Linux?

local_irq_save(flags); This code disables all interrupts at the level of CPU IRQ interface.


2 Answers

Experience tells it is possible to write good and stable user-space drivers for almost any PCI adapter. It just requires some sophistication and a small proxying layer in the kernel. UIO is a step in that direction, but If you want to correctly handle interrupts in user-space then UIO might not be enough, for example if the device doesn't support the PCI-spec's interrupt disable bit which UIO relies on.

Notice that process wakeup latencies are a few microsecs so if your implementation requires very low latency then user-space might be a drag on it.

If I were to implement a user-space driver, I would reduce the kernel ISR to just a "disable & ack & wakeup-userpace" operation, handle the interrupt inside the waked-up process, and then re-enable the interrupt (of course, by writing to mapped PCI memory from the userspace process).

like image 179
Dan Aloni Avatar answered Oct 21 '22 00:10

Dan Aloni


There is Userspace I/O system (UIO), but handling should still be done in kernelspace. OTOH, if you just need to notice the interrupt, you don't need the kernel part.

like image 42
ninjalj Avatar answered Oct 21 '22 00:10

ninjalj