From 3a4dfc91d5b29915357546319bfa4c2a6fa71584 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Mon, 8 Dec 2025 16:36:26 +0100 Subject: [PATCH 1/2] dp: Update file naming to better reflect implementation Update the DP scheduler file name by replacing the proxy postfix to reflect actual content and avoid misleading semantics. The file does not implement any proxy layer, and it is also used when userspace is not active. It contains only the native DP thread. Signed-off-by: Adrian Warecki --- src/schedule/CMakeLists.txt | 2 +- .../{zephyr_dp_schedule_proxy.c => zephyr_dp_schedule_thread.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/schedule/{zephyr_dp_schedule_proxy.c => zephyr_dp_schedule_thread.c} (100%) diff --git a/src/schedule/CMakeLists.txt b/src/schedule/CMakeLists.txt index f501f4ab1893..af660765c162 100644 --- a/src/schedule/CMakeLists.txt +++ b/src/schedule/CMakeLists.txt @@ -41,7 +41,7 @@ endif() if (CONFIG_SOF_USERSPACE_PROXY OR NOT CONFIG_USERSPACE) zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER zephyr_dp_schedule.c - zephyr_dp_schedule_proxy.c + zephyr_dp_schedule_thread.c ) else() zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER diff --git a/src/schedule/zephyr_dp_schedule_proxy.c b/src/schedule/zephyr_dp_schedule_thread.c similarity index 100% rename from src/schedule/zephyr_dp_schedule_proxy.c rename to src/schedule/zephyr_dp_schedule_thread.c From 9e82b197753e1cc4eaf59cf1c54b3e21cdfaf986 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Mon, 8 Dec 2025 17:17:24 +0100 Subject: [PATCH 2/2] dp: Switch DP thread trigger from semaphore to event Replace the DP thread trigger mechanism from semaphore to event to prepare for handling multiple types of signals within the DP thread. The previous semaphore-based approach could only wake the thread without providing context about what needs to be processed. Using an event allows signaling different conditions so the thread can identify which tasks to handle. Currently, no new event types are introduced, but this change lays the groundwork for future extensions without altering existing functionality. Signed-off-by: Adrian Warecki --- src/include/sof/schedule/dp_schedule.h | 5 ++++ src/schedule/zephyr_dp_schedule.c | 28 +++++++++---------- src/schedule/zephyr_dp_schedule.h | 4 +-- src/schedule/zephyr_dp_schedule_application.c | 10 ++++--- src/schedule/zephyr_dp_schedule_thread.c | 10 ++++--- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/include/sof/schedule/dp_schedule.h b/src/include/sof/schedule/dp_schedule.h index 360d7f47c1de..99f1dcd2b16f 100644 --- a/src/include/sof/schedule/dp_schedule.h +++ b/src/include/sof/schedule/dp_schedule.h @@ -86,4 +86,9 @@ int scheduler_dp_task_init(struct task **task, void scheduler_get_task_info_dp(struct scheduler_props *scheduler_props, uint32_t *data_off_size); +enum { + DP_TASK_EVENT_PROCESS = BIT(0), /* Need to process data */ + DP_TASK_EVENT_CANCEL = BIT(1), /* Thread cancellation */ +}; + #endif /* __SOF_SCHEDULE_DP_SCHEDULE_H__ */ diff --git a/src/schedule/zephyr_dp_schedule.c b/src/schedule/zephyr_dp_schedule.c index 9ad384e96ee4..6c46d5157974 100644 --- a/src/schedule/zephyr_dp_schedule.c +++ b/src/schedule/zephyr_dp_schedule.c @@ -253,12 +253,12 @@ static int scheduler_dp_task_cancel(void *data, struct task *task) task->state = SOF_TASK_STATE_CANCEL; list_item_del(&task->list); - /* if there're no more DP task, stop LL tick source */ + /* if there're no more DP task, stop LL tick source */ if (list_is_empty(&dp_sch->tasks)) schedule_task_cancel(&dp_sch->ll_tick_src); - /* if the task is waiting on a semaphore - let it run and self-terminate */ - k_sem_give(pdata->sem); + /* if the task is waiting on a event - let it run and self-terminate */ + k_event_set(pdata->event, DP_TASK_EVENT_CANCEL); scheduler_dp_unlock(lock_key); /* wait till the task has finished, if there was any task created */ @@ -284,8 +284,8 @@ static int scheduler_dp_task_free(void *data, struct task *task) } #ifdef CONFIG_USERSPACE - if (pdata->sem != &pdata->sem_struct) - k_object_free(pdata->sem); + if (pdata->event != &pdata->event_struct) + k_object_free(pdata->event); if (pdata->thread != &pdata->thread_struct) k_object_free(pdata->thread); #endif @@ -418,16 +418,16 @@ int scheduler_dp_task_init(struct task **task, struct task_dp_pdata *pdata = &task_memory->pdata; - /* Point to ksem semaphore for kernel threads synchronization */ + /* Point to event_struct event for kernel threads synchronization */ /* It will be overwritten for K_USER threads to dynamic ones. */ - pdata->sem = &pdata->sem_struct; + pdata->event = &pdata->event_struct; pdata->thread = &pdata->thread_struct; #ifdef CONFIG_USERSPACE if (options & K_USER) { - pdata->sem = k_object_alloc(K_OBJ_SEM); - if (!pdata->sem) { - tr_err(&dp_tr, "Semaphore object allocation failed"); + pdata->event = k_object_alloc(K_OBJ_EVENT); + if (!pdata->event) { + tr_err(&dp_tr, "Event object allocation failed"); ret = -ENOMEM; goto err; } @@ -459,7 +459,7 @@ int scheduler_dp_task_init(struct task **task, stack_size, dp_thread_fn, *task, NULL, NULL, CONFIG_DP_THREAD_PRIORITY, (*task)->flags, K_FOREVER); - k_thread_access_grant(pdata->thread_id, pdata->sem); + k_thread_access_grant(pdata->thread_id, pdata->event); scheduler_dp_grant(pdata->thread_id, cpu_get_id()); /* pin the thread to specific core */ @@ -479,8 +479,8 @@ int scheduler_dp_task_init(struct task **task, } #endif /* CONFIG_USERSPACE */ - /* start the thread, it should immediately stop at a semaphore, so clean it */ - k_sem_init(pdata->sem, 0, 1); + /* start the thread, it should immediately stop at an event */ + k_event_init(pdata->event); k_thread_start(pdata->thread_id); return 0; @@ -493,7 +493,7 @@ int scheduler_dp_task_init(struct task **task, tr_err(&dp_tr, "user_stack_free failed!"); /* k_object_free looks for a pointer in the list, any invalid value can be passed */ - k_object_free(task_memory->pdata.sem); + k_object_free(task_memory->pdata.event); k_object_free(task_memory->pdata.thread); sof_heap_free(user_heap, task_memory); return ret; diff --git a/src/schedule/zephyr_dp_schedule.h b/src/schedule/zephyr_dp_schedule.h index 111b498d3ff2..d146afab65cf 100644 --- a/src/schedule/zephyr_dp_schedule.h +++ b/src/schedule/zephyr_dp_schedule.h @@ -29,8 +29,8 @@ struct task_dp_pdata { uint32_t deadline_clock_ticks; /* dp module deadline in Zephyr ticks */ k_thread_stack_t __sparse_cache *p_stack; /* pointer to thread stack */ size_t stack_size; /* size of the stack in bytes */ - struct k_sem *sem; /* pointer to semaphore for task scheduling */ - struct k_sem sem_struct; /* semaphore for task scheduling for kernel threads */ + struct k_event *event; /* pointer to event for task scheduling */ + struct k_event event_struct; /* event for task scheduling for kernel threads */ struct processing_module *mod; /* the module to be scheduled */ uint32_t ll_cycles_to_start; /* current number of LL cycles till delayed start */ }; diff --git a/src/schedule/zephyr_dp_schedule_application.c b/src/schedule/zephyr_dp_schedule_application.c index fa3f1a808ff6..f5b53d426b01 100644 --- a/src/schedule/zephyr_dp_schedule_application.c +++ b/src/schedule/zephyr_dp_schedule_application.c @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -64,7 +65,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_ pdata->ll_cycles_to_start = 1; } trigger_task = true; - k_sem_give(pdata->sem); + k_event_post(pdata->event, DP_TASK_EVENT_PROCESS); } } if (curr_task->state == SOF_TASK_STATE_RUNNING) { @@ -111,10 +112,11 @@ void dp_thread_fn(void *p1, void *p2, void *p3) do { /* - * the thread is started immediately after creation, it will stop on semaphore - * Semaphore will be released once the task is ready to process + * the thread is started immediately after creation, it will stop on event. + * Event will be signalled once the task is ready to process. */ - k_sem_take(task_pdata->sem, K_FOREVER); + k_event_wait_safe(task_pdata->event, DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL, + false, K_FOREVER); if (task->state == SOF_TASK_STATE_RUNNING) state = task_run(task); diff --git a/src/schedule/zephyr_dp_schedule_thread.c b/src/schedule/zephyr_dp_schedule_thread.c index 62b6db42535a..7a79e214eaca 100644 --- a/src/schedule/zephyr_dp_schedule_thread.c +++ b/src/schedule/zephyr_dp_schedule_thread.c @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -64,7 +65,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_ pdata->ll_cycles_to_start = 1; } trigger_task = true; - k_sem_give(pdata->sem); + k_event_post(pdata->event, DP_TASK_EVENT_PROCESS); } } if (curr_task->state == SOF_TASK_STATE_RUNNING) { @@ -115,10 +116,11 @@ void dp_thread_fn(void *p1, void *p2, void *p3) do { /* - * the thread is started immediately after creation, it will stop on semaphore - * Semaphore will be released once the task is ready to process + * the thread is started immediately after creation, it will stop on event. + * Event will be signalled once the task is ready to process. */ - k_sem_take(task_pdata->sem, K_FOREVER); + k_event_wait_safe(task_pdata->event, DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL, + false, K_FOREVER); if (task->state == SOF_TASK_STATE_RUNNING) state = task_run(task);