Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3853829ybv; Mon, 10 Feb 2020 07:35:33 -0800 (PST) X-Google-Smtp-Source: APXvYqxx8Ge+v9WWqtAcDt1W2acvUFt+B0cwUgg9yVj4EvQSkFhqCpjeEXBciz141aKVz6NkwHn9 X-Received: by 2002:aca:6742:: with SMTP id b2mr1218538oiy.86.1581348933817; Mon, 10 Feb 2020 07:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581348933; cv=none; d=google.com; s=arc-20160816; b=V6al+v0g77zIFqsSDvq0rZrbph6A00cDVc7Lhe5/xET/9aBgizH5T6Bfxf+FbvjjBJ 6mrHHWE7/J4yyPpGxNOcc4jaQwhhP+vPx9+bl4fmF6JTldi9Z0yVus+nlIHy7I08W1q4 5aLueShTamI/1iEwNXD8nV7FdSFJGUoaPEm7MvFHZwvOAAxEqbDh2u9Rk025oKxrltnO 5dJb4TlTVF67sdPj67V9QdqJakp03O+oKJZyetn0XXRy1hBCyUfgGugW9vCu5SFtY/m/ /jlxVwdSJOOZwv5uhT5kZZuDGf3rUmrwupQyMwUvQ40LULZyOtr+u2icMXJg3o3aLYdT DVmg== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kraOaUvBzE4RhyqAmIw9/UceGvGGSH27DUD+H1Apd00=; b=od4Gvi4mnCxrtkyoPNG3HoHnsqC816Ilv6Yx2TYtg6iYcjjCGkwptGctOdtatRrkkd BC3EJ23B7P/jB6t0BM+TMxoLkSNBs7xkjmlqH6h5grW2aWYTDVHRNzuSlenu8OwDZSBC ea2sqeyUzOZxPNsnVR2piRra2tFmSHGq2wfu2M52OdlY7F62txJ0DBFOmr6HX4ouqQZk c/BMwhESAWrC1MeVXPGLK2z0ePxGsNB5reyavgCJzrzcenCpm2H11mc5xf0MbOb9GbVy 2ytQCmX6A8j3aiegWO/aLQTY/MFoigdlqXVJzDO4ehHpFWk/8VyttTx9qbOS5sMcwiDw o+Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=H61TS3Xg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si335324otp.310.2020.02.10.07.35.21; Mon, 10 Feb 2020 07:35:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=H61TS3Xg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbgBJPeG (ORCPT + 99 others); Mon, 10 Feb 2020 10:34:06 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:36778 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727541AbgBJPeF (ORCPT ); Mon, 10 Feb 2020 10:34:05 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 01AFXaRu018605; Mon, 10 Feb 2020 09:33:36 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1581348816; bh=kraOaUvBzE4RhyqAmIw9/UceGvGGSH27DUD+H1Apd00=; h=From:To:CC:Subject:Date; b=H61TS3XgF/QHeD6JlS3lUTygXaiMrbmGqY2jar3YcIGgKwf3JQjEpBYEJKVZW7fj+ r6Pn8kEHPmjM1yqPY49l8X1W4IB6VIFPKC6QX+ML75oQoIg0YQma+D5bCfE1nC7xqe JnehaWaXbokHdHKsaVj6DUpDuXGVi2kz2Ebzmi24= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 01AFXaX3115596; Mon, 10 Feb 2020 09:33:36 -0600 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 10 Feb 2020 09:33:36 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Mon, 10 Feb 2020 09:33:36 -0600 Received: from feketebors.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 01AFXXAi054822; Mon, 10 Feb 2020 09:33:34 -0600 From: Peter Ujfalusi To: , , , CC: , , , Subject: [PATCH v3] ALSA: dmaengine_pcm: Consider DMA cache caused delay in pointer callback Date: Mon, 10 Feb 2020 17:33:36 +0200 Message-ID: <20200210153336.10218-1-peter.ujfalusi@ti.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some DMA engines can have big FIFOs which adds to the latency. The DMAengine framework can report the FIFO utilization in bytes. Use this information for the delay reporting. Signed-off-by: Peter Ujfalusi Reviewed-by: Takashi Iwai --- Hi, Changes since v2: - align the substream->runtime users to use runtime. - added Reviewed-by from Takashi-san Changes since v1: - use bytes_to_frames() for the DMA delay calculation - Drop changes to soc-pcm 5.6-rc1 now have support for reporting the DMA cached data. With this patch we can include it to the delay calculation. The first DMA driver which reports this is the TI K3 UDMA driver. Regards, Peter sound/core/pcm_dmaengine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 5749a8a49784..9d4f48cfe47f 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -240,6 +240,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue); snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); + struct snd_pcm_runtime *runtime = substream->runtime; struct dma_tx_state state; enum dma_status status; unsigned int buf_size; @@ -250,9 +251,12 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) buf_size = snd_pcm_lib_buffer_bytes(substream); if (state.residue > 0 && state.residue <= buf_size) pos = buf_size - state.residue; + + runtime->delay = bytes_to_frames(runtime, + state.in_flight_bytes); } - return bytes_to_frames(substream->runtime, pos); + return bytes_to_frames(runtime, pos); } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer); -- Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki