qemu-devel
[Top][All Lists]
Advanced

[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: Thu, 29 Aug 2013 09:09:45 +0800
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8

于 2013-8-28 16:49, Stefan Hajnoczi 写道:
On Wed, Aug 28, 2013 at 11:25:33AM +0800, Wenchao Xia wrote:
+void aio_context_release(AioContext *ctx)
+{
+    qemu_mutex_lock(&ctx->acquire_lock);
+    assert(ctx->owner && qemu_thread_is_self(ctx->owner));
+    ctx->owner = NULL;
+    qemu_cond_signal(&ctx->acquire_cond);
+    qemu_mutex_unlock(&ctx->acquire_lock);
+}
   if main thread have call bdrv_aio_readv(cb *bdrv_cb), now it
is possible bdrv_cb will be executed in another thread which
aio_context_acquire() it. I think there are some ways to solve,
but leave a comments here now to tip better?

Callbacks, BHs, and timers are executed in the thread that calls
aio_poll().  This is safe since other threads cannot run aio_poll() or
submit new block I/O requests at the same time.

In other words: code should only care which AioContext it runs under,
not which thread ID it runs under.  (I think we talked about this on IRC
a few weeks ago.)

Are there any situations you are worried about?

Stefan

  Yes, we have discussed it before and think it may be safe for block
driver caller. Still, here I mean to add some in-code comment to tip how
to use it safely.

for example:

static int glob_test = 0;

int aio_cb(void *opaque)
{
    glob_test++;
}

Thread A:
bdrv_aio_read(bs, aio_cb...);
.....
glob_test++;


Normally glob_test have no race condition since they supposed
to work in one thread, but it need to be considered when
aio_context_acquire() is involved. How about:
/* Note that callback can run in different thread which acquired the
AioContext and do a poll() call. */

--
Best Regards

Wenchao Xia




reply via email to

[Prev in Thread] Current Thread [Next in Thread]