Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0125DC433FE for ; Thu, 14 Oct 2021 16:09:54 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F8F3610EA for ; Thu, 14 Oct 2021 16:09:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2F8F3610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5D93082C; Thu, 14 Oct 2021 18:09:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5D93082C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1634227791; bh=QAJ5PlaAkPZSPOHmLttI8XK/Cbq9AU5/T3AHEWYmXQ4=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CWFXCBxcyfTeNguiL+A/DF+xVfUZ+SBlaFoXsU3Ma7llLRRYqC4ooGYL7dFwwclT/ QIKLozRSbuVRQA3woGvYB6zP82YAs/xEKD1gM0djymHoorBTWxxhVQWRlvVlVoI2/Y J/ZAMExCkB8M5vK2BeqKCfup8OnKDcHhTEXFInQ8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id DE38EF801F7; Thu, 14 Oct 2021 18:09:00 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C6DC3F80212; Thu, 14 Oct 2021 18:08:59 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E469DF80088 for ; Thu, 14 Oct 2021 18:08:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E469DF80088 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="okmxfpS7"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kMr1/Ltq" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id A678A1FD3B; Thu, 14 Oct 2021 16:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634227730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Dvkea2szPFVj0HsnmeU6zL6qRtZFbSpHbR3Ic+MJTzo=; b=okmxfpS7Ef9vh1LRCfvdLoR0I7+eLG6pkh8OyvO3tPl8A23EsMlImSJs5h3TcLcLvs98vf oBjJ0eAqqELfBRReGKAF5KBx0BNV1MtDih3BV/McoMN7zwYDfHalPK/9zVIm7SmihNXFH9 h8SK5HDRQxwKuWItbZ825nGdJ8HcXz0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634227730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Dvkea2szPFVj0HsnmeU6zL6qRtZFbSpHbR3Ic+MJTzo=; b=kMr1/Ltq9+cctruDt6Fb3oIJajsqkt/tQx5syNYy1/HHG4R4RNNIfmTtcxpj1wCJ6lw19i ED8q3+dPXe3JeBDQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id A11E8A3B83; Thu, 14 Oct 2021 16:08:50 +0000 (UTC) Date: Thu, 14 Oct 2021 18:08:50 +0200 Message-ID: From: Takashi Iwai To: Pierre-Louis Bossart Subject: Re: [PATCH] ALSA: pcm: Unify snd_pcm_delay() and snd_pcm_hwsync() In-Reply-To: <08dec63b-4748-e165-73b4-88a5d2db9597@linux.intel.com> References: <20211014145323.26506-1-tiwai@suse.de> <08dec63b-4748-e165-73b4-88a5d2db9597@linux.intel.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 Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 14 Oct 2021 17:59:21 +0200, Pierre-Louis Bossart wrote: > > > > On 10/14/21 9:53 AM, Takashi Iwai wrote: > > Both snd_pcm_delay() and snd_pcm_hwsync() do the almost same thing. > > The only difference is that the former calculate the delay, so unify > > them as a code cleanup, and treat NULL delay argument only for hwsync > > operation. > > > > Also, the patch does a slight code refactoring in snd_pcm_delay(). > > The initialization of the delay value is done in the caller side now. > > I would have done the opposite change, i.e. keep snd_pcm_hwsync() but > add an optional delay argument/calculation. > > 'snd_pcm_delay' doesn't really hint at any hwsync operation. > > Just a naming difference really. Yes, but also the difference of the number of arguments. Changing other way round would need to more modifications in the end. Which calls what is rather an implementation detail :) Takashi > > Signed-off-by: Takashi Iwai > > --- > > sound/core/pcm_native.c | 24 ++++++++---------------- > > 1 file changed, 8 insertions(+), 16 deletions(-) > > > > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > > index 46c643db18eb..627b201b6084 100644 > > --- a/sound/core/pcm_native.c > > +++ b/sound/core/pcm_native.c > > @@ -2932,32 +2932,24 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream, > > return ret; > > } > > > > -static int snd_pcm_hwsync(struct snd_pcm_substream *substream) > > -{ > > - int err; > > - > > - snd_pcm_stream_lock_irq(substream); > > - err = do_pcm_hwsync(substream); > > - snd_pcm_stream_unlock_irq(substream); > > - return err; > > -} > > - > > static int snd_pcm_delay(struct snd_pcm_substream *substream, > > snd_pcm_sframes_t *delay) > > { > > int err; > > - snd_pcm_sframes_t n = 0; > > > > snd_pcm_stream_lock_irq(substream); > > err = do_pcm_hwsync(substream); > > - if (!err) > > - n = snd_pcm_calc_delay(substream); > > + if (delay && !err) > > + *delay = snd_pcm_calc_delay(substream); > > snd_pcm_stream_unlock_irq(substream); > > - if (!err) > > - *delay = n; > > return err; > > } > > > > +static inline int snd_pcm_hwsync(struct snd_pcm_substream *substream) > > +{ > > + return snd_pcm_delay(substream, NULL); > > +} > > + > > static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, > > struct snd_pcm_sync_ptr __user *_sync_ptr) > > { > > @@ -3275,7 +3267,7 @@ static int snd_pcm_common_ioctl(struct file *file, > > return snd_pcm_hwsync(substream); > > case SNDRV_PCM_IOCTL_DELAY: > > { > > - snd_pcm_sframes_t delay; > > + snd_pcm_sframes_t delay = 0; > > snd_pcm_sframes_t __user *res = arg; > > int err; > > > > >