aboutsummaryrefslogtreecommitdiffstats
path: root/fs/eventpoll.c
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2012-03-23 18:02:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 19:58:38 -0400
commit02edc6fc4d5feb3357aa44ba521e5504b4ff0b60 (patch)
tree20c5f006dee327e42335b4f020452d11f26b78b7 /fs/eventpoll.c
parent626cf236608505d376e4799adb4f7eb00a8594af (diff)
epoll: comment the funky #ifdef
Looking for a bug in -rt, I stumbled across this code here from: commit 2dfa4eeab0fc ("epoll keyed wakeups: teach epoll about hints coming with the wakeup key"), specifically: #ifdef CONFIG_DEBUG_LOCK_ALLOC static inline void ep_wake_up_nested(wait_queue_head_t *wqueue, unsigned long events, int subclass) { unsigned long flags; spin_lock_irqsave_nested(&wqueue->lock, flags, subclass); wake_up_locked_poll(wqueue, events); spin_unlock_irqrestore(&wqueue->lock, flags); } #else static inline void ep_wake_up_nested(wait_queue_head_t *wqueue, unsigned long events, int subclass) { wake_up_poll(wqueue, events); } #endif You change the function of ep_wake_up_nested() depending on whether CONFIG_DEBUG_LOCK_ALLOC is set or not. This looks awfully suspicious, and there's no comment to explain why. I initially thought that this was trying to fool lockdep, and hiding a real bug. Investigating it, I found the creation of wake_up_nested() (which no longer exists) but was created for the sole purpose of epoll and its strange wake ups, as explained in commit 0ccf831cbee9 ("lockdep: annotate epoll") Although the commit message says "annotate epoll" the change log is much better at explaining what is happening than what is in the actual code. Thus a comment is really necessary here. And to save the time of other developers from having to go trudging through the git logs trying to figure out why this code exists. I took parts of the change log and placed it into a comment above the affected code. This will make the description of what is happening more visible to new developers that have to look at this code for the first time. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Cc: Davide Libenzi <davidel@xmailserver.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: Ingo Molnar <mingo@elte.hu> Cc: David Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r--fs/eventpoll.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index ca300071e79c..23c220774d1b 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -427,6 +427,31 @@ out_unlock:
427 return error; 427 return error;
428} 428}
429 429
430/*
431 * As described in commit 0ccf831cb lockdep: annotate epoll
432 * the use of wait queues used by epoll is done in a very controlled
433 * manner. Wake ups can nest inside each other, but are never done
434 * with the same locking. For example:
435 *
436 * dfd = socket(...);
437 * efd1 = epoll_create();
438 * efd2 = epoll_create();
439 * epoll_ctl(efd1, EPOLL_CTL_ADD, dfd, ...);
440 * epoll_ctl(efd2, EPOLL_CTL_ADD, efd1, ...);
441 *
442 * When a packet arrives to the device underneath "dfd", the net code will
443 * issue a wake_up() on its poll wake list. Epoll (efd1) has installed a
444 * callback wakeup entry on that queue, and the wake_up() performed by the
445 * "dfd" net code will end up in ep_poll_callback(). At this point epoll
446 * (efd1) notices that it may have some event ready, so it needs to wake up
447 * the waiters on its poll wait list (efd2). So it calls ep_poll_safewake()
448 * that ends up in another wake_up(), after having checked about the
449 * recursion constraints. That are, no more than EP_MAX_POLLWAKE_NESTS, to
450 * avoid stack blasting.
451 *
452 * When CONFIG_DEBUG_LOCK_ALLOC is enabled, make sure lockdep can handle
453 * this special case of epoll.
454 */
430#ifdef CONFIG_DEBUG_LOCK_ALLOC 455#ifdef CONFIG_DEBUG_LOCK_ALLOC
431static inline void ep_wake_up_nested(wait_queue_head_t *wqueue, 456static inline void ep_wake_up_nested(wait_queue_head_t *wqueue,
432 unsigned long events, int subclass) 457 unsigned long events, int subclass)