Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp274511pxa; Tue, 11 Aug 2020 02:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhl3SciQ9djdLGaNC6fUEIePTC/3SQ6WyrMcgE/piwgtyPZj50cVPbibwxKawBXBcKDqU1 X-Received: by 2002:a17:906:359b:: with SMTP id o27mr26796023ejb.103.1597138750226; Tue, 11 Aug 2020 02:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597138750; cv=none; d=google.com; s=arc-20160816; b=KqAwCOmJ+PsgnzDv2Oi6mYXdGrhxwPF88+AfZbAklaxd7M9PikurnIp5qPXeXOqm7h FwflGVABhotOEhINlmYYmZwTPlsXosnCALHxEC8nGjaMJLKk0nPwLg049vuxu1v9BLUE aa4Z/IY7QAzRPqvp7ZmATEh9QI32hN05GhgbEnw7vu5fSxzVdJGTdB1lELscNDjooG8j I0mYBUQicQ/3oySywyOIpebzPzFpkMoL5xN8RW5PacCvkyeB0Q0mP8ZBfXxF0aby2tL/ OIDT/SCcism96aF7fs8rPDckFJX+IB6vAm5RadEGBPyxRSE5H1MbPhfWi15Ut+JB+UJw LuGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ItIu5ePf9JKIpjj5PDgXBJfnpsujSceF1j6mqZLY9xc=; b=ZVu0EdwHEQKfIAunEsXBpwv0R6/rdkZOx4IZXqONWKz8KrZz7PT9eDVmhjo17DJPAr MccFJrwyxLAGKRjR4PY6ii9qpV5+l+ox/JrVFOa/qUWoqrBcaNw9kQbcjkVGCERWiUwv u7HwzGxnvKTE/bTjtrh8t0ha6J08Mndz5M/+QYiyG/AyATWoGyTDq/9u2HS8792D7TZk gCLLfmZq2ngyE30MaljODM5YVXHofgFLAZG3CiW+jd/X/g5v4HppCrquJkbmV46qrHfW SOzeQxNPadspUGlSxwwdqLKTr5kkVnpvlLw7Dm/IksErMljUaSrEuUqt8bTTQcSHWMNu kw0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fq8SQKvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si12064405ejt.706.2020.08.11.02.38.45; Tue, 11 Aug 2020 02:39:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fq8SQKvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgHKJf6 (ORCPT + 99 others); Tue, 11 Aug 2020 05:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728409AbgHKJf6 (ORCPT ); Tue, 11 Aug 2020 05:35:58 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E22C06174A for ; Tue, 11 Aug 2020 02:35:57 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id c19so1737442wmd.1 for ; Tue, 11 Aug 2020 02:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ItIu5ePf9JKIpjj5PDgXBJfnpsujSceF1j6mqZLY9xc=; b=fq8SQKvgjJxayeI7HmuFGs0oD96AKDdltc0/qy0MyDFZLz1W4mYReqmtyk2nIuCp8V 0mz5asZyNw/it7myybopvl4W3UJaoBxyj72tUdF0QCNbv6/fXNDI2pHx285LdeZUsSsA 6muP/2dkKw5rXn6YPgjCWbLJLC0TKp0d92eV4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ItIu5ePf9JKIpjj5PDgXBJfnpsujSceF1j6mqZLY9xc=; b=IBAwQmpJ4PONUHLPcRrzn4SCyInAlsp8RhWnLAJvfvGh4577aFjTpWo4UTyYdE/yCr XfXNQTMa/arQtPIYQYpzB59eqKR9VgPZG4i4WLzMMZZ6RuImZfyflidPFOR1wob5uQK0 F06Vjh83oM6kIzsp0X32aArrwWOhSOkqM2A7GXRVnJHDbYL1Bce4gWnYscL98p5UUOuH tKRUs2xbu+nAoRf4xaZnoLRmdGavFLiwaJWLc5/2+7j1e44LZT3MblzSzWYr/akbBMVL Go8Yt+1xD8m9AYWXEjYt9lKKQYuOf0tZ6PevmBpNy5xrGGrYLpm5R0vbQg/b7EFYr0gy TOtg== X-Gm-Message-State: AOAM532V99MbD4ci+oW2yjZCxz4G5OWY6LCtQSGhj/KWOghQlW4xJsNC YG4namKvnwiWd2axgbXebw51BbzGKxuURFVYblWnvg== X-Received: by 2002:a7b:c401:: with SMTP id k1mr3153089wmi.18.1597138556389; Tue, 11 Aug 2020 02:35:56 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: From: Yu-Hsuan Hsu Date: Tue, 11 Aug 2020 17:35:45 +0800 Message-ID: Subject: Re: [PATCH v3 2/2] ASoC: Intel: Add period size constraint on strago board To: Takashi Iwai Cc: "Lu, Brent" , Guennadi Liakhovetski , "alsa-devel@alsa-project.org" , Andy Shevchenko , Kuninori Morimoto , Kai Vehmanen , "linux-kernel@vger.kernel.org" , "Rojewski, Cezary" , Jie Yang , Pierre-Louis Bossart , Takashi Iwai , Liam Girdwood , Sam McNally , Mark Brown , Ranjani Sridharan , Daniel Stuart , "yuhsuan@google.com" , Damian van Soelen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Takashi Iwai =E6=96=BC 2020=E5=B9=B48=E6=9C=8811=E6=97=A5 = =E9=80=B1=E4=BA=8C =E4=B8=8B=E5=8D=884:39=E5=AF=AB=E9=81=93=EF=BC=9A > > On Tue, 11 Aug 2020 10:25:22 +0200, > Yu-Hsuan Hsu wrote: > > > > Takashi Iwai =E6=96=BC 2020=E5=B9=B48=E6=9C=8811=E6=97= =A5 =E9=80=B1=E4=BA=8C =E4=B8=8B=E5=8D=883:43=E5=AF=AB=E9=81=93=EF=BC=9A > > > > > > On Tue, 11 Aug 2020 04:29:24 +0200, > > > Yu-Hsuan Hsu wrote: > > > > > > > > Lu, Brent =E6=96=BC 2020=E5=B9=B48=E6=9C=8811= =E6=97=A5 =E9=80=B1=E4=BA=8C =E4=B8=8A=E5=8D=8810:17=E5=AF=AB=E9=81=93=EF= =BC=9A > > > > > > > > > > > > > > > > > Sorry for the late reply. CRAS does not set the period size whe= n using it. > > > > > > The default period size is 256, which consumes the samples quic= kly(about 49627 > > > > > > fps when the rate is 48000 fps) at the beginning of the playbac= k. > > > > > > 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 onl= y consume 240 > > > > > > samples until the ring buffer of DSP is full. This behavior mak= es the samples in > > > > > > the ring buffer of kernel consumed quickly. (Not sure whether t= he explanation is > > > > > > correct. Need Brent to confirm it.) > > > > > > > > > > > > Unfortunately, we can not change the behavior of DSP. After som= e 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. Bec= ause everyone > > > > > > can trigger this issue when using the driver without setting th= e 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 a= nd 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 abo= ut 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 configur= ation 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 co= nstraint 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 support= s. > > > > But in this case, everyone can trigger underrun if he or she does n= ot > > > > the period size to 240. If you still think it's not necessary, I ca= n > > > > 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 > > Thank Takashi, > > > > As I mentioned before, if the period size is set to 256, the measured > > rate of sample-consuming will be around 49627 fps. It causes underrun > > because the rate we set is 48000 fps. > > But this explanation rather sounds like the alignment problem. > However... > > > This behavior also happen on the > > other period rate except for 240. > > ... Why only 240? That's the next logical question. > If you have a clarification for it, it may be the rigid reason to > introduce such a hw constraint. > > > Takashi 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. Hi Brent, can you confirm it? Thanks, Yu-Hsuan