ALSA: pcm: Add xrun counter for snd_pcm_substream
authorNorman Bintang <normanbt@chromium.org>
Fri, 9 Aug 2024 14:06:45 +0000 (22:06 +0800)
committerTakashi Iwai <tiwai@suse.de>
Sat, 10 Aug 2024 08:40:58 +0000 (10:40 +0200)
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>
include/sound/pcm.h
sound/core/pcm.c
sound/core/pcm_lib.c

index ac8f3aef92052384000844dd5077e86034d2d360..384032b6c59cdc7be8532b423795ae8b9819af8e 100644 (file)
@@ -498,6 +498,9 @@ struct snd_pcm_substream {
        /* misc flags */
        unsigned int hw_opened: 1;
        unsigned int managed_buffer_alloc:1;
+#ifdef CONFIG_SND_PCM_XRUN_DEBUG
+       unsigned int xrun_counter; /* number of times xrun happens */
+#endif /* CONFIG_SND_PCM_XRUN_DEBUG */
 };
 
 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
index dc37f3508dc7a04c33d7471293cd9e22ffba66c4..290690fc2abcbbf7cfc4ffcbcd4769d281e64808 100644 (file)
@@ -462,6 +462,9 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
        snd_iprintf(buffer, "-----\n");
        snd_iprintf(buffer, "hw_ptr      : %ld\n", runtime->status->hw_ptr);
        snd_iprintf(buffer, "appl_ptr    : %ld\n", runtime->control->appl_ptr);
+#ifdef CONFIG_SND_PCM_XRUN_DEBUG
+       snd_iprintf(buffer, "xrun_counter: %d\n", substream->xrun_counter);
+#endif
 }
 
 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
@@ -970,6 +973,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
        substream->pid = get_pid(task_pid(current));
        pstr->substream_opened++;
        *rsubstream = substream;
+#ifdef CONFIG_SND_PCM_XRUN_DEBUG
+       substream->xrun_counter = 0;
+#endif /* CONFIG_SND_PCM_XRUN_DEBUG */
        return 0;
 }
 
index 6e7905749c4a3b60be131622309a9d308a5aa499..6eaa950504cfc0e0d93a62e7a341a7e021353eee 100644 (file)
@@ -184,6 +184,9 @@ void __snd_pcm_xrun(struct snd_pcm_substream *substream)
                pcm_warn(substream->pcm, "XRUN: %s\n", name);
                dump_stack_on_xrun(substream);
        }
+#ifdef CONFIG_SND_PCM_XRUN_DEBUG
+       substream->xrun_counter++;
+#endif
 }
 
 #ifdef CONFIG_SND_PCM_XRUN_DEBUG