Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched, wait: Use wrapper functions

epoll should not touch flags in wait_queue_t. This patch introduces a new
function __add_wait_queue_exclusive(), for the users, who use wait queue as a
LIFO queue.

__add_wait_queue_tail_exclusive() is introduced too instead of
add_wait_queue_exclusive_locked(). remove_wait_queue_locked() is removed, as
it is a duplicate of __remove_wait_queue(), disliked by users, and with less
users.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Paul Menage <menage@google.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: <containers@lists.linux-foundation.org>
LKML-Reference: <1273214006-2979-1-git-send-email-xiaosuo@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Changli Gao and committed by
Ingo Molnar
a93d2f17 af507ae8

+18 -25
+1 -2
fs/eventpoll.c
··· 1140 1140 * ep_poll_callback() when events will become available. 1141 1141 */ 1142 1142 init_waitqueue_entry(&wait, current); 1143 - wait.flags |= WQ_FLAG_EXCLUSIVE; 1144 - __add_wait_queue(&ep->wq, &wait); 1143 + __add_wait_queue_exclusive(&ep->wq, &wait); 1145 1144 1146 1145 for (;;) { 1147 1146 /*
+15 -20
include/linux/wait.h
··· 127 127 /* 128 128 * Used for wake-one threads: 129 129 */ 130 + static inline void __add_wait_queue_exclusive(wait_queue_head_t *q, 131 + wait_queue_t *wait) 132 + { 133 + wait->flags |= WQ_FLAG_EXCLUSIVE; 134 + __add_wait_queue(q, wait); 135 + } 136 + 130 137 static inline void __add_wait_queue_tail(wait_queue_head_t *head, 131 - wait_queue_t *new) 138 + wait_queue_t *new) 132 139 { 133 140 list_add_tail(&new->task_list, &head->task_list); 141 + } 142 + 143 + static inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q, 144 + wait_queue_t *wait) 145 + { 146 + wait->flags |= WQ_FLAG_EXCLUSIVE; 147 + __add_wait_queue_tail(q, wait); 134 148 } 135 149 136 150 static inline void __remove_wait_queue(wait_queue_head_t *head, ··· 416 402 __wait_event_killable(wq, condition, __ret); \ 417 403 __ret; \ 418 404 }) 419 - 420 - /* 421 - * Must be called with the spinlock in the wait_queue_head_t held. 422 - */ 423 - static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q, 424 - wait_queue_t * wait) 425 - { 426 - wait->flags |= WQ_FLAG_EXCLUSIVE; 427 - __add_wait_queue_tail(q, wait); 428 - } 429 - 430 - /* 431 - * Must be called with the spinlock in the wait_queue_head_t held. 432 - */ 433 - static inline void remove_wait_queue_locked(wait_queue_head_t *q, 434 - wait_queue_t * wait) 435 - { 436 - __remove_wait_queue(q, wait); 437 - } 438 405 439 406 /* 440 407 * These are the old interfaces to sleep waiting for an event.
+1 -1
kernel/cgroup.c
··· 3010 3010 unsigned long flags = (unsigned long)key; 3011 3011 3012 3012 if (flags & POLLHUP) { 3013 - remove_wait_queue_locked(event->wqh, &event->wait); 3013 + __remove_wait_queue(event->wqh, &event->wait); 3014 3014 spin_lock(&cgrp->event_list_lock); 3015 3015 list_del(&event->list); 3016 3016 spin_unlock(&cgrp->event_list_lock);
+1 -2
kernel/sched.c
··· 3983 3983 if (!x->done) { 3984 3984 DECLARE_WAITQUEUE(wait, current); 3985 3985 3986 - wait.flags |= WQ_FLAG_EXCLUSIVE; 3987 - __add_wait_queue_tail(&x->wait, &wait); 3986 + __add_wait_queue_tail_exclusive(&x->wait, &wait); 3988 3987 do { 3989 3988 if (signal_pending_state(state, current)) { 3990 3989 timeout = -ERESTARTSYS;