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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 A9F2EC433DF for ; Tue, 11 Aug 2020 07:44:11 +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 2AA7F2054F for ; Tue, 11 Aug 2020 07:44:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="Mw1BSsvK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AA7F2054F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@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 8878415F9; Tue, 11 Aug 2020 09:43:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8878415F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1597131849; bh=+VjSSFxwf6hVry26mPLNJYq1KwxWCpIXffYq5jz3210=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Mw1BSsvKzrxTJXiTLg0uqEdBm22qQPkVSMdK+EmbTmv0GvwbcclQJ764eBAL2aOiU Fovkvy8MbwM3tIxAV547Mgn3S6wA6JSLNXwa5Og+ifjE5K5e4zjaog6d6sHAcSbMXp aMFCnugWuMIOTnDMDnwgv3XWyl4PCBkMEkrdY2zo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1E537F8015B; Tue, 11 Aug 2020 09:43:19 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0767BF8015B; Tue, 11 Aug 2020 09:43:18 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 10E56F800D3 for ; Tue, 11 Aug 2020 09:43:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 10E56F800D3 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ADC6BAC52; Tue, 11 Aug 2020 07:43:27 +0000 (UTC) Date: Tue, 11 Aug 2020 09:43:06 +0200 Message-ID: From: Takashi Iwai To: Yu-Hsuan Hsu Subject: Re: [PATCH v3 2/2] ASoC: Intel: Add period size constraint on strago board In-Reply-To: References: <1596020585-11517-1-git-send-email-brent.lu@intel.com> <1596198365-10105-1-git-send-email-brent.lu@intel.com> <1596198365-10105-3-git-send-email-brent.lu@intel.com> <63bca214-3434-16c6-1b60-adf323aec554@linux.intel.com> <6466847a-8aae-24f7-d727-36ba75e95f98@linux.intel.com> <3f3baf5e-f73d-9cd6-cbfb-36746071e126@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=UTF-8 Content-Transfer-Encoding: 8bit Cc: Guennadi Liakhovetski , "alsa-devel@alsa-project.org" , Kai Vehmanen , Kuninori Morimoto , "Rojewski, Cezary" , Takashi Iwai , Jie Yang , "linux-kernel@vger.kernel.org" , Pierre-Louis Bossart , Liam Girdwood , Sam McNally , Mark Brown , "yuhsuan@google.com" , Ranjani Sridharan , Daniel Stuart , Andy Shevchenko , "Lu, Brent" , Damian van Soelen 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 Tue, 11 Aug 2020 04:29:24 +0200, Yu-Hsuan Hsu wrote: > > Lu, Brent 於 2020年8月11日 週二 上午10:17寫道: > > > > > > > > Sorry for the late reply. CRAS does not set the period size when using it. > > > The default period size is 256, which consumes the samples quickly(about 49627 > > > fps when the rate is 48000 fps) at the beginning of the playback. > > > Since CRAS write samples with the fixed frequency, it triggers underruns > > > immidiately. > > > > > > According to Brent, the DSP is using 240 period regardless the hw_param. If the > > > period size is 256, DSP will read 256 samples each time but only consume 240 > > > samples until the ring buffer of DSP is full. This behavior makes the samples in > > > the ring buffer of kernel consumed quickly. (Not sure whether the explanation is > > > correct. Need Brent to confirm it.) > > > > > > Unfortunately, we can not change the behavior of DSP. After some experiments, > > > we found that the issue can be fixed if we set the period size to 240. With the > > > same frequency as the DSP, the samples are consumed stably. Because everyone > > > can trigger this issue when using the driver without setting the period size, we > > > think it is a general issue that should be fixed in the kernel. > > > > I check the code and just realized CRAS does nothing but request maximum buffer > > size. As I know the application needs to decide the buffer time and period time so > > ALSA could generate a hw_param structure with proper period size instead of using > > fixed constraint in machine driver because driver has no idea about the latency you > > want. > > > > You can use snd_pcm_hw_params_set_buffer_time_near() and > > snd_pcm_hw_params_set_period_time_near() to get a proper configuration of > > buffer and period parameters according to the latency requirement. In the CRAS > > code, there is a UCM variable to support this: DmaPeriodMicrosecs. I tested it on > > Celes and it looks quite promising. It seems to me that adding constraint in machine > > driver is not necessary. > > > > SectionDevice."Speaker".0 { > > Value { > > PlaybackPCM "hw:chtrt5650,0" > > DmaPeriodMicrosecs "5000" > > ... > > > > [ 52.434761] sound pcmC1D0p: hw_param > > [ 52.434767] sound pcmC1D0p: ACCESS 0x1 > > [ 52.434770] sound pcmC1D0p: FORMAT 0x4 > > [ 52.434772] sound pcmC1D0p: SUBFORMAT 0x1 > > [ 52.434776] sound pcmC1D0p: SAMPLE_BITS [16:16] > > [ 52.434779] sound pcmC1D0p: FRAME_BITS [32:32] > > [ 52.434782] sound pcmC1D0p: CHANNELS [2:2] > > [ 52.434785] sound pcmC1D0p: RATE [48000:48000] > > [ 52.434788] sound pcmC1D0p: PERIOD_TIME [5000:5000] > > [ 52.434791] sound pcmC1D0p: PERIOD_SIZE [240:240] > > [ 52.434794] sound pcmC1D0p: PERIOD_BYTES [960:960] > > [ 52.434797] sound pcmC1D0p: PERIODS [852:852] > > [ 52.434799] sound pcmC1D0p: BUFFER_TIME [4260000:4260000] > > [ 52.434802] sound pcmC1D0p: BUFFER_SIZE [204480:204480] > > [ 52.434805] sound pcmC1D0p: BUFFER_BYTES [817920:817920] > > [ 52.434808] sound pcmC1D0p: TICK_TIME [0:0] > > > > Regards, > > Brent > Hi Brent, > > Yes, I know we can do it to fix the issue as well. As I mentioned > before, we wanted to fix it in kernel because it is a real issue, > isn't it? Basically, a driver should work with any param it supports. > But in this case, everyone can trigger underrun if he or she does not > the period size to 240. If you still think it's not necessary, I can > modify UCM to make CRAS set the appropriate period size. How does it *not* work if you set other than period size 240, more exactly? The hw_constraint to a fixed period size must be really an exception. If you look at other drivers, you won't find any other doing such. It already indicates that something is wrong. Usually the fixed period size comes from the hardware limitation and defined in snd_pcm_hardware. Or, sometimes it's an alignment issue. If you need more than that, you should doubt what's really not working. Takashi