Reason for sound dropouts found

T.Mertes@mobilkom.at
Fri, 12 Mar 1999 10:26:01 +0100


The good news:

I found the reason of sound dropouts which happen under
disk load and are reported from time to time in linux-kernel.

Statement:

Dropouts during playing of sound using /dev/dsp and
related devices using play, sox, cat and other programms
happen because the read() call of the playing command
has to wait too long when the system is under disk load.
So the internal buffer of the sound driver gets empty
and the driver has to shut the sound card for a short
time. This is true for all sound cards and drivers.

Proof:

With a cold cache on my system it is easy to produce
dropouts using:

penguin> find / -name "*core*" &
penguin> play sound.wav

when sound.wav is some 30 to 40 MB sound file (3 to 4 min).
Additionally xosviews interrupt lights of the sound card
went dark during a dropout while the interrupt lights of
the timer and the scsi stay on. You can do also mouse
activitys like moving the windows during the dropouts.
This is an indication that the dropouts are not related to
switching off the interrupts for too long. During the
dropouts there is usually no big CPU load.

When you do the following (also with a cold cache):

penguin> play sound.wav
penguin> find / -name "*core*" &
penguin> play sound.wav

there are no dropouts. In this case, after the first playing
the file sound.wav is already in the cache and reading it
a second time does not have to wait for disk i/o.

When you do the following (with cold cache):

penguin> strace -f play sound.wav

and in another window

penguin> find / -name "*core*"

you can see that the strace stops showing a read() syscall
every time you have a dropout. This read is from the
sound.wav file.

To proof thet the dropouts are sound card and sound driver
independend is easy: I get the dropouts under load using two
different sound cards and their drivers:

SB 16 Vibra and SB 128 PCI

From that I conclude that it happens also with other cards
and drivers.

I used also the alsa driver for the SB 128 PCI and get the
same results.

Collary:

This sort of sound dropouts are

1. Not related to disallowing interrupts in IDE or
SCSI drivers for too long. This was stated in the
past several times as reason for sound dropouts.
2. Not related to the sound driver and its dma.
3. Not related to CPU load.

Solution(s):

There are several ways to solve this problem:

1. Greatly improve readahead of sequencially readed files.
The readahead must be so good that the data is always
already in the cache when the read() syscall is executed.
In that way the read() would never block. --> no dropout
I know this seems a little bit unrealistic.
2. Every program to play sound should have two threads
for reading and writing and an internal buffer which never
gets empty so that after finishing one write() to the
sound device the next write() can start immidiate without
delay. --> no dropout
This could be done also by a sound demon used by all
sound programms. When this user buffer swaps out,
you get your dropouts aggain.
3. The internal dma buffer of the sound driver could be
enlarged. When the dma buffer is big enough the sound
card would play from this buffer during waits for the
read(). --> no dropout

I would suggest to look at all three ways together to
solve the problem.

About the 3rd way I tried a little bit:

With the ALSA driver I already used 128k of buffer. But it
was not enough (I still get dropouts). To get big buffers
from the kernel I had to change

#define NR_MEM_LISTS 6

to

#define NR_MEM_LISTS 10

in linux/mm/page_alloc.c so that __get_free_pages can
deliver bigger buffers. Is that enough or did I miss
something.

I was up to now not able to lift the limitation of
128k buffers the alsa audiopci driver is using.
I do not know much about ISA and PCI dma.
Is there a limit in the size of a PCI/ISA dma area.
If there are no limits I would suggest to change
the sound drivers to be configurable to have big
buffers. I think that People with 128MB or more would
happily spend even 1MB or more just to have good
sound under every load condition. I think of some
config option or module parameter specifying the
size of the buffer would be enough.

If you have information how to enlarge the dma buffer
of the es1370 driver of the kernel or the audiopci
driver of alsa it would be helpful.

What do the linux kernel specialists think of
having big sound driver buffers?

Greetins Thomas

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/