Skip to content

[For testing] IPC4 timeout fixes (combo of PR6243 and PR6239) - #6242

Closed
kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:topic/ipc4-fixes-all
Closed

kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:topic/ipc4-fixes-all

Conversation

@kv2019i

@kv2019i kv2019i commented Sep 2, 2022 •

Copy link
Copy Markdown
Collaborator

A collection of multiple IPC4 timeout fixes. This PR is for testing to share the fixes and to get testing widers results. I'll probably submit these as separate PRs as they are independent fixes to different parts of the codebase.

This PR is for TESTING.
The more mature fixses are submitted for review separate at #6243
I will close this PR once testing is completed.

In IPC4 protocol, responses are sent over a separate set of
mailbox registers. This creates the following problem:

 a) msg received, IPC IRQ
 b) IRQ masked
 c) handle IPC command, possible in separate core
 d) when command handled, send the IPC reply
 e) IPC driver complete callback called
 f) acknowledge the message (by writing BUSY + DONE)
 g) unmask IRQ

The problem is that the acknowledgement in step (f) is
optional part of the protocol, and in fact, driver in IPC4 mode
will consider the reply in step (d) as a signal that it can send
more messages. If driver sends a new message in quick succession,
this may be lost.

This patch addresses the problem by moving the acknowledge
step earlier so that the sequence becomes:

 A) msg received, IPC IRQ
 B) IRQ masked
 C) acknowledge the message (by writing BUSY + DONE)
 D) handle IPC command, possible in separate core
 E) when command handled, send the IPC reply
 F) IPC driver complete callback called
 G) unmask IRQ

BugLink: thesofproject#6173
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The list fields in the ipc_msg objects used by IPC4 stack, are not
initialized properly. This breaks the queueing logic in ipc_msg_send()
when it checks for "if (list_is_empty(&msg->list))". As a result,
if a IPC could not be sent immediately as the driver is busy, it would
not properly be resent later.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>

@lyakh lyakh left a comment

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.

very nice! Great work! Just would be good to understand why and how can messages be submitted to the queue repeatedly... Perhaps the reason is that SOF IPC messages are persistent objects, and the same object can be sent again by the owner while it is still in processing from the previous sending attempt and so it's on the queue. But maybe then owners should be fixed to not do that...

Comment thread src/ipc/ipc4/handler.c
msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS);
msg_notify.extension = 0;
msg_notify.tx_size = 0;
list_init(&msg_notify.list);

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.

I see that it affects the test in ipc_msg_send() but why is that test needed at all? Why is it possible to call that function for a message, that is already queued?..

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.

Is it OK to list_init() every time?
The problem is that we have single, local msg_notify and msg_reply.
If for example the notify got delayed, put to the list and you will have another notification: you change that message which was queued, list_init it again and things will be in an interesting state, no?

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 We might have contention between FW->HOST replies and FW->HOST notifications. Kernel needs to ack both and until kernel ack is received, ipc_msg_send() will return EBUSY.

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 Just for the record - you probably mean ipc_platform_msg_send(). Ok, so apparently either there's no waiting for the host response or the wait can be preempted.

Comment thread src/include/sof/ipc/common.h 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.

to the commit message: "the platform driver returns -EBUSY?"

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.

Thanks, fixed in #6243

Comment thread src/drivers/intel/cavs/ipc.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.

It is a test. I prefer to do it in ipc4/handler.c without ifdef.

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.

@RanderWang Not sure I follow. This is writing to IPC hw registers and it thus should be done in the driver, not the protocol code in ipc4/handler.c. Right? The ifdef is needed as same driver is used for IPC3 and there the semantics are different ACK/REPLY are the same thing, so the proper place to do is later.

@kv2019i
kv2019i force-pushed the topic/ipc4-fixes-all branch from 6cf62c8 to abe8ea5 Compare September 2, 2022 16:03
ipc_send_buffer_status_notify() uses a static ipc_msg object
to send the notifications. In normal circumstances, notifications
are never queued as they are sent as high-priority messages,
but this is still possible. Requeing the same object can potentially
lead to memory corruption as the caller is modifying the message
object, while it may in fact be in use still.

To avoid this, check in ipc_send_buffer_status_notify() whether
the IPC message queue has the notify object, and if yes, skip
the message. The buffer status notifications can be safely dropped
in error case, as host can read the log buffer status directly from
the SRAM window.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The IPC send queue is used when a message cannot be sent
immediately and/or the platform driver returns -EBUSY.

This mechanism has been broken in Zephyr SOF builds. In XTOS builds, the
ipc_send_queued_msg() was called directly from the operating system main
task in src/schedule/task.c:task_main_primary_core(). This mainloop
functionality is moved to Zephyr, so same implementation cannot be used
on Zephyr.

This commit unifies the implementation and uses a normal LL scheduler
task to manage the send queue. This task is managed by IPC code, so
low-level OS code does not need to call IPC stack directly.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i changed the title [For testing] IPC4 timeout fixes [For testing] IPC4 timeout fixes (combo of PR6243 and PR6239) Sep 2, 2022
@kv2019i

kv2019i commented Sep 6, 2022

Copy link
Copy Markdown
Collaborator Author

Closing this at least for now. #6239 won't be merged in its current form.

@kv2019i kv2019i closed this Sep 6, 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.

4 participants