From: Stefan Hajnoczi <stefanha@gmail.com>
To: Fam Zheng <famz@redhat.com>
Cc: kwolf@redhat.com, Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] main-loop: Pass AioContext into qemu_poll_ns
Date: Thu, 2 Oct 2014 16:26:18 +0100 [thread overview]
Message-ID: <20141002152618.GH6250@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1412048118-24834-2-git-send-email-famz@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1759 bytes --]
On Tue, Sep 30, 2014 at 11:35:17AM +0800, Fam Zheng wrote:
> diff --git a/main-loop.c b/main-loop.c
> index d2e64f1..4641ef4 100644
> --- a/main-loop.c
> +++ b/main-loop.c
> @@ -234,7 +234,8 @@ static int os_host_main_loop_wait(int64_t timeout)
> spin_counter++;
> }
>
> - ret = qemu_poll_ns((GPollFD *)gpollfds->data, gpollfds->len, timeout);
> + ret = qemu_poll_ns(qemu_aio_context, (GPollFD *)gpollfds->data,
> + gpollfds->len, timeout);
>
> if (timeout) {
> qemu_mutex_lock_iothread();
> @@ -439,7 +440,8 @@ static int os_host_main_loop_wait(int64_t timeout)
> poll_timeout_ns = qemu_soonest_timeout(poll_timeout_ns, timeout);
>
> qemu_mutex_unlock_iothread();
> - g_poll_ret = qemu_poll_ns(poll_fds, n_poll_fds + w->num, poll_timeout_ns);
> + g_poll_ret = qemu_poll_ns(qemu_aio_context,
> + poll_fds, n_poll_fds + w->num, poll_timeout_ns);
>
> qemu_mutex_lock_iothread();
> if (g_poll_ret > 0) {
This is a hack.
The immediate problem is that we're not holding the QEMU global mutex
but are accessing qemu_aio_context. What if other threads touch
qemu_aio_context while they hold the QEMU global mutex?
You didn't indicate what thread-safety rules need to be obeyed so I
wonder whether you looked into this.
I'm also concerned that this is somewhat abusing AioContext. You want
to stash fields in there but this poll call is about more than just
AioContext, it also includes non-AioContext file descriptors. So it
seems like a kludge to put the fields into AioContext.
Can you put the state into a separate struct so it's easy to understand
its thread-safety characteristics?
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2014-10-02 15:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 3:35 [Qemu-devel] [PATCH v2 0/2] main-loop: Use epoll on Linux Fam Zheng
2014-09-30 3:35 ` [Qemu-devel] [PATCH v2 1/2] main-loop: Pass AioContext into qemu_poll_ns Fam Zheng
2014-10-02 15:26 ` Stefan Hajnoczi [this message]
2014-09-30 3:35 ` [Qemu-devel] [PATCH v2 2/2] main-loop: Use epoll on Linux Fam Zheng
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=20141002152618.GH6250@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).