Repository navigation
PM: refine algorithm of dai link resuming - #509
Conversation
plbossart
left a comment
There was a problem hiding this comment.
Thanks @RanderWang. This looks much better than the previous versions but can be improved further (also the commit message isn't very clear)
There was a problem hiding this comment.
so this is just to keep track of the fact that the DAI was configured already, right?
There was a problem hiding this comment.
yes, I will add a comment for it
There was a problem hiding this comment.
@RanderWang i'm a bit confused by this logic because there are 3 types of dai's, each with indices ranging from 0 - max_of_each_type. But you use only one array of 0-max. So depending on which order the dai's were added, you could miss out on configuring some dai's. please correct me if i am wrong.
Also, we dont really have any issues because of sending the dai config twice for the same dai. Is it really important to avoid the second IPC if it does no harm?
There was a problem hiding this comment.
@RanderWang i'm a bit confused by this logic because there are 3 types of dai's, each with indices ranging from 0 - max_of_each_type. But you use only one array of 0-max. So depending on which order the dai's were added, you could miss out on configuring some dai's. please correct me if i am wrong.
yes, there maybe 3 types of dais but not each indices ranging from 0 - max. All of them are in the range of 0 - max
Also, we dont really have any issues because of sending the dai config twice for the same dai. Is it really important to avoid the second IPC if it does no harm?
no, we have a issue. If one dai config is set two times, one DMA channel would be wasted in FW. please refer to thesofproject/sof#786
There was a problem hiding this comment.
@RanderWang thanks for confirming that this is required.
But about my first comment, so can different types of DAI's not have the same dai index?
There was a problem hiding this comment.
looking at sof-apl-nocodec.m4 , i feel like the assumption that the dai index for all DAI's is unique is wrong.
There was a problem hiding this comment.
I check the file and don't find a same id. First we should make clear the usage of dai index. It is used in ASoC which doesn't care the type of dai. It just identifies dai by index.
There was a problem hiding this comment.
Meh. if the firmware can detect the configs are the same, why couldn't the driver do it as well?
There was a problem hiding this comment.
@plbossart thanks for your comment. It make easier for me now. And the PR in FW is ready thesofproject/sof#786
There was a problem hiding this comment.
What does this FW PR have to do with configs being sent twice?
There was a problem hiding this comment.
dma channel is not released when config is set again. This PR would check whether dma channel is allocated for a dai link config and avoid allocating dma channel again @keyonjie
There was a problem hiding this comment.
@RanderWang so are you suggesting we just send the config twice as the FW can handle it now?
|
update my PR. |
There was a problem hiding this comment.
@RanderWang did you intend to proceed further if ret is < 0 here?
There was a problem hiding this comment.
@RanderWang the other thing Pierre suggested was to use a loop so you dont have the same code twice for playback and capture. You could try something like this:
for (dir = SNDRV_PCM_STREAM_PLAYBACK; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {
flag = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? link->dpcm_playback : link->dpcm_capture;
if (flag)
ret = sof_set_dai_config(sdev, size, link, config, dir);
}
There was a problem hiding this comment.
do we need to use loop for two items? I don't like it
There was a problem hiding this comment.
I am even wondering why we can't deal with the direction inside of sof_set_dai_config since all the other arguments are identical. It'd simplify the code further.
plbossart
left a comment
There was a problem hiding this comment.
this PR changed directions multiple times, you are soon going to hit your quota of reviewer bandwidth.
There was a problem hiding this comment.
I am even wondering why we can't deal with the direction inside of sof_set_dai_config since all the other arguments are identical. It'd simplify the code further.
|
Update my PR, thanks! |
plbossart
left a comment
There was a problem hiding this comment.
Thanks @RanderWang The first patch was fine and simple-enough (only minor improvement suggested), the second one isn't what I had in mind and makes things less readable.
So either you remove the second patch or you make it nicer, your call.
There was a problem hiding this comment.
What I meant is try to pass link and config ONCE, then use it internablly in sof_set_dai_config.
Passing two arguments, once of which is NULL with additional tests is just horrible and makes the code more confusing.
There was a problem hiding this comment.
for HDA, two different configs need to be set by sof_set_dai_config.
If I just pass config ONCE, I need to add direction and call sof_set_dai_config two times.
The direction info is not included by link setting or config.
I will try to refine it without NULL.
There was a problem hiding this comment.
@RanderWang same here use SNDRV_PCM_STREAM_PLAYBACK instead of 0
There was a problem hiding this comment.
@RanderWang I think this change looks rather awkward. You really only use both playback and capture configs for SSP dai links and in that case both of them are the same.
|
@RanderWang here's a suggestion to modify the patch. It is only compile tested. Please feel free to modify it and clean up as needed. |
6fe0a05 to
dd7f069
Compare
|
update my PR, thanks. |
Thank you very much! I find another simple way to fix it. |
plbossart
left a comment
There was a problem hiding this comment.
I try to be patient, polite and respectful, but I am afraid this is really still quite flaky . It's a mix of basic mistakes like not testing the error status and more fundamental ones with complicated and inefficient code. i've spend several hours this week on this...
There was a problem hiding this comment.
should there be a check that there was at least one change done? Currently this function only return 0 or -ENOMEM. If there was no match we still return zero, is this intentional?
There was a problem hiding this comment.
ok, I will add result check.
There was a problem hiding this comment.
you need to test the status here?
There was a problem hiding this comment.
this look good at first sight, but then looking deeper the code does this
/* for hda link, playback and capture are supported by different
* dai in FW. Here get the dai_index of each dai and send config
* to FW. In FW, each dai sets config by dai_index
*/
list_for_each_entry(dai, &sdev->dai_list, list) {
if (!dai->name)
continue;
if (strcmp(link->name, dai->name) == 0) {
config->dai_index = dai->comp_dai.dai_index;
if (dai->comp_dai.direction ==
SNDRV_PCM_STREAM_PLAYBACK)
config->hda.link_dma_ch = tx_slot;
else
config->hda.link_dma_ch = rx_slot;
ret = sof_set_dai_config(sdev, size, link,
config);
<<<<
static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size,
struct snd_soc_dai_link *link,
struct sof_ipc_dai_config *config)
{
struct snd_sof_dai *dai;
list_for_each_entry(dai, &sdev->dai_list, list) {
if (!dai->name)
continue;
if (strcmp(link->name, dai->name) == 0 &&
dai->comp_dai.dai_index == config->dai_index) {
dai->dai_config = kmemdup(config, size, GFP_KERNEL);
if (!dai->dai_config)
return -ENOMEM;
}
}
return 0;
}
<<<<<
/* send message to DSP */
ret = sof_ipc_tx_message(sdev->ipc,
config->hdr.cmd, config, size,
&reply, sizeof(reply));
if (ret < 0) {
dev_err(sdev->dev, "error: failed to set DAI config for direction:%d of HDA dai %d\n",
dai->comp_dai.direction,
config->dai_index);
return ret;
}
found = 1;
}
}so you have two nested loops that look for the same data. Doesn't seem terribly efficient.
There was a problem hiding this comment.
@plbossart that is a good catch. we should just kmemdup the config before sending the IPC.
There was a problem hiding this comment.
yes, I know this issue but I want to make HDA work as SSP so I call sof_set_dai_config.
Ok, I will refine it to avoid this call.
There was a problem hiding this comment.
this is very hard to review, you add changes to hda_process in this patch, and again changes in the next patch. I had to go directly to the code to figure out what the result is. Please don't do this, it's a waste of time for reviewers.
There was a problem hiding this comment.
This patch is to simplify HDA processing, and another patch is to fix dai saving. I want to make reviewer understand it step by step, not all in one patch. I could merge them together.
|
Thanks for your patient. It is all caused by ugly design of HDA. It is a challenge to build beautiful code based on ugly base. Next let us refine our HDA code as SSP , then we don't have to struggle with divergence. |
3b6e30e to
b891340
Compare
|
update PR, thanks! |
There was a problem hiding this comment.
@RanderWang minor comment. shouldnt this be "failed to find dai" and not dai link
There was a problem hiding this comment.
@RanderWang This looks a lot cleaner but if tx_slot and rx_slot are both non-zero, you need to make sure both are set right? But here, you only check if one is found.
There was a problem hiding this comment.
yes, both are set if non-zero. I get your idea
0d91882 to
6fd38b4
Compare
|
On 1/11/19 2:11 AM, RanderWang wrote:
update PR, thanks for review.
I will look at it if Ranjani/Keyon approve first, other things to do atm.
|
There was a problem hiding this comment.
@RanderWang hopefully this will be the last issue. Apart from checking the direction, you also need to check if tx_slot is non-zero to proceed here. Similarly for capture.
There was a problem hiding this comment.
@ranj063 I have thought about this. There is no need here
(1) if there is a playback dai then tx_slot should be correct, please see sof_link_hda_load.
tx_slot would be queried if this dai link support playback. So I don't want to check it again.
(2) tx_slot could be zero and this means dma channel zero is used for hda.
There was a problem hiding this comment.
@ranj063 I have thought about this. There is no need here
(1) if there is a playback dai then tx_slot should be correct, please see sof_link_hda_load.
tx_slot would be queried if this dai link support playback. So I don't want to check it again.(2) tx_slot could be zero and this means dma channel zero is used for hda.
@RanderWang sorry what does it mean by "dma channel zero is used for hda"?
Also what about the capture case, if rx_slot is zero, you should be doing nothing but with this change you'd still send an ipc, isnt it?
There was a problem hiding this comment.
@RanderWang i think I get your point. Basically if rx_slot is zero, the expectation is there we will not be able to find dai with the same dai_link with a capture direction. Is that your argument?
There was a problem hiding this comment.
@ranj063 I just took playback for example. Capture is the same as playback. tx_slot and rx_slot
could be zero. They could be only sent if this dai link supports them
There was a problem hiding this comment.
@ranj063 But I still don't get why we would remove playback and capture on SSP2 and still have just the dai_config for SSP2 BE dai link.
There was a problem hiding this comment.
@RanderWang the point is you could have just playback or just capture on SSP2.
There was a problem hiding this comment.
you idea is: playback or capture are defined in machine driver, but our topology could support it or not. I discuss with Keyon, and we agree with you at this point. Our idea is: machine driver could define two dai, but topology should support at least one dai. So the error check in sof_set_dai_config is correct. It only check whether at least one dai exist. And in hda function, only check one of playback or capture exsit. The code should be the same as sof_set_dai_config. What is your idea? thanks!
There was a problem hiding this comment.
@RanderWang @keyonjie I think there's no need to check even if one dai is set. The machine driver could define SSP2 but what if I do not want to use SSP2 at all for playback/capture?Logically, in that case i'd probably remove the dai_config for SSP2 but I could just leave it as well.
There was a problem hiding this comment.
@ranj063 if you do not want to use SSP2 at all , why this dai link is set in topology file? If it is not in topology file, these function could not be called.
There was a problem hiding this comment.
@RanderWang as we discussed, let's change this to be:
if ((link->dpcm_playback && playback_found) ||
(link->dpcm_capture && capture_found)) {
dev_info(...);//success
} else {
dev_err();// error.
return -EINVAL;
}
There was a problem hiding this comment.
@RanderWang @keyonjie should it be a warning instead of error. My point is that nothing would be broken in this case. Its just that we will not have a pcm that uses the BE with this config in this case.
There was a problem hiding this comment.
@ranj063 yes, I get your idea and I am refining it now
b71a17b to
4ac1c44
Compare
|
update my PR, after discussing with Ranjani and keyon, I do these change. Thanks for review! |
a20fe4a to
943bae5
Compare
|
LGTM. |
plbossart
left a comment
There was a problem hiding this comment.
There is a very suspicious test that makes me think the code isn't quite right.
Also error handling on found=0 isn't clear (add a comment or fix) and couple of comment style issues.
There was a problem hiding this comment.
Should we really be returning 0 in that case?
There was a problem hiding this comment.
Yes, I will add a comment for it. I discussed with @ranj063 that dai may not be supported by topology although the dai link is defined in machine driver, so none of dai would be found. But we should print a warning to notify user: is this really you want?
There was a problem hiding this comment.
@plbossart the rationale for returning a 0 is that even if we dont find a dai to set the config for, there will really be no negative consequences of having just a BE dai config without a pipeline that uses it.
Of course, logically it probably makes no sense. Thats why the warning here.
There was a problem hiding this comment.
ret is not set before testing it at each iteration, what are you trying to check here?
This looks like a mistake.
There was a problem hiding this comment.
I am very sorry to have this error. I will remove it. I change my code according to reviewer's comment, but here I missed to delete it.
There was a problem hiding this comment.
fix block comment style, should be
/*
* machine
*/Move the code for playback and capture into sof_link_hda_process. This make code simpler and do configuration in one loop Check status in functions for dai link config saving. Machine driver may define dai link with playback and capture enabled, but the dai link in topology would support both, one or none of them. So a warning would be reported here. Signed-off-by: Rander Wang <rander.wang@linux.intel.com>
|
update my PR Test in on WHL. Thanks for review! |
plbossart
left a comment
There was a problem hiding this comment.
ok let's merge. 97 comments is officially a record.
|
if it's not 'fixs' in the header, #442 will be closed after the merge :) |
copy & paste error...... |
|
“fixs #422”字样必须出现在submit PR的那个初始帖子或者commit message里, 否则也是无效的. |
|
🤦♂️ |
The thermal driver [0] for Renesas RZ/G2L SoC does not implement set_trip_temp() callback but has trips commit 9326167 ("thermal/core: Move set_trip_temp ops to the sysfs code") changed the behaviour which causes the below panic when trying to set the trip temperature: root@smarc-rzg2l:~# echo 51000 > /sys/class/thermal/thermal_zone0/trip_point_0_temp [ 92.461521] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 92.470958] Mem abort info: [ 92.474311] ESR = 0x0000000086000004 [ 92.478546] EC = 0x21: IABT (current EL), IL = 32 bits [ 92.484290] SET = 0, FnV = 0 [ 92.487693] EA = 0, S1PTW = 0 [ 92.491153] FSC = 0x04: level 0 translation fault [ 92.496461] user pgtable: 4k pages, 48-bit VAs, pgdp=000000004e885000 [ 92.503736] [0000000000000000] pgd=0000000000000000, p4d=0000000000000000 [ 92.510869] Internal error: Oops: 86000004 [thesofproject#3] PREEMPT SMP [ 92.516556] CPU: 0 PID: 290 Comm: sh Tainted: G D 6.0.0-rc4-next-20220906-arm64-renesas-00124-g84633c87c5f6-dirty thesofproject#509 [ 92.528814] Hardware name: Renesas SMARC EVK based on r9a07g044l2 (DT) [ 92.535441] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 92.542516] pc : 0x0 [ 92.544764] lr : trip_point_temp_store+0x84/0x140 [ 92.549582] sp : ffff80000a92bc10 [ 92.552961] x29: ffff80000a92bc10 x28: ffff00000d8a45c0 x27: 0000000000000000 [ 92.560249] x26: 0000000000000000 x25: ffff8000082b53e8 x24: ffff00000eaffc20 [ 92.567532] x23: ffff80000a92bd68 x22: ffff00000d3e0f80 x21: 0000000000000006 [ 92.574814] x20: ffff800009149000 x19: ffff00000b8ab000 x18: 0000000000000000 [ 92.582097] x17: 0000000000000000 x16: 0000000000000000 x15: 0000aaab028cdee0 [ 92.589378] x14: 0000000000000000 x13: 0000000000000000 x12: ffff80000a92bbd0 [ 92.596659] x11: ffff00000d3e0f80 x10: ffff800009149eb8 x9 : 000000000000000a [ 92.603940] x8 : 00000000ffffffc9 x7 : 0000000000000005 x6 : 000000000000002a [ 92.611220] x5 : 000000000000c738 x4 : 00000000ffffffd3 x3 : 0000000000000000 [ 92.618500] x2 : 000000000000c738 x1 : 0000000000000000 x0 : ffff00000b8ab000 [ 92.625781] Call trace: [ 92.628282] 0x0 [ 92.630176] dev_attr_store+0x14/0x28 [ 92.633935] sysfs_kf_write+0x4c/0x70 [ 92.637681] kernfs_fop_write_iter+0x160/0x1e0 [ 92.642213] vfs_write+0x474/0x540 [ 92.645703] ksys_write+0x68/0xf8 [ 92.649100] __arm64_sys_write+0x18/0x20 [ 92.653111] invoke_syscall+0x40/0xf8 [ 92.656866] el0_svc_common.constprop.3+0x88/0x110 [ 92.661758] do_el0_svc+0x20/0x78 [ 92.665158] el0_svc+0x3c/0x90 [ 92.668291] el0t_64_sync_handler+0x90/0xb8 [ 92.672563] el0t_64_sync+0x148/0x14c [ 92.676322] Code: bad PC value [ 92.679453] ---[ end trace 0000000000000000 ]--- /bin/start_getty: line 40: 290 Segmentation fault ${setsid:-} ${getty} -L $1 $2 $3 Poky (Yocto Project Reference Distro) 3.2.1 smarc-rzg2l ttySC0 smarc-rzg2l login: This patch fixes the above issue by adding a check to see if set_trip_temp() callback is implemented before calling it. [0] drivers/thermal/rzg2l_thermal.c Fixes: 9326167 ("thermal/core: Move set_trip_temp ops to the sysfs code") Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Link: https://lore.kernel.org/r/20220908174610.7837-1-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
With 64K page on arm64, verifier_arena_globals1 failed like below: ... libbpf: map 'arena': failed to create: -E2BIG ... thesofproject#509/1 verifier_arena_globals1/check_reserve1:FAIL ... For 64K page, if the number of arena pages is (1UL << 20), the total memory will exceed 4G and this will cause map creation failure. Adjusting ARENA_PAGES based on the actual page size fixed the problem. Cc: Emil Tsalapatis <emil@etsalapatis.com> Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260113061033.3798549-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
The thermal driver [0] for Renesas RZ/G2L SoC does not implement set_trip_temp() callback but has trips commit 9326167 ("thermal/core: Move set_trip_temp ops to the sysfs code") changed the behaviour which causes the below panic when trying to set the trip temperature: root@smarc-rzg2l:~# echo 51000 > /sys/class/thermal/thermal_zone0/trip_point_0_temp [ 92.461521] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 92.470958] Mem abort info: [ 92.474311] ESR = 0x0000000086000004 [ 92.478546] EC = 0x21: IABT (current EL), IL = 32 bits [ 92.484290] SET = 0, FnV = 0 [ 92.487693] EA = 0, S1PTW = 0 [ 92.491153] FSC = 0x04: level 0 translation fault [ 92.496461] user pgtable: 4k pages, 48-bit VAs, pgdp=000000004e885000 [ 92.503736] [0000000000000000] pgd=0000000000000000, p4d=0000000000000000 [ 92.510869] Internal error: Oops: 86000004 [thesofproject#3] PREEMPT SMP [ 92.516556] CPU: 0 PID: 290 Comm: sh Tainted: G D 6.0.0-rc4-next-20220906-arm64-renesas-00124-g84633c87c5f6-dirty thesofproject#509 [ 92.528814] Hardware name: Renesas SMARC EVK based on r9a07g044l2 (DT) [ 92.535441] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 92.542516] pc : 0x0 [ 92.544764] lr : trip_point_temp_store+0x84/0x140 [ 92.549582] sp : ffff80000a92bc10 [ 92.552961] x29: ffff80000a92bc10 x28: ffff00000d8a45c0 x27: 0000000000000000 [ 92.560249] x26: 0000000000000000 x25: ffff8000082b53e8 x24: ffff00000eaffc20 [ 92.567532] x23: ffff80000a92bd68 x22: ffff00000d3e0f80 x21: 0000000000000006 [ 92.574814] x20: ffff800009149000 x19: ffff00000b8ab000 x18: 0000000000000000 [ 92.582097] x17: 0000000000000000 x16: 0000000000000000 x15: 0000aaab028cdee0 [ 92.589378] x14: 0000000000000000 x13: 0000000000000000 x12: ffff80000a92bbd0 [ 92.596659] x11: ffff00000d3e0f80 x10: ffff800009149eb8 x9 : 000000000000000a [ 92.603940] x8 : 00000000ffffffc9 x7 : 0000000000000005 x6 : 000000000000002a [ 92.611220] x5 : 000000000000c738 x4 : 00000000ffffffd3 x3 : 0000000000000000 [ 92.618500] x2 : 000000000000c738 x1 : 0000000000000000 x0 : ffff00000b8ab000 [ 92.625781] Call trace: [ 92.628282] 0x0 [ 92.630176] dev_attr_store+0x14/0x28 [ 92.633935] sysfs_kf_write+0x4c/0x70 [ 92.637681] kernfs_fop_write_iter+0x160/0x1e0 [ 92.642213] vfs_write+0x474/0x540 [ 92.645703] ksys_write+0x68/0xf8 [ 92.649100] __arm64_sys_write+0x18/0x20 [ 92.653111] invoke_syscall+0x40/0xf8 [ 92.656866] el0_svc_common.constprop.3+0x88/0x110 [ 92.661758] do_el0_svc+0x20/0x78 [ 92.665158] el0_svc+0x3c/0x90 [ 92.668291] el0t_64_sync_handler+0x90/0xb8 [ 92.672563] el0t_64_sync+0x148/0x14c [ 92.676322] Code: bad PC value [ 92.679453] ---[ end trace 0000000000000000 ]--- /bin/start_getty: line 40: 290 Segmentation fault ${setsid:-} ${getty} -L $1 $2 $3 Poky (Yocto Project Reference Distro) 3.2.1 smarc-rzg2l ttySC0 smarc-rzg2l login: This patch fixes the above issue by adding a check to see if set_trip_temp() callback is implemented before calling it. [0] drivers/thermal/rzg2l_thermal.c Bug: 251537418 Fixes: 9326167 ("thermal/core: Move set_trip_temp ops to the sysfs code") Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Signed-off-by: Will McVicker <willmcvicker@google.com> Change-Id: I50656add5bf3971c3b53d027b835de47e1e88e49 (cherry picked from commit 64b269c)
Add a test which builds an ICMP error out of a TCP segment. A tcx prog on the client's egress side trims the first data segment down to the target size and pushes the ICMP error headers in front of it to then reflect the packet back to the sender. # LDLIBS=-static PKG_CONFIG='pkg-config --static' ./vmtest.sh -- ./test_progs -t tc_change_tail [...] thesofproject#509 tc_change_tail:OK thesofproject#510 tc_change_tail_pmtu:OK Summary: 2/0 PASSED, 0 SKIPPED, 0/0 FAILED Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260907121025.1923656-2-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Add direction check in sof_set_dai_config because dai config
is different between playback and capture on HDA platform now,
so dai config would be saved by name and direction
this fixs #442