All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>, Coiby Xu <coiby.xu@gmail.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: Replace GSource with AioContext for chardev
Date: Thu, 9 Apr 2020 14:24:41 +0100	[thread overview]
Message-ID: <20200409132441.GS1202384@redhat.com> (raw)
In-Reply-To: <CAMxuvayJjHH_dqyoPCweQDysubzv=bKnJqgp9TxZNcNKnLTJhw@mail.gmail.com>

On Thu, Apr 09, 2020 at 03:16:01PM +0200, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Apr 9, 2020 at 2:46 PM Coiby Xu <coiby.xu@gmail.com> wrote:
> >
> >
> > Hi,
> >
> > I'm now implementing vhost-user block device backend
> > https://patchew.org/QEMU/20200309100342.14921-1-coiby.xu@gmail.com/
> > and want to use chardev to help manage vhost-user client connections
> > and read socket message. However there are two issues that need to be
> > addressed.
> >
> > Firstly, chardev isn't suitable for the case when exported drive is
> > run in an IOThread because for mow chardev use GSource to dispatch
> > socket fd events. So I have to specify which IOThread the exported
> > drive is using when launching vhost-user block device backend,
> > for example, the following syntax will be used,
> >
> >    -drive file=file.img,id=disk -device virtio-blk,drive=disk,iothread=iothread0 \
> >     -object vhost-user-blk-server,node-name=disk,chardev=mon1,iothread=iothread0 \
> >     -object iothread,id=iothread0 \
> >     -chardev socket,id=mon1,path=/tmp/vhost-user-blk_vhost.socket,server,nowait
> >
> > then iothread_get_g_main_context(IOThread *iothread) has to be called
> > to run the gcontext in IOThread. If we use AioContext to dispatch socket
> > fd events, we needn't to specify IOThread twice. Besides aio_poll is faster
> > than g_main_loop_run.
> >
> > Secondly, socket chardev's async read handler (set through
> > qemu_chr_fe_set_handlers) doesn't take the case of socket short read
> > into consideration.  I plan to add one which will make use qio_channel_yield.
> >
> > According to
> > [1] Improving the QEMU Event Loop - Linux Foundation Events
> > http://events17.linuxfoundation.org/sites/events/files/slides/Improving%20the%20QEMU%20Event%20Loop%20-%203.pdf
> >
> > "Convert chardev GSource to aio or an equivalent source" (p.30) should have
> > been finished. I'm curious why the plan didn't continue. If it's desirable,
> > I'm going to finish the leftover work to resolve the aforementioned two issues.
> 
> Converting all chardevs to Aio might be challenging, and doesn't bring
> much benefits imho.
> 
> Perhaps a better approach would be to rely on a new chardev API to
> steal the chardev underlying fd or QIO... (mostly keeping -chardev for
> CLI/QMP compatibility reason - although breaking some chardev features
> that imho aren't compatible with all use cases, like replay, muxing,
> swapping etc). The chardev should probably be removed after that...

Yeah, I feel like it was a mistake for us to wire up many of our features
to chardevs. We mostly did it because -chardev provides a pre-existing
syntax for TCP/UNIX sockets and we didn't want to invent new CLI args.
IMHO this was a mistake in retrospect.

Unfortunately the -chardev API is absolutely terrible for any usage that
actually cares about the connection based semantics. Witness the horrible
hacks we do for re-connect and re-try when failing to initially connect
in vhost-user net code.

For features in QEMU where the only desirable chardev backend is one with
connection based, socket semantics, I think we would be better off using
the QIOChannel APIs directly and completely avoiding the chardev code.

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 :|



  reply	other threads:[~2020-04-09 13:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 12:46 Replace GSource with AioContext for chardev Coiby Xu
2020-04-09 13:16 ` Marc-André Lureau
2020-04-09 13:24   ` Daniel P. Berrangé [this message]
2020-04-14  7:25     ` Markus Armbruster
2020-04-14 10:27       ` Daniel P. Berrangé
2020-04-14 10:54         ` Paolo Bonzini
2020-04-14 12:13           ` Kevin Wolf
2020-04-15 12:31             ` Daniel P. Berrangé

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=20200409132441.GS1202384@redhat.com \
    --to=berrange@redhat.com \
    --cc=coiby.xu@gmail.com \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.