Skip to content

Commit 7ce46cc

Browse files
committed
zephyr: move threads to use SOF heap
Some Zephyr heap allocations use per-thread heap pointers. By default those allocations end up using the default Zephyr system heap, which is rather small in the SOF case. To overcome that assign the common SOF heap to EDF and IDC threads. Signed-off-by: Guennadi Liakhovetski <[email protected]>
1 parent 1fd682f commit 7ce46cc

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/idc/zephyr_idc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ void idc_init_thread(void)
185185

186186
k_p4wq_enable_static_thread(q_zephyr_idc + cpu,
187187
_p4threads_q_zephyr_idc + cpu, BIT(cpu));
188+
/*
189+
* Assign SOF system heap to the IDC thread. Otherwise by default it
190+
* uses the Zephyr heap for DP stack allocation
191+
*/
192+
k_thread_heap_assign(_p4threads_q_zephyr_idc + cpu, sof_sys_heap_get());
188193
}
189194

190195
#endif /* CONFIG_MULTICORE */

zephyr/edf_schedule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Author: Bartosz Kokoszko <[email protected]>
66

77
#include <sof/audio/component.h>
8+
#include <rtos/alloc.h>
89
#include <rtos/task.h>
910
#include <stdint.h>
1011
#include <sof/schedule/edf_schedule.h>
@@ -111,6 +112,7 @@ int scheduler_init_edf(void)
111112

112113
k_thread_suspend(thread);
113114

115+
k_thread_heap_assign(thread, sof_sys_heap_get());
114116
k_thread_cpu_mask_clear(thread);
115117
k_thread_cpu_mask_enable(thread, PLATFORM_PRIMARY_CORE_ID);
116118
k_thread_name_set(thread, "edf_workq");

zephyr/include/rtos/alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void l3_heap_save(void);
123123
void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
124124
size_t alignment);
125125
void sof_heap_free(struct k_heap *heap, void *addr);
126+
struct k_heap *sof_sys_heap_get(void);
126127

127128
/* TODO: remove - debug only - only needed for linking */
128129
static inline void heap_trace_all(int force) {}

zephyr/lib/alloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ SYS_INIT(virtual_heap_init, POST_KERNEL, 1);
370370

371371
#endif /* CONFIG_VIRTUAL_HEAP */
372372

373+
struct k_heap *sof_sys_heap_get(void)
374+
{
375+
return &sof_heap;
376+
}
377+
373378
static void *heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes)
374379
{
375380
k_spinlock_key_t key;

0 commit comments

Comments
 (0)