[RFC][PATCH 1/5] introduce poll_wait_exclusive() new API

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-mm@...>, <linux-kernel@...>
Cc: <kosaki.motohiro@...>, Marcelo Tosatti <marcelo@...>, Daniel Spang <daniel.spang@...>, Rik van Riel <riel@...>, Andrew Morton <akpm@...>
Date: Monday, January 14, 2008 - 8:59 pm

There are 2 way of adding item to wait_queue,
  1. add_wait_queue()
  2. add_wait_queue_exclusive()
and add_wait_queue_exclusive() is very useful API.

unforunately, poll_wait_exclusive() against poll_wait() doesn't exist. 
it means there is no way that wake up only 1 process where polled.
wake_up() is wake up all sleeping process by poll_wait(), not 1 process.

this patch introduce poll_wait_exclusive() new API for allow wake up only 1 process.

<example of usage>
unsigned int kosaki_poll(struct file *file,
		         struct poll_table_struct *wait)
{
	poll_wait_exclusive(file, &kosaki_wait_queue, wait);
	if (data_exist)
		return POLLIN | POLLRDNORM;
	return 0;
}


Signed-off-by: Marcelo Tosatti <marcelo@kvack.org>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

---
 fs/eventpoll.c       |    7 +++++--
 fs/select.c          |    9 ++++++---
 include/linux/poll.h |   11 +++++++++--
 3 files changed, 20 insertions(+), 7 deletions(-)



Index: linux-2.6.24-rc6-memnotify/fs/eventpoll.c
===================================================================
--- linux-2.6.24-rc6-memnotify.orig/fs/eventpoll.c	2007-12-30 02:08:58.000000000 +0900
+++ linux-2.6.24-rc6-memnotify/fs/eventpoll.c	2007-12-30 07:10:46.000000000 +0900
@@ -676,7 +676,7 @@ out_unlock:
  * target file wakeup lists.
  */
 static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead,
-				 poll_table *pt)
+				 poll_table *pt, int exclusive)
 {
 	struct epitem *epi = ep_item_from_epqueue(pt);
 	struct eppoll_entry *pwq;
@@ -685,7 +685,10 @@ static void ep_ptable_queue_proc(struct 
 		init_waitqueue_func_entry(&pwq->wait, ep_poll_callback);
 		pwq->whead = whead;
 		pwq->base = epi;
-		add_wait_queue(whead, &pwq->wait);
+		if (exclusive)
+			add_wait_queue_exclusive(whead, &pwq->wait);
+		else
+			add_wait_queue(whead, &pwq->wait);
 		list_add_tail(&pwq->llink, &epi->pwqlist);
 		epi->nwait++;
 	} else {
Index: linux-2.6.24-rc6-memnotify/fs/select.c
===================================================================
--- linux-2.6.24-rc6-memnotify.orig/fs/select.c	2007-12-30 02:09:00.000000000 +0900
+++ linux-2.6.24-rc6-memnotify/fs/select.c	2007-12-30 02:34:05.000000000 +0900
@@ -48,7 +48,7 @@ struct poll_table_page {
  * poll table.
  */
 static void __pollwait(struct file *filp, wait_queue_head_t *wait_address,
-		       poll_table *p);
+		       poll_table *p, int exclusive);
 
 void poll_initwait(struct poll_wqueues *pwq)
 {
@@ -117,7 +117,7 @@ static struct poll_table_entry *poll_get
 
 /* Add a new entry */
 static void __pollwait(struct file *filp, wait_queue_head_t *wait_address,
-				poll_table *p)
+		       poll_table *p, int exclusive)
 {
 	struct poll_table_entry *entry = poll_get_entry(p);
 	if (!entry)
@@ -126,7 +126,10 @@ static void __pollwait(struct file *filp
 	entry->filp = filp;
 	entry->wait_address = wait_address;
 	init_waitqueue_entry(&entry->wait, current);
-	add_wait_queue(wait_address, &entry->wait);
+	if (exclusive)
+		add_wait_queue_exclusive(wait_address, &entry->wait);
+	else
+		add_wait_queue(wait_address, &entry->wait);
 }
 
 #define FDS_IN(fds, n)		(fds->in + n)
Index: linux-2.6.24-rc6-memnotify/include/linux/poll.h
===================================================================
--- linux-2.6.24-rc6-memnotify.orig/include/linux/poll.h	2007-12-30 02:09:16.000000000 +0900
+++ linux-2.6.24-rc6-memnotify/include/linux/poll.h	2007-12-30 02:41:35.000000000 +0900
@@ -28,7 +28,8 @@ struct poll_table_struct;
 /* 
  * structures and helpers for f_op->poll implementations
  */
-typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
+typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *,
+				struct poll_table_struct *, int);
 
 typedef struct poll_table_struct {
 	poll_queue_proc qproc;
@@ -37,7 +38,13 @@ typedef struct poll_table_struct {
 static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
 {
 	if (p && wait_address)
-		p->qproc(filp, wait_address, p);
+		p->qproc(filp, wait_address, p, 0);
+}
+
+static inline void poll_wait_exclusive(struct file *filp, wait_queue_head_t *wait_address, poll_table *p)
+{
+	if (p && wait_address)
+		p->qproc(filp, wait_address, p, 1);
 }
 
 static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH 0/5] mem notifications v4, KOSAKI Motohiro, (Mon Jan 14, 8:52 pm)
[RFC][PATCH 5/5] /proc/zoneinfo enhancement, KOSAKI Motohiro, (Mon Jan 14, 9:03 pm)
Re: [RFC][PATCH 5/5] /proc/zoneinfo enhancement, Alan Cox, (Tue Jan 15, 6:44 am)
Re: [RFC][PATCH 5/5] /proc/zoneinfo enhancement, KOSAKI Motohiro, (Tue Jan 15, 6:49 am)
[RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Mon Jan 14, 9:02 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, Daniel Spång, (Tue Jan 15, 6:55 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, Rik van Riel, (Tue Jan 15, 6:59 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, Daniel Spång, (Tue Jan 15, 7:39 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Tue Jan 15, 9:48 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, Daniel Spång, (Wed Jan 16, 7:03 am)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Wed Jan 16, 11:26 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, Daniel Spång, (Fri Jan 18, 6:24 am)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Fri Jan 18, 6:30 am)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KAMEZAWA Hiroyuki, (Mon Jan 14, 10:06 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Mon Jan 14, 10:37 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KAMEZAWA Hiroyuki, (Mon Jan 14, 11:00 pm)
Re: [RFC][PATCH 4/5] memory_pressure_notify() caller, KOSAKI Motohiro, (Mon Jan 14, 11:08 pm)
[RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Mon Jan 14, 9:01 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Pavel Machek, (Tue Jan 15, 6:16 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Tue Jan 15, 9:57 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Marcelo Tosatti, (Wed Jan 16, 12:13 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Pavel Machek, (Wed Jan 16, 7:42 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Daniel Spång, (Wed Jan 16, 7:51 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Wed Jan 16, 11:04 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Alan Cox, (Tue Jan 15, 6:46 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Tue Jan 15, 6:59 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Alan Cox, (Tue Jan 15, 7:20 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Marcelo Tosatti, (Tue Jan 15, 8:05 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Alan Cox, (Tue Jan 15, 9:42 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Tue Jan 15, 7:48 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Alan Cox, (Tue Jan 15, 9:42 am)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Tue Jan 15, 10:43 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KAMEZAWA Hiroyuki, (Mon Jan 14, 10:10 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Mon Jan 14, 10:20 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Rik van Riel, (Mon Jan 14, 10:56 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, Randy Dunlap, (Mon Jan 14, 9:08 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Mon Jan 14, 9:20 pm)
Re: [RFC][PATCH 3/5] add /dev/mem_notify device, KOSAKI Motohiro, (Mon Jan 14, 9:24 pm)
[RFC][PATCH 2/5] introduce wake_up_locked_nr() new API, KOSAKI Motohiro, (Mon Jan 14, 9:00 pm)
[RFC][PATCH 1/5] introduce poll_wait_exclusive() new API , KOSAKI Motohiro, (Mon Jan 14, 8:59 pm)