Skip to content

Commit 2fd74bd

Browse files
lyakhkv2019i
authored andcommitted
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 65bb7ad commit 2fd74bd

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/schedule/zephyr_domain.c

Lines changed: 17 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

@@ -473,6 +481,11 @@ static void zephyr_domain_thread_free(struct ll_schedule_domain *domain,
473481
dt->ll_thread = NULL;
474482
}
475483

484+
if (dt->sem) {
485+
k_object_free(dt->sem);
486+
dt->sem = NULL;
487+
}
488+
476489
tr_info(&ll_tr, "thread_free done, core %d", core);
477490
}
478491

@@ -530,11 +543,11 @@ APP_TASK_DATA static const struct ll_schedule_domain_ops zephyr_domain_ops = {
530543
#endif
531544
};
532545

546+
/* Core 0 only */
533547
struct ll_schedule_domain *zephyr_domain_init(int clk)
534548
{
535549
struct ll_schedule_domain *domain;
536550
struct zephyr_domain *zephyr_domain;
537-
struct zephyr_domain_thread *dt;
538551
int core;
539552

540553
domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false,
@@ -584,14 +597,9 @@ struct ll_schedule_domain *zephyr_domain_init(int clk)
584597
ll_sch_domain_set_pdata(domain, zephyr_domain);
585598

586599
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
600+
#ifndef CONFIG_SOF_USERSPACE_LL
601+
struct zephyr_domain_thread *dt = zephyr_domain->domain_thread + core;
602+
595603
/* not allocated dynamically when LL in kernel space */
596604
dt->sem = &dt->sem_obj;
597605
#endif

0 commit comments

Comments
 (0)