All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Network Nut <sillystack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: FW: WaitForMultipleObjects/etc. In Kernel
Date: Fri, 31 Jan 2014 07:56:52 +0100	[thread overview]
Message-ID: <52EB4934.7070103@gmail.com> (raw)
In-Reply-To: <007c01cf1df6$7ccbe010$7663a030$@gmail.com>

On 01/30/2014 09:04 PM, Network Nut wrote:
>> -----Original Message-----
>> From: Michael Kerrisk (man-pages) [mailto:mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
>> Sent: Wednesday, January 29, 2014 4:40 AM
>> To: Network Nut
>> Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Subject: Re: FW: WaitForMultipleObjects/etc. In Kernel
>>
>> On 01/27/2014 10:21 PM, Network Nut wrote:
>>> See below.
>>>
>>> -----Original Message-----
>>> From: Clemens Ladisch [mailto:clemens-P6GI/4k7KOmELgA04lAiVw@public.gmane.org]
>>> Sent: Monday, January 27, 2014 3:07 AM
>>> To: Network Nut
>>> Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>>> Subject: Re: WaitForMultipleObjects/etc. In Kernel
>>>
>>>> BTW, the man page for epoll_wait seems to be incorrect.
>>>
>>> <https://www.kernel.org/doc/man-pages/reporting_bugs.html>
>>>
>>>> "The timeout argument specifies the minimum number of milliseconds
>>>>        that epoll_wait() will block."
>>>>
>>>> I think the word "minimum" should be "maximum".
>>
>> I've removed the word "minimum" from the sentence. Note that
>> "maximum" would not be correct. See the surrounding text for an
>> explanation of why.
>>
>> Thanks for the report.
>>
>> Cheers,
>>
>> Michael
> 
> Hi Michael,
> 
> I re-read the sentence with the word "minimum" being removed. It makes sense
> now, at least for those of us who already understand how it should work
> [WaitForMultipleObjects]. But I wonder....Imagine a programmer who is
> relatively new to synchronization, just discovering the power of waiting for
> multiple fd's. Reading that statement, s/he might be inclined to believe
> that the function really will wait, say, 1000 milliseconds, without regard
> for signaling state of any of the fd's that might transition during the call
> to epoll_wait. The reason would be that s/he has no reason to believe
> otherwise, as that is what the man page says. By contrast, those of us who
> already know the nature of this function would not be confused because we
> would think, "Ok, I know that epoll_wait will not actually wait 1000 ms in
> all cases, but ..." 
> 
> Not trying to teach the teacher here. :) Just saying'. [Yes, it's a
> nit-pick.]

Fair enough. You're not the fist to comment on this. It seems that more detailed
language would be helpful. I've reworked the text here to read:

       The  timeout argument specifies the number of milliseconds that
       epoll_wait() will block.  The call will block until either:

       *  a file descriptor delivers an event;

       *  the call is interrupted by a signal handler; or

       *  the timout expires.

       Note that the timeout interval will be rounded up to the system
       clock  granularity,  and kernel scheduling delays mean that the
       blocking interval may overrun by a small amount.  Specifying  a
       timeout  of -1 causes epoll_wait() to block indefinitely, while
       specifying a timeout equal to zero cause epoll_wait() to return
       immediately, even if no events are available.

I've also made similar changes in select(2) and poll(2).

> 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.

Cheers,

Michael
> -Nut
> 
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
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

      reply	other threads:[~2014-01-31  6:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-25 22:01 WaitForMultipleObjects/etc. In Kernel Network Nut
2014-01-26 18:33 ` Clemens Ladisch
2014-01-26 22:10   ` Network Nut
2014-01-27  9:06     ` Clemens Ladisch
2014-01-27 19:50       ` Network Nut
2014-01-28  9:04         ` Clemens Ladisch
2014-01-28 21:07           ` Network Nut
2014-01-29  8:30             ` Clemens Ladisch
2014-01-30 23:49               ` Network Nut
2014-01-31 17:05                 ` Austin S. Hemmelgarn
2014-01-31 22:35                   ` Network Nut
2014-01-31 22:53                     ` Clemens Ladisch
2014-01-31 23:00                       ` Network Nut
2014-01-31 23:08                         ` Network Nut
     [not found]       ` <52E6219A.3020405-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>
2014-01-27 21:21         ` FW: " Network Nut
2014-01-29 10:40           ` Michael Kerrisk (man-pages)
     [not found]             ` <52E8DA80.7080204-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-30 20:04               ` Network Nut
2014-01-31  6:56                 ` Michael Kerrisk (man-pages) [this message]

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=52EB4934.7070103@gmail.com \
    --to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sillystack-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.