[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC] aio: add aio_context_acquire() and aio_context_re
From: |
Wenchao Xia |
Subject: |
Re: [Qemu-devel] [RFC] aio: add aio_context_acquire() and aio_context_release() |
Date: |
Fri, 30 Aug 2013 12:02:29 +0800 |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 |
δΊ 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 <address@hidden>
> ---
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
Re: [Qemu-devel] [RFC] aio: add aio_context_acquire() and aio_context_release(),
Wenchao Xia <=