Skip to content

Commit 24dad1c

Browse files
lrgirdwoclaude
andcommitted
schedule: split the scheduler registration out of schedule.c
scheduler_init() and scheduler_register() allocate and register the schedulers at boot, on the kernel heap or, for the user-space schedulers with user-space LL, on the system user heap, and panic on failure. Move them to src/kernel/schedule/schedule-kernel.c. schedule.c keeps schedule_task_init() and the task info query. scheduler_is_user(), which both parts use, becomes a static inline in sof/schedule/schedule.h. The code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 2d1547b commit 24dad1c

4 files changed

Lines changed: 100 additions & 64 deletions

File tree

‎src/include/sof/schedule/schedule.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ struct schedulers **arch_user_schedulers_get(void);
235235
*/
236236
struct schedulers **arch_user_schedulers_get_for_core(int core);
237237

238+
/**
239+
* @brief Check whether a scheduler type is managed in user space.
240+
* @param[in] type Scheduler type identifier (SOF_SCHEDULE_*).
241+
* @return true for the LL timer and DP schedulers.
242+
*/
243+
static inline bool scheduler_is_user(int type)
244+
{
245+
/*
246+
* currently only LL managed in user-space, but longterm
247+
* goal is to move all audio application level scheduling
248+
* to user-space and only keep Zephyr scheduler logic in
249+
* kernel
250+
*/
251+
return type == SOF_SCHEDULE_LL_TIMER || type == SOF_SCHEDULE_DP;
252+
}
238253
/**
239254
* @brief Lookup scheduler private context data by scheduler type from a schedulers container.
240255
* @param[in] schedulers Schedulers list container.

‎src/kernel/schedule/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
is_zephyr(zephyr)
44
if(zephyr)
55
zephyr_library_sources(
6+
schedule-kernel.c
67
zephyr_domain-kernel.c
78
)
89

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2019 Intel Corporation. All rights reserved.
4+
//
5+
// Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
6+
7+
/* Generic scheduler */
8+
9+
#include <rtos/alloc.h>
10+
#include <sof/lib/cpu.h>
11+
#include <sof/lib/cold.h>
12+
#include <sof/lib/uuid.h>
13+
#include <sof/list.h>
14+
#include <sof/schedule/schedule.h>
15+
#include <rtos/task.h>
16+
#include <ipc/topology.h>
17+
#include <errno.h>
18+
#include <stdint.h>
19+
#include <ipc4/base_fw.h>
20+
21+
LOG_MODULE_DECLARE(schedule, CONFIG_SOF_LOG_LEVEL);
22+
23+
extern struct tr_ctx sch_tr;
24+
25+
/* Kernel part of the generic scheduler: scheduler registration. The rest is in
26+
* src/schedule/schedule.c
27+
*/
28+
29+
__cold static void scheduler_register(struct schedule_data *scheduler)
30+
{
31+
struct schedulers **sch = arch_schedulers_get();
32+
struct k_heap *heap = NULL;
33+
34+
assert_can_be_cold();
35+
36+
if (IS_ENABLED(CONFIG_SOF_USERSPACE_LL) && scheduler_is_user(scheduler->type)) {
37+
sch = arch_user_schedulers_get();
38+
heap = sof_sys_user_heap_get();
39+
}
40+
41+
if (!*sch) {
42+
/* init schedulers list */
43+
*sch = sof_heap_alloc(heap, 0, sizeof(**sch), 0);
44+
if (!*sch) {
45+
tr_err(&sch_tr, "allocation failed");
46+
return;
47+
}
48+
memset(*sch, 0, sizeof(**sch));
49+
list_init(&(*sch)->list);
50+
}
51+
52+
list_item_append(&scheduler->list, &(*sch)->list);
53+
}
54+
55+
__cold void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
56+
{
57+
struct schedule_data *sch;
58+
struct k_heap *heap = NULL;
59+
60+
assert_can_be_cold();
61+
62+
if (IS_ENABLED(CONFIG_SOF_USERSPACE_LL) && scheduler_is_user(type))
63+
heap = sof_sys_user_heap_get();
64+
65+
if (!ops || !ops->schedule_task || !ops->schedule_task_cancel ||
66+
!ops->schedule_task_free)
67+
return;
68+
69+
sch = sof_heap_alloc(heap, SOF_MEM_FLAG_KERNEL, sizeof(*sch), 0);
70+
if (!sch) {
71+
tr_err(&sch_tr, "allocation failed");
72+
sof_panic(SOF_IPC_PANIC_IPC);
73+
}
74+
memset(sch, 0, sizeof(*sch));
75+
list_init(&sch->list);
76+
sch->type = type;
77+
sch->ops = ops;
78+
sch->data = data;
79+
80+
scheduler_register(sch);
81+
}

‎src/schedule/schedule.c‎

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,9 @@ SOF_DEFINE_REG_UUID(schedule);
2525
/* unused with Zephyr, generates no output */
2626
DECLARE_TR_CTX(sch_tr, SOF_UUID(schedule_uuid), LOG_LEVEL_INFO);
2727

28-
static inline bool scheduler_is_user(int type)
29-
{
30-
/*
31-
* currently only LL managed in user-space, but longterm
32-
* goal is to move all audio application level scheduling
33-
* to user-space and only keep Zephyr scheduler logic in
34-
* kernel
35-
*/
36-
return type == SOF_SCHEDULE_LL_TIMER || type == SOF_SCHEDULE_DP;
37-
}
28+
/* Scheduler registration, which runs in kernel mode, is in
29+
* src/kernel/schedule/schedule-kernel.c
30+
*/
3831

3932
int schedule_task_init(struct task *task,
4033
const struct sof_uuid_entry *uid, uint16_t type,
@@ -84,60 +77,6 @@ int schedule_task_init(struct task *task,
8477
return 0;
8578
}
8679

87-
__cold static void scheduler_register(struct schedule_data *scheduler)
88-
{
89-
struct schedulers **sch = arch_schedulers_get();
90-
struct k_heap *heap = NULL;
91-
92-
assert_can_be_cold();
93-
94-
if (IS_ENABLED(CONFIG_SOF_USERSPACE_LL) && scheduler_is_user(scheduler->type)) {
95-
sch = arch_user_schedulers_get();
96-
heap = sof_sys_user_heap_get();
97-
}
98-
99-
if (!*sch) {
100-
/* init schedulers list */
101-
*sch = sof_heap_alloc(heap, 0, sizeof(**sch), 0);
102-
if (!*sch) {
103-
tr_err(&sch_tr, "allocation failed");
104-
return;
105-
}
106-
memset(*sch, 0, sizeof(**sch));
107-
list_init(&(*sch)->list);
108-
}
109-
110-
list_item_append(&scheduler->list, &(*sch)->list);
111-
}
112-
113-
__cold void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
114-
{
115-
struct schedule_data *sch;
116-
struct k_heap *heap = NULL;
117-
118-
assert_can_be_cold();
119-
120-
if (IS_ENABLED(CONFIG_SOF_USERSPACE_LL) && scheduler_is_user(type))
121-
heap = sof_sys_user_heap_get();
122-
123-
if (!ops || !ops->schedule_task || !ops->schedule_task_cancel ||
124-
!ops->schedule_task_free)
125-
return;
126-
127-
sch = sof_heap_alloc(heap, SOF_MEM_FLAG_KERNEL, sizeof(*sch), 0);
128-
if (!sch) {
129-
tr_err(&sch_tr, "allocation failed");
130-
sof_panic(SOF_IPC_PANIC_IPC);
131-
}
132-
memset(sch, 0, sizeof(*sch));
133-
list_init(&sch->list);
134-
sch->type = type;
135-
sch->ops = ops;
136-
sch->data = data;
137-
138-
scheduler_register(sch);
139-
}
140-
14180
/* Locks for the list here should be held by the caller,
14281
* as different schedulers use different locks
14382
*/

0 commit comments

Comments
 (0)