svn commit: r232290 - in stable/9: lib/libc/sys sys/compat/freebsd32 sys/i386/conf sys/kern sys/sys

David Xu davidxu at FreeBSD.org
Wed Feb 29 06:19:01 UTC 2012


Author: davidxu
Date: Wed Feb 29 06:19:00 2012
New Revision: 232290
URL: http://svn.freebsd.org/changeset/base/232290

Log:
  MFC 230857:
  
  If multiple threads call kevent() to get AIO events on same kqueue fd,
  it is possible that a single AIO event will be reported to multiple
  threads, it is not threading friendly, and the existing API can not
  control this behavior.
  Allocate a kevent flags field sigev_notify_kevent_flags for AIO event
  notification in sigevent, and allow user to pass EV_CLEAR, EV_DISPATCH
  or EV_ONESHOT to AIO kernel code, user can control whether the event
  should be cleared once it is retrieved by a thread. This change should
  be comptaible with existing application, because the field should have
  already been zero-filled, and no additional action will be taken by
  kernel.
  
  PR:	kern/156567
  
  MFC 231006:
  
  Add 32-bit compat code for AIO kevent flags introduced in revision 230857.
  
  MFC 231724:
  
  Add notes about sigev_notify_kevent_flags introduced in revision 230857
  which enables thread-friendly polling on same fd for AIO events.
  
  Reviewed by:	delphij
  
  MFC 231777:
  
  Bump .Dd date for previous revision.

Modified:
  stable/9/lib/libc/sys/kqueue.2
  stable/9/sys/compat/freebsd32/freebsd32_signal.h
  stable/9/sys/kern/vfs_aio.c
  stable/9/sys/sys/signal.h
Directory Properties:
  stable/9/lib/libc/   (props changed)
  stable/9/lib/libc/stdtime/   (props changed)
  stable/9/lib/libc/sys/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)
  stable/9/sys/i386/conf/XENHVM   (props changed)

Modified: stable/9/lib/libc/sys/kqueue.2
==============================================================================
--- stable/9/lib/libc/sys/kqueue.2	Wed Feb 29 05:48:29 2012	(r232289)
+++ stable/9/lib/libc/sys/kqueue.2	Wed Feb 29 06:19:00 2012	(r232290)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 15, 2009
+.Dd February 15, 2012
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -322,6 +322,9 @@ The sigevent portion of the AIO request 
 .Va sigev_notify_kqueue
 containing the descriptor of the kqueue that the event should
 be attached to,
+.Va sigev_notify_kevent_flags
+containing the kevent flags which should be EV_ONESHOT, EV_CLEAR or
+EV_DISPATCH,
 .Va sigev_value
 containing the udata value, and
 .Va sigev_notify

Modified: stable/9/sys/compat/freebsd32/freebsd32_signal.h
==============================================================================
--- stable/9/sys/compat/freebsd32/freebsd32_signal.h	Wed Feb 29 05:48:29 2012	(r232289)
+++ stable/9/sys/compat/freebsd32/freebsd32_signal.h	Wed Feb 29 06:19:00 2012	(r232290)
@@ -92,6 +92,7 @@ struct sigevent32 {
 			uint32_t _function;
 			uint32_t _attribute;
 		} _sigev_thread;
+		unsigned short	_kevent_flags;
 		uint32_t __spare__[8];
 	} _sigev_un;
 };

Modified: stable/9/sys/kern/vfs_aio.c
==============================================================================
--- stable/9/sys/kern/vfs_aio.c	Wed Feb 29 05:48:29 2012	(r232289)
+++ stable/9/sys/kern/vfs_aio.c	Wed Feb 29 06:19:00 2012	(r232290)
@@ -1524,6 +1524,7 @@ aio_aqueue(struct thread *td, struct aio
 	int error;
 	int fd, kqfd;
 	int jid;
+	u_short evflags;
 
 	if (p->p_aioinfo == NULL)
 		aio_init_aioinfo(p);
@@ -1640,10 +1641,15 @@ aio_aqueue(struct thread *td, struct aio
 
 	if (aiocbe->uaiocb.aio_sigevent.sigev_notify != SIGEV_KEVENT)
 		goto no_kqueue;
+	evflags = aiocbe->uaiocb.aio_sigevent.sigev_notify_kevent_flags;
+	if ((evflags & ~(EV_CLEAR | EV_DISPATCH | EV_ONESHOT)) != 0) {
+		error = EINVAL;
+		goto aqueue_fail;
+	}
 	kqfd = aiocbe->uaiocb.aio_sigevent.sigev_notify_kqueue;
 	kev.ident = (uintptr_t)aiocbe->uuaiocb;
 	kev.filter = EVFILT_AIO;
-	kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1;
+	kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1 | evflags;
 	kev.data = (intptr_t)aiocbe;
 	kev.udata = aiocbe->uaiocb.aio_sigevent.sigev_value.sival_ptr;
 	error = kqfd_register(kqfd, &kev, td, 1);
@@ -2688,6 +2694,7 @@ convert_sigevent32(struct sigevent32 *si
 		break;
 	case SIGEV_KEVENT:
 		CP(*sig32, *sig, sigev_notify_kqueue);
+		CP(*sig32, *sig, sigev_notify_kevent_flags);
 		PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
 		break;
 	default:

Modified: stable/9/sys/sys/signal.h
==============================================================================
--- stable/9/sys/sys/signal.h	Wed Feb 29 05:48:29 2012	(r232289)
+++ stable/9/sys/sys/signal.h	Wed Feb 29 06:19:00 2012	(r232290)
@@ -169,12 +169,14 @@ struct sigevent {
 			void (*_function)(union sigval);
 			void *_attribute; /* pthread_attr_t * */
 		} _sigev_thread;
+		unsigned short _kevent_flags;
 		long __spare__[8];
 	} _sigev_un;
 };
 
 #if __BSD_VISIBLE
 #define	sigev_notify_kqueue		sigev_signo
+#define	sigev_notify_kevent_flags	_sigev_un._kevent_flags
 #define	sigev_notify_thread_id		_sigev_un._threadid
 #endif
 #define	sigev_notify_function		_sigev_un._sigev_thread._function


More information about the svn-src-stable mailing list