ALSA: core: Allow drivers to set R/W wait time.
PATCH v2 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.
include/sound/pcm.h | 1 + sound/core/pcm_lib.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
include/sound/pcm.h +1 -0
@@ -462,6 +462,7 @@ struct snd_pcm_substream {/* -- timer section -- */ struct snd_timer *timer;/* timer */ unsigned timer_running: 1; /* time is running */ +unsigned 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 +8 -2
@@ -1832,12 +1832,18 @@ static int wait_for_avail(struct snd_pcm_substream *substream,if (runtime->no_period_wakeup) wait_time =MAX_SCHEDULE_TIMEOUT ;else { - wait_time =10 ; +/* use wait time from substream if available */ +if (substream->wait_time) { + wait_time = substream->wait_time; + }else { + wait_time =10 *1000 ;/* 10 secs */ + } +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); }for (;;) {
Signature · 1 line
2.17.1
Quoted 38 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.
Signed-off-by Liam Girdwood <[email protected]>---
Changes since V1 :-
o Remove API method and alow drivers to set directly.
o Validate time is driver supplied times.include/sound/pcm.h | 1 + sound/core/pcm_lib.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)include/sound/pcm.h +1
-0@@ -462,6 +462,7 @@ struct snd_pcm_substream {/* -- timer section -- */ struct snd_timer *timer;/* timer */ unsigned timer_running: 1; /* time is running */ +unsigned 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@@ -1832,12 +1832,18 @@ static int wait_for_avail(struct snd_pcm_substream *substream,if (runtime->no_period_wakeup)
sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1841
Quoted 10 lines
sound/core/pcm_lib.c +7
-1wait_time =MAX_SCHEDULE_TIMEOUT ; else { - wait_time =10 ; +/* use wait time from substream if available */ +if (substream->wait_time) { + wait_time = substream->wait_time; + }else { + wait_time =10 *1000 ;/* 10 secs */ + } +
This seems to be msec, but...
sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1844
Quoted 3 lines
sound/core/pcm_lib.c +0
-0if (runtime->rate) {long t = runtime->period_size *2 / runtime->rate; wait_time =max (t, wait_time);
... here handled as a second.
sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1846
Quoted 3 lines
sound/core/pcm_lib.c +1
-1} - wait_time =msecs_to_jiffies (wait_time *1000 ); + wait_time =msecs_to_jiffies (wait_time);
... so this looks inconsistent.
Also, watch out the complaints from checkpatch.pl.
thanks,
Takashi
Quoted 59 lines · Takashi Iwai
Quoted 38 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.
Signed-off-by Liam Girdwood <[email protected]>---
Changes since V1 :-
o Remove API method and alow drivers to set directly.
o Validate time is driver supplied times.include/sound/pcm.h | 1 + sound/core/pcm_lib.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)include/sound/pcm.h +1
-0@@ -462,6 +462,7 @@ struct snd_pcm_substream {/* -- timer section -- */ struct snd_timer *timer;/* timer */ unsigned timer_running: 1; /* time is running */ +unsigned 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@@ -1832,12 +1832,18 @@ static int wait_for_avail(struct snd_pcm_substream *substream,if (runtime->no_period_wakeup)sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1841
Quoted 10 lines
sound/core/pcm_lib.c +7
-1wait_time =MAX_SCHEDULE_TIMEOUT ; else { - wait_time =10 ; +/* use wait time from substream if available */ +if (substream->wait_time) { + wait_time = substream->wait_time; + }else { + wait_time =10 *1000 ;/* 10 secs */ + } +This seems to be msec, but...
sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1844
Quoted 3 lines
sound/core/pcm_lib.c +0
-0if (runtime->rate) {long t = runtime->period_size *2 / runtime->rate; wait_time =max (t, wait_time);
Quoted 7 lines
... here handled as a second.
sound/core/pcm_lib.c static int wait_for_avail(struct snd_pcm_substream *substream, · line 1846
Quoted 3 lines
sound/core/pcm_lib.c +1
-1} - wait_time =msecs_to_jiffies (wait_time *1000 ); + wait_time =msecs_to_jiffies (wait_time);... so this looks inconsistent.
And I think we can forget runtime->rate check if it's specified explicitly. That is, something like:
/* use wait time from substream if available */
if (substream->wait_time) {
wait_time = substream->wait_time;
} else {
wait_time = 10; /* default 10 secs */
if (runtime->rate) {
long t = runtime->period_size * 2 / runtime->rate;
wait_time = max(t, wait_time);
}
wait_time *= 1000;
}
wait_time = msecs_to_jiffies(wait_time * 1000);Takashi