qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: "M. Warner Losh" <imp@bsdimp.com>
Cc: jan.kiszka@web.de, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Re: [5578] Increase default IO timeout from 10ms to 5s
Date: Thu, 6 Nov 2008 00:53:12 +0000	[thread overview]
Message-ID: <20081106005312.GA26173@shareable.org> (raw)
In-Reply-To: <20081105.091015.232928302.imp@bsdimp.com>

M. Warner Losh wrote:
> : > Which ones have a good kernel implementation of it?  FreeBSD's is
> : > currently approximately:
> : > 
> : > 	if (!mask)
> : > 		_sigprocmask(mask, &oldmask);
> : > 	/* here */
> : > 	select();
> : > 	if (!mask)
> : > 		_sigprocmask(oldmask, NULL);
> : > 
> : > I'm assuming that the problem is due to a signal arriving at /* here */.
> : 
> : If that's _kernel_ code and the kernel behaves like Linux, it's not a
> : problem because signals don't affect the control flow until returning
> : to userspace, meaning the select() will return EINTR.
> 
> It is currently user level code, and I'm looking at moving it into the
> kernel, but I need to understand the race being talked about here.

Ugh, I had imagined FreeBSD would have got that right, since it's
quite good in other areas.  I've added FreeBSD to my blacklist of
broken pselect() implementations, thanks for the info.

Do you know if FreeBSD's pread() and pwrite() are also thread-unsafe
userspace wrappers using lseek+read/write?  They are harder to avoid
when you're looking at high performance code.

> Why is it no good.  What is the race here?  Is it just the oldmask
> thing and multiple callers to select, or is it something else?

It's racy with a single caller.  The race is: program's signal handler
sets a flag like "alarm_happened = 1".  The program's main loop checks
the flag before calling select().  If the signal is delivered before
that check, the program doesn't call select() and handles the reason
for the flag.  If the signal is delivered during select(), that
returns EINTR and the program handles the reason for the flag.  But if
the signal is delivered _between_ checking the flag and calling
select(), the program gets stuck.

pselect() avoids that stuck state, by blocking the signal before the
program checks the flag, and guaranteeing if the signal is delivered
after that point, pselect() returns EINTR.  It's sort of analogous to
pthread_cond_wait() needing a mutex.

> And if it is the oldmask thing, why wouldn't multiple callers of
> pselect mess it up depending on what order they have.

Signal masks are per-thread anyway, multiple callers isn't an issue.

-- Jamie

  parent reply	other threads:[~2008-11-06  0:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-31 18:40 [Qemu-devel] [5578] Increase default IO timeout from 10ms to 5s Anthony Liguori
2008-10-31 18:52 ` Anthony Liguori
2008-11-02 19:08   ` [Qemu-devel] " Jan Kiszka
2008-11-03 20:04     ` Anthony Liguori
2008-11-03 20:36       ` Jan Kiszka
2008-11-03 21:50         ` Jan Kiszka
2008-11-03 22:00           ` Anthony Liguori
2008-11-03 22:03             ` Jan Kiszka
2008-11-04  8:07             ` andrzej zaborowski
2008-11-04  8:22               ` Jan Kiszka
2008-11-04  8:33                 ` andrzej zaborowski
2008-11-04 11:32                   ` Jamie Lokier
2008-11-04 16:22                     ` M. Warner Losh
2008-11-04 17:10                       ` Jan Kiszka
2008-11-04 17:55                         ` M. Warner Losh
2008-11-04 19:08                           ` Jan Kiszka
2008-11-05 15:00                       ` Jamie Lokier
2008-11-05 16:10                         ` M. Warner Losh
2008-11-05 18:21                           ` Jan Kiszka
2008-11-05 18:41                             ` Daniel P. Berrange
2008-11-05 20:16                             ` andrzej zaborowski
2008-11-05 20:28                               ` Daniel P. Berrange
2008-11-05 23:38                                 ` Jamie Lokier
2008-11-06  0:53                           ` Jamie Lokier [this message]
2008-11-06  5:19                             ` M. Warner Losh
2008-11-04  8:29           ` Avi Kivity
2008-10-31 19:41 ` [Qemu-devel] " Jamie Lokier
2008-10-31 20:13   ` Anthony Liguori

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=20081106005312.GA26173@shareable.org \
    --to=jamie@shareable.org \
    --cc=imp@bsdimp.com \
    --cc=jan.kiszka@web.de \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).