From: Anthony Liguori <anthony@codemonkey.ws>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, qemu-devel@nongnu.org,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Xen-devel] Re: [Qemu-devel] [PATCH 01/13] Handle terminating signals.
Date: Tue, 26 Aug 2008 10:04:30 -0500 [thread overview]
Message-ID: <48B41B7E.40708@codemonkey.ws> (raw)
In-Reply-To: <18612.1900.73781.314743@mariner.uk.xensource.com>
Ian Jackson wrote:
> Anthony Liguori writes ("[Xen-devel] Re: [Qemu-devel] [PATCH 01/13] Handle terminating signals."):
>
>> The race I know of is that you may get an aio signal completion before
>> select but after you've already qemu_aio_poll()'d. In practice, we only
>> sleep for 10ms at a time in select() so the race is handled by that. If
>> we wanted to increase the amount of time we slept, we would have to
>> handle this race.
>>
>
> Yes. And, 10ms is too long anyway for reasonable performance. During
> my merge with upstream I found that the qemu aio functionality (which
> was done quite differently to the old xen ioemu) caused a severe
> performance regression under some conditions because of this race.
>
Yeah, noticed that too, especially with qcow2.
>> In KVM, we sleep for 1s in select() and use signalfd() to receive the
>> aio notifications. For older hosts, we emulate signalfd using a thread
>> and the pipe-to-self trick.
>>
>
> Why does it need a thread ? You can just write to the pipe in the
> signal handler. I'll post my code.
>
It's a little less perfect. Your signal handler can write() to the pipe
but what happens if you get EAGAIN?
So what we do in KVM is use sigwait() within a separate thread. We
don't set O_NONBLOCK so the thread blocks if the pipe fills up which is
exactly the semantics you would want.
Below is our implementation. I'll queue up to push this change into
QEMU after I finish with the migration patches.
Regards,
Anthony Liguori
#include <sys/syscall.h>
#include <pthread.h>
struct sigfd_compat_info
{
sigset_t mask;
int fd;
};
static void *sigwait_compat(void *opaque)
{
struct sigfd_compat_info *info = opaque;
int err;
sigset_t all;
sigfillset(&all);
sigprocmask(SIG_BLOCK, &all, NULL);
do {
siginfo_t siginfo;
err = sigwaitinfo(&info->mask, &siginfo);
if (err == -1 && errno == EINTR) {
err = 0;
continue;
}
if (err > 0) {
char buffer[128];
size_t offset = 0;
memcpy(buffer, &err, sizeof(err));
while (offset < sizeof(buffer)) {
ssize_t len;
len = write(info->fd, buffer + offset,
sizeof(buffer) - offset);
if (len == -1 && errno == EINTR)
continue;
if (len <= 0) {
err = -1;
break;
}
offset += len;
}
}
} while (err >= 0);
return NULL;
}
static int kvm_signalfd_compat(const sigset_t *mask)
{
pthread_attr_t attr;
pthread_t tid;
struct sigfd_compat_info *info;
int fds[2];
info = malloc(sizeof(*info));
if (info == NULL) {
errno = ENOMEM;
return -1;
}
if (pipe(fds) == -1) {
free(info);
return -1;
}
memcpy(&info->mask, mask, sizeof(*mask));
info->fd = fds[1];
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&tid, &attr, sigwait_compat, info);
pthread_attr_destroy(&attr);
return fds[0];
}
int kvm_signalfd(const sigset_t *mask)
{
#if defined(SYS_signalfd)
int ret;
ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
if (!(ret == -1 && errno == ENOSYS))
return ret;
#endif
return kvm_signalfd_compat(mask);
}
> Ian.
>
next prev parent reply other threads:[~2008-08-26 15:05 UTC|newest]
Thread overview: 117+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-21 16:27 [Qemu-devel] [PATCH 00/13] merge some xen bits into qemu Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 01/13] Handle terminating signals Gerd Hoffmann
2008-08-21 20:11 ` Anthony Liguori
[not found] ` <m2n.s.1KWGbo-001Nr9@chiark.greenend.org.uk>
2008-08-26 10:44 ` Ian Jackson
2008-08-26 12:16 ` Gerd Hoffmann
2008-08-26 12:36 ` Ian Jackson
2008-08-26 12:58 ` Gerd Hoffmann
2008-08-26 17:55 ` Jamie Lokier
2008-08-26 13:17 ` Anthony Liguori
2008-08-26 13:38 ` [Xen-devel] " Ian Jackson
2008-08-26 14:52 ` Avi Kivity
2008-08-26 17:49 ` Jamie Lokier
2008-08-26 15:04 ` Anthony Liguori [this message]
2008-08-26 15:08 ` Ian Jackson
2008-08-26 15:20 ` Anthony Liguori
2008-08-26 15:28 ` Ian Jackson
2008-08-26 15:36 ` Anthony Liguori
2008-08-26 17:47 ` Jamie Lokier
2008-08-26 18:03 ` Jamie Lokier
2008-08-26 18:50 ` Anthony Liguori
2008-08-27 9:46 ` Ian Jackson
2008-08-27 16:27 ` Jamie Lokier
2008-08-27 16:35 ` Ian Jackson
2008-08-27 17:55 ` Anthony Liguori
2008-08-27 18:41 ` Jamie Lokier
2008-08-28 9:34 ` Ian Jackson
2008-09-07 2:41 ` Anthony Liguori
2008-08-26 15:36 ` Samuel Thibault
2008-08-26 15:21 ` Anthony Liguori
[not found] ` <m2n.s.1KXzwZ-002RA9@chiark.greenend.org.uk>
2008-08-26 15:23 ` Ian Jackson
2008-08-26 15:29 ` Avi Kivity
[not found] ` <m2n.s.1KY0XT-002RJM@chiark.greenend.org.uk>
2008-08-26 15:38 ` Ian Jackson
2008-08-26 16:12 ` Avi Kivity
2008-08-26 16:14 ` Julian Seward
2008-08-26 16:39 ` Anthony Liguori
2008-08-27 8:05 ` Avi Kivity
2008-08-27 8:49 ` Alan Cox
2008-08-27 9:10 ` Avi Kivity
2008-08-27 9:16 ` Keir Fraser
2008-08-27 9:12 ` Gleb Natapov
[not found] ` <m2n.s.1KXz4u-002Qvq@chiark.greenend.org.uk>
2008-08-26 14:55 ` Ian Jackson
2008-08-21 16:27 ` [Qemu-devel] [PATCH 02/13] add DisplayState->idle Gerd Hoffmann
2008-08-21 16:33 ` [Qemu-devel] " Samuel Thibault
2008-08-21 20:12 ` [Qemu-devel] " Anthony Liguori
2008-08-21 16:27 ` [Qemu-devel] [PATCH 03/13] add container_of() macro to osdep.h Gerd Hoffmann
2008-08-21 20:12 ` Anthony Liguori
2008-08-21 16:27 ` [Qemu-devel] [PATCH 04/13] move GUI_REFRESH_INTERVAL define from vl.c to console.h Gerd Hoffmann
2008-08-21 20:12 ` Anthony Liguori
2008-08-21 16:27 ` [Qemu-devel] [PATCH 05/13] xen: groundwork for xen support Gerd Hoffmann
2008-08-21 20:18 ` Anthony Liguori
2008-08-21 16:27 ` [Qemu-devel] [PATCH 06/13] xen: backend driver core Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 07/13] xen: add console backend driver Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 08/13] xen: add framebuffer " Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 09/13] xen: add block device " Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 10/13] xen: add net " Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 11/13] xen: blk & nic configuration via cmd line Gerd Hoffmann
2008-08-21 16:27 ` [Qemu-devel] [PATCH 12/13] set vnc password from xenstore Gerd Hoffmann
2008-08-21 20:14 ` Anthony Liguori
2008-08-21 20:19 ` [Xen-devel] " Daniel P. Berrange
2008-08-21 20:22 ` Anthony Liguori
2008-08-21 20:26 ` Daniel P. Berrange
2008-08-21 21:34 ` Gerd Hoffmann
2008-08-21 21:48 ` Daniel P. Berrange
2008-08-21 22:36 ` Anthony Liguori
2008-08-24 9:03 ` Avi Kivity
2008-08-22 7:04 ` Gerd Hoffmann
2008-08-22 19:11 ` Jamie Lokier
2008-08-22 19:01 ` Jamie Lokier
2008-08-21 22:34 ` Anthony Liguori
2008-08-22 8:27 ` Gerd Hoffmann
2008-08-24 8:57 ` Avi Kivity
2008-08-24 9:59 ` Jamie Lokier
2008-08-24 10:07 ` Avi Kivity
2008-08-24 12:48 ` Jamie Lokier
2008-08-21 20:59 ` Jamie Lokier
2008-08-21 21:29 ` Gerd Hoffmann
2008-08-26 10:13 ` Ian Jackson
2008-08-21 20:17 ` [Qemu-devel] Re: [Xen-devel] " Daniel P. Berrange
2008-08-21 21:25 ` Gerd Hoffmann
[not found] ` <m2n.s.1KWHfl-001Ntw@chiark.greenend.org.uk>
2008-08-26 10:47 ` Ian Jackson
2008-08-21 16:27 ` [Qemu-devel] [PATCH 13/13] xen: pv domain builder Gerd Hoffmann
[not found] ` <m2n.s.1KWDD7-002TB9@chiark.greenend.org.uk>
2008-08-26 10:31 ` [Qemu-devel] [PATCH 05/13] xen: groundwork for xen support Ian Jackson
2008-08-26 12:34 ` Gerd Hoffmann
2008-08-26 12:57 ` [Xen-devel] " Daniel P. Berrange
2008-08-26 13:20 ` Gerd Hoffmann
2008-08-26 13:23 ` Daniel P. Berrange
2008-08-26 13:33 ` Ian Jackson
2008-08-26 14:14 ` Daniel P. Berrange
2008-08-26 14:31 ` Gerd Hoffmann
2008-08-26 14:40 ` Daniel P. Berrange
2008-08-26 14:49 ` Gerd Hoffmann
2008-08-26 14:53 ` Daniel P. Berrange
2008-08-26 19:24 ` Gerd Hoffmann
2008-08-26 14:53 ` Ian Jackson
2008-08-27 8:51 ` Gerd Hoffmann
2008-08-27 9:53 ` Ian Jackson
2008-08-27 9:56 ` Daniel P. Berrange
2008-08-27 10:00 ` Ian Jackson
2008-08-27 10:23 ` Daniel P. Berrange
2008-08-27 10:37 ` Gerd Hoffmann
2008-08-27 10:44 ` Daniel P. Berrange
2008-08-27 11:01 ` Gerd Hoffmann
[not found] ` <m2n.s.1KXzR5-002R2A@chiark.greenend.org.uk>
2008-08-26 15:05 ` Ian Jackson
2008-08-26 15:09 ` Daniel P. Berrange
2008-08-26 13:24 ` Ian Jackson
2008-08-26 13:50 ` Daniel P. Berrange
[not found] ` <m2n.s.1KWDfC-002TCd@chiark.greenend.org.uk>
[not found] ` <m2n.s.1KWDGv-002TBJ@chiark.greenend.org.uk>
[not found] ` <m2n.s.1KWDEt-002TBA@chiark.greenend.org.uk>
2008-08-26 10:42 ` [Qemu-devel] [PATCH 13/13] xen: pv domain builder Ian Jackson
2008-08-26 10:50 ` [Xen-devel] " Samuel Thibault
2008-08-26 13:43 ` Ian Jackson
2008-08-26 21:00 ` Markus Armbruster
2008-08-26 12:55 ` Gerd Hoffmann
2008-08-26 13:14 ` Ian Jackson
2008-08-26 13:53 ` Gerd Hoffmann
2008-08-26 14:19 ` Ian Jackson
2008-08-26 20:00 ` [Xen-devel] " Gerd Hoffmann
2008-08-27 9:48 ` Ian Jackson
2008-08-26 13:56 ` Gerd Hoffmann
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=48B41B7E.40708@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=Ian.Jackson@eu.citrix.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xen-devel@lists.xensource.com \
/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).