Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/include/sof/schedule/dp_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ int scheduler_dp_task_init(struct task **task,
uint16_t core,
size_t stack_size,
uint32_t options);
void scheduler_dp_ll_tick(void);

#if defined(__ZEPHYR__) && CONFIG_SOF_FULL_ZEPHYR_APPLICATION
__syscall void scheduler_dp_internal_free(struct task *task);
__syscall void scheduler_dp_ll_tick(void);
#include <zephyr/syscalls/dp_schedule.h>
#endif
Comment thread
lyakh marked this conversation as resolved.

/**
* \brief Extract information about scheduler's tasks
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/schedule/ll_schedule_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ struct ll_schedule_domain *zephyr_domain_init(int clk);
struct k_thread *zephyr_domain_thread_tid(struct ll_schedule_domain *domain);
struct k_thread *zephyr_domain_thread_tid_for_core(int core);
struct k_mem_domain *zephyr_ll_mem_domain(void);
struct k_thread *zephyr_ll_domain_thread(void);
#endif /* CONFIG_SOF_USERSPACE_LL */
#ifdef CONFIG_SOF_FULL_ZEPHYR_APPLICATION
__syscall int zephyr_ll_task_sem_alloc(struct task *task);
Expand Down
12 changes: 12 additions & 0 deletions src/schedule/zephyr_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,18 @@ struct k_thread *zephyr_domain_thread_tid_for_core(int core)
return ll_thread_tid[core];
}

struct k_thread *zephyr_ll_domain_thread(void)
{
struct ll_schedule_domain *ll_domain = zephyr_ll_domain();

if (!ll_domain)
return NULL;

struct zephyr_domain *zephyr_domain = ll_sch_domain_get_pdata(ll_domain);

return zephyr_domain->domain_thread[cpu_get_id()].ll_thread;
}

#endif /* CONFIG_SOF_USERSPACE_LL */

#if CONFIG_CROSS_CORE_STREAM
Expand Down
25 changes: 21 additions & 4 deletions src/schedule/zephyr_dp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void scheduler_dp_unlock(unsigned int key)

void scheduler_dp_grant(k_tid_t thread_id, uint16_t core)
{
k_thread_access_grant(thread_id, &dp_lock[core]);
if (thread_id)
k_thread_access_grant(thread_id, &dp_lock[core]);
}

/* dummy LL task - to start LL on secondary cores */
Expand Down Expand Up @@ -224,10 +225,14 @@ static enum task_state scheduler_dp_ll_tick_dummy(void *data)
* needed 1.2ms for processing - but the example would be too complicated)
*/

void scheduler_dp_ll_tick(void)
void z_impl_scheduler_dp_ll_tick(void)
{
unsigned int lock_key;
#if CONFIG_SOF_USERSPACE_LL
struct scheduler_dp_data *dp_sch = scheduler_get_user_data(SOF_SCHEDULE_DP);
#else
struct scheduler_dp_data *dp_sch = scheduler_get_data(SOF_SCHEDULE_DP);
#endif
Comment on lines +230 to +234

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think longer term we could just call the single function here and have it do the right thing based on the Kconfig.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@lgirdwood yep, will do something about this


if (!dp_sch)
Comment thread
lyakh marked this conversation as resolved.
return;
Expand All @@ -240,6 +245,15 @@ void scheduler_dp_ll_tick(void)
scheduler_dp_unlock(lock_key);
}

#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>
void z_vrfy_scheduler_dp_ll_tick(void)
{
z_impl_scheduler_dp_ll_tick();
}
#include <zephyr/syscalls/scheduler_dp_ll_tick_mrsh.c>
#endif

#if CONFIG_SOF_USERSPACE_APPLICATION
static int scheduler_dp_task_cancel(void *data, struct task *task)
{
Expand Down Expand Up @@ -376,8 +390,11 @@ void scheduler_get_task_info_dp(struct scheduler_props *scheduler_props, uint32_
unsigned int lock_key;

scheduler_props->processing_domain = COMP_PROCESSING_DOMAIN_DP;
struct scheduler_dp_data *dp_sch =
(struct scheduler_dp_data *)scheduler_get_data(SOF_SCHEDULE_DP);
#if CONFIG_SOF_USERSPACE_LL
struct scheduler_dp_data *dp_sch = scheduler_get_user_data(SOF_SCHEDULE_DP);
#else
struct scheduler_dp_data *dp_sch = scheduler_get_data(SOF_SCHEDULE_DP);
#endif

lock_key = scheduler_dp_lock(cpu_get_id());
scheduler_get_task_info(scheduler_props, data_off_size, &dp_sch->tasks);
Expand Down
4 changes: 0 additions & 4 deletions src/schedule/zephyr_dp_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ void dp_thread_fn(void *p1, void *p2, void *p3);
unsigned int scheduler_dp_lock(uint16_t core);
void scheduler_dp_unlock(unsigned int key);
void scheduler_dp_grant(k_tid_t thread_id, uint16_t core);
int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
const struct task_ops *ops, struct processing_module *mod,
uint16_t core, size_t stack_size, uint32_t options);
void scheduler_dp_internal_free(struct task *task);
50 changes: 49 additions & 1 deletion src/schedule/zephyr_dp_schedule_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rtos/task.h>

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/component.h>
#include <sof/common.h>
#include <sof/list.h>
#include <sof/llext_manager.h>
Expand Down Expand Up @@ -400,7 +401,7 @@ struct scheduler_dp_task_memory {
struct ipc4_flat flat;
};

void scheduler_dp_internal_free(struct task *task)
void z_impl_scheduler_dp_internal_free(struct task *task)
{
struct task_dp_pdata *pdata = task->priv_data;

Expand Down Expand Up @@ -527,6 +528,9 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,

k_thread_access_grant(pdata->thread_id, pdata->event, &dp_sync[core]);
scheduler_dp_grant(pdata->thread_id, core);
#if CONFIG_SOF_USERSPACE_LL
scheduler_dp_grant(zephyr_ll_domain_thread(), core);
#endif

struct k_mem_domain *mdom = objpool_alloc(&dp_mdom_head, sizeof(*mdom),
SOF_MEM_FLAG_COHERENT);
Expand Down Expand Up @@ -616,3 +620,47 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
mod_free(mod, task_memory);
return ret;
}

#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>

static void scheduler_dp_mod_vrfy(struct processing_module *mod)
{
K_OOPS(K_SYSCALL_MEMORY_WRITE(mod, sizeof(*mod)));
K_OOPS(K_SYSCALL_MEMORY_WRITE(mod->dev, sizeof(*mod->dev)));
K_OOPS(K_SYSCALL_MEMORY_READ(mod->dev->drv, sizeof(*mod->dev->drv)));

struct mod_alloc_ctx *alloc = mod->priv.resources.alloc;

K_OOPS(K_SYSCALL_MEMORY_WRITE(alloc, sizeof(*alloc)));
if (alloc->heap) {
size_t h_size = 0;
uintptr_t h_start;

mod_heap_info(mod, &h_size, &h_start);
if (h_size)
K_OOPS(K_SYSCALL_MEMORY_WRITE(h_start, h_size));
}
if (alloc->vreg) {
size_t vr_size = 0;
uintptr_t vr_start;

vregion_mem_info(alloc->vreg, &vr_size, &vr_start);
K_OOPS(K_SYSCALL_MEMORY_WRITE(vr_start, vr_size));
}
}

void z_vrfy_scheduler_dp_internal_free(struct task *task)
{
K_OOPS(K_SYSCALL_MEMORY_WRITE(task, sizeof(*task)));

struct task_dp_pdata *pdata = task->priv_data;

K_OOPS(K_SYSCALL_MEMORY_WRITE(pdata, sizeof(*pdata)));
K_OOPS(K_SYSCALL_OBJ(pdata->event, K_OBJ_EVENT));
K_OOPS(K_SYSCALL_OBJ_INIT(pdata->thread, K_OBJ_THREAD));
scheduler_dp_mod_vrfy(pdata->mod);
return z_impl_scheduler_dp_internal_free(task);
}
#include <zephyr/syscalls/scheduler_dp_internal_free_mrsh.c>
#endif
16 changes: 15 additions & 1 deletion src/schedule/zephyr_dp_schedule_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ int scheduler_dp_task_init(struct task **task,
return ret;
}

void scheduler_dp_internal_free(struct task *task)
void z_impl_scheduler_dp_internal_free(struct task *task)
{
struct task_dp_pdata *pdata = task->priv_data;

Expand All @@ -354,3 +354,17 @@ void scheduler_dp_internal_free(struct task *task)
/* task is the first member in task_memory above */
sof_heap_free(pdata->mod->dev->drv->user_heap, task);
}

#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>

void z_vrfy_scheduler_dp_internal_free(struct task *task)
{
/*
* With the thread DP scheduler variant scheduler_dp_internal_free() is
* never called from the userspace context
*/
K_OOPS(true);
}
Comment thread
lyakh marked this conversation as resolved.
#include <zephyr/syscalls/scheduler_dp_internal_free_mrsh.c>
#endif
1 change: 1 addition & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE syscall/cpu.c)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/audio/module_adapter/module/generic.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/lib/fast-get.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/ipc/ipc_reply.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/schedule/dp_schedule.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/schedule/ll_schedule_domain.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/ipc4/handler.h)
zephyr_syscall_header(include/rtos/alloc.h)
Expand Down
Loading