Skip to contentSkip to conversation

alsa: Disable timer-scheduling for PCMs with the BATCH flag

PATCH Raymond Yau 4 participants 7 messages Dec 3, 2013 – Dec 14, 2013 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAN8cciYz=ZFJNW_FNqKTceCV4S=pz3CwkbwKcTeZb4AM=7bWzw@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 41 lines
Quoted 2 lines

PCM Devices which have the BATCH flag set update the PCM pointer

only with

Quoted 1 line

period size granularity. Using timer based scheduling does not have

any

Quoted 1 line

advantage in this mode. For one devices which have that flag set

usually

Quoted 2 lines

update
the position pointer in software after getting the period interrupt.

So

Quoted 1 line

disabling the period interrupt is not possible for this kind of

devices.

Quoted 1 line

Furthermore writing to or reading from the buffer slice for the

current

Quoted 4 lines

period
is not possible since the position inside the buffer is not known. On the other
hand the tsched algorithm seems to get easily confused for this kind

of

Quoted 3 lines

hardware, which results in garbled audio output. This typically means that timer
based scheduling needs to be manually disabled on systems with such

devices.

Quoted 1 line

Auto disabling tsched in this case allows these systems to run with

the

Quoted 5 lines

default
configuration.

If the playback position is reported in steps instead of monotonic

increasing ?

Quoted 2 lines

does this mean that you also need to increase rewind_safeguard to one

period

Quoted 1 line

or modifiy snd_pcm_rewindable ?

Yes that makes sense. The safeguard should probably be 1.5 periods or 1 period + fixed value, since it will always take some time from when the hardware reaches the next period to when userspace is notified about this.

Quoted 8 lines

I'm unfortunately not that familiar with pulseaudio. Maybe there is a better
way to fix this problem then to disable tsched. If anybody wants to recreate
the issue it can easily be emulated by applying the following patch to your kernel:

does all alsa drivers with SNDRV_PCM_INFO_PATCH update the playback/capture position in period interrupt ?

usb-audio seem update when each URB send/receive (in 1ms intervals)

ymfpci driver also update hwptr in 5ms interval but no SNDRV_PCM_INFO_PATCH and no constraint in period time must be interval of 5 ms

the rewind_safeguard is affected by the size of FIFO buffer as you cannot rewind any data in FIFO buffer of DSP/ sound controller

_______________________________________________
pulseaudio-discuss mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

#4 lore raw

At Tue, 3 Dec 2013 08:47:07 +0800,

Quoted 50 lines · Raymond Yau
Quoted 42 lines
Quoted 3 lines

PCM Devices which have the BATCH flag set update the PCM pointer

only with

Quoted 1 line

period size granularity. Using timer based scheduling does not have

any

Quoted 1 line

advantage in this mode. For one devices which have that flag set

usually

Quoted 2 lines

update
the position pointer in software after getting the period interrupt.

So

Quoted 1 line

disabling the period interrupt is not possible for this kind of

devices.

Quoted 1 line

Furthermore writing to or reading from the buffer slice for the

current

Quoted 4 lines

period
is not possible since the position inside the buffer is not known. On the other
hand the tsched algorithm seems to get easily confused for this kind

of

Quoted 3 lines

hardware, which results in garbled audio output. This typically means that timer
based scheduling needs to be manually disabled on systems with such

devices.

Quoted 1 line

Auto disabling tsched in this case allows these systems to run with

the

Quoted 5 lines

default
configuration.

If the playback position is reported in steps instead of monotonic

increasing ?

Quoted 2 lines

does this mean that you also need to increase rewind_safeguard to one

period

Quoted 1 line

or modifiy snd_pcm_rewindable ?

Yes that makes sense. The safeguard should probably be 1.5 periods or 1 period + fixed value, since it will always take some time from when the hardware reaches the next period to when userspace is notified about this.

Quoted 8 lines

I'm unfortunately not that familiar with pulseaudio. Maybe there is a better
way to fix this problem then to disable tsched. If anybody wants to recreate
the issue it can easily be emulated by applying the following patch to your kernel:

Quoted 2 lines

does all alsa drivers with SNDRV_PCM_INFO_PATCH update the playback/capture position in period interrupt ?

In general, yes.

Quoted 1 line

usb-audio seem update when each URB send/receive (in 1ms intervals)

The usb-audio driver behaved in a BATCH way in the very early version, but it was improved. So we can get rid of the flag from this driver now.

Quoted 2 lines

ymfpci driver also update hwptr in 5ms interval but no SNDRV_PCM_INFO_PATCH and no constraint in period time must be interval of 5 ms

It's a subtle driver bug. Feel free to fix it if you have a test hardware :) Otherwise, better not to touch such an old code.

Takashi

#5 lore raw
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Raymond Yau

usb-audio seem update when each URB send/receive (in 1ms intervals)

The default is to use larger intervals.

Quoted 2 lines

The usb-audio driver behaved in a BATCH way in the very early version, but it was improved.

The delay reporting is more precise, but the DMA position still jumps for each URB.

Quoted 1 line

So we can get rid of the flag from this driver now.

How well does timer-scheduling work with large URBs?

Quoted 2 lines
Quoted 2 lines

ymfpci driver also update hwptr in 5ms interval but no SNDRV_PCM_INFO_PATCH and no constraint in period time must be interval of 5 ms

The period length (in frames) is not constant for most sample rates.

However, if the noresample flag is set (which should be the case with PA), the period length should be constant, and such a period constraint might make sense. I'll have to test it ...

Regards,
Clemens

#6 lore raw

At Tue, 03 Dec 2013 10:02:44 +0100,

Quoted 10 lines · Clemens Ladisch
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Raymond Yau

usb-audio seem update when each URB send/receive (in 1ms intervals)

The default is to use larger intervals.

Quoted 2 lines

The usb-audio driver behaved in a BATCH way in the very early version, but it was improved.

Quoted 6 lines

The delay reporting is more precise, but the DMA position still jumps for each URB.

Quoted 1 line

So we can get rid of the flag from this driver now.

How well does timer-scheduling work with large URBs?

I thought PCM runtime delay should give the accurate sample position, irrespective to URB size? It should suffice for PA to control via timer scheduling.

Takashi

#7 lore raw
Quoted 13 lines · Takashi Iwai
Quoted 12 lines · Clemens Ladisch
Quoted 2 lines · Takashi Iwai
Quoted 1 line · Raymond Yau

usb-audio seem update when each URB send/receive (in 1ms intervals)

The default is to use larger intervals.

Quoted 2 lines

The usb-audio driver behaved in a BATCH way in the very early version, but it was improved.

The delay reporting is more precise, but the DMA position still jumps for each URB.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

So we can get rid of the flag from this driver now.

How well does timer-scheduling work with large URBs?

I thought PCM runtime delay should give the accurate sample position, irrespective to URB size?

The position of the sample that is currently being played is accurate (rounded to a USB frame). The DMA position, however, changes only in URB-sized increments. (And that is accurate too, because it describes exactly how the data is copied out of the buffer.)

Quoted 1 line

It should suffice for PA to control via timer scheduling.

Large jumps in the DMA position mean that there is a large part of the buffer which cannot be safely changed by PA. If this is why PA wants to disable tsched, then the BATCH flag should stay.

Regards,
Clemens

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

2013/12/6 Tanu Kaskinen <[email protected]>

Quoted 40 lines · Lars-Peter Clausen
Quoted 1 line

PCM Devices which have the BATCH flag set update the PCM pointer only

with

Quoted 2 lines

period size granularity. Using timer based scheduling does not have any advantage in this mode. For one devices which have that flag set usually

update

Quoted 3 lines

the position pointer in software after getting the period interrupt. So disabling the period interrupt is not possible for this kind of devices. Furthermore writing to or reading from the buffer slice for the current

period

Quoted 1 line

is not possible since the position inside the buffer is not known. On

the other

Quoted 2 lines

hand the tsched algorithm seems to get easily confused for this kind of hardware, which results in garbled audio output. This typically means

that timer

Quoted 1 line

based scheduling needs to be manually disabled on systems with such

devices.

Quoted 1 line

Auto disabling tsched in this case allows these systems to run with the

default

Quoted 12 lines

configuration.

---
 src/modules/alsa/alsa-util.c | 4 ++++
 1 file changed, 4 insertions(+)
src/modules/alsa/alsa-util.c +0 -0
index 75f5858..4b24e47 100644

src/modules/alsa/alsa-util.c int pa_alsa_set_hw_params( · line 252

Quoted 8 lines
src/modules/alsa/alsa-util.c +4 -0
@@ -245,6 +245,10 @@ int pa_alsa_set_hw_params(
     if (!pa_alsa_pcm_is_hw(pcm_handle))
         _use_tsched = false;
 
+    /* The PCM pointer is only updated with period granularity */
+    if (snd_pcm_hw_params_is_batch(hwparams))
+        _use_tsched = false;
+
 #if (SND_LIB_VERSION >= ((1<<16)|(0<<8)|24)) /* API additions in 1.0.24

*/

Quoted 7 lines

src/modules/alsa/alsa-util.c int pa_alsa_set_hw_params( · line 254

Quoted 2 lines
src/modules/alsa/alsa-util.c +0 -0
     if (_use_tsched) {
 

Thanks! I applied the patch.

--

Are you patch sufficient ?

In alsa-lib , snd_pcm_sw_params_set_avail_min always return zero

int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)

{
         assert(pcm && params);
         /* Fix avail_min if it's below period size.  The period_size
          * defines the minimal wake-up timing accuracy, so it doesn't
          * make sense to set below that.
          */
         if (val < pcm->period_size)
                 val = pcm->period_size;
         params->avail_min = val;
         return 0;
}

http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/alsa-sink.c?id=26a270a934f0f174f7bd7eb89e85301963721deb

/* We need at last one frame in the used part of the buffer */
- avail_min = (snd_pcm_uframes_t) u->hwbuf_unused_frames + 1;
+ avail_min = (snd_pcm_uframes_t) u->hwbuf_unused / u->frame_size + 1;

do pulseaudio need to keep at least one periods instead of more than 1 frames for those driver which update hwptr in periods ?

#10 lore raw
Quoted 69 lines · Raymond Yau

2013/12/6 Tanu Kaskinen <[email protected]>

Quoted 40 lines · Lars-Peter Clausen
Quoted 1 line

PCM Devices which have the BATCH flag set update the PCM pointer only

with

Quoted 2 lines

period size granularity. Using timer based scheduling does not have any advantage in this mode. For one devices which have that flag set usually

update

Quoted 3 lines

the position pointer in software after getting the period interrupt. So disabling the period interrupt is not possible for this kind of devices. Furthermore writing to or reading from the buffer slice for the current

period

Quoted 1 line

is not possible since the position inside the buffer is not known. On

the other

Quoted 2 lines

hand the tsched algorithm seems to get easily confused for this kind of hardware, which results in garbled audio output. This typically means

that timer

Quoted 1 line

based scheduling needs to be manually disabled on systems with such

devices.

Quoted 1 line

Auto disabling tsched in this case allows these systems to run with the

default

Quoted 12 lines

configuration.

---
 src/modules/alsa/alsa-util.c | 4 ++++
 1 file changed, 4 insertions(+)
src/modules/alsa/alsa-util.c +0 -0
index 75f5858..4b24e47 100644

src/modules/alsa/alsa-util.c int pa_alsa_set_hw_params( · line 252

Quoted 8 lines
src/modules/alsa/alsa-util.c +4 -0
@@ -245,6 +245,10 @@ int pa_alsa_set_hw_params(
     if (!pa_alsa_pcm_is_hw(pcm_handle))
         _use_tsched = false;
 
+    /* The PCM pointer is only updated with period granularity */
+    if (snd_pcm_hw_params_is_batch(hwparams))
+        _use_tsched = false;
+
 #if (SND_LIB_VERSION >= ((1<<16)|(0<<8)|24)) /* API additions in 1.0.24

*/

Quoted 7 lines

src/modules/alsa/alsa-util.c int pa_alsa_set_hw_params( · line 254

Quoted 2 lines
src/modules/alsa/alsa-util.c +0 -0
     if (_use_tsched) {
 

Thanks! I applied the patch.

--

Are you patch sufficient ?

In alsa-lib , snd_pcm_sw_params_set_avail_min always return zero

int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)

{
         assert(pcm && params);
         /* Fix avail_min if it's below period size.  The period_size
          * defines the minimal wake-up timing accuracy, so it doesn't
          * make sense to set below that.
          */
         if (val < pcm->period_size)
                 val = pcm->period_size;
         params->avail_min = val;
         return 0;
}
Quoted 8 lines

http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/alsa-sink.c?id=26a270a934f0f174f7bd7eb89e85301963721deb

/* We need at last one frame in the used part of the buffer */
- avail_min = (snd_pcm_uframes_t) u->hwbuf_unused_frames + 1;
+ avail_min = (snd_pcm_uframes_t) u->hwbuf_unused / u->frame_size + 1;

do pulseaudio need to keep at least one periods instead of more than 1 frames for those driver which update hwptr in periods ?

I don't know.

Signature · 1 line
Tanu