qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Anton Kuchin <antonkuchin@yandex-team.ru>
Cc: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <famz@redhat.com>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] What events should be handled in iohandler context?
Date: Fri, 19 Jul 2019 10:40:46 +0100	[thread overview]
Message-ID: <20190719094046.GC18585@stefanha-x1.localdomain> (raw)
In-Reply-To: <9f644e46-6fc5-01ea-068a-fdbf9e08b828@yandex-team.ru>

[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]

On Mon, Jul 15, 2019 at 06:19:31PM +0300, Anton Kuchin wrote:
> I'm trying to understand contexts and handlers/notifiers and a bit confused
> about two contexts living in main loop: qemu_aio_context and iohandler_ctx.
> It is mentioned in the iohandler_ctx comment that qemu_aio_context can't be
> reused because "iohandlers mustn't be polled by aio_poll(qemu_aio_context)"
> but there is no exlanation why.

It's a historic thing that existing code depends on.  Users of the
iohandlers API do not expect their fds to be processed when
aio_poll(qemu_aio_context) is called.

New code tends to use qemu_aio_context because the AioContext API can
also be used with IOThreads.  This means processing can run in the main
loop thread or a dedicated thread (IOThread) without code changes.

> I tried to find examples and failed to understand why virtio-net eventfds
> are registred to iohandler_ctx with generic virtio callback
> virtio_device_start_ioeventfd_impl() but TX bottom-half and handlers of
> back-end TAP use qemu_aio_context.
> 
> Can you explain a little bit why we need some fds to be polled and some not
> to be polled? And how can I choose which context is right for me?

By default hw/virtio/virtio.c uses iohandler_ctx although devices can
use virtio_queue_aio_set_host_notifier_handler() to attach the
host_notifier to any AioContext.  virtio-blk and virtio-scsi are
examples of doing with with an IOThread.

The iohandler_ctx vs qemu_aio_context separation is a conservative way
of maintaining assumptions in existing code.  There might be code that
can safely run in qemu_aio_context instead, but it can be hard to
foresee issues caused by switching so it only be done if there is a good
reason.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2019-07-19  9:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 15:19 [Qemu-devel] What events should be handled in iohandler context? Anton Kuchin
2019-07-19  9:40 ` 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=20190719094046.GC18585@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=antonkuchin@yandex-team.ru \
    --cc=armbru@redhat.com \
    --cc=famz@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).