qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Ping Fan Liu <pingfank@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC] aio: add aio_context_acquire() and aio_context_release()
Date: Fri, 30 Aug 2013 12:02:29 +0800	[thread overview]
Message-ID: <52201955.4080003@linux.vnet.ibm.com> (raw)
In-Reply-To: <1377614385-20466-1-git-send-email-stefanha@redhat.com>

于 2013-8-27 22:39, Stefan Hajnoczi 写道:
> It can be useful to run an AioContext from a thread which normally does
> not "own" the AioContext.  For example, request draining can be
> implemented by acquiring the AioContext and looping aio_poll() until all
> requests have been completed.
> 
> The following pattern should work:
> 
>    /* Event loop thread */
>    while (running) {
>        aio_context_acquire(ctx);
>        aio_poll(ctx, true);
>        aio_context_release(ctx);
>    }
> 
>    /* Another thread */
>    aio_context_acquire(ctx);
>    bdrv_read(bs, 0x1000, buf, 1);
>    aio_context_release(ctx);
> 
> This patch implements aio_context_acquire() and aio_context_release().
> Note that existing aio_poll() callers do not need to worry about
> acquiring and releasing - it is only needed when multiple threads will
> call aio_poll() on the same AioContext.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---

  After a chat with Stefan on IRC, To enable block layer usage by
multiple thread, there are two potential program models. Thanks for
Stefan's analysis, I think it would be helpful to share the info as
following, pls correct me if my understanding is not right:

The models:
1) context per request model:
  aio_context_acquire(ctx);
  bds_acquire(bds);
  bdrv_aio_read(AioContext *ctx, BlockDriverStates *bds, ...);
  bds_release(bds);
  aio_context_release(ctx);

2) context per BDS model:
  BlockDriverState *bds = bdrv_new(AioContext *ctx); /* or another API
bind AioContext */
  aio_context_acquire(ctx);
  bdrv_aio_read(BlockDriverStates *bds, ...);
  aio_context_release(ctx);

The difference:
context per request model in 1):
    AioContext c0     AioContext c1
        /|\              /|\
         |----------------|
                 |
                 |
         -------------------
        /|\                |
         |                 |
        BDS b0        BDS b1..
        /|\
         |
     -------------
    /|\         /|\
     |           |
  request      request
from thread   from thread
  t0 who        t1 who
acquired c0   acquired c1


context per BDS model in 2):
AioContext c0    AioContext c1
    /|\               |
     |                |
     |                |
    BDS b0        BDS b1..
    /|\
     |
     |
  request
from thread
  t0 who
acquired c0

(t1's request can't
submitted at this time)

  If BDS is considered as front end used to submit task, AioContext is
considered as a back end used to process task, whether to bind BDS
with AioContext, determine whether the request for one BDS, can be
submitted in front end, processed in the back end, in parallel.
  Generally speaking 1) will gain more parallel capability, it enable
multiple thread usage at BDS level, but requires more code inside block
layer, for sync and series/parallel request converting, so we are
heading to 2), request will be submitted. Interesting thing is
that, it can still enable multiple thread usage in AioContext level:

AioContext c0    AioContext c1
    /|\              /|\
     |                |
     |                |
    BDS b0         BDS b1
    /|\              /|\
     |                |
     |                |
  request          request
from thread     from thread
  t0 who           t1 who
acquired c0     acquired c1

  So later dataplane thread will becomes another user who create a
AioContext to do jobs in parallel.

-- 
Best Regards

Wenchao Xia

      parent reply	other threads:[~2013-08-30  4:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-27 14:39 [Qemu-devel] [RFC] aio: add aio_context_acquire() and aio_context_release() Stefan Hajnoczi
2013-08-27 15:12 ` Paolo Bonzini
2013-08-28  2:41   ` Wenchao Xia
2013-08-27 18:33 ` Alex Bligh
2013-08-28  3:25 ` Wenchao Xia
2013-08-28  8:49   ` Stefan Hajnoczi
2013-08-29  1:09     ` Wenchao Xia
2013-08-29  7:43       ` Stefan Hajnoczi
2013-09-10 19:42         ` Michael Roth
2013-09-12  8:11           ` Stefan Hajnoczi
2013-08-29  8:26 ` Paolo Bonzini
2013-08-30  9:22   ` Stefan Hajnoczi
2013-08-30 13:24     ` Paolo Bonzini
2013-08-30 14:25       ` Stefan Hajnoczi
2013-08-30  4:02 ` Wenchao Xia [this message]

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=52201955.4080003@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=pingfank@linux.vnet.ibm.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).