Skip to contentSkip to conversation

/dev/poll patch for 2.4

PATCH Mathieu Dube 1 participant 1 message Mar 8, 2001

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

Hi,
Somebody asked me for that patch it might need some tweaking, adding
#include <linux/poll.h> somewhere

Signature · 3 lines
Mathieu Dube	
Mondo-Live			
www.flipr.com
drivers/char/Config.in +1 -0
diff -urP linux-2.4.0/drivers/char/Config.in linux-2.4.0-devpoll/drivers/char/Config.in
@@ -156,6 +156,7 @@
 
 dep_tristate 'Intel i8x0 Random Number Generator support' CONFIG_INTEL_RNG $CONFIG_PCI
 tristate '/dev/nvram support' CONFIG_NVRAM
+tristate '/dev/poll support' CONFIG_DEVPOLL
 tristate 'Enhanced Real Time Clock Support' CONFIG_RTC
 if [ "$CONFIG_IA64" = "y" ]; then
    bool 'EFI Real Time Clock Services' CONFIG_EFI_RTC
drivers/char/Makefile +1 -0
diff -urP linux-2.4.0/drivers/char/Makefile linux-2.4.0-devpoll/drivers/char/Makefile
@@ -181,6 +181,7 @@
 obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
 obj-$(CONFIG_WDT) += wdt.o
 obj-$(CONFIG_WDTPCI) += wdt_pci.o
+obj-$(CONFIG_DEVPOLL) += devpoll.o
 obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
 obj-$(CONFIG_977_WATCHDOG) += wdt977.o
 obj-$(CONFIG_I810_TCO) += i810-tco.o
drivers/char/devpoll.c +754 -0

754 lines not on this page · raw message

fs/file_table.c +2 -0
diff -urP linux-2.4.0/fs/file_table.c linux-2.4.0-devpoll/fs/file_table.c
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/smp_lock.h>
+#include <linux/spinlock.h>
 
 /* sysctl tunables... */
 struct files_stat_struct files_stat = {0, 0, NR_FILE};
@@ -45,6 +46,7 @@
 		f->f_version = ++event;
 		f->f_uid = current->fsuid;
 		f->f_gid = current->fsgid;
+		rwlock_init(&f->f_dplock);
 		list_add(&f->f_list, &anon_list);
 		file_list_unlock();
 		return f;
fs/open.c +18 -0
diff -urP linux-2.4.0/fs/open.c linux-2.4.0-devpoll/fs/open.c
@@ -13,6 +13,8 @@
 #include <linux/dnotify.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/devpoll.h>
 
 #include <asm/uaccess.h>
 
@@ -802,6 +804,14 @@
 		unlock_kernel();
 	}
 	fcntl_dirnotify(0, filp, 0);
+	
+	if (filp->f_backmap) {
+		unsigned long flags;
+		write_lock_irqsave(&filp->f_dplock, flags);
+		poll_clean_backmap(&filp->f_backmap);
+		write_unlock_irqrestore(&filp->f_dplock, flags);
+	}
+
 	locks_remove_posix(filp, id);
 	fput(filp);
 	return retval;
@@ -827,6 +837,14 @@
 	FD_CLR(fd, files->close_on_exec);
 	__put_unused_fd(files, fd);
 	write_unlock(&files->file_lock);
+
+	if (filp->f_backmap) {
+		unsigned long flags;
+		write_lock_irqsave(&filp->f_dplock, flags);
+		poll_remove_backmap(&filp->f_backmap, fd, files);
+		write_unlock_irqrestore(&filp->f_dplock, flags);
+	}
+
 	return filp_close(filp, files);
 
 out_unlock:
include/asm-i386/devpoll.h +86 -0

86 lines not on this page · raw message

include/asm-i386/poll.h +2 -0
diff -urP linux-2.4.0/include/asm-i386/poll.h linux-2.4.0-devpoll/include/asm-i386/poll.h
@@ -15,6 +15,8 @@
 #define POLLWRNORM	0x0100
 #define POLLWRBAND	0x0200
 #define POLLMSG		0x0400
+#define POLLREMOVE	0x1000
+#define POLLHINT	0x2000
 
 struct pollfd {
 	int fd;
include/linux/dcache.h +2 -0
diff -urP linux-2.4.0/include/linux/dcache.h linux-2.4.0-devpoll/include/linux/dcache.h
@@ -6,6 +6,8 @@
 #include <asm/atomic.h>
 #include <linux/mount.h>
 
+#include <asm/system.h>
+
 /*
  * linux/include/linux/dcache.h
  *
include/linux/devpoll.h +86 -0

86 lines not on this page · raw message

include/linux/fs.h +5 -0
diff -urP linux-2.4.0/include/linux/fs.h linux-2.4.0-devpoll/include/linux/fs.h
@@ -511,6 +511,11 @@
 
 	unsigned long		f_version;
 
+
+	/* used by /dev/poll hinting */
+	struct poll_backmap	*f_backmap;
+	rwlock_t		f_dplock;
+
 	/* needed for tty driver, and maybe others */
 	void			*private_data;
 };
include/linux/poll.h +90 -0

107 lines not on this page · raw message

include/net/sock.h +4 -0
diff -urP linux-2.4.0/include/net/sock.h linux-2.4.0-devpoll/include/net/sock.h
@@ -655,6 +655,10 @@
 	/* Identd and reporting IO signals */
 	struct socket		*socket;
 
+	/* For Poll hinting */
+	void 			*backmap;
+	void			*dplock;
+
 	/* RPC layer private data */
 	void			*user_data;
   
lib/dec_and_lock.c +1 -0
diff -urP linux-2.4.0/lib/dec_and_lock.c linux-2.4.0-devpoll/lib/dec_and_lock.c
@@ -1,5 +1,6 @@
 #include <linux/spinlock.h>
 #include <asm/atomic.h>
+#include <asm/system.h>
 
 /*
  * This is an architecture-neutral, but slow,
net/atm/common.c +4 -1
diff -urP linux-2.4.0/net/atm/common.c linux-2.4.0-devpoll/net/atm/common.c
@@ -481,7 +481,10 @@
 
 	vcc = ATM_SD(sock);
 	poll_wait(file,&vcc->sleep,wait);
-	mask = 0;
+	sk->backmap = &file->f_backmap;
+	sk->dplock  = &file->f_dplock;
+	mask = POLLHINT;
+
 	if (skb_peek(&vcc->recvq) || skb_peek(&vcc->listenq))
 		mask |= POLLIN | POLLRDNORM;
 	if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
net/core/sock.c +2 -0
diff -urP linux-2.4.0/net/core/sock.c linux-2.4.0-devpoll/net/core/sock.c
@@ -1128,6 +1128,8 @@
 	sk->state 	= 	TCP_CLOSE;
 	sk->zapped	=	1;
 	sk->socket	=	sock;
+	sk->backmap	=	NULL;
+	sk->dplock	=	NULL;
 
 	if(sock)
 	{
net/ipv4/af_inet.c +1 -0
diff -urP linux-2.4.0/net/ipv4/af_inet.c linux-2.4.0-devpoll/net/ipv4/af_inet.c
@@ -442,6 +442,7 @@
 		if (sk->linger && !(current->flags & PF_EXITING))
 			timeout = sk->lingertime;
 		sock->sk = NULL;
+		sk->backmap = NULL;
 		sk->prot->close(sk, timeout);
 	}
 	return(0);
net/ipv4/tcp.c +6 -3
diff -urP linux-2.4.0/net/ipv4/tcp.c linux-2.4.0-devpoll/net/ipv4/tcp.c
@@ -418,6 +418,7 @@
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/poll.h>
+#include <linux/devpoll.h>
 #include <linux/init.h>
 #include <linux/smp_lock.h>
 
@@ -548,15 +549,17 @@
 	struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
 
 	poll_wait(file, sk->sleep, wait);
+	sk->backmap = &file->f_backmap;
+	sk->dplock  = &file->f_dplock;
 	if (sk->state == TCP_LISTEN)
-		return tcp_listen_poll(sk, wait);
+		return tcp_listen_poll(sk, wait) | POLLHINT;
 
 	/* Socket is not locked. We are protected from async events
 	   by poll logic and correct handling of state changes
 	   made by another threads is impossible in any case.
 	 */
 
-	mask = 0;
+	mask = POLLHINT;
 	if (sk->err)
 		mask = POLLERR;
 
@@ -622,7 +625,7 @@
 		if (tp->urg_data & TCP_URG_VALID)
 			mask |= POLLPRI;
 	}
-	return mask;
+	return mask | POLLHINT;
 }
 
 /*
net/ipv4/tcp_input.c +4 -1
diff -urP linux-2.4.0/net/ipv4/tcp_input.c linux-2.4.0-devpoll/net/ipv4/tcp_input.c
@@ -68,6 +68,7 @@
 #include <net/tcp.h>
 #include <net/inet_common.h>
 #include <linux/ipsec.h>
+#include <linux/devpoll.h>
 
 
 /* These are on by default so the code paths get tested.
@@ -2912,8 +2913,10 @@
 
 		clear_bit(SOCK_NOSPACE, &sock->flags);
 
-		if (sk->sleep && waitqueue_active(sk->sleep))
+		if (sk->sleep && waitqueue_active(sk->sleep)) {
+			dp_add_hint(sk->backmap, sk->dplock);
 			wake_up_interruptible(sk->sleep);
+		}
 
 		if (sock->fasync_list && !(sk->shutdown&SEND_SHUTDOWN))
 			sock_wake_async(sock, 2, POLL_OUT);
net/ipx/af_spx.c +4 -1
diff -urP linux-2.4.0/net/ipx/af_spx.c linux-2.4.0-devpoll/net/ipx/af_spx.c
@@ -66,7 +66,10 @@
 	unsigned int mask;
 
 	poll_wait(file, sk->sleep, wait);
-	mask = 0;
+	sk->backmap = &file->f_backmap;
+        sk->dplock  = &file->f_dplock;
+
+	mask = POLLHINT;
 
 	/* exceptional events? */
 	if (sk->err || !skb_queue_empty(&sk->error_queue))
net/irda/af_irda.c +3 -1
diff -urP linux-2.4.0/net/irda/af_irda.c linux-2.4.0-devpoll/net/irda/af_irda.c
@@ -1637,7 +1637,9 @@
 	IRDA_DEBUG(4, __FUNCTION__ "()\n");
 
 	poll_wait(file, sk->sleep, wait);
-	mask = 0;
+	sk->backmap = &file->f_backmap;
+	sk->dplock  = &file->f_dplock;
+	mask = POLLHINT;
 
 	/* exceptional events? */
 	if (sk->err)
net/unix/af_unix.c +8 -2
diff -urP linux-2.4.0/net/unix/af_unix.c linux-2.4.0-devpoll/net/unix/af_unix.c
@@ -107,6 +107,7 @@
 #include <net/scm.h>
 #include <linux/init.h>
 #include <linux/poll.h>
+#include <linux/devpoll.h>
 #include <linux/smp_lock.h>
 
 #include <asm/checksum.h>
@@ -300,8 +301,10 @@
 {
 	read_lock(&sk->callback_lock);
 	if (unix_writable(sk)) {
-		if (sk->sleep && waitqueue_active(sk->sleep))
+		if (sk->sleep && waitqueue_active(sk->sleep)) {
+			dp_add_hint(sk->backmap, sk->dplock);
 			wake_up_interruptible(sk->sleep);
+		}
 		sk_wake_async(sk, 2, POLL_OUT);
 	}
 	read_unlock(&sk->callback_lock);
@@ -1708,7 +1711,10 @@
 	unsigned int mask;
 
 	poll_wait(file, sk->sleep, wait);
-	mask = 0;
+	
+	sk->backmap = &file->f_backmap;
+	sk->dplock = &file->f_dplock;
+	mask = POLLHINT;
 
 	/* exceptional events? */
 	if (sk->err)