All of lore.kernel.org
 help / color / mirror / Atom feed
* dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug?
@ 2017-03-16 12:23 Max Kellermann
  2017-03-20  7:38 ` Takashi Iwai
  2017-03-20  7:39 ` Jaroslav Kysela
  0 siblings, 2 replies; 5+ messages in thread
From: Max Kellermann @ 2017-03-16 12:23 UTC (permalink / raw)
  To: alsa-devel

Hi,

I have received a bug report for the Music Player Daemon which
complains about a freezing MPD process, after I switched MPD's ALSA
output to non-blocking mode:

 https://bugs.musicpd.org/view.php?id=4662

This happens when snd_pcm_drain() is used on a dmix PCM which is in
SND_PCM_NONBLOCK mode.  snd_pcm_drain() will be called repeatedly,
because ALSA's file descriptor is always ready.

According to my research, the bug is in __snd_pcm_dmix_drain().  This
function always returns -EAGAIN when SND_PCM_NONBLOCK is set:

  if (pcm->mode & SND_PCM_NONBLOCK)
        return -EAGAIN;

This comes very early in the function, before any other relevant
checks.  It can never finish that way, and calling it again at any
time will never do anything.  Thus, snd_pcm_drain() appears to be
broken in non-blocking mode.

Or am I misunderstanding how snd_pcm_drain() is supposed to be used in
non-blocking mode?

Max

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug?
  2017-03-16 12:23 dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug? Max Kellermann
@ 2017-03-20  7:38 ` Takashi Iwai
  2017-03-29 17:59   ` Max Kellermann
  2017-03-20  7:39 ` Jaroslav Kysela
  1 sibling, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2017-03-20  7:38 UTC (permalink / raw)
  To: Max Kellermann; +Cc: alsa-devel

On Thu, 16 Mar 2017 13:23:36 +0100,
Max Kellermann wrote:
> 
> Hi,
> 
> I have received a bug report for the Music Player Daemon which
> complains about a freezing MPD process, after I switched MPD's ALSA
> output to non-blocking mode:
> 
>  https://bugs.musicpd.org/view.php?id=4662
> 
> This happens when snd_pcm_drain() is used on a dmix PCM which is in
> SND_PCM_NONBLOCK mode.  snd_pcm_drain() will be called repeatedly,
> because ALSA's file descriptor is always ready.
> 
> According to my research, the bug is in __snd_pcm_dmix_drain().  This
> function always returns -EAGAIN when SND_PCM_NONBLOCK is set:
> 
>   if (pcm->mode & SND_PCM_NONBLOCK)
>         return -EAGAIN;
> 
> This comes very early in the function, before any other relevant
> checks.  It can never finish that way, and calling it again at any
> time will never do anything.  Thus, snd_pcm_drain() appears to be
> broken in non-blocking mode.
> 
> Or am I misunderstanding how snd_pcm_drain() is supposed to be used in
> non-blocking mode?

Yeah, the code is obviously wrong.  And it seems that now Jaroslav
already fixed the issue in git repo.  Please give it a try.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug?
  2017-03-16 12:23 dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug? Max Kellermann
  2017-03-20  7:38 ` Takashi Iwai
@ 2017-03-20  7:39 ` Jaroslav Kysela
  2017-03-20  7:44   ` Jaroslav Kysela
  1 sibling, 1 reply; 5+ messages in thread
From: Jaroslav Kysela @ 2017-03-20  7:39 UTC (permalink / raw)
  To: alsa-devel; +Cc: Max Kellermann

Dne 16.3.2017 v 13:23 Max Kellermann napsal(a):
> Hi,
> 
> I have received a bug report for the Music Player Daemon which
> complains about a freezing MPD process, after I switched MPD's ALSA
> output to non-blocking mode:
> 
>  https://bugs.musicpd.org/view.php?id=4662
> 
> This happens when snd_pcm_drain() is used on a dmix PCM which is in
> SND_PCM_NONBLOCK mode.  snd_pcm_drain() will be called repeatedly,
> because ALSA's file descriptor is always ready.
> 
> According to my research, the bug is in __snd_pcm_dmix_drain().  This
> function always returns -EAGAIN when SND_PCM_NONBLOCK is set:
> 
>   if (pcm->mode & SND_PCM_NONBLOCK)
>         return -EAGAIN;
> 
> This comes very early in the function, before any other relevant
> checks.  It can never finish that way, and calling it again at any
> time will never do anything.  Thus, snd_pcm_drain() appears to be
> broken in non-blocking mode.

Could you test
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=fdc898d41135b26772d0fffe07e9eb0de6597125
? There should be a loop with -EAGAIN, but this loop should end when
then samples and drained.

> Or am I misunderstanding how snd_pcm_drain() is supposed to be used in
> non-blocking mode?

For non-blocking mode, any calls won't block. So if you like to wait for
the completion, you should do a poll/select call or switch the handle to
the blocking mode.

					Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug?
  2017-03-20  7:39 ` Jaroslav Kysela
@ 2017-03-20  7:44   ` Jaroslav Kysela
  0 siblings, 0 replies; 5+ messages in thread
From: Jaroslav Kysela @ 2017-03-20  7:44 UTC (permalink / raw)
  To: alsa-devel; +Cc: Max Kellermann

Dne 20.3.2017 v 08:39 Jaroslav Kysela napsal(a):
> Dne 16.3.2017 v 13:23 Max Kellermann napsal(a):
>> Hi,
>>
>> I have received a bug report for the Music Player Daemon which
>> complains about a freezing MPD process, after I switched MPD's ALSA
>> output to non-blocking mode:
>>
>>  https://bugs.musicpd.org/view.php?id=4662
>>
>> This happens when snd_pcm_drain() is used on a dmix PCM which is in
>> SND_PCM_NONBLOCK mode.  snd_pcm_drain() will be called repeatedly,
>> because ALSA's file descriptor is always ready.
>>
>> According to my research, the bug is in __snd_pcm_dmix_drain().  This
>> function always returns -EAGAIN when SND_PCM_NONBLOCK is set:
>>
>>   if (pcm->mode & SND_PCM_NONBLOCK)
>>         return -EAGAIN;
>>
>> This comes very early in the function, before any other relevant
>> checks.  It can never finish that way, and calling it again at any
>> time will never do anything.  Thus, snd_pcm_drain() appears to be
>> broken in non-blocking mode.
> 
> Could you test
> http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=fdc898d41135b26772d0fffe07e9eb0de6597125
> ? There should be a loop with -EAGAIN, but this loop should end when
> then samples and drained.

Oops. I used wrong handle to check the state. Use commit
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=e4377b16454f3b7b222613a571bf4244ebd28e56
, too.

http://git.alsa-project.org/?p=alsa-lib.git;a=summary

				Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug?
  2017-03-20  7:38 ` Takashi Iwai
@ 2017-03-29 17:59   ` Max Kellermann
  0 siblings, 0 replies; 5+ messages in thread
From: Max Kellermann @ 2017-03-29 17:59 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

On 2017/03/20 08:38, Takashi Iwai <tiwai@suse.de> wrote:
> Yeah, the code is obviously wrong.  And it seems that now Jaroslav
> already fixed the issue in git repo.  Please give it a try.

The bug reporter confirmed that this commit fixes his MPD problem.
Thanks.

Max

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-29 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 12:23 dmix, snd_pcm_drain(), SND_PCM_NONBLOCK - bug? Max Kellermann
2017-03-20  7:38 ` Takashi Iwai
2017-03-29 17:59   ` Max Kellermann
2017-03-20  7:39 ` Jaroslav Kysela
2017-03-20  7:44   ` Jaroslav Kysela

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.