* [PATCH] ALSA: pcm: Add xrun counter for snd_pcm_substream
@ 2024-08-09 14:06 Norman Bintang
2024-08-10 8:41 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Norman Bintang @ 2024-08-09 14:06 UTC (permalink / raw)
To: LKML
Cc: broonie, alsa-devel, Takashi Iwai, cujomalainey, Norman Bintang,
Chih-Yang Hsia, David Riley
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>
---
include/sound/pcm.h | 3 +++
sound/core/pcm.c | 6 ++++++
sound/core/pcm_lib.c | 3 +++
3 files changed, 12 insertions(+)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index ac8f3aef9205..384032b6c59c 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -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)
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index dc37f3508dc7..290690fc2abc 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -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;
}
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 6e7905749c4a..6eaa950504cf 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -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
--
2.46.0.76.ge559c4bf1a-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ALSA: pcm: Add xrun counter for snd_pcm_substream
2024-08-09 14:06 [PATCH] ALSA: pcm: Add xrun counter for snd_pcm_substream Norman Bintang
@ 2024-08-10 8:41 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-08-10 8:41 UTC (permalink / raw)
To: Norman Bintang
Cc: LKML, broonie, alsa-devel, Takashi Iwai, cujomalainey,
Chih-Yang Hsia, David Riley
On Fri, 09 Aug 2024 16:06:45 +0200,
Norman Bintang wrote:
>
> 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>
Applied to for-next branch. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-10 8:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-09 14:06 [PATCH] ALSA: pcm: Add xrun counter for snd_pcm_substream Norman Bintang
2024-08-10 8:41 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®