Skip to content

Commit

Permalink
schedule: twb: run task_complete() as the last step in thread fn
Browse files Browse the repository at this point in the history
Reworked task thread flow to run task_complete as the last step

Signed-off-by: Adrian Bonislawski <[email protected]>
  • Loading branch information
abonislawski committed Feb 10, 2025
1 parent bf73ea6 commit 7bb3c21
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/schedule/zephyr_twb_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ static void twb_thread_fn(void *p1, void *p2, void *p3)

if (task->state == SOF_TASK_STATE_RUNNING) {
state = task_run(task);
if (state == SOF_TASK_STATE_COMPLETED)
task_complete(task);
} else {
state = task->state; /* to avoid undefined variable warning */
}
Expand All @@ -190,18 +188,20 @@ static void twb_thread_fn(void *p1, void *p2, void *p3)
* if not, set the state returned by run procedure
*/
if (task->state == SOF_TASK_STATE_RUNNING) {
task->state = state;
if (pdata->cycles_granted) {
k_thread_runtime_stats_get(pdata->thread_id, &rt_stats_thread);
pdata->cycles_consumed += rt_stats_thread.execution_cycles - pdata->cycles_ref;
pdata->cycles_ref = rt_stats_thread.execution_cycles;
}
switch (state) {
case SOF_TASK_STATE_RESCHEDULE:
/* mark to reschedule, schedule time is already calculated */
task->state = SOF_TASK_STATE_QUEUED;
break;
case SOF_TASK_STATE_CANCEL:
task->state = SOF_TASK_STATE_CANCEL;
break;
case SOF_TASK_STATE_COMPLETED:
if (pdata->cycles_granted) {
k_thread_runtime_stats_get(pdata->thread_id, &rt_stats_thread);
pdata->cycles_consumed += rt_stats_thread.execution_cycles - pdata->cycles_ref;
pdata->cycles_ref = rt_stats_thread.execution_cycles;
}
break;

default:
Expand All @@ -212,7 +212,12 @@ static void twb_thread_fn(void *p1, void *p2, void *p3)

scheduler_twb_unlock(lock_key);

if (task->state != SOF_TASK_STATE_RUNNING)
if (state == SOF_TASK_STATE_COMPLETED) {
task->state = SOF_TASK_STATE_COMPLETED;
task_complete(task);
}

if (state != SOF_TASK_STATE_RUNNING)
k_sem_take(&pdata->sem, K_FOREVER);
};
/* never be here */
Expand Down

0 comments on commit 7bb3c21

Please sign in to comment.