All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Ruslan Ruslichenko <ruslichenko.r@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	peter.maydell@linaro.org, artem_mygaiev@epam.com,
	volodymyr_babchuk@epam.com, takahiro.nakata.wr@renesas.com,
	"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
	francisco.iglesias@amd.com, Ruslan_Ruslichenko@epam.com,
	"Edgar E . Iglesias" <edgar.iglesias@amd.com>
Subject: Re: [PATCH 10/29] hw/core: Implement Remote Port packet dispatch logic
Date: Thu, 5 Feb 2026 20:32:00 +0000	[thread overview]
Message-ID: <aYT-QEM0NBFWNEDI@redhat.com> (raw)
In-Reply-To: <20260205195824.2610192-11-ruslichenko.r@gmail.com>

On Thu, Feb 05, 2026 at 08:58:05PM +0100, Ruslan Ruslichenko wrote:
> From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> 
> Implement the mechanism to transfer packets from the dedicated
> protocol thread to the main QEMU execution loop for processing.
> 
> The patch adds the following features:
> - signaling logic using internal pipe to wake up the main loop
> - the rp_process handler, which retrieves packets from queue and
> dispatches them to the target Remote Port device.
> 
> This enables QEMU device models to handle remote events.
> 
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
> Signed-off-by: Takahiro Nakata <takahiro.nakata.wr@renesas.com>
> Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> ---
>  hw/core/remote-port.c         | 148 +++++++++++++++++++++++++++++++++-
>  include/hw/core/remote-port.h |   5 ++
>  2 files changed, 152 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c
> index 91b0682884..e44d9249c3 100644
> --- a/hw/core/remote-port.c
> +++ b/hw/core/remote-port.c
> @@ -52,6 +52,8 @@
>  #define REMOTE_PORT_CLASS(klass)    \
>       OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT)
>  
> +static void rp_event_read(void *opaque);
> +
>  static void rp_pkt_dump(const char *prefix, const char *buf, size_t len)
>  {
>      qemu_hexdump(stdout, prefix, buf, len);
> @@ -96,6 +98,12 @@ ssize_t rp_write(RemotePort *s, const void *buf, size_t count)
>      return r;
>  }
>  
> +static unsigned int rp_has_work(RemotePort *s)
> +{
> +    unsigned int work = s->rx_queue.wpos - s->rx_queue.rpos;
> +    return work;
> +}
> +
>  static void rp_cmd_hello(RemotePort *s, struct rp_pkt *pkt)
>  {
>      s->peer.version = pkt->hello.version;
> @@ -187,6 +195,135 @@ static Chardev *rp_autocreate_chardev(RemotePort *s, char *name)
>      return chr;
>  }
>  
> +void rp_process(RemotePort *s)
> +{
> +    while (true) {
> +        struct rp_pkt *pkt;
> +        unsigned int rpos;
> +        bool actioned = false;
> +        RemotePortDevice *dev;
> +        RemotePortDeviceClass *rpdc;
> +
> +        qemu_mutex_lock(&s->rsp_mutex);
> +        if (!rp_has_work(s)) {
> +            qemu_mutex_unlock(&s->rsp_mutex);
> +            break;
> +        }
> +        rpos = s->rx_queue.rpos;
> +
> +        pkt = s->rx_queue.pkt[rpos].pkt;
> +        D(qemu_log("%s: io-thread rpos=%d wpos=%d cmd=%d dev=%d\n",
> +                 s->prefix, s->rx_queue.rpos, s->rx_queue.wpos,
> +                 pkt->hdr.cmd, pkt->hdr.dev));

Same point as last patch, that emitted structured data in
tracepoints is preferrable to merely logging. Consider this
to apply to any other qemu_log call, so I won't repeat it
every time.

> +
> +        /*
> +         * To handle recursiveness, we need to advance the index
> +         * index before processing the packet.
> +         */
> +        s->rx_queue.rpos++;
> +        s->rx_queue.rpos %= ARRAY_SIZE(s->rx_queue.pkt);
> +        qemu_mutex_unlock(&s->rsp_mutex);
> +
> +        dev = s->devs[pkt->hdr.dev];
> +        if (dev) {
> +            rpdc = REMOTE_PORT_DEVICE_GET_CLASS(dev);
> +            if (rpdc->ops[pkt->hdr.cmd]) {
> +                rpdc->ops[pkt->hdr.cmd](dev, pkt);
> +                actioned = true;
> +            }
> +        }
> +
> +        switch (pkt->hdr.cmd) {
> +        /* TBD */
> +        default:
> +            assert(actioned);
> +        }
> +
> +        s->rx_queue.inuse[rpos] = false;
> +        qemu_sem_post(&s->rx_queue.sem);
> +    }
> +}
> +
> +static void rp_event_read(void *opaque)
> +{
> +    RemotePort *s = REMOTE_PORT(opaque);
> +    unsigned char buf[32];
> +    ssize_t r;
> +
> +    /* We don't care about the data. Just read it out to clear the event.  */
> +    do {
> +#ifdef _WIN32
> +        r = qemu_recv_wrap(s->event.pipe.read, buf, sizeof buf, 0);
> +#else
> +        r = read(s->event.pipe.read, buf, sizeof buf);
> +#endif
> +        if (r == 0) {
> +            return;
> +        }
> +    } while (r == sizeof buf || (r < 0 && errno == EINTR));
> +
> +    rp_process(s);
> +}
> +
> +static void rp_event_notify(RemotePort *s)
> +{
> +    unsigned char d = 0;
> +    ssize_t r;
> +
> +#ifdef _WIN32
> +    /* Mingw is sensitive about doing write's to socket descriptors.  */
> +    r = qemu_send_wrap(s->event.pipe.write, &d, sizeof d, 0);
> +#else
> +    r = qemu_write_full(s->event.pipe.write, &d, sizeof d);
> +#endif
> +    if (r == 0) {
> +        hw_error("%s: pipe closed\n", s->prefix);
> +    }
> +}
> +
> +/* Handover a pkt to CPU or IO-thread context.  */
> +static void rp_pt_handover_pkt(RemotePort *s, RemotePortDynPkt *dpkt)
> +{
> +    bool full;
> +
> +    /*
> +     * Take the rsp lock around the wpos update, otherwise
> +     * rp_wait_resp will race with us.
> +     */
> +    qemu_mutex_lock(&s->rsp_mutex);
> +    s->rx_queue.wpos++;
> +    s->rx_queue.wpos %= ARRAY_SIZE(s->rx_queue.pkt);
> +    /*
> +     * Ensure rx_queue index update is visible to consumer
> +     * before signaling event, to prevent lost wakeup
> +     */
> +    smp_mb();
> +    rp_event_notify(s);
> +    qemu_cond_signal(&s->progress_cond);
> +    qemu_mutex_unlock(&s->rsp_mutex);
> +
> +    do {
> +        full = s->rx_queue.inuse[s->rx_queue.wpos];
> +        if (full) {
> +            qemu_log("%s: FULL rx queue %d\n", __func__, s->rx_queue.wpos);
> +        if (qemu_sem_timedwait(&s->rx_queue.sem, 2 * 1000) != 0) {
> +#ifndef _WIN32
> +                int sval;
> +
> +#ifndef CONFIG_SEM_TIMEDWAIT
> +                sval = s->rx_queue.sem.count;
> +#else
> +                sem_getvalue(&s->rx_queue.sem.sem, &sval);
> +#endif
> +                qemu_log("semwait: %d rpos=%u wpos=%u\n", sval,
> +                         s->rx_queue.rpos, s->rx_queue.wpos);
> +#endif
> +                qemu_log("Deadlock?\n");
> +        }
> +        }
> +    } while (full);
> +}

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



  reply	other threads:[~2026-02-05 20:32 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05 19:57 [PATCH 00/29] hw/core: Introduce Remote Port Co-simulation Protocol Ruslan Ruslichenko
2026-02-05 19:57 ` [PATCH 01/29] hw/core: Add Remote Port protocol packet definition Ruslan Ruslichenko
2026-02-05 20:38   ` Daniel P. Berrangé
2026-02-06 17:45     ` Ruslan Ruslichenko
2026-02-06 18:06       ` Daniel P. Berrangé
2026-02-05 19:57 ` [PATCH 02/29] hw/core: Add Remote Port header helpers Ruslan Ruslichenko
2026-02-05 19:57 ` [PATCH 03/29] hw/core: Add Remote Port session state and hello protocol Ruslan Ruslichenko
2026-02-05 19:57 ` [PATCH 04/29] hw/core: Implement Remote Port bus access helpers Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 05/29] hw/core: Implement Remote Port irq, sync and ATS helpers Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 06/29] system/vl: Introduce -machine-path command line option Ruslan Ruslichenko
2026-02-05 20:17   ` Daniel P. Berrangé
2026-02-05 19:58 ` [PATCH 07/29] hw/core: Add Remote Port object skeleton Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 08/29] hw/core: Setup Remote Port I/O channels Ruslan Ruslichenko
2026-02-05 20:28   ` Daniel P. Berrangé
2026-02-06 17:33     ` Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 09/29] hw/core: Add Remote Port protocol thread and handshake Ruslan Ruslichenko
2026-02-05 20:29   ` Daniel P. Berrangé
2026-02-06 17:38     ` Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 10/29] hw/core: Implement Remote Port packet dispatch logic Ruslan Ruslichenko
2026-02-05 20:32   ` Daniel P. Berrangé [this message]
2026-02-05 19:58 ` [PATCH 11/29] hw/core: Implement Remote Port response handling Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 12/29] hw/core: Implement Remote Port time synchronization Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 13/29] system/memory: Introduce unified MemoryTransaction and .access callback Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 14/29] hw/core: Add Remote Port Memory Master object skeleton Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 15/29] hw/core: Implement Remote Port Memory Master bus transactions Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 16/29] system/physmem: Add ats_do_translate helper Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 17/29] hw/core: Add Remote Port ATS device skeleton Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 18/29] hw/core: Implement Remote Port ATS logic and cache management Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 19/29] hw/core: Add Remote Port memory slave device Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 20/29] hw/core: Add Remote Port GPIO/Interrupt bridge Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 21/29] hw/core: Add Remote Port Stream device Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 22/29] hw/core: Add Remote Port files to build Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 23/29] system: Introduce -sync-quantum command line option Ruslan Ruslichenko
2026-02-05 20:40   ` Daniel P. Berrangé
2026-02-06 17:57     ` Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 24/29] hw/core: Add FDT support to Remote Port GPIO Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 25/29] hw/core: Add FDT support to Remote Port memory master Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 26/29] hw/core: Add Remote Port connection support to fdt-generic Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 27/29] hw/core: Support IOMMU translation for Remote Port memory slave Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 28/29] hw/core: Add Remote Port attachment helpers Ruslan Ruslichenko
2026-02-05 19:58 ` [PATCH 29/29] hw/core: Add ATS support to Remote Port memory slave Ruslan Ruslichenko

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=aYT-QEM0NBFWNEDI@redhat.com \
    --to=berrange@redhat.com \
    --cc=Ruslan_Ruslichenko@epam.com \
    --cc=artem_mygaiev@epam.com \
    --cc=edgar.iglesias@amd.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=francisco.iglesias@amd.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ruslichenko.r@gmail.com \
    --cc=takahiro.nakata.wr@renesas.com \
    --cc=volodymyr_babchuk@epam.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.