linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] epoll: use wrapper functions
@ 2010-05-06  1:57 Changli Gao
  2010-05-06 18:47 ` Davide Libenzi
  0 siblings, 1 reply; 4+ messages in thread
From: Changli Gao @ 2010-05-06  1:57 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexander Viro, Eric W. Biederman, Davide Libenzi, Roland Dreier,
	Stefan Richter, Ingo Molnar, Peter Zijlstra, Takashi Iwai,
	David Howells, linux-fsdevel, linux-kernel, Changli Gao

use wrapper functions.

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

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
 fs/eventpoll.c       |    5 ++---
 include/linux/wait.h |   15 +++++++++++++--
 2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index bd056a5..8137f6e 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1140,8 +1140,7 @@ retry:
 		 * ep_poll_callback() when events will become available.
 		 */
 		init_waitqueue_entry(&wait, current);
-		wait.flags |= WQ_FLAG_EXCLUSIVE;
-		__add_wait_queue(&ep->wq, &wait);
+		add_wait_queue_head_exclusive_locked(&ep->wq, &wait);
 
 		for (;;) {
 			/*
@@ -1161,7 +1160,7 @@ retry:
 			jtimeout = schedule_timeout(jtimeout);
 			spin_lock_irqsave(&ep->lock, flags);
 		}
-		__remove_wait_queue(&ep->wq, &wait);
+		remove_wait_queue_locked(&ep->wq, &wait);
 
 		set_current_state(TASK_RUNNING);
 	}
diff --git a/include/linux/wait.h b/include/linux/wait.h
index a48e16b..de2566d 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -407,17 +407,28 @@ do {									\
  * Must be called with the spinlock in the wait_queue_head_t held.
  */
 static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
-						   wait_queue_t * wait)
+						   wait_queue_t *wait)
 {
 	wait->flags |= WQ_FLAG_EXCLUSIVE;
 	__add_wait_queue_tail(q,  wait);
 }
 
 /*
+ * Must be called with the spinlock in the wait_queue_head_t held, and
+ * q must be for exclusive wait only.
+ */
+static inline void add_wait_queue_head_exclusive_locked(wait_queue_head_t *q,
+							wait_queue_t *wait)
+{
+	wait->flags |= WQ_FLAG_EXCLUSIVE;
+	__add_wait_queue(q,  wait);
+}
+
+/*
  * Must be called with the spinlock in the wait_queue_head_t held.
  */
 static inline void remove_wait_queue_locked(wait_queue_head_t *q,
-					    wait_queue_t * wait)
+					    wait_queue_t *wait)
 {
 	__remove_wait_queue(q,  wait);
 }

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: use wrapper functions
  2010-05-06  1:57 [PATCH] epoll: use wrapper functions Changli Gao
@ 2010-05-06 18:47 ` Davide Libenzi
  2010-05-06 18:51   ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Davide Libenzi @ 2010-05-06 18:47 UTC (permalink / raw)
  To: Changli Gao
  Cc: Andrew Morton, Alexander Viro, Eric W. Biederman, Roland Dreier,
	Stefan Richter, Ingo Molnar, Peter Zijlstra, Takashi Iwai,
	David Howells, linux-fsdevel, Linux Kernel Mailing List

On Thu, 6 May 2010, Changli Gao wrote:

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

Since we already have __add_wait_queue(), __add_wait_queue_tail() and 
__remove_wait_queue() (which all means "locked"), and while I agree in 
having the exclusive-add wrapped into a function, I much better prefer a:

static inline void __add_wait_queue_excl(wait_queue_head_t *head, 
					 wait_queue_t *new)
{
	new->flags |= WQ_FLAG_EXCLUSIVE;
	__add_wait_queue(head, new);
}

The patch you posted introduces a different naming, which leaves all the 
other __*() untouched, and wraps the already one-liner __remove_wait_queue() 
with yet another one-liner.





> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> ----
>  fs/eventpoll.c       |    5 ++---
>  include/linux/wait.h |   15 +++++++++++++--
>  2 files changed, 15 insertions(+), 5 deletions(-)
> diff --git a/fs/eventpoll.c b/fs/eventpoll.c
> index bd056a5..8137f6e 100644
> --- a/fs/eventpoll.c
> +++ b/fs/eventpoll.c
> @@ -1140,8 +1140,7 @@ retry:
>  		 * ep_poll_callback() when events will become available.
>  		 */
>  		init_waitqueue_entry(&wait, current);
> -		wait.flags |= WQ_FLAG_EXCLUSIVE;
> -		__add_wait_queue(&ep->wq, &wait);
> +		add_wait_queue_head_exclusive_locked(&ep->wq, &wait);
>  
>  		for (;;) {
>  			/*
> @@ -1161,7 +1160,7 @@ retry:
>  			jtimeout = schedule_timeout(jtimeout);
>  			spin_lock_irqsave(&ep->lock, flags);
>  		}
> -		__remove_wait_queue(&ep->wq, &wait);
> +		remove_wait_queue_locked(&ep->wq, &wait);
>  
>  		set_current_state(TASK_RUNNING);
>  	}
> diff --git a/include/linux/wait.h b/include/linux/wait.h
> index a48e16b..de2566d 100644
> --- a/include/linux/wait.h
> +++ b/include/linux/wait.h
> @@ -407,17 +407,28 @@ do {									\
>   * Must be called with the spinlock in the wait_queue_head_t held.
>   */
>  static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
> -						   wait_queue_t * wait)
> +						   wait_queue_t *wait)
>  {
>  	wait->flags |= WQ_FLAG_EXCLUSIVE;
>  	__add_wait_queue_tail(q,  wait);
>  }
>  
>  /*
> + * Must be called with the spinlock in the wait_queue_head_t held, and
> + * q must be for exclusive wait only.
> + */
> +static inline void add_wait_queue_head_exclusive_locked(wait_queue_head_t *q,
> +							wait_queue_t *wait)
> +{
> +	wait->flags |= WQ_FLAG_EXCLUSIVE;
> +	__add_wait_queue(q,  wait);
> +}
> +
> +/*
>   * Must be called with the spinlock in the wait_queue_head_t held.
>   */
>  static inline void remove_wait_queue_locked(wait_queue_head_t *q,
> -					    wait_queue_t * wait)
> +					    wait_queue_t *wait)
>  {
>  	__remove_wait_queue(q,  wait);
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


- Davide



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: use wrapper functions
  2010-05-06 18:47 ` Davide Libenzi
@ 2010-05-06 18:51   ` Peter Zijlstra
  2010-05-07  2:48     ` Changli Gao
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2010-05-06 18:51 UTC (permalink / raw)
  To: Davide Libenzi
  Cc: Changli Gao, Andrew Morton, Alexander Viro, Eric W. Biederman,
	Roland Dreier, Stefan Richter, Ingo Molnar, Takashi Iwai,
	David Howells, linux-fsdevel, Linux Kernel Mailing List

On Thu, 2010-05-06 at 11:47 -0700, Davide Libenzi wrote:
> Since we already have __add_wait_queue(), __add_wait_queue_tail() and 
> __remove_wait_queue() (which all means "locked"), and while I agree in 
> having the exclusive-add wrapped into a function, I much better prefer a:
> 
> static inline void __add_wait_queue_excl(wait_queue_head_t *head, 
>                                          wait_queue_t *new)
> {
>         new->flags |= WQ_FLAG_EXCLUSIVE;
>         __add_wait_queue(head, new);
> }
> 
> The patch you posted introduces a different naming, which leaves all the 
> other __*() untouched, and wraps the already one-liner __remove_wait_queue() 
> with yet another one-liner. 

I concur, I always get confused by the _locked postfix (and its more
typing). Also, it goes against the lock data not code paradigm.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: use wrapper functions
  2010-05-06 18:51   ` Peter Zijlstra
@ 2010-05-07  2:48     ` Changli Gao
  0 siblings, 0 replies; 4+ messages in thread
From: Changli Gao @ 2010-05-07  2:48 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Davide Libenzi, Andrew Morton, Alexander Viro, Eric W. Biederman,
	Roland Dreier, Stefan Richter, Ingo Molnar, Takashi Iwai,
	David Howells, linux-fsdevel, Linux Kernel Mailing List

On Fri, May 7, 2010 at 2:51 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, 2010-05-06 at 11:47 -0700, Davide Libenzi wrote:
>> Since we already have __add_wait_queue(), __add_wait_queue_tail() and
>> __remove_wait_queue() (which all means "locked"), and while I agree in
>> having the exclusive-add wrapped into a function, I much better prefer a:
>>
>> static inline void __add_wait_queue_excl(wait_queue_head_t *head,
>>                                          wait_queue_t *new)
>> {
>>         new->flags |= WQ_FLAG_EXCLUSIVE;
>>         __add_wait_queue(head, new);
>> }
>>
>> The patch you posted introduces a different naming, which leaves all the
>> other __*() untouched, and wraps the already one-liner __remove_wait_queue()
>> with yet another one-liner.
>
> I concur, I always get confused by the _locked postfix (and its more
> typing). Also, it goes against the lock data not code paradigm.
>
>

I greped all the code, and found that
add_wait_queue_head_exclusive_locked() and remove_wait_queue_locked()
aren't used. It seems that no users like these APIs. So I will remove
these two APIs, and add __add_wait_queue_excl() instead. Thanks.


-- 
Regards,
Changli Gao(xiaosuo@gmail.com)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-05-07  2:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-06  1:57 [PATCH] epoll: use wrapper functions Changli Gao
2010-05-06 18:47 ` Davide Libenzi
2010-05-06 18:51   ` Peter Zijlstra
2010-05-07  2:48     ` Changli Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).