Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>,
	Mark Brown <broonie@kernel.org>
Subject: Re: Can I stop sound from driver as system error ?
Date: Tue, 15 Dec 2015 12:55:20 +0900	[thread overview]
Message-ID: <566F8F28.2040208@sakamocchi.jp> (raw)
In-Reply-To: <87y4cwph08.wl%kuninori.morimoto.gx@renesas.com>

Hi,

On Dec 15 2015 11:47, Kuninori Morimoto wrote:
>>> I wonder can I stop sound from driver side (not from user-land)
>>> as system error during playback or capture ?
>>> How to do it if we can ?
>>
>> Stop PCM substreams with SNDRV_PCM_STATE_XRUN. In detail, see
>> implementation of snd_pcm_stop_xrun() available in 3.19 or
>> later. Then, userspace applications cannot continue to read/write PCM
>> frames via ALSA uapi.
>>
>> When using alsa-lib, then, userspace applications receive -EPIPE as
>> return value of calling PCM APIs. The applications can stop their
>> operation for PCM character devices, or can also recover the XRUN
>> state of PCM substream by calling snd_pcm_prepare(). In this case,
>> struct snd_pcm_ops.prepare() is called again in driver side.
>>
>> I think tinyalsa works almost the same.
>
> Thank you for detail explanation !
> I will try/investigate it

The state of PCM substreams can be changed by process context, software 
IRQ (softIRQ) context and hardware IRQ (hardIRQ) context. Therefore, 
ALSA PCM core uses spin_lock_irqsave()/spin_lock_irqrestore() to manage 
the race condition with softIRQ disabled, hardIRQ disabled and 
kernel-preemption disabled in local processor core.

As a glance, snd-soc-rcar in upstream pushes many operations to PCM 
trigger processing, while this trigger processing is protected with the 
critical section.

When you program the xrun handling in hardware/software IRQ context, 
it's better to pay enough attention to the lock, because any process 
contexts can spin in some processor cores.


Regards

Takashi Sakamoto

      reply	other threads:[~2015-12-15  3:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15  1:25 Can I stop sound from driver as system error ? Kuninori Morimoto
2015-12-15  1:48 ` Takashi Sakamoto
2015-12-15  2:47   ` Kuninori Morimoto
2015-12-15  3:55     ` Takashi Sakamoto [this message]

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=566F8F28.2040208@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox