-
Notifications
You must be signed in to change notification settings - Fork 364
audio: pipeline: change locking strategy for user LL builds #10957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kv2019i
wants to merge
3
commits into
thesofproject:main
Choose a base branch
from
kv2019i:202606-ll-locking-change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−37
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/pipeline.h> | ||
| #include <sof/ipc/msg.h> | ||
| #include <sof/schedule/ll_schedule_domain.h> | ||
| #include <sof/lib/vregion.h> | ||
| #include <rtos/interrupt.h> | ||
| #include <rtos/symbol.h> | ||
|
|
@@ -29,6 +30,7 @@ | |
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #include <sof/schedule/ll_schedule_domain.h> | ||
|
|
||
| LOG_MODULE_REGISTER(pipe, CONFIG_SOF_LOG_LEVEL); | ||
|
|
||
|
|
@@ -181,19 +183,24 @@ static void buffer_set_comp(struct comp_buffer *buffer, struct comp_dev *comp, | |
| } | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| /* | ||
| * User-space LL: callers (IPC handlers) already hold the per-core LL | ||
| * lock via user_ll_lock_sched()/ll_block() while modifying pipeline | ||
| * connections, which provides mutual exclusion with the LL thread. No | ||
| * additional lock is taken here; instead assert that the lock is held. | ||
| */ | ||
| #define PPL_LOCK_DECLARE | ||
| #define PPL_LOCK() do { \ | ||
| int ret = sys_mutex_lock(&comp->list_mutex, K_FOREVER); \ | ||
| assert(ret == 0); \ | ||
| } while (0) | ||
| #define PPL_UNLOCK() do { \ | ||
| int ret = sys_mutex_unlock(&comp->list_mutex); \ | ||
| assert(ret == 0); \ | ||
| } while (0) | ||
| #define PPL_LOCK(x) user_ll_assert_locked(x) | ||
| #define PPL_UNLOCK(x) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so |
||
| #else | ||
| /* | ||
| * Kernel-space LL. When modifying pipeline connections, block IRQs | ||
| * and prevent LL from running. No locking needed when iterating | ||
| * the pipeline in the LL thread. | ||
| */ | ||
| #define PPL_LOCK_DECLARE uint32_t flags | ||
| #define PPL_LOCK() irq_local_disable(flags) | ||
| #define PPL_UNLOCK() irq_local_enable(flags) | ||
| #define PPL_LOCK(x) irq_local_disable(flags) | ||
| #define PPL_UNLOCK(x) irq_local_enable(flags) | ||
| #endif | ||
|
|
||
| int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer, | ||
|
|
@@ -208,19 +215,19 @@ int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer, | |
| else | ||
| comp_info(comp, "connect buffer %d as source", buf_get_id(buffer)); | ||
|
|
||
| PPL_LOCK(); | ||
| PPL_LOCK(buffer->core); | ||
|
|
||
| comp_list = comp_buffer_list(comp, dir); | ||
| ret = buffer_attach(buffer, comp_list, dir); | ||
| if (ret < 0) { | ||
| comp_err(comp, "buffer %d already connected dir %d", | ||
| buf_get_id(buffer), dir); | ||
| PPL_UNLOCK(); | ||
| PPL_UNLOCK(buffer->core); | ||
| return ret; | ||
| } | ||
| buffer_set_comp(buffer, comp, dir); | ||
|
|
||
| PPL_UNLOCK(); | ||
| PPL_UNLOCK(buffer->core); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
@@ -235,13 +242,13 @@ void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int | |
| else | ||
| comp_dbg(comp, "disconnect buffer %d as source", buf_get_id(buffer)); | ||
|
|
||
| PPL_LOCK(); | ||
| PPL_LOCK(buffer->core); | ||
|
|
||
| comp_list = comp_buffer_list(comp, dir); | ||
| buffer_detach(buffer, comp_list, dir); | ||
| buffer_set_comp(buffer, NULL, dir); | ||
|
|
||
| PPL_UNLOCK(); | ||
| PPL_UNLOCK(buffer->core); | ||
| } | ||
|
|
||
| /* pipelines must be inactive */ | ||
|
|
||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,10 +448,21 @@ __cold static int ipc_pipeline_module_free(uint32_t pipeline_id) | |
| struct ipc *ipc = ipc_get(); | ||
| struct ipc_comp_dev *icd; | ||
| int ret; | ||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| int ppl_core; | ||
| #endif | ||
|
|
||
| assert_can_be_cold(); | ||
|
|
||
| icd = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_COMPONENT, pipeline_id, IPC_COMP_ALL); | ||
| if (!icd) | ||
| return IPC4_SUCCESS; | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| ppl_core = icd->core; | ||
| user_ll_lock_sched(ppl_core); | ||
| #endif | ||
|
|
||
| while (icd) { | ||
| struct comp_buffer *buffer; | ||
| struct comp_buffer *safe; | ||
|
|
@@ -481,12 +492,20 @@ __cold static int ipc_pipeline_module_free(uint32_t pipeline_id) | |
| else | ||
| ret = ipc_comp_free(ipc, icd->id); | ||
|
|
||
| if (ret) | ||
| if (ret) { | ||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| user_ll_unlock_sched(ppl_core); | ||
| #endif | ||
| return IPC4_INVALID_RESOURCE_STATE; | ||
| } | ||
|
|
||
| icd = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_COMPONENT, pipeline_id, IPC_COMP_ALL); | ||
| } | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_LL | ||
| user_ll_unlock_sched(ppl_core); | ||
| #endif | ||
|
|
||
| return IPC4_SUCCESS; | ||
| } | ||
|
|
||
|
|
@@ -560,21 +579,25 @@ __cold static struct comp_buffer *ipc4_create_buffer(struct comp_dev *src, bool | |
| * disable any interrupts. | ||
| */ | ||
|
|
||
| #define ll_block(cross_core_bind, flags) \ | ||
| #if CONFIG_SOF_USERSPACE_LL | ||
| #error "CONFIG_SOF_USERSPACE_LL not compatible with cross-core streams" | ||
| #else | ||
| #define ll_block(src_core, dst_core, flags) \ | ||
| do { \ | ||
| if (cross_core_bind) \ | ||
| if (src_core != dst_core) \ | ||
| domain_block(sof_get()->platform_timer_domain); \ | ||
| else \ | ||
| irq_local_disable(flags); \ | ||
| } while (0) | ||
|
|
||
| #define ll_unblock(cross_core_bind, flags) \ | ||
| #define ll_unblock(src_core, dst_core, flags) \ | ||
| do { \ | ||
| if (cross_core_bind) \ | ||
| if (src_core != dst_core) \ | ||
| domain_unblock(sof_get()->platform_timer_domain); \ | ||
| else \ | ||
| irq_local_enable(flags); \ | ||
| } while (0) | ||
| #endif | ||
|
|
||
| /* Calling both ll_block() and ll_wait_finished_on_core() makes sure LL will not start its | ||
| * next cycle and its current cycle on specified core has finished. | ||
|
|
@@ -606,8 +629,15 @@ static int ll_wait_finished_on_core(struct comp_dev *dev) | |
|
|
||
| #else | ||
|
|
||
| #define ll_block(cross_core_bind, flags) irq_local_disable(flags) | ||
| #define ll_unblock(cross_core_bind, flags) irq_local_enable(flags) | ||
| #if CONFIG_SOF_USERSPACE_LL | ||
| /* note: cross-core streams are disabled in the build in this branch, | ||
| * so we can safely use 'src_core' only */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could explicitly add a comment that |
||
| #define ll_block(src_core, dst_core, flags) do { user_ll_lock_sched(src_core); (void)flags; } while(0) | ||
| #define ll_unblock(src_core, dst_core, flags) do { user_ll_unlock_sched(src_core) ; (void)flags; } while(0) | ||
| #else | ||
| #define ll_block(src_core, dst_core, flags) irq_local_disable(flags) | ||
| #define ll_unblock(src_core, dst_core, flags) irq_local_enable(flags) | ||
| #endif | ||
|
|
||
| #endif | ||
|
|
||
|
|
@@ -794,7 +824,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) | |
| * blocked on corresponding core(s) to prevent IPC or IDC task getting preempted which | ||
| * could result in buffers being only half connected when a pipeline task gets executed. | ||
| */ | ||
| ll_block(cross_core_bind, flags); | ||
| ll_block(source->ipc_config.core, sink->ipc_config.core, flags); | ||
|
|
||
| if (cross_core_bind) { | ||
| #if CONFIG_CROSS_CORE_STREAM | ||
|
|
@@ -851,7 +881,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) | |
| source->direction_set = true; | ||
| } | ||
|
|
||
| ll_unblock(cross_core_bind, flags); | ||
| ll_unblock(source->ipc_config.core, sink->ipc_config.core, flags); | ||
|
|
||
| return IPC4_SUCCESS; | ||
|
|
||
|
|
@@ -865,7 +895,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) | |
| e_sink_connect: | ||
| pipeline_disconnect(source, buffer, PPL_CONN_DIR_COMP_TO_BUFFER); | ||
| free: | ||
| ll_unblock(cross_core_bind, flags); | ||
| ll_unblock(source->ipc_config.core, sink->ipc_config.core, flags); | ||
| buffer_free(buffer); | ||
| return IPC4_INVALID_RESOURCE_STATE; | ||
| } | ||
|
|
@@ -938,24 +968,24 @@ __cold int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) | |
| * IPC or IDC task getting preempted which could result in buffers being only half connected | ||
| * when a pipeline task gets executed. | ||
| */ | ||
| ll_block(cross_core_unbind, flags); | ||
| ll_block(src->ipc_config.core, sink->ipc_config.core, flags); | ||
|
|
||
| if (cross_core_unbind) { | ||
| #if CONFIG_CROSS_CORE_STREAM | ||
| /* Make sure LL has finished on both cores */ | ||
| if (!cpu_is_me(src->ipc_config.core)) | ||
| if (ll_wait_finished_on_core(src) < 0) { | ||
| ll_unblock(cross_core_unbind, flags); | ||
| ll_unblock(src->ipc_config.core, sink->ipc_config.core, flags); | ||
| return IPC4_FAILURE; | ||
| } | ||
| if (!cpu_is_me(sink->ipc_config.core)) | ||
| if (ll_wait_finished_on_core(sink) < 0) { | ||
| ll_unblock(cross_core_unbind, flags); | ||
| ll_unblock(src->ipc_config.core, sink->ipc_config.core, flags); | ||
| return IPC4_FAILURE; | ||
| } | ||
| #else | ||
| tr_err(&ipc_tr, "Cross-core binding is disabled"); | ||
| ll_unblock(cross_core_unbind, flags); | ||
| ll_unblock(src->ipc_config.core, sink->ipc_config.core, flags); | ||
| return IPC4_FAILURE; | ||
| #endif | ||
| } | ||
|
|
@@ -972,7 +1002,7 @@ __cold int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect) | |
| unbind_data.source = audio_buffer_get_source(&buffer->audio_buffer); | ||
| ret1 = comp_unbind(sink, &unbind_data); | ||
|
|
||
| ll_unblock(cross_core_unbind, flags); | ||
| ll_unblock(src->ipc_config.core, sink->ipc_config.core, flags); | ||
|
|
||
| buffer_free(buffer); | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one too many