Skip to content

Commit 6b462ac

Browse files
committed
schedule: ll: allocate semaphores only for used cores
Instead of allocating semaphores during global initialisation, do that later when initialising the domain for specific cores. This also automatically grants access rights to the allocating thread. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 0b9ad52 commit 6b462ac

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/schedule/zephyr_domain.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ static int zephyr_domain_thread_init(struct ll_schedule_domain *domain,
319319
dt->handler = NULL;
320320
dt->arg = NULL;
321321

322+
dt->sem = k_object_alloc(K_OBJ_SEM);
323+
if (!dt->sem) {
324+
tr_err(&ll_tr, "Failed to allocate semaphore for core %d", core);
325+
return -ENOMEM;
326+
}
327+
322328
/* 10 is rather random, we better not accumulate 10 missed timer interrupts */
323329
k_sem_init(dt->sem, 0, 10);
324330

@@ -328,6 +334,8 @@ static int zephyr_domain_thread_init(struct ll_schedule_domain *domain,
328334
dt->ll_thread = k_object_alloc(K_OBJ_THREAD);
329335
if (!dt->ll_thread) {
330336
tr_err(&ll_tr, "Failed to allocate thread object for core %d", core);
337+
k_object_free(dt->sem);
338+
dt->sem = NULL;
331339
return -ENOMEM;
332340
}
333341

@@ -530,11 +538,11 @@ APP_TASK_DATA static const struct ll_schedule_domain_ops zephyr_domain_ops = {
530538
#endif
531539
};
532540

541+
/* Core 0 only */
533542
struct ll_schedule_domain *zephyr_domain_init(int clk)
534543
{
535544
struct ll_schedule_domain *domain;
536545
struct zephyr_domain *zephyr_domain;
537-
struct zephyr_domain_thread *dt;
538546
int core;
539547

540548
domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false,
@@ -584,14 +592,9 @@ struct ll_schedule_domain *zephyr_domain_init(int clk)
584592
ll_sch_domain_set_pdata(domain, zephyr_domain);
585593

586594
for (core = 0; core < CONFIG_CORE_COUNT; core++) {
587-
dt = zephyr_domain->domain_thread + core;
588-
#ifdef CONFIG_SOF_USERSPACE_LL
589-
dt->sem = k_object_alloc(K_OBJ_SEM);
590-
if (!dt->sem) {
591-
tr_err(&ll_tr, "Failed to allocate semaphore for core %d", core);
592-
k_panic();
593-
}
594-
#else
595+
#ifndef CONFIG_SOF_USERSPACE_LL
596+
struct zephyr_domain_thread *dt = zephyr_domain->domain_thread + core;
597+
595598
/* not allocated dynamically when LL in kernel space */
596599
dt->sem = &dt->sem_obj;
597600
#endif

0 commit comments

Comments
 (0)