From: Stefan Hajnoczi <stefanha@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: mdroth <mdroth@linux.vnet.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, Liu Ping Fan <qemulist@gmail.com>,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [RFC PATCH 0/2] port network layer onto glib
Date: Fri, 15 Mar 2013 10:13:31 +0100 [thread overview]
Message-ID: <20130315091331.GC3943@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <CAFEAcA8oX7U7KMz6rRyfxjUFXF22Aac3RPFG_hFnyRuY9d=2qw@mail.gmail.com>
On Thu, Mar 14, 2013 at 10:04:23AM +0000, Peter Maydell wrote:
> On 13 March 2013 12:34, Anthony Liguori <anthony@codemonkey.ws> wrote:
> > AioContext is necessary for the block layer because the block layer
> > still has synchronous I/O. I think we should aim to replace all sync
> > I/O in the long term with coroutine based I/O.
>
> I think coroutines are dreadful and we should really not be moving
> towards greater use of them. They're just really really not portable
> and they don't fit with the C language, and they're a constant source
> of problems.(For instance I have a bug I need to look into where we
> seem to hang using the gthread coroutine backend but not sigaltstack.)
>
> Use threads, or a genuinely asynchronous API, or a select/poll loop
> with callbacks, but not more coroutines please.
You're right that coroutines make it harder to support QEMU across host
operating systems.
Why we have coroutines
======================
That said, we need an alternative mechanism for writing sequential code.
If we went through the effort of converting all coroutine and blocking
code to asynchronous callbacks the codebase would be very hard to
understand:
Straightforward operations would be split into many little callbacks.
Local variables would turn into state that gets passed between
callbacks. This sort of code is much harder to reason about and is why
coroutines were introduced.
Coroutines allow us to keep the block layer and some of its users
readable. Removing them would not only be a big effort, but would also
make the codebase worse.
An alternative to stack switching
=================================
I was looking at a second approach when considering the options:
continuation passing style transformation. The following research
project implements an extension to C for writing sequential code that
gets converted to callbacks:
http://www.pps.univ-paris-diderot.fr/~kerneis/software/cpc/
Quick summary of how it works:
Continuating passing functions are marked with coroutine_fn, similar to
how we already do it in QEMU. There are APIs to create new coroutines
and to yield. The trick is that stack switching is not used and
therefore this approach is portable C. Instead the code is translated
to callbacks at build-time and variables are automatically passed on the
heap in a "thunk" buffer.
I chatted with the authors and it looks like a good approach. The
problems are:
1. Uses OCaml compiler framework. Should this be part of gcc or an
external tool that is easily consumed on all QEMU host platforms?
2. Debug information - need to make sure that callbacks map back to
sequential code.
3. Maturity - cpc isn't used much to my knowledge.
I'm willing to mentor a Summer of Code project that attempts to replace
coroutines with cpc. There's no guarantee it can replace coroutines due
to the issues I listed, but I think it's worth a shot.
Peter: Does this approach address your concerns about coroutines?
Thoughts about using a build-time tool instead of run-time stack
switching?
Stefan
next prev parent reply other threads:[~2013-03-15 9:13 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-13 5:59 [Qemu-devel] [RFC PATCH 0/2] port network layer onto glib Liu Ping Fan
2013-03-13 5:59 ` [Qemu-devel] [RFC PATCH 1/2] net: port tap " Liu Ping Fan
2013-03-13 5:59 ` [Qemu-devel] [RFC PATCH 2/2] net: port hub " Liu Ping Fan
2013-03-13 10:58 ` [Qemu-devel] [RFC PATCH 0/2] port network layer " Paolo Bonzini
2013-03-13 12:34 ` Anthony Liguori
2013-03-13 16:21 ` Paolo Bonzini
2013-03-13 17:06 ` mdroth
2013-03-13 17:31 ` Paolo Bonzini
2013-03-13 17:52 ` Michael S. Tsirkin
2013-03-13 18:09 ` Anthony Liguori
2013-03-13 17:23 ` Anthony Liguori
2013-03-13 17:35 ` Paolo Bonzini
2013-03-13 17:52 ` Anthony Liguori
2013-03-14 9:29 ` Stefan Hajnoczi
2013-03-14 9:53 ` Paolo Bonzini
2013-03-13 17:58 ` Anthony Liguori
2013-03-13 18:08 ` Paolo Bonzini
2013-03-13 18:51 ` Anthony Liguori
2013-03-14 10:04 ` Peter Maydell
2013-03-14 10:53 ` Paolo Bonzini
2013-03-14 11:00 ` Peter Maydell
2013-03-14 11:04 ` Paolo Bonzini
2013-03-14 11:26 ` Peter Maydell
2013-03-15 9:13 ` Stefan Hajnoczi [this message]
2013-03-19 9:30 ` Markus Armbruster
2013-03-19 10:12 ` Peter Maydell
2013-03-19 10:34 ` Paolo Bonzini
2013-03-19 10:38 ` Peter Maydell
2013-03-19 10:45 ` Paolo Bonzini
2013-03-14 14:08 ` liu ping fan
2013-03-14 14:18 ` Paolo Bonzini
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=20130315091331.GC3943@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=anthony@codemonkey.ws \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.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).