Skip to content

Commit 3feab14

Browse files
kv2019ilgirdwood
authored andcommitted
schedule: add support for user-space LL scheduler
Add option to build SOF with support for running LL scheduler in user-space. This commit adds initial support in the scheduler and does not yet allow to run full SOF application using the new scheduler configuration, but has enough functionality to run scheduler level tests. No functional change to default build configuration where LL scheduler is run in kernel mode, or to platforms with no userspace support. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 683bb21 commit 3feab14

7 files changed

Lines changed: 427 additions & 31 deletions

File tree

src/include/sof/schedule/ll_schedule_domain.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ struct ll_schedule_domain_ops {
6666
struct ll_schedule_domain {
6767
uint64_t next_tick; /**< ticks just set for next run */
6868
uint64_t new_target_tick; /**< for the next set, used during the reschedule stage */
69-
struct k_spinlock lock; /**< standard lock */
69+
#ifdef CONFIG_SOF_USERSPACE_LL
70+
struct k_mutex *lock; /**< standard lock */
71+
#else
72+
struct k_spinlock lock; /**< standard lock */
73+
#endif
7074
atomic_t total_num_tasks; /**< total number of registered tasks */
7175
atomic_t enabled_cores; /**< number of enabled cores */
7276
uint32_t ticks_per_ms; /**< number of clock ticks per ms */
@@ -93,13 +97,26 @@ static inline struct ll_schedule_domain *dma_domain_get(void)
9397
return sof_get()->platform_dma_domain;
9498
}
9599

100+
#ifdef CONFIG_SOF_USERSPACE_LL
101+
struct task *zephyr_ll_task_alloc(void);
102+
struct k_heap *zephyr_ll_user_heap(void);
103+
void zephyr_ll_user_resources_init(void);
104+
#endif /* CONFIG_SOF_USERSPACE_LL */
105+
96106
static inline struct ll_schedule_domain *domain_init
97107
(int type, int clk, bool synchronous,
98108
const struct ll_schedule_domain_ops *ops)
99109
{
100110
struct ll_schedule_domain *domain;
101111

112+
#ifdef CONFIG_SOF_USERSPACE_LL
113+
domain = sof_heap_alloc(zephyr_ll_user_heap(), SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
114+
sizeof(*domain), sizeof(void *));
115+
if (domain)
116+
memset(domain, 0, sizeof(*domain));
117+
#else
102118
domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*domain));
119+
#endif
103120
if (!domain)
104121
return NULL;
105122
domain->type = type;
@@ -116,7 +133,17 @@ static inline struct ll_schedule_domain *domain_init
116133
domain->next_tick = UINT64_MAX;
117134
domain->new_target_tick = UINT64_MAX;
118135

136+
#ifdef CONFIG_SOF_USERSPACE_LL
137+
/* Allocate mutex dynamically for userspace access */
138+
domain->lock = k_object_alloc(K_OBJ_MUTEX);
139+
if (!domain->lock) {
140+
sof_heap_free(zephyr_ll_user_heap(), domain);
141+
return NULL;
142+
}
143+
k_mutex_init(domain->lock);
144+
#else
119145
k_spinlock_init(&domain->lock);
146+
#endif
120147
atomic_init(&domain->total_num_tasks, 0);
121148
atomic_init(&domain->enabled_cores, 0);
122149

@@ -246,7 +273,11 @@ struct ll_schedule_domain *zephyr_dma_domain_init(struct dma *dma_array,
246273
struct ll_schedule_domain *zephyr_ll_domain(void);
247274
struct ll_schedule_domain *zephyr_domain_init(int clk);
248275
#define timer_domain_init(timer, clk) zephyr_domain_init(clk)
249-
#endif
276+
#ifdef CONFIG_SOF_USERSPACE_LL
277+
struct k_thread *zephyr_domain_thread_tid(struct ll_schedule_domain *domain);
278+
struct k_mem_domain *zephyr_ll_mem_domain(void);
279+
#endif /* CONFIG_SOF_USERSPACE_LL */
280+
#endif /* __ZEPHYR__ */
250281

251282
struct ll_schedule_domain *dma_multi_chan_domain_init(struct dma *dma_array,
252283
uint32_t num_dma, int clk,

src/init/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ __cold static int primary_core_init(int argc, char *argv[], struct sof *sof)
218218
io_perf_monitor_init();
219219
#endif
220220

221+
#if CONFIG_SOF_USERSPACE_LL
222+
zephyr_ll_user_resources_init();
223+
#endif
224+
221225
/* init the platform */
222226
if (platform_init(sof) < 0)
223227
sof_panic(SOF_IPC_PANIC_PLATFORM);

src/schedule/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ zephyr_library_sources_ifdef(CONFIG_ZEPHYR_TWB_SCHEDULER
5454
zephyr_twb_schedule.c
5555
)
5656

57+
zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_LL
58+
zephyr_ll_user.c
59+
)
60+
5761
endif()

0 commit comments

Comments
 (0)