Date: Wed, 1 Feb 2012 02:53:06 +0000 (UTC) From: David Xu <davidxu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r230857 - in head/sys: kern sys Message-ID: <201202010253.q112r6nl066691@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: davidxu Date: Wed Feb 1 02:53:06 2012 New Revision: 230857 URL: http://svn.freebsd.org/changeset/base/230857 Log: 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 Modified: head/sys/kern/vfs_aio.c head/sys/sys/signal.h Modified: head/sys/kern/vfs_aio.c ============================================================================== --- head/sys/kern/vfs_aio.c Wed Feb 1 02:16:15 2012 (r230856) +++ head/sys/kern/vfs_aio.c Wed Feb 1 02:53:06 2012 (r230857) @@ -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); @@ -1646,10 +1647,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); Modified: head/sys/sys/signal.h ============================================================================== --- head/sys/sys/signal.h Wed Feb 1 02:16:15 2012 (r230856) +++ head/sys/sys/signal.h Wed Feb 1 02:53:06 2012 (r230857) @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202010253.q112r6nl066691>