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 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.
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.
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.
The bus uses USB Periodic Transactions called "Interrupt Pipe" to get keyboard data, which is formally a form of polling.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With