All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaroslav Kysela <perex@perex.cz>
To: alsa-devel@alsa-project.org
Subject: Re: Deadlock over semaphore issue with aplay while using dmix
Date: Thu, 04 Apr 2013 13:33:08 +0200	[thread overview]
Message-ID: <515D64F4.8030903@perex.cz> (raw)
In-Reply-To: <CADryByGnyH9rUDBuG_JRPrSgCb3LPwhaVdFXXeELiUYQv+ZHwQ@mail.gmail.com>

Date 4.4.2013 11:27, mateen wrote:
> Hi,
> 
> I seeing sometimes deadlock issue with dmix when I press CTRL+C.
> 
> Aplay's signal handler calls snd_pcm_close() if an interrupt occurs.
> snd_pcm_close() will internally call  pcm->ops->close() which will fall to
> snd_pcm_dmix_close() in case you are using dmix.
> 
> snd_pcm_dmix_close() will try to acquire the semaphore with
> snd_pcm_direct_semaphore_down(dmix, DIRECT_IPC_SEM_CLIENT).
> The same semaphore is acquired in snd_pcm_dmix_sync_area() with
> dmix_down_sem() in case of non-concurrent access.
> 
> If semaphore is acquired in snd_pcm_dmix_sync_area() which is in thread
> context and interrupt comes, which invokes the signal handler which is in
> ISR context, which calls snd_pcm_close() which in turn calls
> snd_pcm_dmix_close() then we see a deadlock since semaphore is not released
> from thread context and ISR is waiting indefinitely on the same semaphore.
> 
> Please suggest a suitable solution for this.

It seems that also other configurations (alsa-lib plugins) have trouble
with the closing from the signal handler - I hit mutex issues with the
PulseAudio plugin, too.

The question is, how we can do a clean path in this case. Looking to the
current alsa-lib code, I would suggest to add the snd_pcm_abort()
function (may be called from the interrupt handler) to notify the
library to not ignore -EINTR return codes from poll() and other i/o ops
and pass it to the caller (application) to finish the normal close sequence.

Opinions?

					Jaroslav

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

  reply	other threads:[~2013-04-04 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-04  9:27 Deadlock over semaphore issue with aplay while using dmix mateen
2013-04-04 11:33 ` Jaroslav Kysela [this message]
2013-04-04 16:30   ` Takashi Iwai
2013-04-05 15:19     ` Jaroslav Kysela
2013-04-05 15:27       ` Takashi Iwai
2013-04-05 15:43         ` Jaroslav Kysela
2013-04-05 15:46           ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2013-04-05 13:32 mateen
2013-04-05 13:48 ` Takashi Iwai
2013-04-05 16:33   ` mateen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=515D64F4.8030903@perex.cz \
    --to=perex@perex.cz \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.