virtio-snd: snapshot prep cleanups
cover virtio-snd: snapshot prep cleanups
I am currently working on adding snapshot support for the virtio-snd device. While implementing the VMStateDescription, I noticed that the device currently retains more internal state than is strictly necessary, including unused fields and full transport-specific layouts.
This patch series cleans up the internal PCM state to reduce the overall allocation footprint and simplify the upcoming snapshotting and migration handling code.
Roman Kiryanov (3):
virtio-snd: remove the unused field
virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream
virtio-snd: introduce VirtIOPcmParams
hw/audio/virtio-snd.c | 21 +++++++++------------ include/hw/audio/virtio-snd.h | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 16 deletions(-)
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
PATCH 1/3 virtio-snd: remove the unused field
VirtIOSoundPCMStream::positions is set but
never read from. It can be added back once
required.
--- hw/audio/virtio-snd.c | 3 --- include/hw/audio/virtio-snd.h | 2 -- 2 files changed, 5 deletions(-)
hw/audio/virtio-snd.c +0 -3
@@ -462,9 +462,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id) stream->info.formats = supported_formats; stream->info.rates = supported_rates; stream->params = *params; - - stream->positions[0 ] =VIRTIO_SND_CHMAP_FL ; - stream->positions[1 ] =VIRTIO_SND_CHMAP_FR ; stream->as = as;if (stream->info.direction ==VIRTIO_SND_D_OUTPUT ) {
include/hw/audio/virtio-snd.h +0 -2
@@ -137,8 +137,6 @@ 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;bool flushing;audsettings as;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
PATCH 2/3 virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream
In reply to Roman KiryanovThe virtio_snd_pcm_set_params values are latched into a VirtIOSoundPCMStream instance during the PREPARE request where they are converted into audsettings. Only the period_bytes value is used afterwards.
Having both audsettings and virtio_snd_pcm_set_params next to each other grows sizeof and adds confusion to snapshot handling.
--- hw/audio/virtio-snd.c | 6 +++--- include/hw/audio/virtio-snd.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
hw/audio/virtio-snd.c +3 -3
@@ -461,7 +461,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id) stream->info.channels_max = as.nchannels; stream->info.formats = supported_formats; stream->info.rates = supported_rates; - stream->params = *params; + stream->period_bytes = params->period_bytes; stream->as = as;if (stream->info.direction ==VIRTIO_SND_D_OUTPUT ) {
@@ -1271,7 +1271,7 @@ static void virtio_snd_pcm_in_cb(void *data, int available)return_rx_buffer (stream, buffer);break ; } - to_read = stream->params.period_bytes - buffer->size; + to_read = stream->period_bytes - buffer->size; to_read =MIN (to_read, available); to_read =MIN (to_read, max_size - buffer->size); size = audio_be_read(stream->s->audio_be,
@@ -1284,7 +1284,7 @@ static void virtio_snd_pcm_in_cb(void *data, int available) } buffer->size += size; available -= size; -if (buffer->size >= stream->params.period_bytes) { +if (buffer->size >= stream->period_bytes) {return_rx_buffer (stream, buffer);break ; }
include/hw/audio/virtio-snd.h +1 -1
@@ -135,8 +135,8 @@ struct VirtIOSoundPCM {struct VirtIOSoundPCMStream {virtio_snd_pcm_info info; -virtio_snd_pcm_set_params params;uint32_t id; +uint32_t period_bytes;/* from virtio_snd_pcm_set_params */ VirtIOSound *s;bool flushing;audsettings as;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
PATCH 3/3 virtio-snd: introduce VirtIOPcmParams
In reply to Roman KiryanovIntroduce the VirtIOPcmParams struct to represent the payload of virtio_snd_pcm_set_params without the VirtIO transport-specific header fields.
By decoupling the internal PCM state from the transport layout, VirtIOPcmParams simplifies the snapshot and migration handling code and slightly reduces the allocation footprint per stream.
--- hw/audio/virtio-snd.c | 12 ++++++------ include/hw/audio/virtio-snd.h | 13 ++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-)
hw/audio/virtio-snd.c +6 -6
@@ -139,8 +139,8 @@ static VirtIOSoundPCMStream *virtio_snd_pcm_get_stream(VirtIOSound *s,* @s: VirtIOSound device * @stream_id: stream id */ -static virtio_snd_pcm_set_params *virtio_snd_pcm_get_params (VirtIOSound *s, -uint32_t stream_id) +static VirtIOPcmParams *virtio_snd_pcm_get_params (VirtIOSound *s, +uint32_t stream_id) {return stream_id >= s->snd_conf.streams ?NULL : &s->pcm.pcm_params[stream_id];
@@ -258,7 +258,7 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,uint32_t stream_id, virtio_snd_pcm_set_params *params) { - virtio_snd_pcm_set_params *st_params; + VirtIOPcmParams *st_params;if (stream_id >= s->snd_conf.streams || s->pcm.pcm_params ==NULL ) {virtio_error (VIRTIO_DEVICE (s),"Streams have not been initialized.\n" );
@@ -384,7 +384,7 @@ static uint32_t virtio_snd_get_qemu_freq(uint32_t rate)* params. */ static void virtio_snd_get_qemu_audsettings (audsettings *as, -virtio_snd_pcm_set_params *params) +VirtIOPcmParams *params) { as->nchannels =MIN (AUDIO_MAX_CHANNELS , params->channels); as->fmt =virtio_snd_get_qemu_format (params->format);
@@ -421,7 +421,7 @@ static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream)static uint32_t virtio_snd_pcm_prepare (VirtIOSound *s,uint32_t stream_id) {audsettings as; -virtio_snd_pcm_set_params *params; +VirtIOPcmParams *params;VirtIOSoundPCMStream *stream; if (s->pcm.streams == NULL ||
@@ -1063,7 +1063,7 @@ static void virtio_snd_realize(DeviceState *dev, Error **errp) vsnd->pcm.streams = g_new0(VirtIOSoundPCMStream *, vsnd->snd_conf.streams); vsnd->pcm.pcm_params = -g_new0 (virtio_snd_pcm_set_params, vsnd->snd_conf.streams); +g_new0 (VirtIOPcmParams, vsnd->snd_conf.streams);virtio_init (vdev,VIRTIO_ID_SOUND ,sizeof (virtio_snd_config));virtio_add_feature (&vsnd->features,VIRTIO_F_VERSION_1 );
include/hw/audio/virtio-snd.h +12 -1
@@ -71,6 +71,8 @@ typedef struct virtio_snd_pcm_status virtio_snd_pcm_status;typedef struct VirtIOSound VirtIOSound ; +typedef struct VirtIOPcmParams VirtIOPcmParams ; +typedef struct VirtIOSoundPCMStream VirtIOSoundPCMStream ;typedef struct virtio_snd_ctrl_command virtio_snd_ctrl_command ;
@@ -121,6 +123,15 @@ struct VirtIOSoundPCMBuffer {uint8_t data[]; }; +struct VirtIOPcmParams { +uint32_t buffer_bytes; +uint32_t period_bytes; +uint32_t features; +uint8_t channels; +uint8_t format; +uint8_t rate; +}; +struct VirtIOSoundPCM {/* * PCM parameters are a separate field instead of a VirtIOSoundPCMStream
@@ -129,7 +140,7 @@ struct VirtIOSoundPCM {* means that some times we get parameters without having an allocated * stream yet. */ -virtio_snd_pcm_set_params *pcm_params; +VirtIOPcmParams *pcm_params;VirtIOSoundPCMStream **streams; };
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 3 lines · Roman Kiryanov
I am currently working on adding snapshot support for the virtio-snd device.
This patch series cleans up the internal PCM state ...
Hi everyone, just a quick ping on this cleanup series.
Let me know if anyone has had a chance to look over these patch series or if there are any concerns.
Thanks, Roman
Hi
Quoted 10 lines · Roman Kiryanov
I am currently working on adding snapshot support for the virtio-snd device. While implementing the VMStateDescription, I noticed that the device currently retains more internal state than is strictly necessary, including unused fields and full transport-specific layouts.
This patch series cleans up the internal PCM state to reduce the overall allocation footprint and simplify the upcoming snapshotting and migration handling code.
Quoted 8 lines
Roman Kiryanov (3):
virtio-snd: remove the unused field
virtio-snd: removevirtio_snd_pcm_set_paramsfrom VirtIOSoundPCMStream
virtio-snd: introduce VirtIOPcmParamshw/audio/virtio-snd.c | 21 +++++++++------------ include/hw/audio/virtio-snd.h | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 16 deletions(-)
For the series:
Signature · 1 line
Marc-André Lureau