Skip to content

Commit a93d2f1

Browse files
xiaosuoIngo Molnar
authored and
Ingo Molnar
committed
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>
1 parent af507ae commit a93d2f1

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

fs/eventpoll.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
11401140
* ep_poll_callback() when events will become available.
11411141
*/
11421142
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);
11451144

11461145
for (;;) {
11471146
/*

include/linux/wait.h

+15-20
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,26 @@ static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
127127
/*
128128
* Used for wake-one threads:
129129
*/
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+
130137
static inline void __add_wait_queue_tail(wait_queue_head_t *head,
131-
wait_queue_t *new)
138+
wait_queue_t *new)
132139
{
133140
list_add_tail(&new->task_list, &head->task_list);
134141
}
135142

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);
148+
}
149+
136150
static inline void __remove_wait_queue(wait_queue_head_t *head,
137151
wait_queue_t *old)
138152
{
@@ -403,25 +417,6 @@ do { \
403417
__ret; \
404418
})
405419

406-
/*
407-
* Must be called with the spinlock in the wait_queue_head_t held.
408-
*/
409-
static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
410-
wait_queue_t * wait)
411-
{
412-
wait->flags |= WQ_FLAG_EXCLUSIVE;
413-
__add_wait_queue_tail(q, wait);
414-
}
415-
416-
/*
417-
* Must be called with the spinlock in the wait_queue_head_t held.
418-
*/
419-
static inline void remove_wait_queue_locked(wait_queue_head_t *q,
420-
wait_queue_t * wait)
421-
{
422-
__remove_wait_queue(q, wait);
423-
}
424-
425420
/*
426421
* These are the old interfaces to sleep waiting for an event.
427422
* They are racy. DO NOT use them, use the wait_event* interfaces above.

kernel/cgroup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
30103010
unsigned long flags = (unsigned long)key;
30113011

30123012
if (flags & POLLHUP) {
3013-
remove_wait_queue_locked(event->wqh, &event->wait);
3013+
__remove_wait_queue(event->wqh, &event->wait);
30143014
spin_lock(&cgrp->event_list_lock);
30153015
list_del(&event->list);
30163016
spin_unlock(&cgrp->event_list_lock);

kernel/sched.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -3983,8 +3983,7 @@ do_wait_for_common(struct completion *x, long timeout, int state)
39833983
if (!x->done) {
39843984
DECLARE_WAITQUEUE(wait, current);
39853985

3986-
wait.flags |= WQ_FLAG_EXCLUSIVE;
3987-
__add_wait_queue_tail(&x->wait, &wait);
3986+
__add_wait_queue_tail_exclusive(&x->wait, &wait);
39883987
do {
39893988
if (signal_pending_state(state, current)) {
39903989
timeout = -ERESTARTSYS;

0 commit comments

Comments
 (0)