qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Miles Glenn <milesg@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com
Subject: Best practice for issuing blocking calls in response to an event
Date: Thu, 20 Mar 2025 11:34:38 -0500	[thread overview]
Message-ID: <9d87fed729b2697605bcf5b6062669b6239e5c0f.camel@linux.ibm.com> (raw)

Hello,

I am attempting to simulate a system with multiple CPU
architectures.  To do this I am starting a unique QEMU process for each
CPU architecture that is needed. I'm also developing some QEMU code
that aids in transporting MMIO transactions across the process
boundaries using sockets.

The design takes MMIO request messages off of a socket, services the
request by calling address_space_ldq_be(), then sends a response
message (containing the requested data) over the same
socket.  Currently, this is all done inside the socket IOReadHandler
callback function.

This works as long as the targeted register exists in the same QEMU
process that received the request.  However, If the register exists in
another QEMU process, then the call to address_space_ldq_be() results
in another socket message being sent to that QEMU process, requesting
the data, and then waiting (blocking) for the response message
containing the data.  In other words, it ends up blocking inside the
event handler and even though the QEMU process containing the target
register was able to receive the request and send the response, the
originator of the request is unable to receive the response until it
eventually times out and stops blocking.  Once it times out and stops
blocking, it does receive the response, but now it is too late.

Here's a summary of the stack up to where the code blocks:

IOReadHandler callback
  calls address_space_ldq_be()
    resolves to mmio read op of a remote device
      sends request over socket and waits (blocks) for response

So, I'm looking for a way to handle the work of calling
address_space_ldq_be(), which might block when attempting to read a
register of a remote device, without blocking inside the IOReadHandler
callback context.

I've done a lot of searches and reading about how to do this on the web
and in the QEMU code but it's still not really clear to me how this
should be done in QEMU.  I've seen a lot about using coroutines to
handle cases like this. Is that what I should be using here?

Thanks,

Glenn Miles



             reply	other threads:[~2025-03-20 16:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 16:34 Miles Glenn [this message]
2025-03-20 20:09 ` Best practice for issuing blocking calls in response to an event Stefan Hajnoczi
2025-03-21 15:17   ` Miles Glenn
2025-03-24 18:35     ` Stefan Hajnoczi
2025-03-25 15:08       ` Miles Glenn

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=9d87fed729b2697605bcf5b6062669b6239e5c0f.camel@linux.ibm.com \
    --to=milesg@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).