Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3767522ybv; Mon, 10 Feb 2020 06:07:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzbwLaP/lIpneTMuiMgiF4GzO6qaryXrPQIKvAgaOi0ukpd4zwc4K4IoM8JJIPal7xptd5P X-Received: by 2002:a9d:51c1:: with SMTP id d1mr1140558oth.136.1581343655850; Mon, 10 Feb 2020 06:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581343655; cv=none; d=google.com; s=arc-20160816; b=0buufNNdYzsR/H+/RmNOSCeMIkDA78igC7PIws8hudwCkb6PtqvWkWFnOh7h245Kvp ljp6xtBzDb8ml1sreTVfEYPjF+Eb2+Trfur1z30W6Bp5w0YC+c+3FoxuNRWx222Lj+Uz JTTzVY7i8e0LzV7pdZRPlX/02D2nq3aJN4MTkgC+anNGXfidy60J/+ZIQb9R6wel7wiO w7URZ1zohRxUUsH/ozkVRWresU6g/9LYMLTYaLVaC8FWpcsOMZhoXWUN4loI6IBS34XC m26gH6qx+ZQpk1AN/5iernyV0WomQZwem/Ysa5P/BLgGHziLCKhbtzQMGzaw6DSu7La2 RCoQ== 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=M7oV+dgNDePW9F+75A8vypX+j/v5tDexHBLLV1ccDfU=; b=YUVepM/FJeEb1YH0BiQok/wUh+4N2r+j5eMHGB/wYHX38jD+Qt+yXBEZxO2WEZg/CG 71StxDApW0w7grDHwO8tycvyaUegKQ02YbhXDlNG9C8QbhKy19nykgcAG0PK0ie5oaLD zj7WAiorZJFwxd+bf2LJmguAPHK7CxvOiARFmdLu6Tv83XduLFtrqtqQ9VTug2f8q9T+ q8TpLo9KJEnO1j5mTwTJMo8Vvxr+ltqNQ5PmKRZS7vr184svjBCguDqmGZdI463X79+J upaBIR8k5O0YfqPIB/dErFX5LHVuZJumn1soDmYI9sPtOTDSNqbznV9Q09H9s0Mw1O1B oZKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=x8MujdPN; 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 v11si235071otp.279.2020.02.10.06.07.23; Mon, 10 Feb 2020 06:07:35 -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=x8MujdPN; 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 S1728579AbgBJOGm (ORCPT + 99 others); Mon, 10 Feb 2020 09:06:42 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:41074 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727884AbgBJOGm (ORCPT ); Mon, 10 Feb 2020 09:06:42 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 01AE4O7g041894; Mon, 10 Feb 2020 08:04:24 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1581343464; bh=M7oV+dgNDePW9F+75A8vypX+j/v5tDexHBLLV1ccDfU=; h=From:To:CC:Subject:Date; b=x8MujdPN9PMGtYJardUmXjE4MOYPRuJh3p6eY1P17yHBEOMeOlw6pQeWroHLai4ug A7QzYoCcsIlnPtsG/9+M5MOzoR0oLV+LqVtayhQpyFGg0/bMKX2vMvWrJCWG4IwFQc Jm5wAMc/isV2eOzn737sG3Lf3p4b1niknRU5s0wE= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 01AE4Ols086430 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 10 Feb 2020 08:04:24 -0600 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE107.ent.ti.com (157.170.170.37) 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 08:04:23 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) 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 08:04:23 -0600 Received: from feketebors.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 01AE4Klm024323; Mon, 10 Feb 2020 08:04:21 -0600 From: Peter Ujfalusi To: , , , CC: , , , Subject: [PATCH] ASoC: dmaengine_pcm: Consider DMA cache caused delay in pointer callback Date: Mon, 10 Feb 2020 16:04:23 +0200 Message-ID: <20200210140423.10232-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 --- Hi, 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 ++++++ sound/soc/soc-pcm.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 5749a8a49784..4f1395fd0160 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -247,9 +247,15 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) { + struct snd_pcm_runtime *runtime = substream->runtime; + int sample_bits = snd_pcm_format_physical_width(runtime->format); + buf_size = snd_pcm_lib_buffer_bytes(substream); if (state.residue > 0 && state.residue <= buf_size) pos = buf_size - state.residue; + + sample_bits *= runtime->channels; + runtime->delay = state.in_flight_bytes / (sample_bits / 8); } return bytes_to_frames(substream->runtime, pos); diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index ff1b7c7078e5..58ef508d70a3 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1151,7 +1151,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) } delay += codec_delay; - runtime->delay = delay; + runtime->delay += delay; return offset; } -- Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki