Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Interrupt vs. Polling

I am developing a system with a DSP and an ARM. On the ARM there is a linux OS. I have a DSP sending data to the ARM (Linux) - In the Linux there is a kernel module which read the data received from the DSP. The kernel module is waking up to read the data, using an hardware interrupt between the DSP to the ARM.

I want to write a user space app, that will read the data from the kernel space (The kernel module) each time there's a new data arrived from the DSP.
The question is:

What is better approach to do that, a software interrupt from the kernel to the user-space or polling from the user-space (reading a known memory address with the kernel) every 10ms..?

Knowing that:

  • The data from the DSP to the kernel must arrive in very short time - 100us.
  • The data from the kernel to the user-space can take 10ms to 30ms.
  • The data that is being read is regarded small - around 100 bytes.
like image 878
Gold Fish Avatar asked Mar 26 '14 13:03

Gold Fish


People also ask

What is the difference between polling and interrupt?

The main difference between interrupt and polling is that, in the case of an interrupt, the system informs the CPU that it needs attention, while talking about polling, the CPU constantly inspects the status of the system to find whether it needs attention.

Is interrupt better than polling?

Advantages of Interrupt over Polling. The first advantage is- the performance of microcontroller is far better in Interrupt method than Polling Method. In polling method, the microcontroller is checking continuously whether the device is ready or not, but the chances of data loss are greater in Polling than Interrupt.

Is polling a type of interrupt?

In a computer, a polled interrupt is a specific type of I/O interrupt that notifies the part of the computer containing the I/O interface that a device is ready to be read or otherwise handled but does not indicate which device.

Are keyboards polling or interrupt?

The bus uses USB Periodic Transactions called "Interrupt Pipe" to get keyboard data, which is formally a form of polling.


1 Answers

I would create a device and have the userland program block on read. No need to wait 10ms in between, this is handled efficiently by blocking.

Polling in a sense of using poll (yes, I understood that's not what you meant) would work fine, but there is no reason to call two functions (first poll and then read) when one function can do it anyway. No need to do it every 10ms, you can immediately call poll again after having processed what you got from your last read.

Polling in a sense of checking a known memory location every 10ms is not advisable. Not only is this an ugly hack and more complicated than you think (you will have to map the page containing that memory location to user space), and a form of busy waiting which needlessly consumes CPU, it also has an average latency of 5ms and a worst case latency of 10ms, which is entirely unnecessary. Average and worst case latency of read is approximately zero (well, not quite, but nearly so... it's as fast as waking a blocked task goes).

Interrupts (i.e. signals) are very efficient but make the program a lot more complicated/contorted compared to simply reading and blocking (have to write a signal handler, may not use certain functions in handlers, must communicate to main app, etc.). While technically a good solution, I would advise against them because a program needs not be more complicated than necessary.

like image 88
Damon Avatar answered Sep 29 '22 15:09

Damon