Skip to content

Commit

Permalink
dp: LL tick source start/stop fix
Browse files Browse the repository at this point in the history
as DP uses LL as a tick source, it starts an empty LL task
to ensure that an instance of LL is running
This applies to mostly to secondary cores, but is may happen
that there's no LL instance started on primary

This commit fixes 2 problems
 - LL tick source was stated once for every DP module
 - LL tick source wasn't stopped when there were no DP
   modules running anymore

Signed-off-by: Marcin Szkudlinski <[email protected]>
  • Loading branch information
marcinszkudlinski committed Oct 10, 2023
1 parent 15ef953 commit 9f6c3dc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/schedule/zephyr_dp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DECLARE_TR_CTX(dp_tr, SOF_UUID(dp_sched_uuid), LOG_LEVEL_INFO);

struct scheduler_dp_data {
struct list_item tasks; /* list of active dp tasks */
struct task task; /* LL task - source of DP tick */
struct task ll_tick_src; /* LL task - source of DP tick */
};

struct task_dp_pdata {
Expand Down Expand Up @@ -103,32 +103,31 @@ void scheduler_dp_ll_tick(void *receiver_data, enum notify_id event_type, void *
static int scheduler_dp_task_cancel(void *data, struct task *task)
{
unsigned int lock_key;
struct scheduler_dp_data *dp_sch = (struct scheduler_dp_data *)data;

/* this is asyn cancel - mark the task as canceled and remove it from scheduling */
lock_key = scheduler_dp_lock();

task->state = SOF_TASK_STATE_CANCEL;
list_item_del(&task->list);

/* if there're no more DP task, stop LL tick source */
if (list_is_empty(&dp_sch->tasks))
schedule_task_cancel(&dp_sch->ll_tick_src);

scheduler_dp_unlock(lock_key);

return 0;
}

static int scheduler_dp_task_free(void *data, struct task *task)
{
unsigned int lock_key;
struct task_dp_pdata *pdata = task->priv_data;

scheduler_dp_task_cancel(data, task);

/* abort the execution of the thread */
k_thread_abort(pdata->thread_id);

lock_key = scheduler_dp_lock();
list_item_del(&task->list);
task->priv_data = NULL;
task->state = SOF_TASK_STATE_FREE;
scheduler_dp_unlock(lock_key);

/* free task stack */
rfree((__sparse_force void *)pdata->p_stack);

Expand Down Expand Up @@ -212,15 +211,17 @@ static int scheduler_dp_task_shedule(void *data, struct task *task, uint64_t sta
return -EINVAL;
}

/* if there's no DP tasks scheduled yet, run ll tick source task */
if (list_is_empty(&task->list))
schedule_task(&dp_sch->ll_tick_src, 0, 0);

/* add a task to DP scheduler list */
task->state = SOF_TASK_STATE_QUEUED;
list_item_prepend(&task->list, &dp_sch->tasks);

pdata->period = period;
scheduler_dp_unlock(lock_key);

/* start LL task - run DP tick start and period are irrelevant for LL (that's bad)*/
schedule_task(&dp_sch->task, 0, 0);
return 0;
}

Expand All @@ -243,7 +244,7 @@ int scheduler_dp_init(void)
scheduler_init(SOF_SCHEDULE_DP, &schedule_dp_ops, dp_sch);

/* init src of DP tick */
ret = schedule_task_init_ll(&dp_sch->task,
ret = schedule_task_init_ll(&dp_sch->ll_tick_src,
SOF_UUID(dp_sched_uuid),
SOF_SCHEDULE_LL_TIMER,
0, scheduler_dp_ll_tick_dummy, dp_sch,
Expand Down

0 comments on commit 9f6c3dc

Please sign in to comment.