Question on poll interface in Linux

From: sainath grandhi
Date: Tue Apr 27 2021 - 00:21:21 EST


Hello,
Looking for some guidance on using poll interfaces in Linux
We have a scenario where userspace has to wait on an interrupt from
the device. Inclined towards using poll interface on a file descriptor
in the userspace. When the device driver executes the interrupt
handler, it notifies the file descriptor and wakes up the Userspace
thread. Userspace thread reads the interrupt reason and handles the
reason.

I am afraid we have a scenario where we could lose notification from
kernel to Userspace thread if an interrupt happens during the time
window between 2 and 3 steps in the sequence below

1. Userspace thread is woken up
2. Userspace thread read the interrupt reason and handle the interrupt reason
3. Userspace thread goes back to blocked state again for next notification

Brief search on the Linux source code tells me that the kernel notify
function will wake up only a sleeping thread. So if the new interrupt
happens between steps 2 and 3, and the state of Userspace thread is
active, the kernel would not "notify" the Userspace thread and the
Userspace processing of new interrupt is missed.

In such scenarios, what is the best kernel-user notification interface
to use? Please advise