From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org,
qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [PATCH experiment 00/16] C++20 coroutine backend
Date: Tue, 15 Mar 2022 16:15:46 +0000 [thread overview]
Message-ID: <YjC7sorD36xWfhHD@redhat.com> (raw)
In-Reply-To: <20220314093203.1420404-1-pbonzini@redhat.com>
On Mon, Mar 14, 2022 at 10:31:47AM +0100, Paolo Bonzini wrote:
> However, there are no ramifications to actual coroutine code, except
> for the template syntax "CoroutineFn<return_type>" for the function and
> the mandatory co_await/co_return keywords... both of which are an
> improvement, really: the fact that a single function cannot run either
> inside or outside coroutines is checked by the compiler now, because
> qemu_coroutine_create accepts a function that returns CoroutineFn<void>.
> Therefore I had to disable some more code in util/ and qapi/ that used
> qemu_in_coroutine() or coroutine_fn.
Bear with me as I suggest something potentially/probably silly
given my limited knowledge of C++ coroutines.
Given a function I know about:
void coroutine_fn qio_channel_yield(QIOChannel *ioc,
GIOCondition condition);
IIUC, you previously indicated that the header file declaration,
the implementation and any callers of this would need to be in
C++ source files.
The caller is what I'm most curious about, because I feel that
is where the big ripple effects come into play that cause large
parts of QEMU to become C++ code.
In general it is possible to call C++ functions from C.
I presume there is something special about the CoroutineFn<void>
prototype preventing that from working as needed, thus requiring
the caller to be compiled as C++ ? IIUC compiling as C++ though
is not neccessarily the same as using C++ linkage.
So I'm assuming the caller as C++ requirement is not recursive,
otherwise it would immediately mean all of QEMU needs to be C++.
This leads me to wonder if we can workaround this problem with
a wrapper function. eg in a io/channel.hpp file can be declare
something like:
CoroutineFn<void> qio_channel_yield_impl(QIOChannel *ioc,
GIOCondition condition);
extern "C" {
static inline void qio_chanel_yield(QIOChannel *ioc,
GIOCondition condition) {
qio_channel_yield_impl(ioc, condition)
}
}
With this qio_channel_yield_impl and qio_channel_yield are both
compiled as C++, but qio_channel_yield is exposed with C linkage
semantics. Thus enabling callers of qio_channel_yield can carry
on being compiled as C, since the invokation of the CoroutineFn
is in the inline C++ function ?
This would mean an extra function call, but perhaps this gets
optimized away, espeically with LTO, such that it doesn't impact
performance negatively ?
The impl of qio_channel_yield_impl() could also call from C++
back to C functions as much as possible.
IOW, can we get it such that the C++ bit is just a thin shim
"C -> C++ wrapper -> C++ CoroutineFn -> C", enabling all the
C++ bits to be well encapsulated and thus prevent arbitrary
usage of C++ features leaking all across the codebase ?
With Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-03-15 16:20 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 9:31 [PATCH experiment 00/16] C++20 coroutine backend Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 01/16] coroutine: add missing coroutine_fn annotations for CoRwlock functions Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 02/16] coroutine: qemu_coroutine_get_aio_context is not a coroutine_fn Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 03/16] coroutine: small code cleanup in qemu_co_rwlock_wrlock Paolo Bonzini
2022-03-14 13:32 ` Philippe Mathieu-Daudé
2022-03-14 9:31 ` [PATCH experiment 04/16] coroutine: introduce QemuCoLockable Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 05/16] port atomic.h to C++ Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 06/16] use g_new0 instead of g_malloc0 Paolo Bonzini
2022-03-14 11:16 ` Markus Armbruster
2022-03-14 9:31 ` [PATCH experiment 07/16] start porting compiler.h to C++ Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 08/16] tracetool: add extern "C" around generated headers Paolo Bonzini
2022-03-14 13:33 ` Philippe Mathieu-Daudé
2022-03-14 13:44 ` Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 09/16] start adding extern "C" markers Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 10/16] add space between liter and string macro Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 11/16] bump to C++20 Paolo Bonzini
2022-03-14 9:31 ` [PATCH experiment 12/16] remove "new" keyword from trace-events Paolo Bonzini
2022-03-14 13:30 ` Philippe Mathieu-Daudé
2022-03-14 9:32 ` [PATCH experiment 13/16] disable some code Paolo Bonzini
2022-03-14 9:32 ` [PATCH experiment 14/16] util: introduce C++ stackless coroutine backend Paolo Bonzini
2022-03-14 14:37 ` Stefan Hajnoczi
2022-03-14 19:36 ` Paolo Bonzini
2022-03-14 9:32 ` [PATCH experiment 15/16] port QemuCoLockable to C++ coroutines Paolo Bonzini
2022-03-14 9:32 ` [PATCH experiment 16/16] port test-coroutine " Paolo Bonzini
2022-03-14 14:07 ` [PATCH experiment 00/16] C++20 coroutine backend Stefan Hajnoczi
2022-03-14 16:21 ` Paolo Bonzini
2022-03-14 19:51 ` Richard Henderson
2022-03-15 14:05 ` Stefan Hajnoczi
2022-03-15 14:24 ` Peter Maydell
2022-03-15 17:29 ` Paolo Bonzini
2022-03-16 12:32 ` Stefan Hajnoczi
2022-03-16 13:06 ` Daniel P. Berrangé
2022-03-16 16:44 ` Stefan Hajnoczi
2022-03-17 15:11 ` Paolo Bonzini
2022-03-17 15:53 ` Hanna Reitz
2022-03-31 11:37 ` Markus Armbruster
2022-03-15 14:50 ` Kevin Wolf
2022-03-15 15:35 ` Stefan Hajnoczi
2022-03-15 15:55 ` Daniel P. Berrangé
2022-03-15 23:08 ` Paolo Bonzini
2022-03-16 12:40 ` Stefan Hajnoczi
2022-03-16 16:15 ` Kevin Wolf
2022-03-17 12:16 ` Dr. David Alan Gilbert
2022-03-17 12:51 ` Daniel P. Berrangé
2022-03-31 11:52 ` Markus Armbruster
2022-03-15 17:23 ` When and how to use C++ (was Re: [PATCH experiment 00/16] C++20 coroutine backend) Paolo Bonzini
2022-03-14 16:52 ` [PATCH experiment 00/16] C++20 coroutine backend Daniel P. Berrangé
2022-03-15 9:05 ` Paolo Bonzini
2022-03-15 9:32 ` Daniel P. Berrangé
2022-03-15 17:27 ` Paolo Bonzini
2022-03-15 18:12 ` Daniel P. Berrangé
2022-03-15 16:15 ` Daniel P. Berrangé [this message]
2022-03-15 17:50 ` 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=YjC7sorD36xWfhHD@redhat.com \
--to=berrange@redhat.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--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).