Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: pcm: Add xrun counter for snd_pcm_substream

This patch adds an xrun counter to snd_pcm_substream as an alternative
to using logs from XRUN_DEBUG_BASIC. The counter provides a way to track
the number of xrun occurences, accessible through the /proc interface.

The counter is enabled when CONFIG_SND_PCM_XRUN_DEBUG is set.

Example output:

$ cat /proc/asound/card0/pcm9p/sub0/status

owner_pid : 1425
trigger_time: 235.248957291
tstamp : 0.000000000
delay : 1912
avail : 480
avail_max : 1920
-----
hw_ptr : 672000
appl_ptr : 673440
xrun_counter: 3 # (new row)

Signed-off-by: Norman Bintang <normanbt@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Link: https://patch.msgid.link/20240809140648.3414349-1-normanbt@chromium.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Norman Bintang and committed by
Takashi Iwai
72c0f57d e9606148

+12
+3
include/sound/pcm.h
··· 498 498 /* misc flags */ 499 499 unsigned int hw_opened: 1; 500 500 unsigned int managed_buffer_alloc:1; 501 + #ifdef CONFIG_SND_PCM_XRUN_DEBUG 502 + unsigned int xrun_counter; /* number of times xrun happens */ 503 + #endif /* CONFIG_SND_PCM_XRUN_DEBUG */ 501 504 }; 502 505 503 506 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
+6
sound/core/pcm.c
··· 462 462 snd_iprintf(buffer, "-----\n"); 463 463 snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr); 464 464 snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr); 465 + #ifdef CONFIG_SND_PCM_XRUN_DEBUG 466 + snd_iprintf(buffer, "xrun_counter: %d\n", substream->xrun_counter); 467 + #endif 465 468 } 466 469 467 470 #ifdef CONFIG_SND_PCM_XRUN_DEBUG ··· 973 970 substream->pid = get_pid(task_pid(current)); 974 971 pstr->substream_opened++; 975 972 *rsubstream = substream; 973 + #ifdef CONFIG_SND_PCM_XRUN_DEBUG 974 + substream->xrun_counter = 0; 975 + #endif /* CONFIG_SND_PCM_XRUN_DEBUG */ 976 976 return 0; 977 977 } 978 978
+3
sound/core/pcm_lib.c
··· 184 184 pcm_warn(substream->pcm, "XRUN: %s\n", name); 185 185 dump_stack_on_xrun(substream); 186 186 } 187 + #ifdef CONFIG_SND_PCM_XRUN_DEBUG 188 + substream->xrun_counter++; 189 + #endif 187 190 } 188 191 189 192 #ifdef CONFIG_SND_PCM_XRUN_DEBUG