linux - Event notification from kernel space to user space -
how notify user space application whenever event occurs in kernel space?
a hardware generates interrupt when data arrives @ gpio. data copied kernel buffer. @ point, want driver notify application can call read
function copy data form kernel buffer user space buffer.
i thought of using epoll
method, epoll
indicates whether device ready read from. want that, epoll
indicate whenever kernel buffer full.
and, there way modify behavior of poll_wait()
function in driver?
(had replied in chat session seems should in answer putting here more detail.)
what poll_wait add driver list of file descriptors being waited user space program. pattern is:
- user program calls poll/select/epoll_ctl
- core kernel calls driver's poll entry point
- driver calls poll_wait add wait queue list of waitqueues (unless gpio data readable, indicate via return value)
- later, when device interrupts, call wake_up on wait queue, unblocks process if it's (still) waiting in poll/select call
- user-mode program wakes up, calls read obtain data
iow, poll_wait doesn't sleep (or block); adds device list of programs might wake process later. sleep done in core kernel (inside select system call, example). way, user program can wait on number of devices @ once using select.
if user-space program doesn't have else while waiting, can have user-program call read, , have driver set wait queue , call wait_event_interruptible (or 1 of other wait_event_* variants). block process until interrupt handler calls wake_up; @ time copy kernel buffer user buffer.
or support both methods. typically if support select method, check o_nonblock file flag in read function user code has option not block in read.
yes, isrs can call wake_up. it's common pattern device i/o: wait/block in "process context", wake-up in "interrupt context", complete i/o after returning process context.
btw, driver point of view, using select, poll or epoll typically same. user point of view, using select or poll easier. it's "one shot" deal: "here set of file descriptors; block until 1 of them ready read (or write etc) or until timeout".
whereas epoll, first create epoll descriptor, add i/o file descriptors individually. "wait" call specifies single epoll descriptor. if have large number of file descriptors wait on, don't have specify of them in each system call leads lower system call overhead on each epoll call.
Comments
Post a Comment