qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	John Snow <jsnow@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/4] block: extract AIO_WAIT_WHILE() from BlockDriverState
Date: Wed, 14 Feb 2018 16:31:45 -0600	[thread overview]
Message-ID: <8894e9fa-8e3d-ecfe-07f4-61a465f4bf57@redhat.com> (raw)
In-Reply-To: <20180214140647.GC7545@stefanha-x1.localdomain>

On 02/14/2018 08:06 AM, Stefan Hajnoczi wrote:
> On Tue, Feb 13, 2018 at 10:01:06AM -0600, Eric Blake wrote:
>> Trying to understand here:
>>
>>
>>> +#define AIO_WAIT_WHILE(wait, ctx, cond) ({                  \
>>> +    bool waited_ = false;                                   \
>>> +    bool busy_ = true;                                      \
>>> +    AioWait *wait_ = (wait);                                \
>>> +    AioContext *ctx_ = (ctx);                               \
>>> +    if (aio_context_in_iothread(ctx_)) {                    \
>>> +        while ((cond) || busy_) {                           \
>>> +            busy_ = aio_poll(ctx_, (cond));                 \
>>> +            waited_ |= !!(cond) | busy_;                    \
>>> +        }                                                   \
>>
>> If we are in an iothread already, we never dereference wait,
> 
> No, the name and documentation for aio_context_in_iothread() is
> misleading.  It actually means "does this AioContext belong to the
> current thread?", which is more general than just the IOThread case.
> 
> aio_context_in_iothread() returns true when:
> 1. We are the IOThread that owns ctx. <-- the case you thought of
> 2. We are the main loop and ctx == qemu_get_aio_context().
>     ^--- the sneaky case that BDRV_POLL_WHILE() has always relied on

Thanks, that helps.


>>> +    AIO_WAIT_WHILE(bdrv_get_aio_wait(bs_),                 \
>>> +                   bdrv_get_aio_context(bs_),              \
>>> +                   cond); })
>>
>> ...we can pass NULL as the wait parameter, which will crash.
> 
> It won't crash since if (aio_context_in_iothread(ctx_)) will take the true
> case when bs_ == NULL.

Okay, you've solved that one.

> 
>>> +++ b/block/io.c
>>
>>>    void bdrv_wakeup(BlockDriverState *bs)
>>>    {
>>> -    /* The barrier (or an atomic op) is in the caller.  */
>>> -    if (atomic_read(&bs->wakeup)) {
>>> -        aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
>>> -    }
>>> +    aio_wait_kick(bdrv_get_aio_wait(bs));
>>
>> this is another case where passing NULL...
> 
> bdrv_wakeup() is only called when bs != NULL.

And looks like we're safe, there, as well.

> 
> I hope this explains things!  The main issue that raised these questions
> was that aio_context_in_iothread() has a misleading name.  Shall we
> rename it?

Maybe, but that's a separate patch.  What name would we bikeshed, maybe 
aio_context_correct_thread() (we are the correct thread if we are the 
iothread that owns ctx, or if we are the main thread and have properly 
acquired ctx) or aio_context_use_okay() (we can only use the ctx if we 
own it [native iothread] or have acquired it [main loop])

> 
> I'm having a hard time picking a new name because it must not be
> confused with AioContext acquire/release, which doesn't influence the
> "native" AioContext that the current thread has an affinity with.
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2018-02-14 22:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 14:20 [Qemu-devel] [PATCH v2 0/4] block: fix blk_aio_*() segfault when blk->root == NULL Stefan Hajnoczi
2018-02-13 14:20 ` [Qemu-devel] [PATCH v2 1/4] block: extract AIO_WAIT_WHILE() from BlockDriverState Stefan Hajnoczi
2018-02-13 16:01   ` Eric Blake
2018-02-14 14:06     ` Stefan Hajnoczi
2018-02-14 22:31       ` Eric Blake [this message]
2018-02-15  9:27         ` Stefan Hajnoczi
2018-02-15 10:12           ` Kevin Wolf
2018-02-15 14:15             ` Eric Blake
2018-02-14 22:33     ` Eric Blake
2018-02-13 14:21 ` [Qemu-devel] [PATCH v2 2/4] block: add BlockBackend->in_flight counter Stefan Hajnoczi
2018-02-13 16:03   ` Eric Blake
2018-02-13 14:21 ` [Qemu-devel] [PATCH v2 3/4] block: test blk_aio_flush() with blk->root == NULL Stefan Hajnoczi
2018-02-13 14:21 ` [Qemu-devel] [PATCH v2 4/4] Revert "IDE: Do not flush empty CDROM drives" Stefan Hajnoczi
2018-02-15  9:28 ` [Qemu-devel] [PATCH v2 0/4] block: fix blk_aio_*() segfault when blk->root == NULL Stefan Hajnoczi

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=8894e9fa-8e3d-ecfe-07f4-61a465f4bf57@redhat.com \
    --to=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@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).