Skip to content

Commit b343b2b

Browse files
committed
schedule: zephyr_ll: implement scheduler_init_context()
Implement the optional scheduler_init_context() and scheduler_free_context() ops for user-space LL scheduler. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 4510838 commit b343b2b

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

src/schedule/zephyr_domain.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,24 @@ static int zephyr_domain_register_user(struct ll_schedule_domain *domain,
294294
void (*handler)(void *arg), void *arg)
295295
{
296296
struct zephyr_domain *zephyr_domain = ll_sch_domain_get_pdata(domain);
297-
int core = 0; /* cpu_get_id(); */
298-
struct zephyr_domain_thread *dt = zephyr_domain->domain_thread + core;
297+
struct zephyr_domain_thread *dt;
299298
char thread_name[] = "ll_thread0";
300299
k_tid_t thread;
300+
int core;
301301

302302
tr_dbg(&ll_tr, "entry");
303303

304+
if (task->core < 0 || task->core >= CONFIG_CORE_COUNT)
305+
return -EINVAL;
306+
307+
dt = zephyr_domain->domain_thread + task->core;
308+
304309
/* domain work only needs registered once on each core */
305310
if (dt->handler)
306311
return 0;
307312

308-
__ASSERT_NO_MSG(task->core == core);
313+
/* safety check executed in kernel mode */
314+
__ASSERT_NO_MSG(cpu_get_id() == core);
309315

310316
dt->handler = handler;
311317
dt->arg = arg;

src/schedule/zephyr_ll.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,7 @@ static int zephyr_ll_task_schedule_common(struct zephyr_ll *sch, struct task *ta
363363

364364
ret = domain_register(sch->ll_domain, task, &schedule_ll_callback, sch);
365365
if (ret < 0)
366-
tr_err(&ll_tr, "cannot register domain %d",
367-
ret);
368-
369-
#if CONFIG_SOF_USERSPACE_LL
370-
k_thread_access_grant(zephyr_domain_thread_tid(sch->ll_domain), sch->lock);
371-
372-
tr_dbg(&ll_tr, "granting access to lock %p for thread %p", sch->lock,
373-
zephyr_domain_thread_tid(sch->ll_domain));
374-
tr_dbg(&ll_tr, "granting access to domain lock %p for thread %p", &sch->ll_domain->lock,
375-
zephyr_domain_thread_tid(sch->ll_domain));
376-
#endif
366+
tr_err(&ll_tr, "cannot register domain %d", ret);
377367

378368
return 0;
379369
}
@@ -518,13 +508,49 @@ static void zephyr_ll_scheduler_free(void *data, uint32_t flags)
518508
sch->n_tasks);
519509
}
520510

511+
#if CONFIG_SOF_USERSPACE_LL
512+
struct k_thread *zephyr_ll_init_context(void *data, struct task *task)
513+
{
514+
struct zephyr_ll *sch = data;
515+
int ret;
516+
517+
ret = domain_register(sch->ll_domain, task, &schedule_ll_callback, sch);
518+
if (ret < 0) {
519+
tr_err(&ll_tr, "cannot init_context %d", ret);
520+
return NULL;
521+
}
522+
523+
if (!k_is_user_context()) {
524+
k_thread_access_grant(zephyr_domain_thread_tid(sch->ll_domain), sch->lock);
525+
526+
tr_dbg(&ll_tr, "granting access to lock %p for thread %p", sch->lock,
527+
zephyr_domain_thread_tid(sch->ll_domain));
528+
tr_dbg(&ll_tr, "granting access to domain lock %p for thread %p", &sch->ll_domain->lock,
529+
zephyr_domain_thread_tid(sch->ll_domain));
530+
}
531+
532+
return zephyr_domain_thread_tid(sch->ll_domain);
533+
}
534+
535+
void zephyr_ll_free_context(void *data)
536+
{
537+
struct zephyr_ll *sch = data;
538+
539+
(void *)sch;
540+
}
541+
#endif
542+
521543
static const struct scheduler_ops zephyr_ll_ops = {
522544
.schedule_task = zephyr_ll_task_schedule,
523545
.schedule_task_before = zephyr_ll_task_schedule_before,
524546
.schedule_task_after = zephyr_ll_task_schedule_after,
525547
.schedule_task_free = zephyr_ll_task_sched_free,
526548
.schedule_task_cancel = zephyr_ll_task_cancel,
527549
.scheduler_free = zephyr_ll_scheduler_free,
550+
#if CONFIG_SOF_USERSPACE_LL
551+
.scheduler_init_context = zephyr_ll_init_context,
552+
.scheduler_free_context = zephyr_ll_free_context,
553+
#endif
528554
};
529555

530556
#if CONFIG_SOF_USERSPACE_LL

0 commit comments

Comments
 (0)