ipc: do not hold a spinlock when calling schedule_ipc_worker()#10170
Draft
kv2019i wants to merge 1 commit intothesofproject:mainfrom
Draft
ipc: do not hold a spinlock when calling schedule_ipc_worker()#10170kv2019i wants to merge 1 commit intothesofproject:mainfrom
kv2019i wants to merge 1 commit intothesofproject:mainfrom
Conversation
Calling schedule_ipc_worker() with spinlock held is not stricly required. schedule_ipc_worker() calls k_work_schedule_for_queue() and the Zephyr workqueue has an internal lock protecting the workqueue structures. Keeping spinlock held during the call does lead to complex scenarios to debug and verify as schedule_ipc_worker() itself is dispatched from a work queue. Simplify the flow and release spinlock before rescheduling the worker. In ipc_work_handler(), this leaves a small window where the message is just sent after we release the spinlock, and before we call schedule_ipc_worker(). This is however harmless, as in worst case the IPC worker is woken up one extra time. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the IPC (Inter-Process Communication) code to avoid holding a spinlock when calling schedule_ipc_worker(). The change simplifies the locking flow by releasing the spinlock before scheduling work operations, which prevents complex debugging scenarios since schedule_ipc_worker() itself is dispatched from a work queue.
Key changes:
- Move
schedule_ipc_worker()call outside the spinlock inipc_msg_send() - Refactor
ipc_work_handler()to use a local boolean flag to defer the scheduling call until after the spinlock is released - Add explanatory comments about the potential harmless race condition
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Collaborator
Author
|
Discussed with @lyakh . He'd like to see a concrete case where this causes failures and I don't have one at this point. Putting as draft for now to prevent merge until we have better consensus. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling schedule_ipc_worker() with spinlock held is not stricly required. schedule_ipc_worker() calls k_work_schedule_for_queue() and the Zephyr workqueue has an internal lock protecting the workqueue structures. Keeping spinlock held during the call does lead to complex scenarios to debug and verify as schedule_ipc_worker() itself is dispatched from a work queue.
Simplify the flow and release spinlock before rescheduling the worker. In ipc_work_handler(), this leaves a small window where the message is just sent after we release the spinlock, and before we call schedule_ipc_worker(). This is however harmless, as in worst case the IPC worker is woken up one extra time.