Skip to content

Commit 3378368

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 3378368

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ static int scheduler_dp_task_shedule(void *data, struct task *task, uint64_t sta
380380
struct task_dp_pdata *pdata = task->priv_data;
381381
unsigned int lock_key;
382382
uint64_t deadline_clock_ticks;
383-
int ret;
384383

385384
lock_key = scheduler_dp_lock();
386385

@@ -391,16 +390,6 @@ static int scheduler_dp_task_shedule(void *data, struct task *task, uint64_t sta
391390
return -EINVAL;
392391
}
393392

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);
404393

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

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;
432416
}
433417

434418
static struct scheduler_ops schedule_dp_ops = {
@@ -539,7 +523,19 @@ int scheduler_dp_task_init(struct task **task,
539523
stack_size, dp_thread_fn, &task_memory->task, NULL, NULL,
540524
CONFIG_DP_THREAD_PRIORITY, K_USER, K_FOREVER);
541525

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

0 commit comments

Comments
 (0)