From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF9E7C43381 for ; Mon, 25 Mar 2019 16:07:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A3CE20830 for ; Mon, 25 Mar 2019 16:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbfCYQHF (ORCPT ); Mon, 25 Mar 2019 12:07:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:39942 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725788AbfCYQHE (ORCPT ); Mon, 25 Mar 2019 12:07:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C90EEAFCC; Mon, 25 Mar 2019 16:07:02 +0000 (UTC) Date: Mon, 25 Mar 2019 17:07:02 +0100 Message-ID: From: Takashi Iwai To: Cc: , , , Subject: Re: [PATCH 04/10] ALSA: aloop: Use always spin_lock_irqsave() for cable->lock In-Reply-To: <1553529644-5654-5-git-send-email-twischer@de.adit-jv.com> References: <1553529644-5654-1-git-send-email-twischer@de.adit-jv.com> <1553529644-5654-5-git-send-email-twischer@de.adit-jv.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Mar 2019 17:00:38 +0100, wrote: > > From: Timo Wischer > > to allow the usage of timer callbacks from interrupt context. > For example the sound timer. The trigger callback is already irq-disabled. And, open/close must not be irq-disabled OTOH. So these changes must be superfluous. thanks, Takashi > > Signed-off-by: Timo Wischer > --- > sound/drivers/aloop.c | 33 +++++++++++++++++++-------------- > 1 file changed, 19 insertions(+), 14 deletions(-) > > diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c > index 11e8ed6..c6217c4 100644 > --- a/sound/drivers/aloop.c > +++ b/sound/drivers/aloop.c > @@ -272,6 +272,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) > struct loopback_pcm *dpcm = runtime->private_data; > struct loopback_cable *cable = dpcm->cable; > int err = 0, stream = 1 << substream->stream; > + unsigned long flags; > > switch (cmd) { > case SNDRV_PCM_TRIGGER_START: > @@ -281,39 +282,39 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) > dpcm->last_jiffies = jiffies; > dpcm->pcm_rate_shift = 0; > dpcm->last_drift = 0; > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->running |= stream; > cable->pause &= ~stream; > err = loopback_timer_start(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_STOP: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->running &= ~stream; > cable->pause &= ~stream; > err = loopback_timer_stop(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > case SNDRV_PCM_TRIGGER_SUSPEND: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->pause |= stream; > err = loopback_timer_stop(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > case SNDRV_PCM_TRIGGER_RESUME: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > dpcm->last_jiffies = jiffies; > cable->pause &= ~stream; > err = loopback_timer_start(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > @@ -557,12 +558,13 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct loopback_pcm *dpcm = runtime->private_data; > + unsigned long flags; > snd_pcm_uframes_t pos; > > - spin_lock(&dpcm->cable->lock); > + spin_lock_irqsave(&dpcm->cable->lock, flags); > loopback_pos_update(dpcm->cable); > pos = dpcm->buf_pos; > - spin_unlock(&dpcm->cable->lock); > + spin_unlock_irqrestore(&dpcm->cable->lock, flags); > return bytes_to_frames(runtime, pos); > } > > @@ -679,10 +681,12 @@ static void free_cable(struct snd_pcm_substream *substream) > if (!cable) > return; > if (cable->streams[!substream->stream]) { > + unsigned long flags; > + > /* other stream is still alive */ > - spin_lock_irq(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->streams[substream->stream] = NULL; > - spin_unlock_irq(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > } else { > /* free the cable */ > loopback->cables[substream->number][dev] = NULL; > @@ -698,6 +702,7 @@ static int loopback_open(struct snd_pcm_substream *substream) > struct loopback_cable *cable = NULL; > int err = 0; > int dev = get_cable_index(substream); > + unsigned long flags; > > mutex_lock(&loopback->cable_lock); > dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); > @@ -753,9 +758,9 @@ static int loopback_open(struct snd_pcm_substream *substream) > else > runtime->hw = cable->hw; > > - spin_lock_irq(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->streams[substream->stream] = dpcm; > - spin_unlock_irq(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > > unlock: > if (err < 0) { > -- > 2.7.4 > > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH 04/10] ALSA: aloop: Use always spin_lock_irqsave() for cable->lock Date: Mon, 25 Mar 2019 17:07:02 +0100 Message-ID: References: <1553529644-5654-1-git-send-email-twischer@de.adit-jv.com> <1553529644-5654-5-git-send-email-twischer@de.adit-jv.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <1553529644-5654-5-git-send-email-twischer@de.adit-jv.com> Sender: linux-kernel-owner@vger.kernel.org To: twischer@de.adit-jv.com Cc: broonie@kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org List-Id: alsa-devel@alsa-project.org On Mon, 25 Mar 2019 17:00:38 +0100, wrote: > > From: Timo Wischer > > to allow the usage of timer callbacks from interrupt context. > For example the sound timer. The trigger callback is already irq-disabled. And, open/close must not be irq-disabled OTOH. So these changes must be superfluous. thanks, Takashi > > Signed-off-by: Timo Wischer > --- > sound/drivers/aloop.c | 33 +++++++++++++++++++-------------- > 1 file changed, 19 insertions(+), 14 deletions(-) > > diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c > index 11e8ed6..c6217c4 100644 > --- a/sound/drivers/aloop.c > +++ b/sound/drivers/aloop.c > @@ -272,6 +272,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) > struct loopback_pcm *dpcm = runtime->private_data; > struct loopback_cable *cable = dpcm->cable; > int err = 0, stream = 1 << substream->stream; > + unsigned long flags; > > switch (cmd) { > case SNDRV_PCM_TRIGGER_START: > @@ -281,39 +282,39 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) > dpcm->last_jiffies = jiffies; > dpcm->pcm_rate_shift = 0; > dpcm->last_drift = 0; > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->running |= stream; > cable->pause &= ~stream; > err = loopback_timer_start(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_STOP: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->running &= ~stream; > cable->pause &= ~stream; > err = loopback_timer_stop(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > case SNDRV_PCM_TRIGGER_SUSPEND: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->pause |= stream; > err = loopback_timer_stop(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > case SNDRV_PCM_TRIGGER_RESUME: > - spin_lock(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > dpcm->last_jiffies = jiffies; > cable->pause &= ~stream; > err = loopback_timer_start(dpcm); > - spin_unlock(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) > loopback_active_notify(dpcm); > break; > @@ -557,12 +558,13 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct loopback_pcm *dpcm = runtime->private_data; > + unsigned long flags; > snd_pcm_uframes_t pos; > > - spin_lock(&dpcm->cable->lock); > + spin_lock_irqsave(&dpcm->cable->lock, flags); > loopback_pos_update(dpcm->cable); > pos = dpcm->buf_pos; > - spin_unlock(&dpcm->cable->lock); > + spin_unlock_irqrestore(&dpcm->cable->lock, flags); > return bytes_to_frames(runtime, pos); > } > > @@ -679,10 +681,12 @@ static void free_cable(struct snd_pcm_substream *substream) > if (!cable) > return; > if (cable->streams[!substream->stream]) { > + unsigned long flags; > + > /* other stream is still alive */ > - spin_lock_irq(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->streams[substream->stream] = NULL; > - spin_unlock_irq(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > } else { > /* free the cable */ > loopback->cables[substream->number][dev] = NULL; > @@ -698,6 +702,7 @@ static int loopback_open(struct snd_pcm_substream *substream) > struct loopback_cable *cable = NULL; > int err = 0; > int dev = get_cable_index(substream); > + unsigned long flags; > > mutex_lock(&loopback->cable_lock); > dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); > @@ -753,9 +758,9 @@ static int loopback_open(struct snd_pcm_substream *substream) > else > runtime->hw = cable->hw; > > - spin_lock_irq(&cable->lock); > + spin_lock_irqsave(&cable->lock, flags); > cable->streams[substream->stream] = dpcm; > - spin_unlock_irq(&cable->lock); > + spin_unlock_irqrestore(&cable->lock, flags); > > unlock: > if (err < 0) { > -- > 2.7.4 > >