From 7e2cd02c022a051975c6c1b142ae7a648e79ef21 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 8 Jul 2025 15:19:01 +0200 Subject: [PATCH] build: remove scheduling-related XTOS remainders Remove XTOS scheduling and related inintialisation code. Signed-off-by: Guennadi Liakhovetski --- src/schedule/edf_schedule.c | 344 ------------------------------------ src/schedule/task.c | 115 ------------ src/schedule/timer_domain.c | 177 ------------------- zephyr/CMakeLists.txt | 5 - 4 files changed, 641 deletions(-) delete mode 100644 src/schedule/edf_schedule.c delete mode 100644 src/schedule/task.c delete mode 100644 src/schedule/timer_domain.c diff --git a/src/schedule/edf_schedule.c b/src/schedule/edf_schedule.c deleted file mode 100644 index 5e601fea1bff..000000000000 --- a/src/schedule/edf_schedule.c +++ /dev/null @@ -1,344 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2017 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood -// Tomasz Lauda - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -SOF_DEFINE_REG_UUID(edf_sched); - -DECLARE_TR_CTX(edf_tr, SOF_UUID(edf_sched_uuid), LOG_LEVEL_INFO); - -struct edf_schedule_data { - struct list_item list; /* list of tasks in priority queue */ - uint32_t clock; - int irq; -}; - -static const struct scheduler_ops schedule_edf_ops; - -static int schedule_edf_task_complete(void *data, struct task *task); -static int schedule_edf_task_running(void *data, struct task *task); -static void schedule_edf(struct edf_schedule_data *edf_sch); - -static void schedule_edf_task_run(struct task *task, void *data) -{ - while (1) { - /* execute task run function and remove task from the list - * only if completed - */ - if (task_run(task) == SOF_TASK_STATE_COMPLETED) - schedule_edf_task_complete(data, task); - - /* find new task for execution */ - schedule_edf(data); - } -} - -static void edf_scheduler_run(void *data) -{ - struct edf_schedule_data *edf_sch = data; - uint64_t deadline_next = SOF_TASK_DEADLINE_IDLE; - struct task *task_next = NULL; - struct list_item *tlist; - struct task *task; - uint64_t deadline; - uint32_t flags; - - tr_dbg(&edf_tr, "edf_scheduler_run()"); - - irq_local_disable(flags); - - /* find next task to run */ - list_for_item(tlist, &edf_sch->list) { - task = container_of(tlist, struct task, list); - - if (task->state != SOF_TASK_STATE_QUEUED && - task->state != SOF_TASK_STATE_RUNNING) - continue; - - deadline = task_get_deadline(task); - - if (deadline == SOF_TASK_DEADLINE_NOW) { - /* task needs to be scheduled ASAP */ - task_next = task; - break; - } - - /* get earliest deadline */ - if (deadline <= deadline_next) { - deadline_next = deadline; - task_next = task; - } - } - - irq_local_enable(flags); - - /* schedule next pending task */ - if (task_next) - schedule_edf_task_running(data, task_next); -} - -static int schedule_edf_task(void *data, struct task *task, uint64_t start, - uint64_t period) -{ - struct edf_schedule_data *edf_sch = data; - uint32_t flags; - (void) period; /* not used */ - (void) start; /* not used */ - - irq_local_disable(flags); - - /* not enough MCPS to complete */ - if (task->state == SOF_TASK_STATE_QUEUED || - task->state == SOF_TASK_STATE_RUNNING) { - tr_err(&edf_tr, "schedule_edf_task(), task already queued or running %d", - task->state); - irq_local_enable(flags); - return -EALREADY; - } - - /* add task to the list */ - list_item_append(&task->list, &edf_sch->list); - - task->state = SOF_TASK_STATE_QUEUED; - - irq_local_enable(flags); - - schedule_edf(edf_sch); - - return 0; -} - -int schedule_task_init_edf(struct task *task, const struct sof_uuid_entry *uid, - const struct task_ops *ops, - void *data, uint16_t core, uint32_t flags) -{ - struct edf_task_pdata *edf_pdata = NULL; - int ret; - - ret = schedule_task_init(task, uid, SOF_SCHEDULE_EDF, 0, ops->run, data, - core, flags); - if (ret < 0) - return ret; - - if (edf_sch_get_pdata(task)) - return -EEXIST; - - edf_pdata = rzalloc(SOF_MEM_FLAG_KERNEL, - sizeof(*edf_pdata)); - if (!edf_pdata) { - tr_err(&edf_tr, "schedule_task_init_edf(): alloc failed"); - return -ENOMEM; - } - - edf_sch_set_pdata(task, edf_pdata); - - task->ops.complete = ops->complete; - task->ops.get_deadline = ops->get_deadline; - - if (task_context_alloc(&edf_pdata->ctx) < 0) - goto error; - if (task_context_init(edf_pdata->ctx, &schedule_edf_task_run, - task, scheduler_get_data(SOF_SCHEDULE_EDF), - task->core, NULL, 0) < 0) - goto error; - - /* flush for secondary core */ - if (!cpu_is_primary(task->core)) - dcache_writeback_invalidate_region(edf_pdata, - sizeof(*edf_pdata)); - return 0; - -error: - tr_err(&edf_tr, "schedule_task_init_edf(): init context failed"); - if (edf_pdata->ctx) - task_context_free(edf_pdata->ctx); - rfree(edf_pdata); - edf_sch_set_pdata(task, NULL); - return -EINVAL; -} - -static int schedule_edf_task_running(void *data, struct task *task) -{ - struct edf_task_pdata *edf_pdata = edf_sch_get_pdata(task); - uint32_t flags; - - tr_dbg(&edf_tr, "schedule_edf_task_running()"); - - irq_local_disable(flags); - - task_context_set(edf_pdata->ctx); - task->state = SOF_TASK_STATE_RUNNING; - - irq_local_enable(flags); - - return 0; -} - -static int schedule_edf_task_complete(void *data, struct task *task) -{ - uint32_t flags; - - tr_dbg(&edf_tr, "schedule_edf_task_complete()"); - - irq_local_disable(flags); - - task_complete(task); - - task->state = SOF_TASK_STATE_COMPLETED; - list_item_del(&task->list); - - irq_local_enable(flags); - - return 0; -} - -static int schedule_edf_task_cancel(void *data, struct task *task) -{ - uint32_t flags; - - tr_dbg(&edf_tr, "schedule_edf_task_cancel()"); - - irq_local_disable(flags); - - /* cancel and delete only if queued */ - if (task->state == SOF_TASK_STATE_QUEUED) { - task->state = SOF_TASK_STATE_CANCEL; - list_item_del(&task->list); - } - - irq_local_enable(flags); - - return 0; -} - -static int schedule_edf_task_free(void *data, struct task *task) -{ - struct edf_task_pdata *edf_pdata = edf_sch_get_pdata(task); - uint32_t flags; - - irq_local_disable(flags); - - task->state = SOF_TASK_STATE_FREE; - - task_context_free(edf_pdata->ctx); - edf_pdata->ctx = NULL; - rfree(edf_pdata); - edf_sch_set_pdata(task, NULL); - - irq_local_enable(flags); - - return 0; -} - -int scheduler_init_edf(void) -{ - struct edf_schedule_data *edf_sch; - int ret; - - tr_info(&edf_tr, "edf_scheduler_init()"); - - edf_sch = rzalloc(SOF_MEM_FLAG_KERNEL, - sizeof(*edf_sch)); - if (!edf_sch) { - tr_err(&edf_tr, "scheduler_init_edf(): allocation failed"); - return -ENOMEM; - } - - list_init(&edf_sch->list); - edf_sch->clock = PLATFORM_DEFAULT_CLOCK; - - scheduler_init(SOF_SCHEDULE_EDF, &schedule_edf_ops, edf_sch); - - /* initialize main task context before enabling interrupt */ - task_main_init(); - - /* configure EDF scheduler interrupt */ - ret = interrupt_get_irq(PLATFORM_SCHEDULE_IRQ, - PLATFORM_SCHEDULE_IRQ_NAME); - if (ret < 0) { - free(edf_sch); - return ret; - } - - edf_sch->irq = ret; - interrupt_register(edf_sch->irq, edf_scheduler_run, edf_sch); - interrupt_enable(edf_sch->irq, edf_sch); - - return ret; -} - -static void scheduler_free_edf(void *data, uint32_t flags) -{ - struct edf_schedule_data *edf_sch = data; - uint32_t irq_flags; - - irq_local_disable(irq_flags); - - /* disable and unregister EDF scheduler interrupt */ - interrupt_disable(edf_sch->irq, edf_sch); - interrupt_unregister(edf_sch->irq, edf_sch); - - if (!(flags & SOF_SCHEDULER_FREE_IRQ_ONLY)) - /* free main task context */ - task_main_free(); - - irq_local_enable(irq_flags); -} - -static int scheduler_restore_edf(void *data) -{ - struct edf_schedule_data *edf_sch = data; - uint32_t flags; - - irq_local_disable(flags); - - edf_sch->irq = interrupt_get_irq(PLATFORM_SCHEDULE_IRQ, - PLATFORM_SCHEDULE_IRQ_NAME); - - if (edf_sch->irq < 0) { - tr_err(&edf_tr, "scheduler_restore_edf(): getting irq failed."); - return edf_sch->irq; - } - - interrupt_register(edf_sch->irq, edf_scheduler_run, edf_sch); - interrupt_enable(edf_sch->irq, edf_sch); - - irq_local_enable(flags); - - return 0; -} - -static void schedule_edf(struct edf_schedule_data *edf_sch) -{ - interrupt_set(edf_sch->irq); -} - -static const struct scheduler_ops schedule_edf_ops = { - .schedule_task = schedule_edf_task, - .schedule_task_running = schedule_edf_task_running, - .reschedule_task = NULL, - .schedule_task_cancel = schedule_edf_task_cancel, - .schedule_task_free = schedule_edf_task_free, - .scheduler_free = scheduler_free_edf, - .scheduler_restore = scheduler_restore_edf, -}; diff --git a/src/schedule/task.c b/src/schedule/task.c deleted file mode 100644 index 9a728ba163a8..000000000000 --- a/src/schedule/task.c +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2016 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood - -/* - * Generic audio task. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef enum task_state (*task_main)(void *); - -SOF_DEFINE_REG_UUID(main_task); - -static void sys_module_init(void) -{ - intptr_t *module_init = (intptr_t *)(&_module_init_start); - - for (; module_init < (intptr_t *)&_module_init_end; ++module_init) - ((void(*)(void))(*module_init))(); -} - -static uint64_t task_main_deadline(void *data) -{ - return SOF_TASK_DEADLINE_IDLE; -} - -enum task_state task_main_primary_core(void *data) -{ - struct ipc *ipc = ipc_get(); - - /* main audio processing loop */ - while (1) { - /* sleep until next IPC or DMA */ - wait_for_interrupt(0); - - if (!ipc->pm_prepare_D3) - ipc_send_queued_msg(); - - } - - return SOF_TASK_STATE_COMPLETED; -} - -void task_main_init(void) -{ - struct task **main_task = task_main_get(); - int cpu = cpu_get_id(); - int ret; - task_main main_main = cpu == PLATFORM_PRIMARY_CORE_ID ? - &task_main_primary_core : &task_main_secondary_core; - struct task_ops ops = { - .run = main_main, - .get_deadline = task_main_deadline, - }; - - *main_task = rzalloc(SOF_MEM_FLAG_KERNEL, - sizeof(**main_task)); - if (!*main_task) - panic(SOF_IPC_PANIC_MEM); - - ret = schedule_task_init_edf(*main_task, SOF_UUID(main_task_uuid), - &ops, NULL, cpu, 0); - assert(!ret); -} - -void task_main_free(void) -{ - schedule_task_free(*task_main_get()); -} - -int task_main_start(struct sof *sof) -{ - int ret; - - /* init default audio components */ - sys_comp_init(sof); - - /* init self-registered modules */ - sys_module_init(); - - /* init pipeline position offsets */ - pipeline_posn_init(sof); - - /* let host know DSP boot is complete */ - ret = platform_boot_complete(0); - if (ret < 0) - return ret; - - /* task initialized in edf_scheduler_init */ - schedule_task(*task_main_get(), 0, UINT64_MAX); - - /* something bad happened */ - return -EIO; -} diff --git a/src/schedule/timer_domain.c b/src/schedule/timer_domain.c deleted file mode 100644 index b810a2fea4df..000000000000 --- a/src/schedule/timer_domain.c +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2019 Intel Corporation. All rights reserved. -// -// Author: Tomasz Lauda - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LL_TIMER_SET_OVERHEAD_TICKS 1000 /* overhead/delay to set the tick, in ticks */ - -struct timer_domain { - struct timer *timer; - void *arg[CONFIG_CORE_COUNT]; -}; - -static void timer_report_delay(int id, uint64_t delay) -{ - uint32_t ll_delay_us = (delay * 1000) / - clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1); - - if (delay <= UINT_MAX) - tr_err(&ll_tr, "timer_report_delay(): timer %d delayed by %d uS %d ticks", - id, ll_delay_us, (unsigned int)delay); - else - tr_err(&ll_tr, "timer_report_delay(): timer %d delayed by %d uS, ticks > %u", - id, ll_delay_us, UINT_MAX); - - /* Fix compile error when traces are disabled */ - (void)ll_delay_us; -} - -static int timer_domain_register(struct ll_schedule_domain *domain, - struct task *task, - void (*handler)(void *arg), void *arg) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - int core = cpu_get_id(); - - tr_dbg(&ll_tr, "timer_domain_register()"); - - /* tasks already registered on this core */ - if (timer_domain->arg[core]) - return 0; - - timer_domain->arg[core] = arg; - - tr_info(&ll_tr, "timer_domain_register domain->type %d domain->clk %d domain->ticks_per_ms %d", - domain->type, domain->clk, domain->ticks_per_ms); - - return timer_register(timer_domain->timer, handler, arg); -} - -static int timer_domain_unregister(struct ll_schedule_domain *domain, - struct task *task, uint32_t num_tasks) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - int core = cpu_get_id(); - - if (task) - return 0; - - tr_dbg(&ll_tr, "timer_domain_unregister()"); - - /* tasks still registered on this core */ - if (!timer_domain->arg[core] || num_tasks) - return 0; - - tr_info(&ll_tr, "timer_domain_unregister domain->type %d domain->clk %d", - domain->type, domain->clk); - - timer_unregister(timer_domain->timer, timer_domain->arg[core]); - - timer_domain->arg[core] = NULL; - - return 0; -} - -static void timer_domain_enable(struct ll_schedule_domain *domain, int core) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - - timer_enable(timer_domain->timer, timer_domain->arg[core], core); -} - -static void timer_domain_disable(struct ll_schedule_domain *domain, int core) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - - timer_disable(timer_domain->timer, timer_domain->arg[core], core); -} - -static void timer_domain_set(struct ll_schedule_domain *domain, uint64_t start) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - uint64_t ticks_set; - /* make sure to require for ticks later than tout from now */ - const uint64_t time = platform_timer_get_atomic(timer_domain->timer); - const uint64_t ticks_req = MAX(start, time + LL_TIMER_SET_OVERHEAD_TICKS); - - ticks_set = platform_timer_set(timer_domain->timer, ticks_req); - - tr_dbg(&ll_tr, "timer_domain_set(): ticks_set %u ticks_req %u current %u", - (unsigned int)ticks_set, (unsigned int)ticks_req, - (unsigned int)platform_timer_get_atomic(timer_get())); - - /* Was timer set to the value we requested? If no it means some - * delay occurred and we should report that in error log. - */ - if (ticks_req < ticks_set) - timer_report_delay(timer_domain->timer->id, - ticks_set - ticks_req); - - domain->next_tick = ticks_set; - -} - -static void timer_domain_clear(struct ll_schedule_domain *domain) -{ - struct timer_domain *timer_domain = ll_sch_domain_get_pdata(domain); - - platform_timer_clear(timer_domain->timer); -} - -static bool timer_domain_is_pending(struct ll_schedule_domain *domain, - struct task *task, struct comp_dev **comp) -{ - return task->start <= platform_timer_get_atomic(timer_get()); -} - -static const struct ll_schedule_domain_ops timer_domain_ops = { - .domain_register = timer_domain_register, - .domain_unregister = timer_domain_unregister, - .domain_enable = timer_domain_enable, - .domain_disable = timer_domain_disable, - .domain_set = timer_domain_set, - .domain_clear = timer_domain_clear, - .domain_is_pending = timer_domain_is_pending -}; - -struct ll_schedule_domain *timer_domain_init(struct timer *timer, int clk) -{ - struct ll_schedule_domain *domain; - struct timer_domain *timer_domain; - - domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false, - &timer_domain_ops); - if (!domain) { - r_err(&ll_tr, "timer_domain_init(): domain init failed"); - return NULL; - } - - timer_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*timer_domain)); - if (!timer_domain) { - tr_err(&ll_tr, "timer_domain_init(): allocation failed"); - rfree(domain); - return NULL; - } - timer_domain->timer = timer; - - ll_sch_domain_set_pdata(domain, timer_domain); - - return domain; -} diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e4d18c2f94f8..f0dd442af0c1 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -275,11 +275,6 @@ if (CONFIG_SOC_SERIES_INTEL_ADSP_ACE) ${SOF_PLATFORM_PATH}/ace30/lib/clk.c ) - # SOF core infrastructure - runs on top of Zephyr - zephyr_library_sources( - ${SOF_SRC_PATH}/schedule/zephyr_ll.c - ) - # Sources for virtual heap management zephyr_library_sources( lib/regions_mm.c