Skip to contentSkip to conversation

ALSA: core: Allow drivers to set R/W wait time.

PATCH Applied Liam Girdwood 3 participants 3 messages Jul 6, 2018 – Mar 26, 2019 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ALSA: core: Allow drivers to set R/W wait time.

Currently ALSA core blocks userspace for about 10 seconds for PCM R/W IO. This needs to be configurable for modern hardware like DSPs where no pointer update in milliseconds can indicate terminal DSP errors.

Add a substream variable to set the wait time in ms. This allows userspace and drivers to recover more quickly from terminal DSP errors.

---

Changes since V1 :-
o Remove API method and alow drivers to set directly.
o Validate time is driver supplied times.

V2 :-
o Max wait calc now in ms.
o checkpatch.

v3:-
o Remove driver supplied time validation.

 include/sound/pcm.h  |  1 +
 sound/core/pcm_lib.c | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
include/sound/pcm.h +1 -0
index e054c583d3b3..fcdf358a25f0 100644
@@ -462,6 +462,7 @@ struct snd_pcm_substream {
         /* -- timer section -- */
 	struct snd_timer *timer;		/* timer */
 	unsigned timer_running: 1;	/* time is running */
+	long wait_time;	/* time in ms for R/W to wait for avail */
 	/* -- next substream -- */
 	struct snd_pcm_substream *next;
 	/* -- linked substreams -- */
sound/core/pcm_lib.c +12 -5
index 44b5ae833082..eecbfdc7a2c9 100644
@@ -1832,12 +1832,19 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 	if (runtime->no_period_wakeup)
 		wait_time = MAX_SCHEDULE_TIMEOUT;
 	else {
-		wait_time = 10;
-		if (runtime->rate) {
-			long t = runtime->period_size * 2 / runtime->rate;
-			wait_time = max(t, wait_time);
+		/* use wait time from substream if available */
+		if (substream->wait_time) {
+			wait_time = substream->wait_time;
+		} else {
+			wait_time = 10;
+
+			if (runtime->rate) {
+				long t = runtime->period_size * 2 /
+					 runtime->rate;
+				wait_time = max(t, wait_time);
+			}
+			wait_time = msecs_to_jiffies(wait_time * 1000);
 		}
-		wait_time = msecs_to_jiffies(wait_time * 1000);
 	}
 
 	for (;;) {
Signature · 1 line
2.17.1
Applied
#1 lore raw
Quoted 15 lines · Liam Girdwood

Currently ALSA core blocks userspace for about 10 seconds for PCM R/W IO. This needs to be configurable for modern hardware like DSPs where no pointer update in milliseconds can indicate terminal DSP errors.

Add a substream variable to set the wait time in ms. This allows userspace and drivers to recover more quickly from terminal DSP errors.

---

Changes since V1 :-
o Remove API method and alow drivers to set directly.
o Validate time is driver supplied times.

Quoted 6 lines

V2 :-
o Max wait calc now in ms.
o checkpatch.

v3:-
o Remove driver supplied time validation.

Applied, thanks.

Takashi

#2 lore raw
In reply to Liam Girdwood
Quoted 42 lines · Liam Girdwood

Currently ALSA core blocks userspace for about 10 seconds for PCM R/W IO. This needs to be configurable for modern hardware like DSPs where no pointer update in milliseconds can indicate terminal DSP errors.

Add a substream variable to set the wait time in ms. This allows userspace and drivers to recover more quickly from terminal DSP errors.

---

Changes since V1 :-
o Remove API method and alow drivers to set directly.
o Validate time is driver supplied times.

V2 :-
o Max wait calc now in ms.
o checkpatch.

v3:-
o Remove driver supplied time validation.

 include/sound/pcm.h  |  1 +
 sound/core/pcm_lib.c | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
include/sound/pcm.h +1 -0
index e054c583d3b3..fcdf358a25f0 100644
@@ -462,6 +462,7 @@ struct snd_pcm_substream {
         /* -- timer section -- */
 	struct snd_timer *timer;		/* timer */
 	unsigned timer_running: 1;	/* time is running */
+	long wait_time;	/* time in ms for R/W to wait for avail */
 	/* -- next substream -- */
 	struct snd_pcm_substream *next;
 	/* -- linked substreams -- */
sound/core/pcm_lib.c +0 -0
index 44b5ae833082..eecbfdc7a2c9 100644

sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1837

Quoted 10 lines
sound/core/pcm_lib.c +3 -4
@@ -1832,12 +1832,19 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 	if (runtime->no_period_wakeup)
 		wait_time = MAX_SCHEDULE_TIMEOUT;
 	else {
-		wait_time = 10;
-		if (runtime->rate) {
-			long t = runtime->period_size * 2 / runtime->rate;
-			wait_time = max(t, wait_time);
+		/* use wait time from substream if available */
+		if (substream->wait_time) {
+			wait_time = substream->wait_time;

I investigated the sof driver recently,  and found this  patch is a little bit confused,  if substream->wait_time is set, why don't  convert the wait_time to jiffies here? Is it a bug or an on-purpose design?

Thanks,

Hui.

Quoted 4 lines
sound/core/pcm_lib.c +4 -0
+		} else {
+			wait_time = 10;
+
+			if (runtime->rate) {

sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1850

Quoted 10 lines
sound/core/pcm_lib.c +5 -1
+				long t = runtime->period_size * 2 /
+					 runtime->rate;
+				wait_time = max(t, wait_time);
+			}
+			wait_time = msecs_to_jiffies(wait_time * 1000);
 		}
-		wait_time = msecs_to_jiffies(wait_time * 1000);
 	}
 
 	for (;;) {

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel