Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/include/sof/schedule/dp_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
2 changes: 1 addition & 1 deletion src/schedule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/schedule/zephyr_dp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/schedule/zephyr_dp_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively to changing the "application" version in this commit too, you can add the two new members without removing the semaphore, then I'll migrate the other version later too.

struct processing_module *mod; /* the module to be scheduled */
uint32_t ll_cycles_to_start; /* current number of LL cycles till delayed start */
};
Expand Down
10 changes: 6 additions & 4 deletions src/schedule/zephyr_dp_schedule_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sof/common.h>
#include <sof/list.h>
#include <sof/schedule/ll_schedule_domain.h>
#include <sof/schedule/dp_schedule.h>

#include <zephyr/kernel.h>

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sof/common.h>
#include <sof/list.h>
#include <sof/schedule/ll_schedule_domain.h>
#include <sof/schedule/dp_schedule.h>

#include <zephyr/kernel.h>

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading