From: "Network Nut" <sillystack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: "'Michael Kerrisk (man-pages)'"
<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: epoll_wait() - Honor Order of Specification of fds to epoll_ctl()
Date: Sun, 2 Feb 2014 22:52:52 -0600 [thread overview]
Message-ID: <000301cf209b$cbf95ad0$63ec1070$@gmail.com> (raw)
> -----Original Message-----
> From: Michael Kerrisk (man-pages) [mailto:mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
>
> > Since we are on the subject, I also believe that the man page for
epoll_wait
> > should state whether sequence of the signaled fd's is guaranteed to be
> > correlated to the order in which they were specified.
>
> There is not such a guarantee, as far as I know.
>
> > As you know, there are
> > many situations where programmer might want to wait on, say, eventfd
> that
> > says that thread should exit, plus four other semaphores, etc. If the
four
> > other semaphores guard queues that are, in general, never empty, then on
> > each loop, the semaphores will be triggered. If then, on one of the
loops,
> > the eventfd for "exit" is triggered, there is no guarantee, according to
the
> > man page, that the "exit" eventfd will be returned in the triggered-set.
It
> > would seem natural that, if the "exit" eventfd is added to the first
> > position with epoll_ctl, then of any trigger-set where "exit" eventfd is
> > set, that "exit" eventfd ~must~ be included as a matter of explicit
> > prioritization. Guaranteeing a correlation between specified order in
> > epoll_ctrl and yielded order in epoll_wait would allow the programmer to
> > specify maxevents=1 to epoll_wait, at which point, the "exit" eventfd,
if
> > triggered, would preempt any of the semaphores.
> >
> > Or...maybe I am missing something else?
>
> The only guarantee that I know of is that if multiple FDs a ready and
> epoll_wait() requests fewer events than there are FDs ready, then
> successive calls will cycle though the list of ready FDs. This helps avoid
> starvation.
I am starting a new thread since my last question was answered sufficiently
to get my work done.
I believe that epoll_wait should guarantee that it will yield the triggered
fd's in the order in which they were specified to epoll_ctl.
Just yesterday, I had a situation where I needed this guarantee. I had four
queues that are annotated with semaphores. I intended to use epoll_wait to
wait on the semaphores, in addition to several other fd's. When my thread
unblocks, I need two of the semaphores to take priority over the other two.
Normally, I would specify those two fd's first in my array to epoll_ctl.
As is known, WaitForMultipleObjects, under Windows, yields only 1 fd per
invocation, and that fd is the first fd in the array that was specified to
WaitForMultipleObjects that has become triggered. This gives the programmer
a convenient to specifying arbitration (prioritizations) among
simultaneously triggered fd's.
With epoll_wait, if say, 4 fd's are triggered, without a guarantee to honor
order-of-specification, the programmer would effectively have to sort the
triggered fd's in the order that makes sense for his/her application to
determine if one or more "critical" fd's have been triggered.
-Nut
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2014-02-03 4:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-03 4:52 Network Nut [this message]
2014-02-03 6:51 ` epoll_wait() - Honor Order of Specification of fds to epoll_ctl() Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000301cf209b$cbf95ad0$63ec1070$@gmail.com' \
--to=sillystack-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.