Skip to content
Draft
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
29 changes: 13 additions & 16 deletions src/schedule/zephyr_dp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,33 @@ SOF_DEFINE_REG_UUID(dp_sched);

DECLARE_TR_CTX(dp_tr, SOF_UUID(dp_sched_uuid), LOG_LEVEL_INFO);

#define DP_LOCK_INIT(i, _) Z_SEM_INITIALIZER(dp_lock[i], 1, 1)
#ifdef CONFIG_USERSPACE
#define SYS_SEM_INITIALIZER(obj, n_init, n_max) {.futex = {n_init}, .limit = n_max}
#else
#define SYS_SEM_INITIALIZER(obj, n_init, n_max) {Z_SEM_INITIALIZER(obj.kernel_sem, 1, 1)}
#endif

#define DP_LOCK_INIT(i, _) SYS_SEM_INITIALIZER(dp_lock[i], 1, 1)
#define DP_LOCK_INIT_LIST LISTIFY(CONFIG_MP_MAX_NUM_CPUS, DP_LOCK_INIT, (,))

/* User threads don't need access to this array. Access is performed from
* the kernel space via a syscall. Array must be placed in special section
* to be qualified as initialized by the gen_kobject_list.py script.
*/
static
STRUCT_SECTION_ITERABLE_ARRAY(k_sem, dp_lock, CONFIG_MP_MAX_NUM_CPUS) = { DP_LOCK_INIT_LIST };
static struct sys_sem dp_lock[CONFIG_MP_MAX_NUM_CPUS] = {
DP_LOCK_INIT_LIST
};

/* Each per-core instance of DP scheduler has separate structures; hence, locks are per-core.
*
* TODO: consider using cpu_get_id() instead of supplying core as a parameter.
*/
unsigned int scheduler_dp_lock(uint16_t core)
{
k_sem_take(&dp_lock[core], K_FOREVER);
sys_sem_take(&dp_lock[core], K_FOREVER);

return core;
}

void scheduler_dp_unlock(unsigned int key)
{
k_sem_give(&dp_lock[key]);
}

void scheduler_dp_grant(k_tid_t thread_id, uint16_t core)
{
#if CONFIG_USERSPACE
k_thread_access_grant(thread_id, &dp_lock[core]);
#endif
sys_sem_give(&dp_lock[key]);
}

/* dummy LL task - to start LL on secondary cores */
Expand Down
1 change: 0 additions & 1 deletion src/schedule/zephyr_dp_schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
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);
Expand Down
1 change: 0 additions & 1 deletion src/schedule/zephyr_dp_schedule_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,

#if CONFIG_USERSPACE
k_thread_access_grant(pdata->thread_id, pdata->sem, &dp_sync[core]);
scheduler_dp_grant(pdata->thread_id, core);

unsigned int pidx;
size_t size;
Expand Down
1 change: 0 additions & 1 deletion src/schedule/zephyr_dp_schedule_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ int scheduler_dp_task_init(struct task **task,
CONFIG_DP_THREAD_PRIORITY, (*task)->flags, K_FOREVER);

k_thread_access_grant(pdata->thread_id, pdata->event);
scheduler_dp_grant(pdata->thread_id, cpu_get_id());

/* pin the thread to specific core */
ret = k_thread_cpu_pin(pdata->thread_id, core);
Expand Down