Hi,

While investigating capture stalls, I needed to tell whether a control request 
had timed out, completed later, or been canceled during teardown. The existing 
timeout log gives the raw opcode, but repeated requests need an identifier to 
follow their lifetimes (or cycles).

This RFC adds one trace event to sound/virtio. Its enqueue, response, cancel 
and wait records share a per-send ID. Wait records describe the sender's 
outcome, response and cancel records describe queue completion. Therefore a 
timed-out wait can be followed by a response with the same identifier.

The patch applies directly to the mainline base listed below. PCM capture 
staging, split-ACK accounting, workqueue priority and application recovery 
changes are outside this RFC.

Validation of the exact source diff:
- ARM64 W=1 kernel/module builds with KASAN and lockdep; additional object 
builds with BPF events enabled and with event tracing disabled.
- Six QEMU cases compare baseline, trace-off and trace-on for a delayed PREPARE 
response and cancellation during unbind/rebind. Each checks subsequent capture 
and playback. No KASAN/lockdep diagnostics or trace loss were recorded. These 
tests use a patched synthetic QEMU backend.
- Eighteen QEMU performance trials, 9,000 timed open/start/drop/close cycles, 
use a 4,096-frame buffer. Enabled trials produce the expected 
enqueue/response/wait counts. Steady capture produces no control events.

The added message fields cost 24 bytes per request on the tested ARM64 
configurations, even with tracing off. Module sections grew by 11,160 bytes in 
the debug build. Actual allocation depends on slab/page layout.

A further non-debug comparison used this exact candidate with QEMU 11.1.2 and 
HVF, sharing the same Image/config and differing only in virtio_snd.ko. Six 
balanced orders exercised 90,000 timed lifecycle cycles at 4,096 frames, 
followed by three 30-second synthetic captures. All functional checks passed, 
as each capture read 1,440,000 frames, with zero XRUNs or read errors. Each 
trace-on lifecycle trial recorded 90,000 events without loss. Steady capture 
recorded no control events.

Observed medians of six per-trial p95/p99 lifecycle times, in microseconds, 
were 201.105/349.729 for baseline, 254.146/334.416 for trace off, and 
291.667/413.083 for trace on. Median process CPU time per lifecycle was 70.437, 
70.532 and 77.300 microseconds, respectively. These measure the 
open/configure/prepare/start/drop/close sequence, rather than audio delivery 
latency.

Native VZ with the unpatched baseline and internal microphone completed 100 
lifecycle cycles, but a 30-second capture returned EIO after 1,131,472 frames 
(23.57 seconds of audio). Native VZ steady-capture performance remains 
unverified. Earlier VZ integration results included experimental capture 
changes and a different port of the trace implementation, as they do not 
establish performance of this exact candidate.

Additional ARM64 QEMU fault injection exercises the real send and completion 
paths through a separate test-only caller. The backend returns status 
`0xdeadbeef` and used lengths 0, 3 and 37 for a 36-byte response capacity. 
Blocking queue consumption fills 64 entries; the 65th send returns -ENOSPC. A 
held asynchronous request returns before its response, while SIGUSR1 interrupts 
a synchronous wait with kernel -ERESTARTSYS and userspace EINTR. Both requests 
complete later without another sender wait. Each fault is followed by a 
successful query, then the suite checks an additional-SG query, capture and 
capture reopen at 4,096 frames, plus playback.

The length faults deliberately write a complete response within the writable 
buffers and alter only the reported used length. Baseline and instrumented 
senders still return success in those cases. The event records the raw length 
with status_valid=0 and status=0; this patch does not change protocol 
validation. An unknown status with a valid length is recorded verbatim, with 
the existing sender path returning -EINVAL. Here status_valid describes 
coverage of the response header word. The raw used length remains available for 
opcode-specific payload checks.

Two fresh boots each of baseline, feature trace-off and feature trace-on passed 
all 42 fault scenarios with identical sender results. Each trace-on run 
contained 280 events with no trace loss. The original, unmodified production 
modules also passed six repeated timeout/reset regressions. Seven deliberately 
corrupted evidence sets were rejected by the oracle.

The fault caller and QEMU changes are local test fixtures, excluded from this 
patch. The production control implementation remains byte-for-byte the 
candidate tested above. The fixture modules were rebuilt with W=1; KASAN and 
lockdep remain enabled. These synthetic tests do not exercise physical 
microphone input or establish additional VZ compatibility.

Thanks,
Joonho

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

 sound/virtio/Makefile               |   2 +
 sound/virtio/virtio_ctl_msg.c       | 156 +++++++++++++++++++++++++++-
 sound/virtio/virtio_ctl_msg_trace.h | 107 +++++++++++++++++++
 3 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 sound/virtio/virtio_ctl_msg_trace.h

 base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e

Reply via email to