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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 7B166C33CB1 for ; Thu, 16 Jan 2020 09:42:25 +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 0868820748 for ; Thu, 16 Jan 2020 09:42:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="Ju/8mpwl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0868820748 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com 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 309DE17A1; Thu, 16 Jan 2020 10:41:33 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 309DE17A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1579167743; bh=NaTgKaOqOWYQofvv8eHgnggDmb6lWITxeH46Ogh9Rqw=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ju/8mpwlhi9AMlv2d6Cp78fJ/f/KzoX2h/k7rW0Sw7hsOgOBSleqAkWtGUVnf16LW QnR2N3jvn2Hj+7fpdlrFpUYgCmtL+qnZEIaN9YCLRKW5KGc3KX6VXd3ZA/kF5ChFqY jgTPcFg/mhICQ/HlOfNjV42uudq92ldeX36BXflU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B01E2F8014D; Thu, 16 Jan 2020 10:41:32 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0BECBF8014D; Thu, 16 Jan 2020 10:41:30 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 42741F80086 for ; Thu, 16 Jan 2020 10:41:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 42741F80086 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2020 01:41:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,325,1574150400"; d="scan'208";a="225904916" Received: from unknown (HELO keyon-X299) ([10.239.159.75]) by orsmga003.jf.intel.com with ESMTP; 16 Jan 2020 01:41:24 -0800 Message-ID: <97bbe88d1a6b63fe8e9b02bf0c5ce4a80553c48d.camel@linux.intel.com> From: Keyon Jie To: Takashi Iwai Date: Thu, 16 Jan 2020 17:50:33 +0800 In-Reply-To: References: <20200116045318.5498-1-yang.jie@linux.intel.com> User-Agent: Evolution 3.34.1-2 MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH] ALSA: pcm: fix buffer_bytes max constrained by preallocated bytes issue 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 2020-01-16 at 08:15 +0100, Takashi Iwai wrote: > On Thu, 16 Jan 2020 05:53:18 +0100, > Keyon Jie wrote: > > With today's code, we preallocate DMA buffer for substreams at > > pcm_new() > > stage, and the substream->buffer_bytes_max and substream->dma_max > > will > > save as the actually preallocated buffer size and maximum size that > > the > > dma buffer can be expanded by at hw_params() state, > > correspondingly. > > No, it's other way round: the former, buffer_bytes_max, is the max > size defined by the driver (i.e. passed in snd_pcm_hardware) and the > latter, dma_max, is the max preallocation size (passed to > preallocation helper). Hi Takashi, thanks for your comment. First of all, have you ever hit issue I mentioned in the commit message that we can't set buffer_bytes larger than the preallocated dma bytes? I found this issue in kinds of platforms, not only on SOF/SoC ones, but also on legacy HDA ones. Secondly, I am not clear about the design intention of the substream- >buffer_bytes_max and substream->dma_max, if it is as you commented above, can you help answer my questions below inline the code? void snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream, int type, struct device *data, size_t size, size_t max) static void preallocate_pages(struct snd_pcm_substream *substream, int type, struct device *data, size_t size, size_t max, bool managed) { ... if (substream->dma_buffer.bytes > 0) substream->buffer_bytes_max = substream- >dma_buffer.bytes;//Keyon: this is the actual allocated buffer bytes, what is the intention here and why it is assigned to buffer_bytes_max which will be used to constrain on the _HW_PARAM_BUFFER_BYTES later? substream->dma_max = max; //Keyon: looks here it is where the *max* param used only if we don't define SND_VERBOSE_PROCFS? what relationship can we have with the preallocation itself? ... } > > > At pcm_open() stage, the maximum constraint of > > HW_PARAM_BUFFER_BYTES is > > set to substream->buffer_bytes_max and returned to user space as > > the max > > interval of the HW_PARAM_BUFFER_BYTES, this will lead to issue that > > user > > can't choose any buffer-bytes larger than the preallocated buffer > > size, > > and the buffer reallocation will never happen actually. > > > > Here change to use substream->dma_max as the maximum constraint of > > the > > HW_PARAM_BUFFER_BYTES and fix the issue mentioned above. > > I don't think the logic in the current code you're changing is wrong. > If there is any, it must be something else. > > This might be rather the FIXME code found in > snd_pcm_hw_constraints_complete()? I just tried removing the FIXME part code and it doesn't help, the rule snd_pcm_hw_rule_buffer_bytes_max here limit the max of the SNDRV_PCM_HW_PARAM_BUFFER_BYTES and this will returned to user space like aplay for the subsequent hw_params(), is this intentional? int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) { ... err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, snd_pcm_hw_rule_buffer_bytes_max, substream, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1); if (err < 0) return err; /* FIXME: remove */ if (runtime->dma_bytes) { err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes); if (err < 0) return err; } ... return 0; } Thanks, ~Keyon _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel