From: Stefan Hajnoczi <stefanha@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: Ari Sundholm <ari@tuxera.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org,
Aapo Vienamo <aapo@tuxera.com>
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 1/5] block: Add blklogwrites
Date: Mon, 4 Jun 2018 10:59:48 +0100 [thread overview]
Message-ID: <20180604095948.GF13674@stefanha-x1.localdomain> (raw)
In-Reply-To: <e890432c-cfb4-d933-c1a8-d571ac5687e8@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]
On Fri, Jun 01, 2018 at 07:26:03AM -0500, Eric Blake wrote:
> On 05/31/2018 04:17 PM, Ari Sundholm wrote:
> > +static void blk_log_writes_co_do_file(void *opaque)
> > +{
> > + BlkLogWritesFileReq *fr = opaque;
> > +
> > + fr->file_ret = fr->func(fr);
> > +
> > + fr->r->done++;
>
> Two non-atomic increments...
>
> > + qemu_coroutine_enter_if_inactive(fr->r->co);
> > +}
> > +
> > +static int coroutine_fn
> > +blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
> > + QEMUIOVector *qiov, int flags,
> > + int (*file_func)(BlkLogWritesFileReq *r),
> > + uint64_t entry_flags)
> > +{
>
> > + qemu_coroutine_enter(co_file);
> > + qemu_coroutine_enter(co_log);
> > +
> > + while (r.done < 2) {
> > + qemu_coroutine_yield();
> > + }
>
> ...used as the condition for waiting. Since the point of coroutines is to
> allow (restricted) parallel operation, there's a chance that the coroutine
> implementation can be utilizing parallel threads; if that's the case, then
> on the rare race when both threads try to increment at near the same time,
> they can both read 0 and write 1, at which point this wait loop would be an
> infinite loop. You're probably better off using atomics (even if I'm wrong
> about coroutines being able to race each other on the increment, as the
> other point of coroutines is that they provide restricted parallelism where
> you can also implement them in only a single thread because of well-defined
> yield points).
In this case the coroutines run from a single event loop (the
BlockDriverState's AioContext) so they cannot race.
As QEMU transitions to a multi-queue block layer we will need to think
about parallelism more. But the multi-queue block layer isn't
implemented yet, so I prefer writing straightforward code now without
trying to anticipate what parallelism issues might arise in the future.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2018-06-04 9:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-31 21:17 [Qemu-devel] [PATCH 1/5] block: Add blklogwrites Ari Sundholm
2018-05-31 21:17 ` [Qemu-devel] [PATCH 2/5] block: Add a mechanism for passing a block driver a block configuration Ari Sundholm
2018-05-31 21:17 ` [Qemu-devel] [PATCH 3/5] hw/scsi/scsi-disk: Always apply block configuration to block driver Ari Sundholm
2018-05-31 21:17 ` [Qemu-devel] [PATCH 4/5] block/blklogwrites: Use block limits from the backend block configuration Ari Sundholm
2018-05-31 21:17 ` [Qemu-devel] [PATCH 5/5] block/blklogwrites: Use the block device logical sector size when logging writes Ari Sundholm
2018-06-01 12:26 ` [Qemu-devel] [PATCH 1/5] block: Add blklogwrites Eric Blake
2018-06-01 13:31 ` Ari Sundholm
2018-06-01 15:05 ` Eric Blake
2018-06-01 15:15 ` Ari Sundholm
2018-06-01 15:44 ` Eric Blake
2018-06-04 9:59 ` Stefan Hajnoczi [this message]
2018-06-01 13:32 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2018-06-01 14:24 ` Ari Sundholm
2018-06-04 9:51 ` Stefan Hajnoczi
2018-06-04 12:10 ` Ari Sundholm
2018-06-07 12:30 ` Stefan Hajnoczi
2018-06-07 13:13 ` Ari Sundholm
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=20180604095948.GF13674@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=aapo@tuxera.com \
--cc=ari@tuxera.com \
--cc=eblake@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).