]> git.hungrycats.org Git - linux/commitdiff
[PATCH] One-shot support for epoll
authorAndrew Morton <akpm@osdl.org>
Tue, 20 Jan 2004 11:11:23 +0000 (03:11 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Tue, 20 Jan 2004 11:11:23 +0000 (03:11 -0800)
From: Davide Libenzi <davidel@xmailserver.org>

The attached patch implements the one-shot support for epoll.  Because of
the way epoll works (hooking f_op->poll()) the ET behavior is not really ET
because it might happen that, while data is still available to read (for
the EPOLLIN case), another chunk will become available triggering another
event.

While those conditions can be easily be handled in userspace, the absolute
triviality of the patch and the avoidance of user/kernel space switches and
f_op->poll() calls, make IMHO worth doing this inside epoll itself.

fs/eventpoll.c
include/linux/eventpoll.h

index 9c37105b8a5bfd692926ae39e2421795ffb46d62..128465c75aefd68243fad57c38516ecae9f2403b 100644 (file)
@@ -93,6 +93,8 @@
 #define EPI_SLAB_DEBUG 0
 #endif /* #if DEBUG_EPI != 0 */
 
+/* Epoll private bits inside the event mask */
+#define EP_PRIVATE_BITS (EPOLLONESHOT | EPOLLET)
 
 /* Maximum number of poll wake up nests we are allowing */
 #define EP_MAX_POLLWAKE_NESTS 4
@@ -1306,6 +1308,15 @@ static int ep_poll_callback(wait_queue_t *wait, unsigned mode, int sync)
 
        write_lock_irqsave(&ep->lock, flags);
 
+       /*
+        * If the event mask does not contain any poll(2) event, we consider the
+        * descriptor to be disabled. This condition is likely the effect of the
+        * EPOLLONESHOT bit that disables the descriptor when an event is received,
+        * until the next EPOLL_CTL_MOD will be issued.
+        */
+       if (!(epi->event.events & ~EP_PRIVATE_BITS))
+               goto is_disabled;
+
        /* If this file is already in the ready list we exit soon */
        if (EP_IS_LINKED(&epi->rdllink))
                goto is_linked;
@@ -1322,6 +1333,7 @@ is_linked:
        if (waitqueue_active(&ep->poll_wait))
                pwake++;
 
+is_disabled:
        write_unlock_irqrestore(&ep->lock, flags);
 
        /* We have to call this outside the lock */
@@ -1458,6 +1470,8 @@ static int ep_send_events(struct eventpoll *ep, struct list_head *txlist,
                                eventcnt += eventbuf;
                                eventbuf = 0;
                        }
+                       if (epi->event.events & EPOLLONESHOT)
+                               epi->event.events &= EP_PRIVATE_BITS;
                }
        }
 
index 1ece9f119220676312232a317b6656ec452c624e..136c6315e6af363cedf15888a3ac62c58ca1cb6b 100644 (file)
@@ -22,6 +22,9 @@
 #define EPOLL_CTL_DEL 2
 #define EPOLL_CTL_MOD 3
 
+/* Set the One Shot behaviour for the target file descriptor */
+#define EPOLLONESHOT (1 << 30)
+
 /* Set the Edge Triggered behaviour for the target file descriptor */
 #define EPOLLET (1 << 31)