qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] coroutine: use AioContext for CoQueue BH
Date: Thu, 7 Mar 2013 11:25:28 +0100	[thread overview]
Message-ID: <20130307102528.GD14726@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <20130306154101.GD2285@dhcp-200-207.str.redhat.com>

On Wed, Mar 06, 2013 at 04:41:01PM +0100, Kevin Wolf wrote:
> Am 06.03.2013 um 15:53 hat Stefan Hajnoczi geschrieben:
> > CoQueue uses a BH to awake coroutines that were made ready to run again
> > using qemu_co_queue_next() or qemu_co_queue_restart_all().  The BH
> > currently runs in the iothread AioContext and would break coroutines
> > that run in a different AioContext.
> > 
> > This is a slightly tricky problem because the lifetime of the BH exceeds
> > that of the CoQueue.  This means coroutines can be awoken after CoQueue
> > itself has been freed.
> 
> Does this really happen in practice? If so, that sounds like a bug to
> me.

I didn't audit the callers.  It seems reasonable that a CoQueue is
allowed to go out of scope once qemu_co_queue_empty() returns true.  I
don't see what is buggy about that.

> > Finally, I don't want to move unlock_queue and unlock_bh into
> > AioContext.  That would break encapsulation - AioContext isn't supposed
> > to know about CoQueue.
> 
> So what you would need here is "AioContext local storage". I wonder if
> this will stay a requirement unique to CoQueues when AioContexts gain
> wider use.

I'm not convinced we need AioContext local storage.

We could go all the way and make AioContext* thread-local.  Then we can
figure out the current AioContext* or NULL, if none, at any location in
the code.

Then CoQueue (and others?) could attach their resources to AioContext
local storage.

But let's avoid it if there are clean solutions because implicit state
like globals or thread-locals makes code harder to understand.

Stefan

      reply	other threads:[~2013-03-07 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06 14:53 [Qemu-devel] [PATCH] coroutine: use AioContext for CoQueue BH Stefan Hajnoczi
2013-03-06 15:03 ` Paolo Bonzini
2013-03-07 10:09   ` Stefan Hajnoczi
2013-03-06 15:41 ` Kevin Wolf
2013-03-07 10:25   ` Stefan Hajnoczi [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=20130307102528.GD14726@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --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).