qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] QEMUBH: introduce canceled member for bh
Date: Wed, 26 Jun 2013 01:38:34 +0800	[thread overview]
Message-ID: <1372181916-4676-2-git-send-email-pingfank@linux.vnet.ibm.com> (raw)
In-Reply-To: <1372181916-4676-1-git-send-email-pingfank@linux.vnet.ibm.com>

When dismissing the bh scheduling(delete/cancel/schedule), we need to
reset bh->scheduled to zero and release the refcnt of object which is
referred by bh(will introduced by next patch).
Currently, the bh->scheduled will be reset to zero by many writers,
so atomic ops should be involved in, which results in expensive memory
barrier. With this patch, bh->scheduled is only reset by aio_bh_poll().

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 async.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/async.c b/async.c
index e73b93c..bea3d7e 100644
--- a/async.c
+++ b/async.c
@@ -38,6 +38,7 @@ struct QEMUBH {
     bool scheduled;
     bool idle;
     bool deleted;
+    bool canceled;
 };
 
 QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
@@ -69,8 +70,15 @@ int aio_bh_poll(AioContext *ctx)
         /* Make sure that fetching bh happens before accessing its members */
         smp_read_barrier_depends();
         next = bh->next;
-        if (!bh->deleted && bh->scheduled) {
+        if (bh->scheduled) {
             bh->scheduled = 0;
+            if (unlikely(bh->deleted)) {
+                continue;
+            }
+            if (unlikely(bh->canceled)) {
+                bh->canceled = 0;
+                continue;
+            }
             /* Paired with write barrier in bh schedule to ensure reading for
              * idle & callbacks coming after bh's scheduling.
              */
@@ -133,7 +141,7 @@ void qemu_bh_schedule(QEMUBH *bh)
  */
 void qemu_bh_cancel(QEMUBH *bh)
 {
-    bh->scheduled = 0;
+    bh->canceled = 1;
 }
 
 /* This func is async.The bottom half will do the delete action at the finial
@@ -141,7 +149,6 @@ void qemu_bh_cancel(QEMUBH *bh)
  */
 void qemu_bh_delete(QEMUBH *bh)
 {
-    bh->scheduled = 0;
     bh->deleted = 1;
 }
 
@@ -152,7 +159,7 @@ aio_ctx_prepare(GSource *source, gint    *timeout)
     QEMUBH *bh;
 
     for (bh = ctx->first_bh; bh; bh = bh->next) {
-        if (!bh->deleted && bh->scheduled) {
+        if (!bh->deleted && !bh->canceled && bh->scheduled) {
             if (bh->idle) {
                 /* idle bottom halves will be polled at least
                  * every 10ms */
@@ -176,7 +183,7 @@ aio_ctx_check(GSource *source)
     QEMUBH *bh;
 
     for (bh = ctx->first_bh; bh; bh = bh->next) {
-        if (!bh->deleted && bh->scheduled) {
+        if (!bh->deleted && !bh->canceled && bh->scheduled) {
             return true;
 	}
     }
-- 
1.8.1.4

  parent reply	other threads:[~2013-06-25  5:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-25 17:38 [Qemu-devel] [PATCH 0/3] make bh safe with hot-unplug Liu Ping Fan
2013-06-25  6:24 ` Paolo Bonzini
2013-06-25  6:32   ` liu ping fan
2013-06-25  7:53     ` Paolo Bonzini
2013-06-26  2:59       ` liu ping fan
2013-06-26  6:34         ` Paolo Bonzini
2013-06-26  8:20           ` liu ping fan
2013-06-26  8:38             ` Paolo Bonzini
2013-06-26  9:44               ` liu ping fan
2013-06-26  9:55                 ` Paolo Bonzini
2013-06-27  2:08                   ` liu ping fan
2013-06-27  6:59                     ` Paolo Bonzini
2013-06-25 17:38 ` Liu Ping Fan [this message]
2013-06-25 17:38 ` [Qemu-devel] [PATCH 2/3] QEMUBH: pin bh's referring object while scheduling Liu Ping Fan
2013-06-25 17:38 ` [Qemu-devel] [PATCH 3/3] virtio-net: set referred object for virtio net's bh Liu Ping Fan

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=1372181916-4676-2-git-send-email-pingfank@linux.vnet.ibm.com \
    --to=qemulist@gmail.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).