As part as an embedded project in a Zynq SoC, I was following this guide to create a userspace interrupt in Linux: https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html
I was successful in getting everything up and running. In summary I was able to create a userspace device, generate interrupts from it, and read back the interrupts from my application program running on the target (written in C).
This is quite different from writing an ISR in a bare metal application. In the bare metal application I was able to create an interrupt handler and then connect that to the GIC and the interrupt ID. Then my program could do whatever, for example, it could be in an infinite while loop printing some strings and whenever that interrupt occurred, the interrupt handler code would get executed before going back to the while loop.
With the Linux application, as the guide showed, I am using a blocking read inside a while loop:
nb = read(fd, &info, sizeof(info));
if (nb == (ssize_t)sizeof(info)) {
/* Do something in response to the interrupt. */
printf("Interrupt #%u!n", info);
}
This seems like it defeats the purpose of using an interrupt, I need to constantly check if an interrupt has arrived and cannot do anything else in my program. To me, this seems like a flaw with userspace interrupt handling which I doubt was not thought about.
So my question is: what am I missing here? And if I am thinking about it in the wrong way, what is the correct way to make efficient use of userspace interrupts as a more traditional interrupts that do not require constant polling?
I am currently using the blocking read code inside a while loop, which gives me the functionality I am looking for regarding to this specific interrupt handling. However, this is not an ideal solution because I am stuck always polling for the interrupt.
There are other functions available like select() and poll(), but they still do not solve my question.
1