Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect LLP reported for SSP on LNL, causing broken delay reporting for user space #9377

Closed
ujfalusi opened this issue Aug 20, 2024 · 4 comments
Assignees
Labels
bug Something isn't working as expected LNL Applies to Lunar Lake platform P1 Blocker bugs or important features

Comments

@ujfalusi
Copy link
Contributor

ujfalusi commented Aug 20, 2024

Describe the bug
The firmware reported llp value is incorrect for SSP link type.

To Reproduce
Run audio playback on SSP with application that uses the delay value, like mpv:

mpv --audio-device=alsa/hw:0,0 Echoplex-48KHz_S16_LE.wav

and observe the playback progress:

A: -13315594829:59:14 / 00:04:45 (0%)

Reproduction Rate
10/10 (always)

Expected behavior
The LLP value reported by the firmware is correct.

Impact
video playback with audio using SSP link will fail as the audio delay is incorrect

Environment
LNL with nocodec topology

Screenshots or console output
Debug diff for the kernel:

diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c
index 4df2be3d39eb..b816ffc454f2 100644
--- a/sound/soc/sof/ipc4-pcm.c
+++ b/sound/soc/sof/ipc4-pcm.c
@@ -966,6 +975,7 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component,
 	struct snd_sof_pcm_stream *sps;
 	u64 dai_cnt, host_cnt, host_ptr;
 	struct snd_sof_pcm *spcm;
+	u64 tmp_cnt;
 	int ret;
 
 	spcm = snd_sof_find_spcm_dai(component, rtd);
@@ -1008,6 +1018,7 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component,
 		sof_mailbox_read(sdev, time_info->llp_offset, &llp, sizeof(llp));
 		dai_cnt = ((u64)llp.reading.llp_u << 32) | llp.reading.llp_l;
 	}
+	tmp_cnt = dai_cnt;
 	dai_cnt += time_info->stream_end_offset;
 
 	/* In two cases dai dma counter is not accurate
@@ -1053,10 +1064,18 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component,
 	}
 
 	if (head_cnt < tail_cnt) {
+		pr_warn("[peter] | llp_offset: %#x, offset: %llu / %llu, tail_cnt: %lu (%llu), head_cnt: %lu, delay: %lu (OhNooo)\n",
+			time_info->llp_offset, time_info->stream_start_offset, time_info->stream_end_offset,
+			tail_cnt, tmp_cnt, head_cnt,
+			substream->runtime->boundary - tail_cnt + head_cnt);
 		time_info->delay = time_info->boundary - tail_cnt + head_cnt;
 		goto out;
 	}
 
+	pr_warn("[peter] | llp_offset: %#x, offset: %llu / %llu, tail_cnt: %lu (%llu), head_cnt: %lu, delay: %lu\n",
+		time_info->llp_offset, time_info->stream_start_offset, time_info->stream_end_offset,
+		tail_cnt, tmp_cnt, head_cnt, head_cnt - tail_cnt);
+
 	time_info->delay =  head_cnt - tail_cnt;
 
 out:
@@ -1067,6 +1086,7 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component,
 	div64_u64_rem(host_ptr, snd_pcm_lib_buffer_bytes(substream), &host_ptr);
 	*pointer = bytes_to_frames(substream->runtime, host_ptr);
 
+	pr_warn("[peter] | ldp pointer: %lu\n", *pointer);
 	return 0;
 }

Run:

mpv --audio-device=alsa/hw:0,0 Echoplex-48KHz_S16_LE.wav

On LNL-SSP:

[   36.261531] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310751231805576626 (11534123268660352640), head_cnt: 192, delay: 3093568321039018766 (OhNooo)
[   36.261537] [peter] | ldp pointer: 192
[   36.261651] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310751231805576626 (11534123268660352640), head_cnt: 192, delay: 3093568321039018766 (OhNooo)
[   36.261662] [peter] | ldp pointer: 192
[   36.261737] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310751231805576626 (11534123268660352640), head_cnt: 192, delay: 3093568321039018766 (OhNooo)
[   36.261741] [peter] | ldp pointer: 192
[   36.262599] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310749582538134962 (11534121619392910976), head_cnt: 240, delay: 3093569970306460478 (OhNooo)
[   36.262603] [peter] | ldp pointer: 240
[   36.281912] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310749582538134962 (11534121619392910976), head_cnt: 1200, delay: 3093569970306461438 (OhNooo)
[   36.281917] [peter] | ldp pointer: 1200
[   36.286111] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310749582538134962 (11534121619392910976), head_cnt: 1392, delay: 3093569970306461630 (OhNooo)
[   36.286117] [peter] | ldp pointer: 1392
[   36.286140] [peter] | llp_offset: 0x180740, offset: 208 / 0, tail_cnt: 2310749582538134962 (11534121619392910976), head_cnt: 1392, delay: 3093569970306461630 (OhNooo)
[   36.286142] [peter] | ldp pointer: 1392

On LNL-SDW:

[   44.441260] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 0 (79), head_cnt: 241, delay: 241
[   44.441267] [peter] | ldp pointer: 192
[   44.441335] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 0 (83), head_cnt: 237, delay: 237
[   44.441339] [peter] | ldp pointer: 192
[   44.441506] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 0 (91), head_cnt: 229, delay: 229
[   44.441509] [peter] | ldp pointer: 192
[   44.442082] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 0 (119), head_cnt: 249, delay: 249
[   44.442085] [peter] | ldp pointer: 240
[   44.461763] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 936 (1064), head_cnt: 1200, delay: 264
[   44.461767] [peter] | ldp pointer: 1200
[   44.466563] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 1166 (1294), head_cnt: 1392, delay: 226
[   44.466568] [peter] | ldp pointer: 1392
[   44.466596] [peter] | llp_offset: 0x0, offset: 128 / 0, tail_cnt: 1168 (1296), head_cnt: 1392, delay: 224
[   44.466599] [peter] | ldp pointer: 1392

On MTL-SSP:

[  712.712353] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 0 (99), head_cnt: 301, delay: 301
[  712.712358] [peter] | ldp pointer: 240
[  712.712403] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 0 (99), head_cnt: 301, delay: 301
[  712.712412] [peter] | ldp pointer: 240
[  712.712560] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 0 (99), head_cnt: 301, delay: 301
[  712.712563] [peter] | ldp pointer: 240
[  712.713336] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 0 (147), head_cnt: 301, delay: 301
[  712.713339] [peter] | ldp pointer: 288
[  712.732365] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 899 (1059), head_cnt: 1200, delay: 301
[  712.732368] [peter] | ldp pointer: 1200
[  712.737518] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 1139 (1299), head_cnt: 1440, delay: 301
[  712.737525] [peter] | ldp pointer: 1440
[  712.737545] [peter] | llp_offset: 0x180740, offset: 160 / 0, tail_cnt: 1139 (1299), head_cnt: 1440, delay: 301
[  712.737546] [peter] | ldp pointer: 1440

On MTL-SDW:

[   25.807972] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 0 (49), head_cnt: 263, delay: 263
[   25.807978] [peter] | ldp pointer: 192
[   25.808028] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 0 (49), head_cnt: 263, delay: 263
[   25.808037] [peter] | ldp pointer: 192
[   25.808094] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 0 (49), head_cnt: 263, delay: 263
[   25.808097] [peter] | ldp pointer: 192
[   25.808575] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 0 (95), head_cnt: 265, delay: 265
[   25.808578] [peter] | ldp pointer: 240
[   25.828391] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 935 (1055), head_cnt: 1200, delay: 265
[   25.828394] [peter] | ldp pointer: 1200
[   25.833133] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 1127 (1247), head_cnt: 1392, delay: 265
[   25.833140] [peter] | ldp pointer: 1392
[   25.833155] [peter] | llp_offset: 0x180740, offset: 120 / 0, tail_cnt: 1127 (1247), head_cnt: 1392, delay: 265
[   25.833159] [peter] | ldp pointer: 1392
@ujfalusi ujfalusi added bug Something isn't working as expected LNL Applies to Lunar Lake platform labels Aug 20, 2024
@ujfalusi ujfalusi changed the title [BUG] Incdorrect LLP reported for SSP on LNL, causing broken delay reporting for user space [BUG] Incorrect LLP reported for SSP on LNL, causing broken delay reporting for user space Aug 20, 2024
@ujfalusi
Copy link
Contributor Author

Description updated with correct LNL-SDW pointer log

@lgirdwood
Copy link
Member

@abonislawski @softwarecki could we have an incorrect DT entry that means we read the wrong LLP register ?

@ujfalusi
Copy link
Contributor Author

Zephyr PR with a fix: zephyrproject-rtos/zephyr#77726

@kv2019i kv2019i added the P1 Blocker bugs or important features label Sep 3, 2024
@kv2019i
Copy link
Collaborator

kv2019i commented Sep 5, 2024

Fixed via #9437

@kv2019i kv2019i closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected LNL Applies to Lunar Lake platform P1 Blocker bugs or important features
Projects
None yet
Development

No branches or pull requests

4 participants