Skip to content

IPC4: Improve TX resend logic on Zephyr - #6275

Merged
lgirdwood merged 2 commits into
thesofproject:mainfrom
kv2019i:topic/ipc4-tx-queued-kwork
Sep 12, 2022
Merged

lgirdwood merged 2 commits into
thesofproject:mainfrom
kv2019i:topic/ipc4-tx-queued-kwork

Conversation

@kv2019i

@kv2019i kv2019i commented Sep 8, 2022

Copy link
Copy Markdown
Collaborator

After realizing we have a competing "TX sender" in zephyr/wrapper.c, I've modified the approach in #6243 . This takes benefit of the Zephyr CONFIG_SCHED_CPU_MASK_PIN_ONLY feature which allows to pin systems threads to specific cores of the system. In practise we can simply use the Zephyr system work queue, instead of using a LL-scheduler task, or a LL_POST_RUN notifier, to flush out pending IPC messages.

This fixes the issues with current codebase (Zephyr builds) where IPC TX messages were not flushed out if no LL task was running.

This also cleans up code from zephyr/wrapper.c.

Comment thread src/ipc/ipc-common.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need logic similar to the present one to avoid scheduling IPCs when preparing to suspend?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh Good question. ipc_send_queued_msg() won't send anything in we are going to D0. Not sure if rescheduling the task would block D0 sequence (if the flag is set, we've already made the decision to power off). I guess it wouldn't hurt.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed V2 that stops re-queuing if D3 request flag is set to keep the old behaviour.

Comment thread src/ipc/ipc-common.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you'd retry every 100us?.. I think previously IPC_PERIOD_USEC was actually unused - it was "used" as a task period for the IPC task, but the IPC task was an EDF task, and the EDF scheduler ignores period...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh yes. this is fairly reasonable as we are mostly waiting for the kernel side to ACK the previous message and this should be very fast. OTOH, we could also trigger resend from the IPC driver and use a much slower timer to handle any lingering cases (maybe just to log an error). I can see from history that there was something like this in the old times, but Keyon removed it. Downside is that this needs to be added to all IPC drivers, while this logic is common for all.

@kv2019i
kv2019i force-pushed the topic/ipc4-tx-queued-kwork branch from 899698a to 0c2b5c1 Compare September 9, 2022 14:14
@kv2019i

kv2019i commented Sep 9, 2022

Copy link
Copy Markdown
Collaborator Author

V2 update:

  • stop requeuing the work item if D3 request is raised (like old code did)
  • otherwise no changes

I think I do agree with @lyakh that we should look at removing this delayed-sending and instead trigger the sends directly from IRQ handler (immediately when channel becomes free). But given that was explicitly removed in commit "cavs-ipc: remove the superfluous message sending", this is probably for another PR to handle.

Given current codebase does not do resends correct when LL scheduler domain is not running, I think this PR is valuable addition to the codebase. This also reduces the rate of notification that get sent every LL/1msec cycle.

Comment thread src/ipc/ipc-common.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for a late comment, but how about

if (!list_is_empty(&ipc->msg_list) || ipc->pm_prepare_D3)
	schedule_ipc_worker();

and removing the goto and the label?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh I actually put this in just for you :D not to have a double-negative check. The full check needs to be

if (!list_is_empty(&ipc->msg_list) && !ipc->pm_prepare_D3)
	schedule_ipc_worker();

I actually prefer that, so I'll change.

if (!(list_is_empty(&ipc->msg_list) || ipc->pm_prepare_D3))
	schedule_ipc_worker();

... I find that harder to read myself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh, I think this would be the correct check:

if (!list_is_empty(&ipc->msg_list) && !ipc->pm_prepare_D3)
	schedule_ipc_worker();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V3 update:

  • goto out, double negative check in
  • no changes otherwise

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kv2019i @ujfalusi oops, missed that the if had two conditions in it, sorry, you're certainly right with the correction

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh I actually put this in just for you :D

:-D sure, where removing a negation simplifies the code I'm all for it, in cases like

if (!a)
	x();
else
	y();

and similar. But without an else I usually prefer a negation over a goto. Of course, there are exceptions: for error handling, when the label is already there etc.

@marc-hb marc-hb Sep 12, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rule of thumb for deciding between !(A || B) versus !A && !B is: how closely related are A and B? If they're mostly independent of each then !A && !B is more readable, otherwise it's !(A || B). I think this approach makes the code closer to plain English / more readable.

My 2 cents; as long as there is no double negation then either is fine :-)

In many places of SOF code, assumption is that code is only run
on a specific core. This allows to reduce overhead of cache
coherency management. For example this is used in the IPC stack.

In Zephyr, we can force threads to be pinned by default using
the CONFIG_SCHED_CPU_MASK_PIN_ONLY setting. Enable this setting
for all SOF builds.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Continue changes in commit c194125 ("zephyr: add
notifier_register(ipc_send_queued_msg) in task_main_start()") and
implement the delayed IPC msg sending in Zephyr work queue.

The old implementation did not cover cases where IPC needed to be resent
when no active LL scheduler tasks were active.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
kv2019i force-pushed the topic/ipc4-tx-queued-kwork branch from 0c2b5c1 to cea53ec Compare September 12, 2022 09:13
@kv2019i
kv2019i requested a review from lyakh September 12, 2022 09:14

@ujfalusi ujfalusi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing along with thesofproject/linux#3843 looks really good locally.

@lgirdwood

Copy link
Copy Markdown
Member

@wszypelt @lrudyX looks like the CI is stuck as I cant read the logs for the failed platform. Not expecting this to fail at the copy stage.

@wszypelt

Copy link
Copy Markdown

@lgirdwood fixed :)

@lgirdwood
lgirdwood merged commit 38d92ef into thesofproject:main Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants