Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions posix/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
size_t alignment);
void sof_heap_free(struct k_heap *heap, void *addr);
struct k_heap *sof_sys_heap_get(void);
struct k_heap *sof_sys_user_heap_get(void);

/**
* Calculates length of the null-terminated string.
Expand Down
5 changes: 5 additions & 0 deletions src/platform/library/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ struct k_heap *sof_sys_heap_get(void)
{
return NULL;
}

struct k_heap *sof_sys_user_heap_get(void)
{
return NULL;
}
16 changes: 16 additions & 0 deletions zephyr/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
void sof_heap_free(struct k_heap *heap, void *addr);
struct k_heap *sof_sys_heap_get(void);

/**
* Returns heap object to use for SOF heap allocations
* for audio application code.
*
Comment thread
kv2019i marked this conversation as resolved.
* The returned value may be NULL. This matches with semantics
* of sof_heap_alloc() that allows passing NULL as the 'heap'.
* In this case, the heap implementation will choose the heap to
* use.
*
* The function should not be used for heap allocations for objects that
* are only used in SOF kernel space.
*
* Note: audio modules should use mod_alloc() instead!
*/
struct k_heap *sof_sys_user_heap_get(void);

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

Expand Down
31 changes: 31 additions & 0 deletions zephyr/include/rtos/userspace_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
#define APP_TASK_BSS K_APP_BMEM(common_partition)
#define APP_TASK_DATA K_APP_DMEM(common_partition)

#ifdef CONFIG_SOF_USERSPACE_LL
#define APP_SYSUSER_BSS K_APP_BMEM(sysuser_partition)
#define APP_SYSUSER_DATA K_APP_DMEM(sysuser_partition)
Comment thread
kv2019i marked this conversation as resolved.
#else
#define APP_SYSUSER_BSS
#define APP_SYSUSER_DATA
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do I understand it correctly, that in principle we could just use APP_TASK_BSS and APP_TASK_DATA but the difference is that these only place the affected data in that new partition if CONFIG_SOF_USERSPACE_LL is selected, while APP_TASK_* do that unconditionally? If that my understanding is correct, maybe would be good to explain it somewhere.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does apply, but also APP_SYSUSER objects are NOT available to all user-space threads. The LL user thread has much more access to system resources than e.g. DP modules running in their own user-space thread. So we do not want to use APP_TASK for these objects.

But ack, better to clarify in inline comments.


struct processing_module;
struct userspace_context;

Expand Down Expand Up @@ -137,4 +145,27 @@ static inline int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t th

#endif /* CONFIG_USERSPACE */

#ifdef CONFIG_SOF_USERSPACE_LL

int user_memory_attach_system_user_partition(struct k_mem_domain *dom);
Comment thread
kv2019i marked this conversation as resolved.

#else

/**
* Attach SOF system user memory partition to a memory domain.
* @param dom - memory domain to attach the sysuser partition to.
*
* @return 0 for success, error otherwise.
*
* @note
* Function used only when CONFIG_USERSPACE is set.
* The sysuser partition contains shared objects required by user-space modules.
*/
static inline int user_memory_attach_system_user_partition(struct k_mem_domain *dom)
{
return 0;
}

#endif /* CONFIG_SOF_USERSPACE_LL */

#endif /* __ZEPHYR_LIB_USERSPACE_HELPER_H__ */
11 changes: 11 additions & 0 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sof/lib/notifier.h>
#include <sof/lib/pm_runtime.h>
#include <sof/audio/pipeline.h>
#include <sof/schedule/ll_schedule_domain.h> /* for zephyr_ll_user_heap() */
#include <sof/trace/trace.h>
#include <rtos/symbol.h>
#include <rtos/wait.h>
Expand Down Expand Up @@ -380,6 +381,16 @@ struct k_heap *sof_sys_heap_get(void)
return &sof_heap;
}

struct k_heap *sof_sys_user_heap_get(void)
{
#ifdef CONFIG_SOF_USERSPACE_LL
return zephyr_ll_user_heap();
#else
/* let sof_heap_alloc() pick */
return NULL;
#endif
}

static void *heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes)
{
k_spinlock_key_t key;
Expand Down
8 changes: 8 additions & 0 deletions zephyr/lib/userspace_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ LOG_MODULE_REGISTER(userspace_helper, CONFIG_SOF_LOG_LEVEL);

K_APPMEM_PARTITION_DEFINE(common_partition);

#ifdef CONFIG_SOF_USERSPACE_LL
K_APPMEM_PARTITION_DEFINE(sysuser_partition);
#endif

struct k_heap *module_driver_heap_init(void)
{
struct k_heap *mod_drv_heap = rballoc(SOF_MEM_FLAG_USER, sizeof(*mod_drv_heap));
Expand Down Expand Up @@ -83,6 +87,10 @@ int user_memory_attach_common_partition(struct k_mem_domain *dom)
}

#ifdef CONFIG_SOF_USERSPACE_LL
int user_memory_attach_system_user_partition(struct k_mem_domain *dom)
{
return k_mem_domain_add_partition(dom, &sysuser_partition);
}

int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id)
{
Comment thread
kv2019i marked this conversation as resolved.
Expand Down
Loading