From 3856eabd8db463a53f3905d17e469fcace0edc74 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 21 Nov 2026 16:29:46 +0000 Subject: [PATCH 1/3] schedule: remove the XTOS LL scheduler The XTOS LL scheduler (ll_schedule_xtos.c) is the last scheduler left from the XTOS firmware build, which has been removed: Zephyr is the only supported RTOS. ACP 6.0 is the only platform that still builds it, when the DMA domain is off, which is its default. All other platforms use the Zephyr LL scheduler (zephyr_ll.c). Remove it and enable the DMA domain on ACP 6.0, so ACP 6.0 uses the Zephyr LL scheduler with the Zephyr DMA domain, the configuration that was already supported for it. The platform code needs no change: on Zephyr, scheduler_init_ll(), timer_domain_init() and dma_multi_chan_domain_init() already map to the Zephyr scheduler and domains. The Zephyr LL scheduler and its kernel half are now built for every platform. ACP 6.0 does not build on main (the IPC3 DAI code and the HS DAI driver fail to compile), and its errors are unchanged. The XTOS LL scheduler also registered for the clock change notification, which nothing sends. It was the only receiver, so this is also part of removing the notifier, which is not usable from user space (Phase 5 of the kernel / user-space partition). Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- app/boards/acp_6_0_adsp.conf | 1 + scripts/kernel_user_partition.txt | 1 - src/kernel/schedule/CMakeLists.txt | 8 +- src/schedule/CMakeLists.txt | 21 +- src/schedule/ll_schedule_xtos.c | 818 ----------------------------- 5 files changed, 6 insertions(+), 843 deletions(-) delete mode 100644 src/schedule/ll_schedule_xtos.c diff --git a/app/boards/acp_6_0_adsp.conf b/app/boards/acp_6_0_adsp.conf index b527ea3753a7..9fe8a6e3cefc 100644 --- a/app/boards/acp_6_0_adsp.conf +++ b/app/boards/acp_6_0_adsp.conf @@ -6,6 +6,7 @@ CONFIG_DYNAMIC_INTERRUPTS=y CONFIG_SHARED_INTERRUPTS=n CONFIG_ZEPHYR_LOG=n CONFIG_DMA=y +CONFIG_DMA_DOMAIN=y CONFIG_ZEPHYR_NATIVE_DRIVERS=n CONFIG_AMS=n CONFIG_COMP_SRC=n diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index b8246ad9d479..86444d31c4db 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -27,7 +27,6 @@ src/audio/dai-legacy.c src/audio/host-legacy.c src/schedule/dma_multi_chan_domain.c src/schedule/dma_single_chan_domain.c -src/schedule/ll_schedule_xtos.c src/schedule/zephyr_dma_domain.c # Headers that user-space code may include, checked with --sources: they diff --git a/src/kernel/schedule/CMakeLists.txt b/src/kernel/schedule/CMakeLists.txt index 8711fde99b95..153065893e2f 100644 --- a/src/kernel/schedule/CMakeLists.txt +++ b/src/kernel/schedule/CMakeLists.txt @@ -5,15 +5,9 @@ if(zephyr) zephyr_library_sources( schedule-kernel.c zephyr_domain-kernel.c + zephyr_ll-kernel.c ) - # The kernel part of zephyr_ll.c, built with it, see src/schedule/CMakeLists.txt - if(NOT CONFIG_SOC_ACP_6_0 OR CONFIG_DMA_DOMAIN) - zephyr_library_sources( - zephyr_ll-kernel.c - ) - endif() - zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_LL zephyr_ll_user.c ) diff --git a/src/schedule/CMakeLists.txt b/src/schedule/CMakeLists.txt index ee9ceb32ef9d..3b7da1aef2d5 100644 --- a/src/schedule/CMakeLists.txt +++ b/src/schedule/CMakeLists.txt @@ -18,25 +18,12 @@ if(zephyr) ### Zephyr ### zephyr_library_sources( ${base_files} zephyr_domain.c + zephyr_ll.c ) -if (CONFIG_SOC_ACP_6_0) - # Zephyr DMA domain should only be used with zephyr_ll - if (CONFIG_DMA_DOMAIN) - zephyr_library_sources( - zephyr_ll.c - zephyr_dma_domain.c - ) - else() - zephyr_library_sources( - ll_schedule_xtos.c - ) - endif() -else() - zephyr_library_sources( - zephyr_ll.c - ) -endif() +zephyr_library_sources_ifdef(CONFIG_DMA_DOMAIN + zephyr_dma_domain.c +) if (CONFIG_SOF_USERSPACE_APPLICATION) zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER diff --git a/src/schedule/ll_schedule_xtos.c b/src/schedule/ll_schedule_xtos.c deleted file mode 100644 index 1321dcf89c62..000000000000 --- a/src/schedule/ll_schedule_xtos.c +++ /dev/null @@ -1,818 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2016 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood -// Keyon Jie -// Tomasz Lauda - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -LOG_MODULE_REGISTER(ll_schedule, CONFIG_SOF_LOG_LEVEL); - -SOF_DEFINE_REG_UUID(ll_sched); - -/* unused with Zephyr, generates no output */ -DECLARE_TR_CTX(ll_tr, SOF_UUID(ll_sched_uuid), LOG_LEVEL_INFO); - -/* - * LL Scheduler Task State Transition Diagram - * - * schedule_task() +---------+ - * +------------------| INIT | - * | +---------+ - * | - * v - * +--------+ is_pending() +---------+ is_pending() +----------+ - * | QUEUED |------------->| PENDING |<-------------|RESCHEDULE| - * +--------+ +---------+ +----------+ - * | ^ - * execute()| | - * v | - * +---------+ task_run() | - * | RUNNING |--------------------+ - * +---------+ reschedule - * | - * task_run()| - * completed v - * +---------+ - * |COMPLETED| - * +---------+ - */ - -/* one instance of data allocated per core */ -struct ll_schedule_data { - struct list_item tasks; /* list of ll tasks */ - atomic_t num_tasks; /* number of ll tasks */ -#if CONFIG_PERFORMANCE_COUNTERS__LL_TASKS - struct perf_cnt_data pcd; -#endif - struct ll_schedule_domain *domain; /* scheduling domain */ -}; - -static const struct scheduler_ops schedule_ll_ops; - -#if CONFIG_PERFORMANCE_COUNTERS__LL_TASKS -static void perf_ll_sched_trace(struct perf_cnt_data *pcd, int ignored) -{ - tr_info(&ll_tr, "perf ll_work peak plat %u cpu %u", - (uint32_t)((pcd)->plat_delta_peak), - (uint32_t)((pcd)->cpu_delta_peak)); -} - -static void perf_avg_ll_sched_trace(struct perf_cnt_data *pcd, int ignored) -{ - tr_info(&ll_tr, "perf ll_work cpu avg %u (current peak %u)", - (uint32_t)((pcd)->cpu_delta_sum), - (uint32_t)((pcd)->cpu_delta_peak)); -} - -#endif - -static bool schedule_ll_is_pending(struct ll_schedule_data *sch) -{ - struct ll_schedule_domain *domain = sch->domain; - struct list_item *tlist; - struct task *task; - uint32_t pending_count = 0; - struct comp_dev *sched_comp; - k_spinlock_key_t key; - - key = k_spin_lock(&domain->lock); - - do { - sched_comp = NULL; - - /* mark each valid task as pending */ - list_for_item(tlist, &sch->tasks) { - task = container_of(tlist, struct task, list); - - /* - * only tasks queued or waiting for reschedule are - * pending for scheduling - */ - if (task->state != SOF_TASK_STATE_QUEUED && - task->state != SOF_TASK_STATE_RESCHEDULE) - continue; - - if (domain_is_pending(domain, task, &sched_comp)) { - task->state = SOF_TASK_STATE_PENDING; - pending_count++; - } - } - } while (sched_comp); - - k_spin_unlock(&domain->lock, key); - - return pending_count > 0; -} - -static void schedule_ll_task_update_start(struct ll_schedule_data *sch, - struct task *task) -{ - struct ll_task_pdata *pdata = ll_sch_get_pdata(task); - uint64_t next; - - next = sch->domain->ticks_per_ms * pdata->period / 1000; - - task->start += next; -} - -/* caller should hold the domain lock */ -static void schedule_ll_task_done(struct ll_schedule_data *sch, - struct task *task) -{ - /* Remove from the task list, schedule_task_cancel() won't handle it again */ - list_item_del(&task->list); - - /* unregister the task */ - domain_unregister(sch->domain, task, atomic_sub(&sch->num_tasks, 1) - 1); - - tr_info(&ll_tr, "task complete %p %pU", task, task->uid); - tr_info(&ll_tr, "num_tasks %ld total_num_tasks %ld", - atomic_read(&sch->num_tasks), - atomic_read(&sch->domain->total_num_tasks)); -} - -/* perf measurement windows size 2^x */ -#define CHECKS_WINDOW_SIZE 10 - -#ifdef CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS -static inline void dsp_load_check(struct task *task, uint32_t cycles0, uint32_t cycles1) -{ - uint32_t diff; - - if (cycles1 > cycles0) - diff = cycles1 - cycles0; - else - diff = UINT32_MAX - cycles0 + cycles1; - - task->cycles_sum += diff; - - if (task->cycles_max < diff) - task->cycles_max = diff; - - if (++task->cycles_cnt == 1 << CHECKS_WINDOW_SIZE) { - task->cycles_sum >>= CHECKS_WINDOW_SIZE; - tr_info(&ll_tr, "task %p %pU avg %u, max %u", task, task->uid, - task->cycles_sum, task->cycles_max); - task->cycles_sum = 0; - task->cycles_max = 0; - task->cycles_cnt = 0; - } -} -#endif /* CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS */ - -static void schedule_ll_tasks_execute(struct ll_schedule_data *sch) -{ - struct ll_schedule_domain *domain = sch->domain; - struct list_item *wlist; - struct task *task; - k_spinlock_key_t key; - - /* check each task in the list for pending */ - wlist = sch->tasks.next; - - /* - * Cannot use list_for_item(_safe)() because the task can cancel some - * other tasks, removing them from the list. This happens, e.g. when - * a pipeline task terminates a DMIC task. - */ - while (wlist != &sch->tasks) { -#ifdef CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS - uint32_t cycles0, cycles1; -#endif - task = list_item(wlist, struct task, list); - - if (task->state != SOF_TASK_STATE_PENDING) { - wlist = task->list.next; - continue; - } - - tr_dbg(&ll_tr, "task %p %pU being started...", task, task->uid); - -#ifdef CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS - cycles0 = (uint32_t)sof_cycle_get_64(); -#endif - task->state = SOF_TASK_STATE_RUNNING; - - /* - * The running task might cancel other tasks, which then get - * removed from the list - */ - task->state = task_run(task); - - wlist = task->list.next; - - key = k_spin_lock(&domain->lock); - - /* do we need to reschedule this task */ - if (task->state == SOF_TASK_STATE_COMPLETED) { - schedule_ll_task_done(sch, task); - } else { - /* update task's start time */ - schedule_ll_task_update_start(sch, task); - tr_dbg(&ll_tr, "task %p uid %pU finished, next period ticks %u, domain->next_tick %u", - task, task->uid, (uint32_t)task->start, - (uint32_t)domain->next_tick); - } - - k_spin_unlock(&domain->lock, key); - -#ifdef CONFIG_SCHEDULE_LOG_CYCLE_STATISTICS - cycles1 = (uint32_t)sof_cycle_get_64(); - dsp_load_check(task, cycles0, cycles1); -#endif - } -} - -static void schedule_ll_client_reschedule(struct ll_schedule_data *sch) -{ - struct list_item *tlist; - struct task *task; - struct task *task_take = NULL; - uint64_t next_tick = sch->domain->new_target_tick; - - /* rearm only if there is work to do */ - if (atomic_read(&sch->domain->total_num_tasks)) { - /* traverse to set timer according to the earliest task */ - list_for_item(tlist, &sch->tasks) { - task = container_of(tlist, struct task, list); - - /* only check tasks asked for rescheduling */ - if (task->state != SOF_TASK_STATE_RESCHEDULE) - continue; - - /* update to use the earlier tick */ - if (task->start < next_tick) { - next_tick = task->start; - task_take = task; - } - } - - tr_dbg(&ll_tr, - "schedule_ll_clients_reschedule next_tick %u task_take %p", - (unsigned int)next_tick, task_take); - - /* update the target_tick */ - if (task_take) - sch->domain->new_target_tick = next_tick; - } - -} - -static void schedule_ll_tasks_run(void *data) -{ - struct ll_schedule_data *sch = data; - struct ll_schedule_domain *domain = sch->domain; - k_spinlock_key_t key; - uint32_t flags; - uint32_t core = cpu_get_id(); - - tr_dbg(&ll_tr, "timer interrupt on core %d, at %u, previous next_tick %u", - core, - (unsigned int)sof_cycle_get_64_atomic(), - (unsigned int)domain->next_tick); - - irq_local_disable(flags); - key = k_spin_lock(&domain->lock); - - /* disable domain on current core until tasks are finished */ - domain_disable(domain, core); - - if (!atomic_read(&domain->enabled_cores)) { - /* clear the domain/interrupts */ - domain_clear(domain); - } - - k_spin_unlock(&domain->lock, key); - - perf_cnt_init(&sch->pcd); - - /* run tasks if there are any pending */ - if (schedule_ll_is_pending(sch)) - schedule_ll_tasks_execute(sch); - -#ifdef CONFIG_ZEPHYR_DP_SCHEDULER - scheduler_dp_ll_tick(); -#endif - - perf_cnt_stamp(&sch->pcd, perf_ll_sched_trace, 0 /* ignored */); - perf_cnt_average(&sch->pcd, perf_avg_ll_sched_trace, 0 /* ignored */); - - key = k_spin_lock(&domain->lock); - - /* reset the new_target_tick for the first core */ - if (domain->new_target_tick < sof_cycle_get_64_atomic()) - domain->new_target_tick = UINT64_MAX; - - /* update the new_target_tick according to tasks on current core */ - schedule_ll_client_reschedule(sch); - - /* set the next interrupt according to the new_target_tick */ - if (domain->new_target_tick < domain->next_tick) { - domain_set(domain, domain->new_target_tick); - tr_dbg(&ll_tr, "tasks on core %d done, new_target_tick %u set", - core, (unsigned int)domain->new_target_tick); - } - - /* tasks on current core finished, re-enable domain on it */ - if (atomic_read(&sch->num_tasks)) - domain_enable(domain, core); - - k_spin_unlock(&domain->lock, key); - - irq_local_enable(flags); -} - -static int schedule_ll_domain_set(struct ll_schedule_data *sch, - struct task *task, uint64_t start, - uint64_t period, struct task *reference) -{ - struct ll_schedule_domain *domain = sch->domain; - int core = cpu_get_id(); - uint64_t task_start_us; - uint64_t task_start_ticks; - uint64_t task_start; - uint64_t offset; - k_spinlock_key_t key; - int ret; - - key = k_spin_lock(&domain->lock); - - ret = domain_register(domain, task, &schedule_ll_tasks_run, sch); - if (ret < 0) { - tr_err(&ll_tr, "cannot register domain %d", - ret); - goto done; - } - - tr_dbg(&ll_tr, "task->start %u next_tick %u", - (unsigned int)task->start, - (unsigned int)domain->next_tick); - - task_start_us = period ? period : start; - task_start_ticks = domain->ticks_per_ms * task_start_us / 1000; - task_start = task_start_ticks + sof_cycle_get_64_atomic(); - - if (reference) { - task->start = reference->start; - } else if (domain->next_tick == UINT64_MAX) { - /* first task, set domain */ - domain_set(domain, task_start); - task->start = domain->next_tick; - } else if (!period) { - /* one shot task, set domain if it is earlier */ - task->start = task_start; - if (task->start < domain->next_tick) - domain_set(domain, task_start); - } else if (task_start + task_start_ticks < domain->next_tick) { - /* - * Earlier periodic task, try to make it cadence-aligned with the existed task. - * In this case task_start_ticks is the number of ticks per period. - */ - offset = (domain->next_tick - task_start) % task_start_ticks; - task_start += offset; - domain_set(domain, task_start); - task->start = domain->next_tick; - } else { - /* later periodic task, simplify and cover it by the coming interrupt */ - task->start = domain->next_tick; - } - - /* increase task number of the core */ - atomic_add(&sch->num_tasks, 1); - - /* make sure enable domain on the core */ - domain_enable(domain, core); - - tr_info(&ll_tr, "new added task->start %u at %u", - (unsigned int)task->start, - (unsigned int)sof_cycle_get_64_atomic()); - tr_info(&ll_tr, "num_tasks %ld total_num_tasks %ld", - atomic_read(&sch->num_tasks), - atomic_read(&domain->total_num_tasks)); - -done: - k_spin_unlock(&domain->lock, key); - - return ret; -} - -static void schedule_ll_domain_clear(struct ll_schedule_data *sch, - struct task *task) -{ - struct ll_schedule_domain *domain = sch->domain; - k_spinlock_key_t key; - - key = k_spin_lock(&domain->lock); - - /* - * Decrement the number of tasks on the core. - * Disable domain on the core if needed - */ - if (atomic_sub(&sch->num_tasks, 1) == 1) - domain_disable(domain, cpu_get_id()); - - /* unregister the task */ - domain_unregister(domain, task, atomic_read(&sch->num_tasks)); - - tr_info(&ll_tr, "num_tasks %ld total_num_tasks %ld", - atomic_read(&sch->num_tasks), - atomic_read(&domain->total_num_tasks)); - - k_spin_unlock(&domain->lock, key); -} - -static void schedule_ll_task_insert(struct task *task, struct list_item *tasks) -{ - struct list_item *tlist; - struct task *curr_task; - - /* tasks are added into the list from highest to lowest priority - * and tasks with the same priority should be served on - * a first-come-first-serve basis - */ - list_for_item(tlist, tasks) { - curr_task = container_of(tlist, struct task, list); - if (task->priority < curr_task->priority) { - list_item_append(&task->list, &curr_task->list); - return; - } - } - - /* if task has not been added, means that it has the lowest - * priority and should be added at the end of the list - */ - list_item_append(&task->list, tasks); -} - -static void schedule_ll_task_insert_before(struct task *task, struct task *before) -{ - list_item_append(&task->list, &before->list); -} - -static void schedule_ll_task_insert_after(struct task *task, struct task *after) -{ - list_item_prepend(&task->list, &after->list); -} - -static int schedule_ll_task_common(struct ll_schedule_data *sch, struct task *task, - uint64_t start, uint64_t period, - struct task *reference, bool before) -{ - struct ll_task_pdata *pdata; - struct ll_task_pdata *reg_pdata; - struct list_item *tlist; - struct task *curr_task; - struct task *registrable_task = NULL; - struct pipeline_task *pipe_task; - uint32_t flags; - int ret = 0; - - irq_local_disable(flags); - - /* check if task is already scheduled */ - list_for_item(tlist, &sch->tasks) { - curr_task = container_of(tlist, struct task, list); - - /* keep original start */ - if (curr_task == task) - goto out; - } - - pdata = ll_sch_get_pdata(task); - - tr_info(&ll_tr, "task add %p %pU", task, task->uid); - if (start <= UINT_MAX && period <= UINT_MAX) - tr_info(&ll_tr, "task params pri %d flags %d start %u period %u", - task->priority, task->flags, - (unsigned int)start, (unsigned int)period); - else - tr_info(&ll_tr, "task params pri %d flags %d start or period > %u", - task->priority, task->flags, UINT_MAX); - - pdata->period = period; - - /* for full synchronous domain, calculate ratio and initialize skip_cnt for task */ - if (sch->domain->full_sync) { - pdata->ratio = 1; - pdata->skip_cnt = (uint16_t)SOF_TASK_SKIP_COUNT; - - /* get the registrable task */ - list_for_item(tlist, &sch->tasks) { - curr_task = container_of(tlist, struct task, list); - pipe_task = pipeline_task_get(curr_task); - - /* registrable task found */ - if (pipe_task->registrable) { - registrable_task = curr_task; - break; - } - } - - /* we found a registrable task */ - if (registrable_task) { - reg_pdata = ll_sch_get_pdata(registrable_task); - - /* update ratio for all tasks */ - list_for_item(tlist, &sch->tasks) { - curr_task = container_of(tlist, struct task, list); - pdata = ll_sch_get_pdata(curr_task); - - /* the assumption is that the registrable - * task has the smallest period - */ - if (pdata->period < reg_pdata->period) { - tr_err(&ll_tr, - "registrable task has a period longer than current task"); - ret = -EINVAL; - goto out; - } - - pdata->ratio = period / reg_pdata->period; - } - } - } - - /* insert task into the list */ - if (!reference) - schedule_ll_task_insert(task, &sch->tasks); - else if (before) - schedule_ll_task_insert_before(task, reference); - else - schedule_ll_task_insert_after(task, reference); - task->state = SOF_TASK_STATE_QUEUED; - - /* set schedule domain */ - ret = schedule_ll_domain_set(sch, task, start, period, reference); - if (ret < 0) { - list_item_del(&task->list); - goto out; - } - - -out: - irq_local_enable(flags); - - return ret; -} - -static int schedule_ll_task(void *data, struct task *task, uint64_t start, - uint64_t period) -{ - struct ll_schedule_data *sch = data; - - return schedule_ll_task_common(sch, task, start, period, NULL, false); -} - -static int schedule_ll_task_before(void *data, struct task *task, uint64_t start, - uint64_t period, struct task *before) -{ - struct ll_schedule_data *sch = data; - - return schedule_ll_task_common(sch, task, start, period, before, true); -} - -static int schedule_ll_task_after(void *data, struct task *task, uint64_t start, - uint64_t period, struct task *after) -{ - struct ll_schedule_data *sch = data; - - return schedule_ll_task_common(sch, task, start, period, after, false); -} - -int schedule_task_init_ll(struct task *task, - const struct sof_uuid_entry *uid, uint16_t type, - int16_t priority, enum task_state (*run)(void *data), - void *data, uint16_t core, uint32_t flags) -{ - struct ll_task_pdata *ll_pdata; - int ret; - - ret = schedule_task_init(task, uid, type, priority, run, data, core, - flags); - if (ret < 0) - return ret; - - if (ll_sch_get_pdata(task)) - return -EEXIST; - - ll_pdata = rzalloc(SOF_MEM_FLAG_KERNEL, - sizeof(*ll_pdata)); - - if (!ll_pdata) { - tr_err(&ll_tr, "alloc failed"); - return -ENOMEM; - } - - ll_sch_set_pdata(task, ll_pdata); - - return 0; -} - -static int schedule_ll_task_free(void *data, struct task *task) -{ - struct ll_task_pdata *ll_pdata; - uint32_t flags; - - irq_local_disable(flags); - - /* release the resources */ - task->state = SOF_TASK_STATE_FREE; - ll_pdata = ll_sch_get_pdata(task); - rfree(ll_pdata); - ll_sch_set_pdata(task, NULL); - - irq_local_enable(flags); - - return 0; -} - -static int schedule_ll_task_cancel(void *data, struct task *task) -{ - struct ll_schedule_data *sch = data; - struct list_item *tlist; - struct task *curr_task; - uint32_t flags; - - irq_local_disable(flags); - - tr_info(&ll_tr, "task cancel %p %pU", task, task->uid); - - /* check to see if we are scheduled */ - list_for_item(tlist, &sch->tasks) { - curr_task = container_of(tlist, struct task, list); - - /* found it */ - if (curr_task == task) { - schedule_ll_domain_clear(sch, task); - - /* remove work from list */ - task->state = SOF_TASK_STATE_CANCEL; - list_item_del(&task->list); - - break; - } - } - - irq_local_enable(flags); - - return 0; -} - -#if CONFIG_SCHEDULE_LL_NO_RESCHEDULE_TASK -/* As a null function pointer */ -#define reschedule_ll_task ((void*)0) - -#else -static int reschedule_ll_task(void *data, struct task *task, uint64_t start) -{ - struct ll_schedule_data *sch = data; - struct list_item *tlist; - struct task *curr_task; - uint32_t flags; - uint64_t time; - - time = sch->domain->ticks_per_ms * start / 1000; - - time += sof_cycle_get_64_atomic(); - - irq_local_disable(flags); - - /* check to see if we are already scheduled */ - list_for_item(tlist, &sch->tasks) { - curr_task = container_of(tlist, struct task, list); - /* found it */ - if (curr_task == task) { - /* set start time */ - task->start = time; - goto out; - } - } - - tr_err(&ll_tr, "task not found"); - -out: - - irq_local_enable(flags); - - return 0; -} -#endif /* CONFIG_SCHEDULE_LL_NO_RESCHEDULE_TASK */ - -#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY -static void scheduler_free_ll(void *data, uint32_t flags) -{ - struct ll_schedule_data *sch = data; - uint32_t irq_flags; - - irq_local_disable(irq_flags); - - domain_unregister(sch->domain, NULL, 0); - - if (!(flags & SOF_SCHEDULER_FREE_IRQ_ONLY)) - notifier_unregister(sch, NULL, - NOTIFIER_CLK_CHANGE_ID(sch->domain->clk)); - - irq_local_enable(irq_flags); -} -#endif /* CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY */ - -static void ll_scheduler_recalculate_tasks(struct ll_schedule_data *sch, - struct clock_notify_data *clk_data) -{ - uint64_t current = sof_cycle_get_64_atomic(); - struct list_item *tlist; - struct task *task; - uint64_t delta_ms; - - list_for_item(tlist, &sch->tasks) { - task = container_of(tlist, struct task, list); - delta_ms = (task->start - current) / - clk_data->old_ticks_per_msec; - - task->start = delta_ms ? - current + sch->domain->ticks_per_ms * delta_ms : - current + (sch->domain->ticks_per_ms >> 3); - } -} - -static void ll_scheduler_notify(void *arg, enum notify_id type, void *data) -{ - struct ll_schedule_data *sch = arg; - struct clock_notify_data *clk_data = data; - uint32_t flags; - - irq_local_disable(flags); - - /* we need to recalculate tasks when clock frequency changes */ - if (clk_data->message == CLOCK_NOTIFY_POST) { - sch->domain->ticks_per_ms = k_ms_to_cyc_ceil64(1); - ll_scheduler_recalculate_tasks(sch, clk_data); - } - - irq_local_enable(flags); -} - -int scheduler_init_ll(struct ll_schedule_domain *domain) -{ - struct ll_schedule_data *sch; - - /* initialize scheduler private data */ - sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); - if (!sch) { - tr_err(&ll_tr, "allocation failed"); - return -ENOMEM; - } - list_init(&sch->tasks); - atomic_init(&sch->num_tasks, 0); - sch->domain = domain; - - /* notification of clock changes */ - notifier_register(sch, NULL, NOTIFIER_CLK_CHANGE_ID(domain->clk), ll_scheduler_notify); - - scheduler_init(domain->type, &schedule_ll_ops, sch); - - - return 0; -} - -static const struct scheduler_ops schedule_ll_ops = { - .schedule_task = schedule_ll_task, - .schedule_task_before = schedule_ll_task_before, - .schedule_task_after = schedule_ll_task_after, - .schedule_task_free = schedule_ll_task_free, - .schedule_task_cancel = schedule_ll_task_cancel, - .reschedule_task = reschedule_ll_task, -#if CONFIG_SOF_BOOT_TEST_STANDALONE || CONFIG_LIBRARY - .scheduler_free = scheduler_free_ll, -#endif - .schedule_task_running = NULL, -}; From da0def000ce0479ef830cb5037e144071faba340 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 21 Nov 2026 13:28:16 +0000 Subject: [PATCH 2/3] clk: remove the notification fields from struct clock_info Every platform sets notification_id and notification_mask in its clock information, to NOTIFIER_ID_CPU_FREQ and its core mask, but nothing reads them: no clock driver sends a clock change notification. Remove the fields, and the notifier.h includes that only the clock tables needed. The generic clock code (src/kernel/lib/clk.c) included notifier.h too, left from when clock_set_freq() sent the notification, so drop it there as well. This is part of removing the notifier, which is not usable from user space (Phase 5 of the kernel / user-space partition). No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/clk.h | 2 -- src/kernel/lib/clk.c | 1 - src/kernel/platform/amd/acp_7_0/lib/clk.c | 4 ---- src/kernel/platform/amd/acp_7_x/lib/clk.c | 4 ---- src/kernel/platform/amd/rembrandt/lib/clk.c | 3 --- src/kernel/platform/imx8/lib/clk.c | 3 --- src/kernel/platform/imx8m/lib/clk.c | 3 --- src/kernel/platform/imx8m_cm7/lib/clk.c | 3 --- src/kernel/platform/imx8ulp/lib/clk.c | 3 --- src/kernel/platform/imx93_a55/lib/clk.c | 3 --- src/kernel/platform/imx95/lib/clk.c | 3 --- src/kernel/platform/mtk/platform.c | 3 --- src/kernel/platform/posix/posix.c | 2 -- zephyr/include/rtos/clk.h | 2 -- zephyr/lib/clk.c | 3 --- 15 files changed, 42 deletions(-) diff --git a/posix/include/rtos/clk.h b/posix/include/rtos/clk.h index e9a36796bc42..4439686ee01a 100644 --- a/posix/include/rtos/clk.h +++ b/posix/include/rtos/clk.h @@ -39,8 +39,6 @@ struct clock_info { uint32_t default_freq_idx; uint32_t current_freq_idx; uint32_t lowest_freq_idx; /* lowest possible clock */ - uint32_t notification_id; - uint32_t notification_mask; /* persistent change clock value in active state, caller must hold clk_lock */ int (*set_freq)(int clock, int freq_idx); diff --git a/src/kernel/lib/clk.c b/src/kernel/lib/clk.c index d1349557d17a..9319450b7091 100644 --- a/src/kernel/lib/clk.c +++ b/src/kernel/lib/clk.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/src/kernel/platform/amd/acp_7_0/lib/clk.c b/src/kernel/platform/amd/acp_7_0/lib/clk.c index 6c1ecb37fda3..a1fdc35285ca 100644 --- a/src/kernel/platform/amd/acp_7_0/lib/clk.c +++ b/src/kernel/platform/amd/acp_7_0/lib/clk.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -25,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -477,8 +475,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/amd/acp_7_x/lib/clk.c b/src/kernel/platform/amd/acp_7_x/lib/clk.c index 14e212425192..d11471988d66 100644 --- a/src/kernel/platform/amd/acp_7_x/lib/clk.c +++ b/src/kernel/platform/amd/acp_7_x/lib/clk.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -175,8 +173,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/amd/rembrandt/lib/clk.c b/src/kernel/platform/amd/rembrandt/lib/clk.c index 8f2529f21d57..15796ed9079d 100644 --- a/src/kernel/platform/amd/rembrandt/lib/clk.c +++ b/src/kernel/platform/amd/rembrandt/lib/clk.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -134,8 +133,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx8/lib/clk.c b/src/kernel/platform/imx8/lib/clk.c index 4eeb2dac3357..ff097ddd9f2f 100644 --- a/src/kernel/platform/imx8/lib/clk.c +++ b/src/kernel/platform/imx8/lib/clk.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -38,8 +37,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx8m/lib/clk.c b/src/kernel/platform/imx8m/lib/clk.c index 573858873ef8..105d48c608b0 100644 --- a/src/kernel/platform/imx8m/lib/clk.c +++ b/src/kernel/platform/imx8m/lib/clk.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -33,8 +32,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx8m_cm7/lib/clk.c b/src/kernel/platform/imx8m_cm7/lib/clk.c index 9c2bcd70f63f..c2fc923dd264 100644 --- a/src/kernel/platform/imx8m_cm7/lib/clk.c +++ b/src/kernel/platform/imx8m_cm7/lib/clk.c @@ -4,7 +4,6 @@ */ #include -#include static const struct freq_table platform_cpu_freq[] = { { @@ -27,8 +26,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx8ulp/lib/clk.c b/src/kernel/platform/imx8ulp/lib/clk.c index 3bdc873eacf9..6e7342515216 100644 --- a/src/kernel/platform/imx8ulp/lib/clk.c +++ b/src/kernel/platform/imx8ulp/lib/clk.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -33,8 +32,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx93_a55/lib/clk.c b/src/kernel/platform/imx93_a55/lib/clk.c index 2fcd3d7814ab..4b7c16509dce 100644 --- a/src/kernel/platform/imx93_a55/lib/clk.c +++ b/src/kernel/platform/imx93_a55/lib/clk.c @@ -4,7 +4,6 @@ */ #include -#include static const struct freq_table platform_cpu_freq[] = { { CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, @@ -38,8 +37,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/imx95/lib/clk.c b/src/kernel/platform/imx95/lib/clk.c index 8f9e2763057d..7cf60544030e 100644 --- a/src/kernel/platform/imx95/lib/clk.c +++ b/src/kernel/platform/imx95/lib/clk.c @@ -4,7 +4,6 @@ */ #include -#include static const struct freq_table platform_cpu_freq[] = { { @@ -27,8 +26,6 @@ void platform_clock_init(struct sof *sof) .freqs = platform_cpu_freq, .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = NULL, }; } diff --git a/src/kernel/platform/mtk/platform.c b/src/kernel/platform/mtk/platform.c index 7d22531df130..68122e15708f 100644 --- a/src/kernel/platform/mtk/platform.c +++ b/src/kernel/platform/mtk/platform.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -209,8 +208,6 @@ void clocks_init(struct sof *sof) static struct clock_info clks[] = { { .freqs_num = ARRAY_SIZE(freqs), .freqs = freqs, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(0), .set_freq = set_cpuclk, }, }; sof->clocks = clks; diff --git a/src/kernel/platform/posix/posix.c b/src/kernel/platform/posix/posix.c index 859ce6744789..0b0ff92bfa2a 100644 --- a/src/kernel/platform/posix/posix.c +++ b/src/kernel/platform/posix/posix.c @@ -60,8 +60,6 @@ static void posix_clk_init(struct sof *sof) { .freqs_num = ARRAY_SIZE(cpu_freq), .freqs = cpu_freq, - .notification_id = 0, - .notification_mask = 1, }, }; diff --git a/zephyr/include/rtos/clk.h b/zephyr/include/rtos/clk.h index 20cd6a1ac87c..65bb83c1bc87 100644 --- a/zephyr/include/rtos/clk.h +++ b/zephyr/include/rtos/clk.h @@ -49,8 +49,6 @@ struct clock_info { uint32_t default_freq_idx; uint32_t current_freq_idx; uint32_t lowest_freq_idx; /* lowest possible clock */ - uint32_t notification_id; - uint32_t notification_mask; /* persistent change clock value in active state, caller must hold clk_lock */ int (*set_freq)(int clock, int freq_idx); diff --git a/zephyr/lib/clk.c b/zephyr/lib/clk.c index 5aa3ba191236..f3748b81d698 100644 --- a/zephyr/lib/clk.c +++ b/zephyr/lib/clk.c @@ -4,7 +4,6 @@ // // Author: Janusz Jankowski -#include #include #include #include @@ -43,8 +42,6 @@ void platform_clock_init(struct sof *sof) .default_freq_idx = CPU_DEFAULT_IDX, .current_freq_idx = CPU_DEFAULT_IDX, .lowest_freq_idx = platform_lowest_clock, - .notification_id = NOTIFIER_ID_CPU_FREQ, - .notification_mask = NOTIFIER_TARGET_CORE_MASK(i), .set_freq = select_cpu_freq, }; } From 08f6161765b1011962520a21deb3472028f24f0e Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 21 Nov 2026 13:28:47 +0000 Subject: [PATCH 3/3] notifier: remove the clock change notification Nothing sends NOTIFIER_ID_CPU_FREQ or NOTIFIER_ID_SSP_FREQ, and nothing registers for them any more. Remove the event IDs, NOTIFIER_CLK_CHANGE_ID(), and the notification payload struct clock_notify_data with its CLOCK_NOTIFY_PRE and CLOCK_NOTIFY_POST messages. The notifier checked and walked the IDs from NOTIFIER_ID_CPU_FREQ, which was 0. It now starts from 0. The other IDs are renumbered; they are internal to the firmware. This is part of removing the notifier, which is not usable from user space (Phase 5 of the kernel / user-space partition). Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/clk.h | 11 ----------- src/include/sof/lib/notifier.h | 9 --------- src/lib/notifier.c | 8 ++++---- zephyr/include/rtos/clk.h | 13 +------------ 4 files changed, 5 insertions(+), 36 deletions(-) diff --git a/posix/include/rtos/clk.h b/posix/include/rtos/clk.h index 4439686ee01a..5ccea34b7981 100644 --- a/posix/include/rtos/clk.h +++ b/posix/include/rtos/clk.h @@ -17,17 +17,6 @@ struct timer; -#define CLOCK_NOTIFY_PRE 0 -#define CLOCK_NOTIFY_POST 1 - -struct clock_notify_data { - uint32_t old_freq; - uint32_t old_ticks_per_msec; - uint32_t freq; - uint32_t ticks_per_msec; - uint32_t message; -}; - struct freq_table { uint32_t freq; uint32_t ticks_per_msec; diff --git a/src/include/sof/lib/notifier.h b/src/include/sof/lib/notifier.h index e5413a512cb4..bee6e304653c 100644 --- a/src/include/sof/lib/notifier.h +++ b/src/include/sof/lib/notifier.h @@ -20,8 +20,6 @@ #define NOTIFIER_TARGET_CORE_ALL_MASK 0xFFFFFFFF enum notify_id { - NOTIFIER_ID_CPU_FREQ = 0, /* struct clock_notify_data * */ - NOTIFIER_ID_SSP_FREQ, /* struct clock_notify_data * */ NOTIFIER_ID_KPB_CLIENT_EVT, /* struct kpb_event_data * */ NOTIFIER_ID_DMA_DOMAIN_CHANGE, /* struct dma_chan_data * */ NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */ @@ -44,13 +42,6 @@ struct notify_data { void *data; }; -#ifdef CLK_SSP -#define NOTIFIER_CLK_CHANGE_ID(clk) \ - ((clk) == CLK_SSP ? NOTIFIER_ID_SSP_FREQ : NOTIFIER_ID_CPU_FREQ) -#else -#define NOTIFIER_CLK_CHANGE_ID(clk) NOTIFIER_ID_CPU_FREQ -#endif - struct notify **arch_notify_get(void); typedef void (*notifier_callback_t)(void *receiver_data, enum notify_id event_type, diff --git a/src/lib/notifier.c b/src/lib/notifier.c index cbc9ff5cd7f8..42e9e50ef66b 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -44,7 +44,7 @@ int notifier_register(void *receiver, void *caller, enum notify_id type, k_spinlock_key_t key; int ret = 0; - assert(type >= NOTIFIER_ID_CPU_FREQ && type < NOTIFIER_ID_COUNT); + assert((unsigned int)type < NOTIFIER_ID_COUNT); key = k_spin_lock(¬ify->lock); @@ -77,7 +77,7 @@ void notifier_unregister(void *receiver, void *caller, enum notify_id type) struct callback_handle *handle; k_spinlock_key_t key; - assert(type >= NOTIFIER_ID_CPU_FREQ && type < NOTIFIER_ID_COUNT); + assert((unsigned int)type < NOTIFIER_ID_COUNT); key = k_spin_lock(¬ify->lock); @@ -110,7 +110,7 @@ void notifier_unregister_all(void *receiver, void *caller) { int i; - for (i = NOTIFIER_ID_CPU_FREQ; i < NOTIFIER_ID_COUNT; i++) + for (i = 0; i < NOTIFIER_ID_COUNT; i++) notifier_unregister(receiver, caller, i); } @@ -193,7 +193,7 @@ __cold void init_system_notify(struct sof *sof) } k_spinlock_init(&(*notify)->lock); - for (i = NOTIFIER_ID_CPU_FREQ; i < NOTIFIER_ID_COUNT; i++) + for (i = 0; i < NOTIFIER_ID_COUNT; i++) list_init(&(*notify)->list[i]); if (cpu_get_id() == PLATFORM_PRIMARY_CORE_ID) diff --git a/zephyr/include/rtos/clk.h b/zephyr/include/rtos/clk.h index 65bb83c1bc87..a54de620bc03 100644 --- a/zephyr/include/rtos/clk.h +++ b/zephyr/include/rtos/clk.h @@ -5,7 +5,7 @@ /** * @file rtos/clk.h - * @brief RTOS DSP clock frequency management and notification interfaces. + * @brief RTOS DSP clock frequency management interfaces. * @ingroup rtos_api */ @@ -27,17 +27,6 @@ struct timer; -#define CLOCK_NOTIFY_PRE 0 -#define CLOCK_NOTIFY_POST 1 - -struct clock_notify_data { - uint32_t old_freq; - uint32_t old_ticks_per_msec; - uint32_t freq; - uint32_t ticks_per_msec; - uint32_t message; -}; - struct freq_table { uint32_t freq; uint32_t ticks_per_msec;