Skip to contentSkip to conversation

pcm: dmix: Add option to allow alignment of slave pointers

PATCH Applied [email protected] 2 participants 3 messages Nov 13, 2018

lore
Share & tools
lore
#0 lore raw

v5 cover pcm: dmix: Add option to allow alignment of slave pointers

Quoted 10 lines · Takashi Iwai

Please provide your own sign-off when you submitting a patch, too.

The subject line should be adjusted better to match with the change; it's about adding an option to allow alignment of hwptr reporting.

About the changes:
the term "hw_ptr_filter" might sound confusing. IMO, this is about the (hw)ptr alignment, not about filtering.
Also, a too long option string can easily lead to a misspell :)

Quoted 7 lines

After all, we do either "no" alignment, "roundup" or "rounddown", or "auto" choice.

thanks,

Takashi

Subject changed.
Sign-off added.
Option changed to hw_ptr_alignment.
Option values changed to no, roundup, rounddown, auto

Best regards

Timo

#1 lore raw

PATCH v5 1/1 pcm: dmix: Add option to allow alignment of slave pointers

From: Laxmi Devi <[email protected]>

These changes are required due to the kernel
commit 07b7acb51d283d8469696c906b91f1882696a4d4
("ASoC: rsnd: update pointer more accurate")

Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr is not period aligned. Therefore snd_pcm_wait() will block for a longer time as required.

With these rcar driver changes the exact position of the dma is returned. During snd_pcm_start they read hw_ptr as reference, and this hw_ptr is now not period aligned, and is a little ahead over the period while it is read. Therefore when the avail is calculated during snd_pcm_wait(), it is missing the avail_min by a few frames.

An additional option hw_ptr_alignment is provided to dmix configuration, to allow the user to configure the slave application and hw pointer alignment at startup

src/pcm/pcm_direct.c +23 -0
index 091fd78..a264197 100644
@@ -1883,6 +1883,7 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
 	rec->max_periods = 0;
 	rec->var_periodsize = 0;
 	rec->direct_memory_access = 1;
+	rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_AUTO;
 
 	/* read defaults */
 	if (snd_config_search(root, "defaults.pcm.dmix_max_periods", &n) >= 0) {
@@ -1924,6 +1925,28 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
 			rec->ipc_perm = perm;
 			continue;
 		}
+		if (strcmp(id, "hw_ptr_alignment") == 0) {
+			const char *str;
+			err = snd_config_get_string(n, &str);
+			if (err < 0) {
+				SNDERR("Invalid type for %s", id);
+				return -EINVAL;
+			}
+			if (strcmp(str, "no") == 0)
+				rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_NO;
+			else if (strcmp(str, "roundup") == 0)
+				rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP;
+			else if (strcmp(str, "rounddown") == 0)
+				rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN;
+			else if (strcmp(str, "auto") == 0)
+				rec->hw_ptr_alignment = SND_PCM_HW_PTR_ALIGNMENT_AUTO;
+			else {
+				SNDERR("The field hw_ptr_alignment is invalid : %s", str);
+				return -EINVAL;
+			}
+
+			continue;
+		}
 		if (strcmp(id, "ipc_gid") == 0) {
 			char *group;
 			char *endp;
src/pcm/pcm_direct.h +9 -0
index 582f055..a487616 100644
@@ -49,6 +49,13 @@ typedef void (mix_areas_u8_t)(unsigned int size,
 			      volatile signed int *sum, size_t dst_step,
 			      size_t src_step, size_t sum_step);
 
+typedef enum snd_pcm_direct_hw_ptr_alignment {
+	SND_PCM_HW_PTR_ALIGNMENT_NO = 0,	/* use the hw_ptr as is and do no rounding */
+	SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP = 1,	/* round the slave_appl_ptr up to slave_period */
+	SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN = 2,	/* round slave_hw_ptr and slave_appl_ptr down to slave_period */
+	SND_PCM_HW_PTR_ALIGNMENT_AUTO = 3	/* automatic selection */
+} snd_pcm_direct_hw_ptr_alignment_t;
+
 struct slave_params {
 	snd_pcm_format_t format;
 	int rate;
@@ -159,6 +166,7 @@ struct snd_pcm_direct {
 	unsigned int *bindings;
 	unsigned int recoveries;	/* mirror of executed recoveries on slave */
 	int direct_memory_access;	/* use arch-optimized buffer RW */
+	snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment;
 	union {
 		struct {
 			int shmid_sum;			/* IPC global sum ring buffer memory identification */
@@ -341,6 +349,7 @@ struct snd_pcm_direct_open_conf {
 	int max_periods;
 	int var_periodsize;
 	int direct_memory_access;
+	snd_pcm_direct_hw_ptr_alignment_t hw_ptr_alignment;
 	snd_config_t *slave;
 	snd_config_t *bindings;
 };
src/pcm/pcm_dmix.c +38 -7

76 lines not on this page · raw message

Signature · 1 line
2.7.4
Applied
#2 lore raw
Quoted 17 lines · On Tue, 13 Nov 2018 08:43:00 +0100, <[email protected]> wrote:

From: Laxmi Devi <[email protected]>

These changes are required due to the kernel
commit 07b7acb51d283d8469696c906b91f1882696a4d4
("ASoC: rsnd: update pointer more accurate")

Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr is not period aligned. Therefore snd_pcm_wait() will block for a longer time as required.

With these rcar driver changes the exact position of the dma is returned. During snd_pcm_start they read hw_ptr as reference, and this hw_ptr is now not period aligned, and is a little ahead over the period while it is read. Therefore when the avail is calculated during snd_pcm_wait(), it is missing the avail_min by a few frames.

Quoted 7 lines

An additional option hw_ptr_alignment is provided to dmix configuration, to allow the user to configure the slave application and hw pointer alignment at startup

Thanks, applied now with minor fixes (mostly spaces and line breaks).

Takashi