From: Kevyn-Alexandre P. <ka...@ro...> - 2011-04-11 18:38:35
|
Hi Dave, Markus, Instead of signals, inotify communicates with applications via a single file descriptor. This file descriptor is select-, poll-, epoll- and read-able. Simple and fast. Also, On Mon, 2011-04-11 at 00:32 +0100, Dave Hylands wrote: > Hi Markus, > > On Fri, Apr 8, 2011 at 9:14 PM, Markus Svilans <msv...@ae...> wrote: > > Kevyn, > > > > Can you share some code, showing how you would use inotify with a serial > > port, to detect when data is received on the port? Why is that approach > > better/simpler than using just plain select() or poll()? > > When using select or poll, there may be some latency since your thread > which does the select or poll may be off doing something else when the > new data arrive son the serial port. > > When you use inotify, I see 2 choices: 1 - you process the data in the > signal handler - which reduces the latency, The old version, called dnotify, interface to user space is signals. Not inotify the new version. > or 2 - you just set a flag > which causes the data to be processed later - which is essentially the > same as select/poll. A call to inotify_add_watch() adds a watch for the one or more events given by the bitmask mask on the file path to the inotify instance associated with the file descriptor fd. > inotify will still have slightly higher latency > than using a separate thread, since signal handlers are only called > when the user code does system calls. > > Using a separate thread gives the best responsiveness, but has a > slightly higher complexity to setup than using inotify or select/poll. > > Using a separate thread should also require less kernel-to-user transitions. > Blocking on a read() system call does not give nice responsiveness, unless your application is multi thread, You will need to add that new thread! Like Robert says: "Thankfully, the inotify file descriptor can be polled or selected on, allowing inotify to be multiplexed along with other I/O and optionally integrated into an application's mainloop." You can found advantages / disadvantages on internet about select / poll (Poll have been design to fix problem of select, but this one is sometimes even use for a reason of compatibility). Epoll is there to improve poll / select limitations, when hundreds of file descriptors have to be polled. Concerning the latency, it depends on your needs. Inotify events are queued asynchronously, in real time as the events happen. It's to you to decide how you will read these event if latency is a real issue and not early optimization. Best Regards, Kevyn-Alexandre Paré |