Using kevent for signalling user app from kernel

John Baldwin jhb at freebsd.org
Thu Dec 22 13:07:41 UTC 2011


On Thursday, December 22, 2011 1:03:31 am Sushanth Rai wrote:
> Hi,
> 
> I'm planning to use kqueue/kevent mechanism to notify a user application 
from the kernel. Basically I set up a file descriptor for read event from the 
user application by calling kevent(). Now, I would like to wake-up the process 
from within the kernel. The wake-up will happen due to one of the internal 
events (not due to data being available to read). I have access to the process 
structure and vnode corresponding to file descriptor. Is there a mechanism 
available from the kernel to trigger a wakeup and clear the kernel break 
notify message ?

In the kernel you'd typically use KNOTE() to signal that an event should be 
signalled.  However, that will only post the event if the file is now 
readable.  I think you have a couple of options:

 1) You can send a signal to the process which will interrupt the kevent.

 2) You can add a new filter type and use it with your file descriptor to
    signal your special side-band events.  The userland app will have to add
    both an EVFILT_READ event and and event for your custom filter type.
    You can then use KNOTE when your side-band event happens and your custom
    filter's f_event hook can signal the event in that case.

-- 
John Baldwin


More information about the freebsd-hackers mailing list