All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: Alexander Mikhalitsyn <alexander@mihalicyn.com>, qemu-devel@nongnu.org
Cc: "Volker Rümelin" <vr_qemu@t-online.de>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Stéphane Graber" <stgraber@stgraber.org>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Alexander Mikhalitsyn" <alexander@mihalicyn.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alexander Mikhalitsyn" <aleksandr.mikhalitsyn@futurfusion.io>
Subject: Re: [PATCH v3 2/9] hw/audio/virtio-sound: allocate an array of streams
Date: Mon, 29 Jun 2026 10:44:54 +0300	[thread overview]
Message-ID: <thdv34.1hr3kwq58lz3p@linaro.org> (raw)
In-Reply-To: <20260626123531.132078-3-alexander@mihalicyn.com>

On Fri, 26 Jun 2026 15:35, Alexander Mikhalitsyn <alexander@mihalicyn.com> wrote:
>From: Volker Rümelin <vr_qemu@t-online.de>
>
>It is much easier to migrate an array of structs than individual
>structs that are accessed via a pointer to a pointer to an array
>of pointers to struct.
>
>For this reason, allocate an array of streams in
>virtio_snd_realize() and initialise all stream variables that
>are constant at runtime immediately after allocation.
>
>This makes it easier to remove the virtio_snd_set_pcm_params()
>and virtio_snd_pcm_prepare() calls in the realisation phase and
>to migrate the audio streams of the virtio sound device after
>the next few patches.
>
>Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
>[AM: there were too many conflicts, I did `git checkout --ours -- <.>`
>     and then reimplemented the patch idea
>/AM]
>Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
>Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>---
>v3:
>	As suggested by Marc-André Lureau:
>	- drop VirtIOSoundPCMStream's id field
>---
> hw/audio/virtio-snd.c         | 34 +++++++++++++++++++++-------------
> include/hw/audio/virtio-snd.h |  2 +-
> 2 files changed, 22 insertions(+), 14 deletions(-)
>
>diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
>index 6eb31e2838e..859c2770195 100644
>--- a/hw/audio/virtio-snd.c
>+++ b/hw/audio/virtio-snd.c
>@@ -436,12 +436,9 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
> 
>     stream = virtio_snd_pcm_get_stream(s, stream_id);
>     if (stream == NULL) {
>-        stream = g_new0(VirtIOSoundPCMStream, 1);
>+        stream = &s->streams[stream_id];
>         stream->active = false;
>-        stream->id = stream_id;
>-        stream->s = s;
>         stream->latency_bytes = 0;
>-        QSIMPLEQ_INIT(&stream->queue);
> 
>         /*
>          * stream_id >= s->snd_conf.streams was checked before so this is
>@@ -451,14 +448,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
>     }
> 
>     virtio_snd_get_qemu_audsettings(&as, params);
>-    stream->info.direction = stream_id < s->snd_conf.streams / 2 +
>-        (s->snd_conf.streams & 1) ? VIRTIO_SND_D_OUTPUT : VIRTIO_SND_D_INPUT;
>-    stream->info.hdr.hda_fn_nid = VIRTIO_SOUND_HDA_FN_NID;
>-    stream->info.features = 0;
>-    stream->info.channels_min = 1;
>-    stream->info.channels_max = as.nchannels;
>-    stream->info.formats = supported_formats;
>-    stream->info.rates = supported_rates;
>     stream->params = *params;
> 
>     stream->positions[0] = VIRTIO_SND_CHMAP_FL;
>@@ -1046,6 +1035,24 @@ static void virtio_snd_realize(DeviceState *dev, Error **errp)
>     vsnd->vmstate =
>         qemu_add_vm_change_state_handler(virtio_snd_vm_state_change, vsnd);
> 
>+    vsnd->streams = g_new0(VirtIOSoundPCMStream, vsnd->snd_conf.streams);
>+
>+    for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
>+        VirtIOSoundPCMStream *stream = &vsnd->streams[i];
>+
>+        stream->s = vsnd;
>+        QSIMPLEQ_INIT(&stream->queue);
>+        stream->info.hdr.hda_fn_nid = VIRTIO_SOUND_HDA_FN_NID;
>+        stream->info.features = 0;
>+        stream->info.formats = supported_formats;
>+        stream->info.rates = supported_rates;
>+        stream->info.direction =
>+            i < vsnd->snd_conf.streams / 2 + (vsnd->snd_conf.streams & 1)
>+            ? VIRTIO_SND_D_OUTPUT : VIRTIO_SND_D_INPUT;
>+        stream->info.channels_min = 1;
>+        stream->info.channels_max = 2;


Why 2 instead of as.nchannels? Does this break support for more than 2 
channels?

>+    }
>+
>     vsnd->pcm.streams =
>         g_new0(VirtIOSoundPCMStream *, vsnd->snd_conf.streams);
>     vsnd->pcm.pcm_params =
>@@ -1314,12 +1321,13 @@ static void virtio_snd_unrealize(DeviceState *dev)
>             if (stream) {
>                 virtio_snd_process_cmdq(stream->s);
>                 virtio_snd_pcm_close(stream);
>-                g_free(stream);
>             }
>         }
>         g_free(vsnd->pcm.streams);
>     }
>     g_free(vsnd->pcm.pcm_params);
>+    g_free(vsnd->streams);
>+    vsnd->streams = NULL;
>     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]);
>     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]);
>     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_TX]);
>diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
>index fce7d1feea2..41c63b3f23b 100644
>--- a/include/hw/audio/virtio-snd.h
>+++ b/include/hw/audio/virtio-snd.h
>@@ -136,7 +136,6 @@ struct VirtIOSoundPCM {
> struct VirtIOSoundPCMStream {
>     virtio_snd_pcm_info info;
>     virtio_snd_pcm_set_params params;
>-    uint32_t id;
>     /* channel position values (VIRTIO_SND_CHMAP_XXX) */
>     uint8_t positions[VIRTIO_SND_CHMAP_MAX_SIZE];
>     VirtIOSound *s;
>@@ -214,6 +213,7 @@ struct VirtIOSound {
>     VirtQueue *queues[VIRTIO_SND_VQ_MAX];
>     uint64_t features;
>     VirtIOSoundPCM pcm;
>+    VirtIOSoundPCMStream *streams;
>     AudioBackend *audio_be;
>     VMChangeStateEntry *vmstate;
>     virtio_snd_config snd_conf;
>-- 
>2.47.3
>


  reply	other threads:[~2026-06-29  7:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 12:35 [PATCH v3 0/9] hw/audio/virtio-sound: basic migration support Alexander Mikhalitsyn
2026-06-26 12:35 ` [PATCH v3 1/9] hw/audio/virtio-sound: remove command and stream mutexes Alexander Mikhalitsyn
2026-06-29  7:43   ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 2/9] hw/audio/virtio-sound: allocate an array of streams Alexander Mikhalitsyn
2026-06-29  7:44   ` Manos Pitsidianakis [this message]
2026-06-26 12:35 ` [PATCH v3 3/9] hw/audio/virtio-sound: free all stream buffers on reset Alexander Mikhalitsyn
2026-06-29  7:50   ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 4/9] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() Alexander Mikhalitsyn
2026-06-29  7:51   ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 5/9] hw/audio/virtio-sound: add stream state variable Alexander Mikhalitsyn
2026-06-26 14:12   ` marcandre.lureau
2026-06-29  7:58   ` Manos Pitsidianakis
2026-06-29  8:21     ` Michael S. Tsirkin
2026-06-29  8:31       ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 6/9] hw/audio/virtio-sound: introduce virtio_snd_pcm_open() Alexander Mikhalitsyn
2026-06-29  8:19   ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 7/9] hw/audio/virtio-sound: introduce virtio_snd_set_active() Alexander Mikhalitsyn
2026-06-26 12:35 ` [PATCH v3 8/9] hw/audio/virtio-sound: remove channel positions field from VirtIOSoundPCMStream Alexander Mikhalitsyn
2026-06-26 14:12   ` marcandre.lureau
2026-06-29  8:22   ` Manos Pitsidianakis
2026-06-26 12:35 ` [PATCH v3 9/9] hw/audio/virtio-sound: add missing vmstate fields Alexander Mikhalitsyn
2026-06-26 14:12   ` marcandre.lureau
2026-06-29  8:23   ` Manos Pitsidianakis
2026-06-29 11:04 ` [PATCH v3 0/9] hw/audio/virtio-sound: basic migration support Manos Pitsidianakis
2026-06-29 11:32   ` Aleksandr Mikhalitsyn
2026-06-29 12:01     ` Manos Pitsidianakis

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=thdv34.1hr3kwq58lz3p@linaro.org \
    --to=manos.pitsidianakis@linaro.org \
    --cc=aleksandr.mikhalitsyn@futurfusion.io \
    --cc=alexander@mihalicyn.com \
    --cc=berrange@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stgraber@stgraber.org \
    --cc=vr_qemu@t-online.de \
    /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.