The imx's remoteproc driver uses a kworker from its mailbox callback to complete the request. The reason is that the imx mailbox driver invokes the callback from its interrupt handler and the remoteproc callback (at least the rpmsg-tty) requires a preemptible context.
This works but is problematic in a PREEMPT_RT environment where the latency of the invocation is important. By scheduling a kworker the high task priority from the threaded handler is lost and the kworker competes for CPU ressources with every SCHED_OTHER task in the system. This can lead to long delays on a busy system with other RT threads which are less important than the completion of this request. Looking over other mailbox driver, like the arm_mhu for instance, they use a threaded interrupt handler to invoke the callback. This avoids the kworker detour. The here suggested change utilises a threaded interrupt to invoke the callback. The primary handler mask the interrupt source so that the handler can run without getting interrupted by the interrupt again. Doing so avoids marking the interrupt IRQF_ONESHOT so that in a shared-interrupt environment the other interrupt can still fire while the first is masked. The first four patches are result of the sashiko review. Does not look critical. This change was tested on a im93 board with rpmsg-tty driver. v2…v3: https://lore.kernel.org/r/[email protected] - Forward the error in imx_mu_generic_tx() to the caller (new patch #1) - Extend the patch description a bit for for "Start splitting the IRQ handler" to briefly explain why callbacks are moved to the threaded handler. - Drop imx_mu_con_priv::pending. The primary handler wakes its threaded handler. Once the handler is woken, the pending flag must be set and there is no need to set/ clear it. - Avoid the double clk_disable_unprepare() if devm_mbox_controller_register() fails. v1…v2: https://lore.kernel.org/r/[email protected] - Using correct register to enable RXDB event. - Update commit description for the "threaded interrupt", "unmasks the interrupt" => "masks the interrupt event". - Add a shutdown field so that the interrupt does not unmask the interrupt if it has been already disabled because the channel is about to be shutdown. A possible race mentioned by sashiko. - Use devm_pm_runtime_enable(). This should avoid a possible race sashiko mentioned. - Use devm_of_platform_populate(). Signed-off-by: Sebastian Andrzej Siewior <[email protected]> --- Sebastian Andrzej Siewior (10): mailbox: imx: Forward the timeout/ error in imx_mu_generic_tx() mailbox: imx: Add a channel shutdown field mailbox: imx: Use devm_pm_runtime_enable() mailbox: imx: use devm_of_platform_populate() mailbox: imx: Use channel index instead of zero in imx_mu_specific_rx() mailbox: imx: Start splitting the IRQ handler in primary and threaded handler mailbox: imx: Move the RX part of the mailbox into the threaded handler mailbox: imx: Move the RXDB part of the mailbox into the threaded handler mailbox: imx: Don't force-thread the primary handler remoteproc: imx_rproc: Invoke the callback directly drivers/mailbox/imx-mailbox.c | 117 ++++++++++++++++++++++++++++++----------- drivers/remoteproc/imx_rproc.c | 33 +----------- 2 files changed, 88 insertions(+), 62 deletions(-) --- base-commit: b3f94b2b3f3e51ab880a51fc6510e1dafba654ed change-id: 20260529-imx_mbox_rproc-7d512f5a6f78 Best regards, -- Sebastian Andrzej Siewior <[email protected]>
