[alsa-devel] [alsa-lib][v1.1.19][pcm][multi plug] multi plug stuck in busy loop which caused high cpu loading.

eleven xiang eleven.xiang at gmail.com
Thu Jul 25 11:59:42 CEST 2019


Dear,

Currently, for Audio Echo Cancellation process, we combined both mic signal
and reference signal into one pcm with the multi plug.
And both the mic and ref signal are hw pcm devices, and they lived in the
same sound card in driver.

Here is the issue:

1. the master slave pcm device is already for read;
2. the second salve pcm is not ready for read, which means no data;
3. under this situation, snd_pcm_read_areas function will be stuck in busy
loop as below:

        avail = snd_pcm_avail_update(pcm); * // here always return avail=0,
due to the second salve pcm device wasn't ready*
        if (avail < 0) {
            err = avail;
            goto _end;
        }
        if (avail == 0) {
            if (state == SND_PCM_STATE_DRAINING)
                goto _end;
            if (pcm->mode & SND_PCM_NONBLOCK) {
                err = -EAGAIN;
                goto _end;
            }

            err = snd_pcm_wait(pcm, -1); * // return immediately, due to
the master slave pcm was ready for read.*
            if (err < 0)
                break;
            goto _again; *// stuck in busy loop !! again and again until
the second pcm data was ready !!!*

        }

it seemed that the root cause is that the two devices have obvious
interrupt period gap , and we also found that this issue can be easily
reproduced on our device under low memory case.

Currently we monitor this gap and return error to up layer to
close-and-reopen device to fix this issue.
So I wonder if there is any good solution ?

Thanks
-- 
BR,

eleven_xiang


More information about the Alsa-devel mailing list