qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	pbonzini@redhat.com, Fam Zheng <famz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	borntraeger@de.ibm.com
Subject: [Qemu-devel] [PATCH] thread-pool: Notify AIO context upon completion
Date: Thu,  2 Jul 2015 14:33:59 +0800	[thread overview]
Message-ID: <1435818839-5376-1-git-send-email-famz@redhat.com> (raw)

bdrv_flush() uses a loop like

    while (rwco.ret == NOT_DONE) {
        aio_poll(aio_context, true);
    }

to wait for thread pool, which may not get notified about the scheduled
BH right away, if there is no new event that wakes up a blocking
qemu_poll_ns(). In this case, it may even be a permanent hang.

Wake the main thread up by writing to the event notifier fd.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Fam Zheng <famz@redhat.com>

---

I suspect this may relate to

[Qemu-devel] "iothread: release iothread around aio_poll" causes random
hangs at startup

[http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg00623.html]

reported by Christian Borntraeger. Because in iothread there is rarely
any fd activity, so the blocking aio_poll() may block forever if it
misses the BH schedule.

Christian, could you test this patch against your reproducer?
---
 thread-pool.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/thread-pool.c b/thread-pool.c
index ac909f4..9b9c065 100644
--- a/thread-pool.c
+++ b/thread-pool.c
@@ -112,6 +112,7 @@ static void *worker_thread(void *opaque)
         qemu_mutex_lock(&pool->lock);
 
         qemu_bh_schedule(pool->completion_bh);
+        aio_notify(pool->ctx);
     }
 
     pool->cur_threads--;
-- 
2.4.3

             reply	other threads:[~2015-07-02  6:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-02  6:33 Fam Zheng [this message]
2015-07-02  6:45 ` [Qemu-devel] [PATCH] thread-pool: Notify AIO context upon completion Christian Borntraeger
2015-07-02  7:11 ` Paolo Bonzini
2015-07-02  7:17   ` 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=1435818839-5376-1-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=borntraeger@de.ibm.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).