Skip to contentSkip to conversation

ALSA: virtio: trace control message lifecycles

RFC PATCH New Joonho Lee 2 participants 3 messages Oct 17

Subsystems (3)
lore
Share & tools
lore

Joonho Lee

author
#0 lore raw

v2 cover ALSA: virtio: trace control message lifecycles

Hi,

This adds a control-message lifecycle trace event to virtio-snd. A per-send ID connects enqueue, response, cancellation and sender wait outcomes, including a response arriving after a timeout.

Changes in v2:
- Group internal helper event arguments in struct virtsnd_ctl_event.
- Use designated initializers and named validity flags instead of positional booleans. Keep TRACE_EVENT and its record format unchanged.

The event definition, error handling and request lifetime are unchanged from v1. The patch applies directly to the base below and has no dependency on the experimental VZ capture changes.

Validation of v2:
- ARM64 W=1 builds, including KASAN/lockdep, BPF events and tracing-disabled configurations, passed without warnings or errors.
- Eight QEMU boots passed malformed-response, enqueue failure, asynchronous completion, interrupted wait, timeout and reset/recovery checks. Trace-on fixture runs recorded 280 events each without loss or KASAN/lockdep reports.
- A non-debug QEMU/HVF comparison completed 90,000 lifecycle cycles and three 10-second synthetic captures at 4,096 frames. All functional checks passed; captures each read 480,000 frames with no XRUNs or read errors.

On GCC 14.2.0 ARM64, the event arguments are scalarized. The control object text shrinks by 56 bytes and the send stack frame drops from 192 to 176 bytes. With event tracing compiled out, the old and new object text is identical. The existing 24-byte per-request metadata cost remains unchanged.

Host-load stability checks failed during the timing comparison, so those measurements do not establish an isolated runtime overhead percentage. These regressions use synthetic QEMU devices; native VZ steady-capture performance and physical microphone acceptance remain unverified.

The malformed-length fixture writes a full response and changes only the reported used length. The sender retains its existing behavior; this patch records diagnostic fields without changing protocol validation.

Previous version:
https://lore.kernel.org/linux-sound/[email protected]/T/

Thanks,
Joonho

Joonho Lee (1):
ALSA: virtio: trace control message lifecycles

 sound/virtio/Makefile               |   2 +
 sound/virtio/virtio_ctl_msg.c       | 178 +++++++++++++++++++++++++++++++++++-
 sound/virtio/virtio_ctl_msg_trace.h | 107 ++++++++++++++++++++++
 3 files changed, 286 insertions(+), 1 deletion(-)

base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e

author
#1 lore raw

RFC PATCH v2 1/1 ALSA: virtio: trace control message lifecycles

A timed-out control request can complete later or be canceled during teardown. The existing opcode-only timeout message does not identify the request or show when the queue gives it back, which makes it difficult to correlate control stalls with guest scheduling and device reset activity.

Add a virtio_snd_ctl_msg trace event with a per-send identifier and phases for enqueue, response, cancellation and the sender's wait outcome. Record PCM stream IDs where the request layout supplies one, the enqueue or wait result, and the device's used length and response status. Mark optional fields explicitly and check the writable response capacity before reading a status for the event.

Assign IDs only to requests sent while the event is enabled. Keep sender wait outcomes separate from queue completion so a timeout followed by a late response retains the same ID. Include neither audio data nor kernel addresses in the event.

Leave protocol results, request ownership and timeout handling unchanged. The added fields increase each control-message structure by 24 bytes on the tested ARM64 configurations, including when tracing is disabled. No events are added to PCM data completions.

Assisted-by LLM

---
Changes in v2:
- Group internal helper event arguments in struct virtsnd_ctl_event.
- Use designated initializers and named validity flags instead of positional booleans. Keep TRACE_EVENT and its record format unchanged.

 sound/virtio/Makefile               |   2 +
 sound/virtio/virtio_ctl_msg.c       | 178 +++++++++++++++++++++++++++++++++++-
 sound/virtio/virtio_ctl_msg_trace.h | 107 ++++++++++++++++++++++
 3 files changed, 286 insertions(+), 1 deletion(-)
sound/virtio/Makefile +2 -0
index 3ca41b3c8..3db8ad687 100644
@@ -2,6 +2,8 @@
 
 obj-$(CONFIG_SND_VIRTIO) += virtio_snd.o
 
+CFLAGS_virtio_ctl_msg.o := -I$(src)
+
 virtio_snd-y := \
 	virtio_card.o \
 	virtio_chmap.o \
sound/virtio/virtio_ctl_msg.c +177 -1

239 lines not on this page · raw message

sound/virtio/virtio_ctl_msg_trace.h new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.50.1
#2 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

A timed-out control request can complete later or be canceled during teardown. The existing opcode-only timeout message does not identify the request or show when the queue gives it back, which makes it difficult to correlate control stalls with guest scheduling and device reset activity.

Add a virtio_snd_ctl_msg trace event with a per-send identifier and phases for enqueue, response, cancellation and the sender's wait outcome. Record PCM stream IDs where the request layout supplies one, the enqueue or wait result, and the device's used length and response status. Mark optional fields explicitly and check the writable response capacity before reading a status for the event.

Assign IDs only to requests sent while the event is enabled. Keep sender wait outcomes separate from queue completion so a timeout followed by a late response retains the same ID. Include neither audio data nor kernel addresses in the event.

Quoted 7 lines

Leave protocol results, request ownership and timeout handling unchanged. The added fields increase each control-message structure by 24 bytes on the tested ARM64 configurations, including when tracing is disabled. No events are added to PCM data completions.

Assisted-by LLM

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1