Skip to content

Commit 46b3950

Browse files
committed
schedule: dp: start the task early
We need to run all module callbacks in DP thread context, for this the thread has to be started early - before the first module callback is called. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 35a1373 commit 46b3950

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
102102
mod->dev = dev;
103103
dev->mod = mod;
104104

105+
#if CONFIG_ZEPHYR_DP_SCHEDULER
106+
/* create a task for DP processing */
107+
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP) {
108+
/* All data allocated, create a thread */
109+
pipeline_comp_dp_task_init(dev);
110+
}
111+
#endif /* CONFIG_ZEPHYR_DP_SCHEDULER */
112+
105113
list_init(&mod->raw_data_buffers_list);
106114

107115
ret = module_adapter_init_data(dev, dst, config, spec);
@@ -133,12 +141,6 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
133141
goto err;
134142
}
135143

136-
#if CONFIG_ZEPHYR_DP_SCHEDULER
137-
/* create a task for DP processing */
138-
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP)
139-
pipeline_comp_dp_task_init(dev);
140-
#endif /* CONFIG_ZEPHYR_DP_SCHEDULER */
141-
142144
module_adapter_reset_data(dst);
143145

144146
dev->state = COMP_STATE_READY;
@@ -159,7 +161,12 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
159161

160162
comp_dbg(dev, "done");
161163
return dev;
164+
162165
err:
166+
#if CONFIG_ZEPHYR_DP_SCHEDULER
167+
if (dev->task)
168+
schedule_task_free(dev->task);
169+
#endif
163170
#if CONFIG_IPC_MAJOR_4
164171
if (mod)
165172
rfree(mod->priv.cfg.input_pins);

src/schedule/zephyr_dp_schedule.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,6 @@ static int scheduler_dp_task_shedule(void *data, struct task *task, uint64_t sta
391391
return -EINVAL;
392392
}
393393

394-
/* pin the thread to specific core */
395-
ret = k_thread_cpu_pin(pdata->thread_id, task->core);
396-
if (ret < 0) {
397-
tr_err(&dp_tr, "zephyr_dp_task_init(): zephyr task pin to core failed");
398-
goto err;
399-
}
400-
401-
/* start the thread, it should immediately stop at a semaphore, so clean it */
402-
k_sem_reset(&pdata->sem);
403-
k_thread_start(pdata->thread_id);
404394

405395
/* if there's no DP tasks scheduled yet, run ll tick source task */
406396
if (list_is_empty(&dp_sch->tasks))
@@ -424,11 +414,6 @@ static int scheduler_dp_task_shedule(void *data, struct task *task, uint64_t sta
424414
tr_dbg(&dp_tr, "DP task scheduled with period %u [us]", (uint32_t)period);
425415
return 0;
426416

427-
err:
428-
/* cleanup - unlock and free all allocated resources */
429-
scheduler_dp_unlock(lock_key);
430-
k_thread_abort(pdata->thread_id);
431-
return ret;
432417
}
433418

434419
static struct scheduler_ops schedule_dp_ops = {
@@ -539,7 +524,19 @@ int scheduler_dp_task_init(struct task **task,
539524
stack_size, dp_thread_fn, &task_memory->task, NULL, NULL,
540525
CONFIG_DP_THREAD_PRIORITY, K_USER, K_FOREVER);
541526

527+
/* pin the thread to specific core */
528+
ret = k_thread_cpu_pin(pdata->thread_id, core);
529+
if (ret < 0) {
530+
tr_err(&dp_tr, "zephyr_dp_task_init(): zephyr task pin to core failed");
531+
goto e_thread;
532+
}
533+
534+
k_thread_start(pdata->thread_id);
535+
542536
return 0;
537+
538+
e_thread:
539+
k_thread_abort(pdata->thread_id);
543540
err:
544541
/* cleanup - free all allocated resources */
545542
rfree((__sparse_force void *)p_stack);

0 commit comments

Comments
 (0)