stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 1/5] ASoC: q6apm-dai: schedule all available frames to avoid dsp under-runs
       [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
@ 2025-03-14 17:47 ` srinivas.kandagatla
  2025-03-14 17:47 ` [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper srinivas.kandagatla
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-03-14 17:47 UTC (permalink / raw)
  To: broonie
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, Srinivas Kandagatla,
	stable

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

With the existing code, we are only setting up one period at a time, in a
ping-pong buffer style. This triggers lot of underruns in the dsp
leading to jitter noise during audio playback.

Fix this by scheduling all available periods, this will ensure that the dsp
has enough buffer feed and ultimatley fixing the underruns and audio
distortion.

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Cc: stable@vger.kernel.org
Reported-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/qdsp6/q6apm-dai.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index c9404b5934c7..9d8e8e37c6de 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -70,6 +70,7 @@ struct q6apm_dai_rtd {
 	unsigned int bytes_received;
 	unsigned int copied_total;
 	uint16_t bits_per_sample;
+	snd_pcm_uframes_t queue_ptr;
 	bool next_track;
 	enum stream_state state;
 	struct q6apm_graph *graph;
@@ -134,8 +135,6 @@ static void event_handler(uint32_t opcode, uint32_t token, void *payload, void *
 		prtd->pos += prtd->pcm_count;
 		spin_unlock_irqrestore(&prtd->lock, flags);
 		snd_pcm_period_elapsed(substream);
-		if (prtd->state == Q6APM_STREAM_RUNNING)
-			q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
 
 		break;
 	case APM_CLIENT_EVENT_DATA_READ_DONE:
@@ -294,6 +293,27 @@ static int q6apm_dai_prepare(struct snd_soc_component *component,
 	return 0;
 }
 
+static int q6apm_dai_ack(struct snd_soc_component *component, struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct q6apm_dai_rtd *prtd = runtime->private_data;
+	int i, ret = 0, avail_periods;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		avail_periods = (runtime->control->appl_ptr - prtd->queue_ptr)/runtime->period_size;
+		for (i = 0; i < avail_periods; i++) {
+			ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+			if (ret < 0) {
+				dev_err(component->dev, "Error queuing playback buffer %d\n", ret);
+				return ret;
+			}
+			prtd->queue_ptr += runtime->period_size;
+		}
+	}
+
+	return ret;
+}
+
 static int q6apm_dai_trigger(struct snd_soc_component *component,
 			     struct snd_pcm_substream *substream, int cmd)
 {
@@ -305,9 +325,6 @@ static int q6apm_dai_trigger(struct snd_soc_component *component,
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		 /* start writing buffers for playback only as we already queued capture buffers */
-		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-			ret = q6apm_write_async(prtd->graph, prtd->pcm_count, 0, 0, 0);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 		/* TODO support be handled via SoftPause Module */
@@ -836,6 +853,7 @@ static const struct snd_soc_component_driver q6apm_fe_dai_component = {
 	.hw_params	= q6apm_dai_hw_params,
 	.pointer	= q6apm_dai_pointer,
 	.trigger	= q6apm_dai_trigger,
+	.ack		= q6apm_dai_ack,
 	.compress_ops	= &q6apm_dai_compress_ops,
 	.use_dai_pcm_id = true,
 };
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper
       [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
  2025-03-14 17:47 ` [PATCH v5 1/5] ASoC: q6apm-dai: schedule all available frames to avoid dsp under-runs srinivas.kandagatla
@ 2025-03-14 17:47 ` srinivas.kandagatla
  2025-04-07 11:25   ` Johan Hovold
  2025-03-14 17:47 ` [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer srinivas.kandagatla
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: srinivas.kandagatla @ 2025-03-14 17:47 UTC (permalink / raw)
  To: broonie
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, Srinivas Kandagatla,
	stable

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

Implement an helper function in q6apm to be able to read the current
hardware pointer for both read and write buffers.

This should help q6apm-dai to get the hardware pointer consistently
without it doing manual calculation, which could go wrong in some race
conditions.

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/qdsp6/q6apm.c | 18 +++++++++++++++++-
 sound/soc/qcom/qdsp6/q6apm.h |  3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index 2a2a5bd98110..ca57413cb784 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -494,6 +494,19 @@ int q6apm_read(struct q6apm_graph *graph)
 }
 EXPORT_SYMBOL_GPL(q6apm_read);
 
+int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir)
+{
+	struct audioreach_graph_data *data;
+
+	if (dir == SNDRV_PCM_STREAM_PLAYBACK)
+		data = &graph->rx_data;
+	else
+		data = &graph->tx_data;
+
+	return (int)atomic_read(&data->hw_ptr);
+}
+EXPORT_SYMBOL_GPL(q6apm_get_hw_pointer);
+
 static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
 {
 	struct data_cmd_rsp_rd_sh_mem_ep_data_buffer_done_v2 *rd_done;
@@ -520,7 +533,8 @@ static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
 		done = data->payload;
 		phys = graph->rx_data.buf[token].phys;
 		mutex_unlock(&graph->lock);
-
+		/* token numbering starts at 0 */
+		atomic_set(&graph->rx_data.hw_ptr, token + 1);
 		if (lower_32_bits(phys) == done->buf_addr_lsw &&
 		    upper_32_bits(phys) == done->buf_addr_msw) {
 			graph->result.opcode = hdr->opcode;
@@ -553,6 +567,8 @@ static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
 		rd_done = data->payload;
 		phys = graph->tx_data.buf[hdr->token].phys;
 		mutex_unlock(&graph->lock);
+		/* token numbering starts at 0 */
+		atomic_set(&graph->tx_data.hw_ptr, hdr->token + 1);
 
 		if (upper_32_bits(phys) == rd_done->buf_addr_msw &&
 		    lower_32_bits(phys) == rd_done->buf_addr_lsw) {
diff --git a/sound/soc/qcom/qdsp6/q6apm.h b/sound/soc/qcom/qdsp6/q6apm.h
index c248c8d2b1ab..7ce08b401e31 100644
--- a/sound/soc/qcom/qdsp6/q6apm.h
+++ b/sound/soc/qcom/qdsp6/q6apm.h
@@ -2,6 +2,7 @@
 #ifndef __Q6APM_H__
 #define __Q6APM_H__
 #include <linux/types.h>
+#include <linux/atomic.h>
 #include <linux/slab.h>
 #include <linux/wait.h>
 #include <linux/kernel.h>
@@ -77,6 +78,7 @@ struct audioreach_graph_data {
 	uint32_t num_periods;
 	uint32_t dsp_buf;
 	uint32_t mem_map_handle;
+	atomic_t hw_ptr;
 };
 
 struct audioreach_graph {
@@ -150,4 +152,5 @@ int q6apm_enable_compress_module(struct device *dev, struct q6apm_graph *graph,
 int q6apm_remove_initial_silence(struct device *dev, struct q6apm_graph *graph, uint32_t samples);
 int q6apm_remove_trailing_silence(struct device *dev, struct q6apm_graph *graph, uint32_t samples);
 int q6apm_set_real_module_id(struct device *dev, struct q6apm_graph *graph, uint32_t codec_id);
+int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir);
 #endif /* __APM_GRAPH_ */
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer
       [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
  2025-03-14 17:47 ` [PATCH v5 1/5] ASoC: q6apm-dai: schedule all available frames to avoid dsp under-runs srinivas.kandagatla
  2025-03-14 17:47 ` [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper srinivas.kandagatla
@ 2025-03-14 17:47 ` srinivas.kandagatla
  2025-03-31 12:32   ` Mark Brown
  2025-03-31 15:35   ` Christopher Obbard
  2025-03-14 17:47 ` [PATCH v5 4/5] ASoC: qdsp6: q6apm-dai: set 10 ms period and buffer alignment srinivas.kandagatla
  2025-03-14 17:48 ` [PATCH v5 5/5] ASoC: qdsp6: q6apm-dai: fix capture pipeline overruns srinivas.kandagatla
  4 siblings, 2 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-03-14 17:47 UTC (permalink / raw)
  To: broonie
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, Srinivas Kandagatla,
	stable

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

With the existing code, the buffer position is only reset in pointer
callback, which leaves the possiblity of it going over the size of
buffer size and reporting incorrect position to userspace.

Without this patch, its possible to see errors like:
snd-x1e80100 sound: invalid position: pcmC0D0p:0, pos = 12288, buffer size = 12288, period size = 1536
snd-x1e80100 sound: invalid position: pcmC0D0p:0, pos = 12288, buffer size = 12288, period size = 1536

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/qdsp6/q6apm-dai.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index 9d8e8e37c6de..90cb24947f31 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -64,7 +64,6 @@ struct q6apm_dai_rtd {
 	phys_addr_t phys;
 	unsigned int pcm_size;
 	unsigned int pcm_count;
-	unsigned int pos;       /* Buffer position */
 	unsigned int periods;
 	unsigned int bytes_sent;
 	unsigned int bytes_received;
@@ -124,23 +123,16 @@ static void event_handler(uint32_t opcode, uint32_t token, void *payload, void *
 {
 	struct q6apm_dai_rtd *prtd = priv;
 	struct snd_pcm_substream *substream = prtd->substream;
-	unsigned long flags;
 
 	switch (opcode) {
 	case APM_CLIENT_EVENT_CMD_EOS_DONE:
 		prtd->state = Q6APM_STREAM_STOPPED;
 		break;
 	case APM_CLIENT_EVENT_DATA_WRITE_DONE:
-		spin_lock_irqsave(&prtd->lock, flags);
-		prtd->pos += prtd->pcm_count;
-		spin_unlock_irqrestore(&prtd->lock, flags);
 		snd_pcm_period_elapsed(substream);
 
 		break;
 	case APM_CLIENT_EVENT_DATA_READ_DONE:
-		spin_lock_irqsave(&prtd->lock, flags);
-		prtd->pos += prtd->pcm_count;
-		spin_unlock_irqrestore(&prtd->lock, flags);
 		snd_pcm_period_elapsed(substream);
 		if (prtd->state == Q6APM_STREAM_RUNNING)
 			q6apm_read(prtd->graph);
@@ -247,7 +239,6 @@ static int q6apm_dai_prepare(struct snd_soc_component *component,
 	}
 
 	prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
-	prtd->pos = 0;
 	/* rate and channels are sent to audio driver */
 	ret = q6apm_graph_media_format_shmem(prtd->graph, &cfg);
 	if (ret < 0) {
@@ -445,16 +436,12 @@ static snd_pcm_uframes_t q6apm_dai_pointer(struct snd_soc_component *component,
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct q6apm_dai_rtd *prtd = runtime->private_data;
 	snd_pcm_uframes_t ptr;
-	unsigned long flags;
 
-	spin_lock_irqsave(&prtd->lock, flags);
-	if (prtd->pos == prtd->pcm_size)
-		prtd->pos = 0;
-
-	ptr =  bytes_to_frames(runtime, prtd->pos);
-	spin_unlock_irqrestore(&prtd->lock, flags);
+	ptr = q6apm_get_hw_pointer(prtd->graph, substream->stream) * runtime->period_size;
+	if (ptr)
+		return ptr - 1;
 
-	return ptr;
+	return 0;
 }
 
 static int q6apm_dai_hw_params(struct snd_soc_component *component,
@@ -669,8 +656,6 @@ static int q6apm_dai_compr_set_params(struct snd_soc_component *component,
 	prtd->pcm_size = runtime->fragments * runtime->fragment_size;
 	prtd->bits_per_sample = 16;
 
-	prtd->pos = 0;
-
 	if (prtd->next_track != true) {
 		memcpy(&prtd->codec, codec, sizeof(*codec));
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 4/5] ASoC: qdsp6: q6apm-dai: set 10 ms period and buffer alignment.
       [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
                   ` (2 preceding siblings ...)
  2025-03-14 17:47 ` [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer srinivas.kandagatla
@ 2025-03-14 17:47 ` srinivas.kandagatla
  2025-03-14 17:48 ` [PATCH v5 5/5] ASoC: qdsp6: q6apm-dai: fix capture pipeline overruns srinivas.kandagatla
  4 siblings, 0 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-03-14 17:47 UTC (permalink / raw)
  To: broonie
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, Srinivas Kandagatla,
	stable

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

DSP expects the periods to be aligned to fragment sizes, currently
setting up to hw constriants on periods bytes is not going to work
correctly as we can endup with periods sizes aligned to 32 bytes however
not aligned to fragment size.

Update the constriants to use fragment size, and also set at step of
10ms for period size to accommodate DSP requirements of 10ms latency.

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/qdsp6/q6apm-dai.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index 90cb24947f31..180ff24041bf 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -385,13 +385,14 @@ static int q6apm_dai_open(struct snd_soc_component *component,
 		}
 	}
 
-	ret = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
+	/* setup 10ms latency to accommodate DSP restrictions */
+	ret = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 480);
 	if (ret < 0) {
 		dev_err(dev, "constraint for period bytes step ret = %d\n", ret);
 		goto err;
 	}
 
-	ret = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
+	ret = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 480);
 	if (ret < 0) {
 		dev_err(dev, "constraint for buffer bytes step ret = %d\n", ret);
 		goto err;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 5/5] ASoC: qdsp6: q6apm-dai: fix capture pipeline overruns.
       [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
                   ` (3 preceding siblings ...)
  2025-03-14 17:47 ` [PATCH v5 4/5] ASoC: qdsp6: q6apm-dai: set 10 ms period and buffer alignment srinivas.kandagatla
@ 2025-03-14 17:48 ` srinivas.kandagatla
  4 siblings, 0 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-03-14 17:48 UTC (permalink / raw)
  To: broonie
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, Srinivas Kandagatla,
	stable

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

Period sizes less than 6k for capture path triggers overruns in the
dsp capture pipeline.

Change the period size and number of periods to value which DSP is happy with.

Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/qdsp6/q6apm-dai.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
index 180ff24041bf..2cd522108221 100644
--- a/sound/soc/qcom/qdsp6/q6apm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
@@ -24,8 +24,8 @@
 #define PLAYBACK_MIN_PERIOD_SIZE	128
 #define CAPTURE_MIN_NUM_PERIODS		2
 #define CAPTURE_MAX_NUM_PERIODS		8
-#define CAPTURE_MAX_PERIOD_SIZE		4096
-#define CAPTURE_MIN_PERIOD_SIZE		320
+#define CAPTURE_MAX_PERIOD_SIZE		65536
+#define CAPTURE_MIN_PERIOD_SIZE		6144
 #define BUFFER_BYTES_MAX (PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE)
 #define BUFFER_BYTES_MIN (PLAYBACK_MIN_NUM_PERIODS * PLAYBACK_MIN_PERIOD_SIZE)
 #define COMPR_PLAYBACK_MAX_FRAGMENT_SIZE (128 * 1024)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer
  2025-03-14 17:47 ` [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer srinivas.kandagatla
@ 2025-03-31 12:32   ` Mark Brown
  2025-03-31 13:22     ` Johan Hovold
  2025-03-31 15:35   ` Christopher Obbard
  1 sibling, 1 reply; 12+ messages in thread
From: Mark Brown @ 2025-03-31 12:32 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: perex, tiwai, krzysztof.kozlowski, linux-sound, linux-arm-msm,
	linux-kernel, dmitry.baryshkov, johan+linaro, stable

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

On Fri, Mar 14, 2025 at 05:47:58PM +0000, srinivas.kandagatla@linaro.org wrote:

> Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
> Cc: stable@vger.kernel.org

This commit doesn't appear to exist.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer
  2025-03-31 12:32   ` Mark Brown
@ 2025-03-31 13:22     ` Johan Hovold
  2025-03-31 14:00       ` Mark Brown
  0 siblings, 1 reply; 12+ messages in thread
From: Johan Hovold @ 2025-03-31 13:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: srinivas.kandagatla, perex, tiwai, krzysztof.kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, dmitry.baryshkov,
	johan+linaro, stable

[-- Attachment #1: Type: text/plain, Size: 1079 bytes --]

On Mon, Mar 31, 2025 at 01:32:36PM +0100, Mark Brown wrote:
> On Fri, Mar 14, 2025 at 05:47:58PM +0000, srinivas.kandagatla@linaro.org wrote:
> 
> > Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
> > Cc: stable@vger.kernel.org
> 
> This commit doesn't appear to exist.

I think some tool (e.g. b4) incorrectly indicated that that may be the
case here, but the commit does exist:

commit 9b4fe0f1cd791d540100d98a3baf94c1f9994647
Author:     Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
AuthorDate: Tue Oct 26 12:16:52 2021 +0100
Commit:     Mark Brown <broonie@kernel.org>
CommitDate: Tue Oct 26 13:50:09 2021 +0100

    ASoC: qdsp6: audioreach: add q6apm-dai support

    Add support to pcm dais in Audio Process Manager.

    Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
    Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
    Link: https://lore.kernel.org/r/20211026111655.1702-15-srinivas.kandagatla@linaro.org
    Signed-off-by: Mark Brown <broonie@kernel.org>

Johan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer
  2025-03-31 13:22     ` Johan Hovold
@ 2025-03-31 14:00       ` Mark Brown
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2025-03-31 14:00 UTC (permalink / raw)
  To: Johan Hovold
  Cc: srinivas.kandagatla, perex, tiwai, krzysztof.kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, dmitry.baryshkov,
	johan+linaro, stable

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

On Mon, Mar 31, 2025 at 03:22:13PM +0200, Johan Hovold wrote:
> On Mon, Mar 31, 2025 at 01:32:36PM +0100, Mark Brown wrote:
> > On Fri, Mar 14, 2025 at 05:47:58PM +0000, srinivas.kandagatla@linaro.org wrote:

> > > Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")

> > This commit doesn't appear to exist.

> I think some tool (e.g. b4) incorrectly indicated that that may be the
> case here, but the commit does exist:

Oh, actually it's a parse error with the way the tag is written - not
quite sure why but for some reason adding the next digit to the hash
massages things enough.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer
  2025-03-14 17:47 ` [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer srinivas.kandagatla
  2025-03-31 12:32   ` Mark Brown
@ 2025-03-31 15:35   ` Christopher Obbard
  1 sibling, 0 replies; 12+ messages in thread
From: Christopher Obbard @ 2025-03-31 15:35 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: broonie, perex, tiwai, krzysztof.kozlowski, linux-sound,
	linux-arm-msm, linux-kernel, dmitry.baryshkov, johan+linaro,
	stable

Hi Srini,

On Fri, 14 Mar 2025 at 18:49, <srinivas.kandagatla@linaro.org> wrote:
>
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>
> With the existing code, the buffer position is only reset in pointer
> callback, which leaves the possiblity of it going over the size of
> buffer size and reporting incorrect position to userspace.
>
> Without this patch, its possible to see errors like:
> snd-x1e80100 sound: invalid position: pcmC0D0p:0, pos = 12288, buffer size = 12288, period size = 1536
> snd-x1e80100 sound: invalid position: pcmC0D0p:0, pos = 12288, buffer size = 12288, period size = 1536
>
> Fixes: 9b4fe0f1cd79 ("ASoC: qdsp6: audioreach: add q6apm-dai support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Tested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Tested-by: Johan Hovold <johan+linaro@kernel.org>

Seems like I missed adding my T-b to this patch. If it's not too late,
please add:

Tested-by: Christopher Obbard <christopher.obbard@linaro.org>

> ---
>  sound/soc/qcom/qdsp6/q6apm-dai.c | 23 ++++-------------------
>  1 file changed, 4 insertions(+), 19 deletions(-)
>
> diff --git a/sound/soc/qcom/qdsp6/q6apm-dai.c b/sound/soc/qcom/qdsp6/q6apm-dai.c
> index 9d8e8e37c6de..90cb24947f31 100644
> --- a/sound/soc/qcom/qdsp6/q6apm-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6apm-dai.c
> @@ -64,7 +64,6 @@ struct q6apm_dai_rtd {
>         phys_addr_t phys;
>         unsigned int pcm_size;
>         unsigned int pcm_count;
> -       unsigned int pos;       /* Buffer position */
>         unsigned int periods;
>         unsigned int bytes_sent;
>         unsigned int bytes_received;
> @@ -124,23 +123,16 @@ static void event_handler(uint32_t opcode, uint32_t token, void *payload, void *
>  {
>         struct q6apm_dai_rtd *prtd = priv;
>         struct snd_pcm_substream *substream = prtd->substream;
> -       unsigned long flags;
>
>         switch (opcode) {
>         case APM_CLIENT_EVENT_CMD_EOS_DONE:
>                 prtd->state = Q6APM_STREAM_STOPPED;
>                 break;
>         case APM_CLIENT_EVENT_DATA_WRITE_DONE:
> -               spin_lock_irqsave(&prtd->lock, flags);
> -               prtd->pos += prtd->pcm_count;
> -               spin_unlock_irqrestore(&prtd->lock, flags);
>                 snd_pcm_period_elapsed(substream);
>
>                 break;
>         case APM_CLIENT_EVENT_DATA_READ_DONE:
> -               spin_lock_irqsave(&prtd->lock, flags);
> -               prtd->pos += prtd->pcm_count;
> -               spin_unlock_irqrestore(&prtd->lock, flags);
>                 snd_pcm_period_elapsed(substream);
>                 if (prtd->state == Q6APM_STREAM_RUNNING)
>                         q6apm_read(prtd->graph);
> @@ -247,7 +239,6 @@ static int q6apm_dai_prepare(struct snd_soc_component *component,
>         }
>
>         prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
> -       prtd->pos = 0;
>         /* rate and channels are sent to audio driver */
>         ret = q6apm_graph_media_format_shmem(prtd->graph, &cfg);
>         if (ret < 0) {
> @@ -445,16 +436,12 @@ static snd_pcm_uframes_t q6apm_dai_pointer(struct snd_soc_component *component,
>         struct snd_pcm_runtime *runtime = substream->runtime;
>         struct q6apm_dai_rtd *prtd = runtime->private_data;
>         snd_pcm_uframes_t ptr;
> -       unsigned long flags;
>
> -       spin_lock_irqsave(&prtd->lock, flags);
> -       if (prtd->pos == prtd->pcm_size)
> -               prtd->pos = 0;
> -
> -       ptr =  bytes_to_frames(runtime, prtd->pos);
> -       spin_unlock_irqrestore(&prtd->lock, flags);
> +       ptr = q6apm_get_hw_pointer(prtd->graph, substream->stream) * runtime->period_size;
> +       if (ptr)
> +               return ptr - 1;
>
> -       return ptr;
> +       return 0;
>  }
>
>  static int q6apm_dai_hw_params(struct snd_soc_component *component,
> @@ -669,8 +656,6 @@ static int q6apm_dai_compr_set_params(struct snd_soc_component *component,
>         prtd->pcm_size = runtime->fragments * runtime->fragment_size;
>         prtd->bits_per_sample = 16;
>
> -       prtd->pos = 0;
> -
>         if (prtd->next_track != true) {
>                 memcpy(&prtd->codec, codec, sizeof(*codec));
>
> --
> 2.39.5
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper
  2025-03-14 17:47 ` [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper srinivas.kandagatla
@ 2025-04-07 11:25   ` Johan Hovold
  2025-04-08  8:07     ` Srinivas Kandagatla
  0 siblings, 1 reply; 12+ messages in thread
From: Johan Hovold @ 2025-04-07 11:25 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: broonie, perex, tiwai, krzysztof.kozlowski, linux-sound,
	linux-arm-msm, linux-kernel, dmitry.baryshkov, johan+linaro,
	stable

Hi Srini,

On Fri, Mar 14, 2025 at 05:47:57PM +0000, Srinivas Kandagatla wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 
> Implement an helper function in q6apm to be able to read the current
> hardware pointer for both read and write buffers.
> 
> This should help q6apm-dai to get the hardware pointer consistently
> without it doing manual calculation, which could go wrong in some race
> conditions.
 
> +int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir)
> +{
> +	struct audioreach_graph_data *data;
> +
> +	if (dir == SNDRV_PCM_STREAM_PLAYBACK)
> +		data = &graph->rx_data;
> +	else
> +		data = &graph->tx_data;
> +
> +	return (int)atomic_read(&data->hw_ptr);
> +}
> +EXPORT_SYMBOL_GPL(q6apm_get_hw_pointer);

> @@ -553,6 +567,8 @@ static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
>  		rd_done = data->payload;
>  		phys = graph->tx_data.buf[hdr->token].phys;
>  		mutex_unlock(&graph->lock);
> +		/* token numbering starts at 0 */
> +		atomic_set(&graph->tx_data.hw_ptr, hdr->token + 1);
>  
>  		if (upper_32_bits(phys) == rd_done->buf_addr_msw &&
>  		    lower_32_bits(phys) == rd_done->buf_addr_lsw) {

			graph->result.opcode = hdr->opcode;
                        graph->result.status = rd_done->status;
                        if (graph->cb)
                                graph->cb(client_event, hdr->token, data->payload, graph->priv);
                } else {
                        dev_err(dev, "RD BUFF Unexpected addr %08x-%08x\n", rd_done->buf_addr_lsw,
                                rd_done->buf_addr_msw);
                }

I just hit the following error on the T14s with 6.15-rc1 that I've never
seen before and which looks like it could be related to this series:

	q6apm-dai 6800000.remoteproc:glink-edge:gpr:service@1:dais: RD BUFF Unexpected addr ffe0d200-00000001

Any ideas about what may be causing this?

Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper
  2025-04-07 11:25   ` Johan Hovold
@ 2025-04-08  8:07     ` Srinivas Kandagatla
  2025-04-10  7:16       ` Johan Hovold
  0 siblings, 1 reply; 12+ messages in thread
From: Srinivas Kandagatla @ 2025-04-08  8:07 UTC (permalink / raw)
  To: Johan Hovold
  Cc: broonie, perex, tiwai, krzysztof.kozlowski, linux-sound,
	linux-arm-msm, linux-kernel, dmitry.baryshkov, johan+linaro,
	stable

Thanks Johan,

On 07/04/2025 12:25, Johan Hovold wrote:
> Hi Srini,
> 
> On Fri, Mar 14, 2025 at 05:47:57PM +0000, Srinivas Kandagatla wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
>> Implement an helper function in q6apm to be able to read the current
>> hardware pointer for both read and write buffers.
>>
>> This should help q6apm-dai to get the hardware pointer consistently
>> without it doing manual calculation, which could go wrong in some race
>> conditions.
>   
>> +int q6apm_get_hw_pointer(struct q6apm_graph *graph, int dir)
>> +{
>> +	struct audioreach_graph_data *data;
>> +
>> +	if (dir == SNDRV_PCM_STREAM_PLAYBACK)
>> +		data = &graph->rx_data;
>> +	else
>> +		data = &graph->tx_data;
>> +
>> +	return (int)atomic_read(&data->hw_ptr);
>> +}
>> +EXPORT_SYMBOL_GPL(q6apm_get_hw_pointer);
> 
>> @@ -553,6 +567,8 @@ static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
>>   		rd_done = data->payload;
>>   		phys = graph->tx_data.buf[hdr->token].phys;
>>   		mutex_unlock(&graph->lock);
>> +		/* token numbering starts at 0 */
>> +		atomic_set(&graph->tx_data.hw_ptr, hdr->token + 1);
>>   
>>   		if (upper_32_bits(phys) == rd_done->buf_addr_msw &&
>>   		    lower_32_bits(phys) == rd_done->buf_addr_lsw) {
> 
> 			graph->result.opcode = hdr->opcode;
>                          graph->result.status = rd_done->status;
>                          if (graph->cb)
>                                  graph->cb(client_event, hdr->token, data->payload, graph->priv);
>                  } else {
>                          dev_err(dev, "RD BUFF Unexpected addr %08x-%08x\n", rd_done->buf_addr_lsw,
>                                  rd_done->buf_addr_msw);
>                  }
> 
> I just hit the following error on the T14s with 6.15-rc1 that I've never
> seen before and which looks like it could be related to this series:
Its unlikely, but the timings have changed here.
I have not seen it either, but I will try to reproduce this with 6.15-rc1.
> 
> 	q6apm-dai 6800000.remoteproc:glink-edge:gpr:service@1:dais: RD BUFF Unexpected addr ffe0d200-00000001
> 
> Any ideas about what may be causing this?
How easy is this to reproduce?

--srini
> 
> Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper
  2025-04-08  8:07     ` Srinivas Kandagatla
@ 2025-04-10  7:16       ` Johan Hovold
  0 siblings, 0 replies; 12+ messages in thread
From: Johan Hovold @ 2025-04-10  7:16 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: broonie, perex, tiwai, krzysztof.kozlowski, linux-sound,
	linux-arm-msm, linux-kernel, dmitry.baryshkov, johan+linaro,
	stable

On Tue, Apr 08, 2025 at 09:07:27AM +0100, Srinivas Kandagatla wrote:
> On 07/04/2025 12:25, Johan Hovold wrote:
> > On Fri, Mar 14, 2025 at 05:47:57PM +0000, Srinivas Kandagatla wrote:
> >> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> >>
> >> Implement an helper function in q6apm to be able to read the current
> >> hardware pointer for both read and write buffers.
> >>
> >> This should help q6apm-dai to get the hardware pointer consistently
> >> without it doing manual calculation, which could go wrong in some race
> >> conditions.

> >> @@ -553,6 +567,8 @@ static int graph_callback(struct gpr_resp_pkt *data, void *priv, int op)
> >>   		rd_done = data->payload;
> >>   		phys = graph->tx_data.buf[hdr->token].phys;
> >>   		mutex_unlock(&graph->lock);
> >> +		/* token numbering starts at 0 */
> >> +		atomic_set(&graph->tx_data.hw_ptr, hdr->token + 1);
> >>   
> >>   		if (upper_32_bits(phys) == rd_done->buf_addr_msw &&
> >>   		    lower_32_bits(phys) == rd_done->buf_addr_lsw) {
> > 
> > 			graph->result.opcode = hdr->opcode;
> >                          graph->result.status = rd_done->status;
> >                          if (graph->cb)
> >                                  graph->cb(client_event, hdr->token, data->payload, graph->priv);
> >                  } else {
> >                          dev_err(dev, "RD BUFF Unexpected addr %08x-%08x\n", rd_done->buf_addr_lsw,
> >                                  rd_done->buf_addr_msw);
> >                  }
> > 
> > I just hit the following error on the T14s with 6.15-rc1 that I've never
> > seen before and which looks like it could be related to this series:

> Its unlikely, but the timings have changed here.
> I have not seen it either, but I will try to reproduce this with 6.15-rc1.
> > 
> > 	q6apm-dai 6800000.remoteproc:glink-edge:gpr:service@1:dais: RD BUFF Unexpected addr ffe0d200-00000001
> > 
> > Any ideas about what may be causing this?

> How easy is this to reproduce?

I've only noticed this error once on the first boot of 6.15-rc1, and it
does not seem to show up again now.

I did a fair bit of testing with this series on 6.14-rcs, but did not
check the logs while doing so (and there's nothing in the logs I still
have).

Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-04-10  7:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250314174800.10142-1-srinivas.kandagatla@linaro.org>
2025-03-14 17:47 ` [PATCH v5 1/5] ASoC: q6apm-dai: schedule all available frames to avoid dsp under-runs srinivas.kandagatla
2025-03-14 17:47 ` [PATCH v5 2/5] ASoC: q6apm: add q6apm_get_hw_pointer helper srinivas.kandagatla
2025-04-07 11:25   ` Johan Hovold
2025-04-08  8:07     ` Srinivas Kandagatla
2025-04-10  7:16       ` Johan Hovold
2025-03-14 17:47 ` [PATCH v5 3/5] ASoC: q6apm-dai: make use of q6apm_get_hw_pointer srinivas.kandagatla
2025-03-31 12:32   ` Mark Brown
2025-03-31 13:22     ` Johan Hovold
2025-03-31 14:00       ` Mark Brown
2025-03-31 15:35   ` Christopher Obbard
2025-03-14 17:47 ` [PATCH v5 4/5] ASoC: qdsp6: q6apm-dai: set 10 ms period and buffer alignment srinivas.kandagatla
2025-03-14 17:48 ` [PATCH v5 5/5] ASoC: qdsp6: q6apm-dai: fix capture pipeline overruns srinivas.kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).