Skip to content

Add sof_sys_user_heap_get() and APP_SYSUSER_DATA/BSS macros#10732

Open
kv2019i wants to merge 2 commits intothesofproject:mainfrom
kv2019i:202604-sysheap
Open

Add sof_sys_user_heap_get() and APP_SYSUSER_DATA/BSS macros#10732
kv2019i wants to merge 2 commits intothesofproject:mainfrom
kv2019i:202604-sysheap

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented Apr 28, 2026

Add helpers to allocate heap memory that should be accessible to the LL audio pipelines when they are ran in a user-space thread. Also add userspace helper macros for APP_SYSUSER_DATA/BSS to allow tag static objects such that they are made accessible to the LL userspace threads. These changes have no impact to regular SOF builds where LL audio pipelines are run in kernel threads.

For context, these commits are part of #10558

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds APIs and macros to support running low-latency (LL) audio pipeline code in Zephyr user-space by ensuring certain heaps/static objects are accessible from non-privileged LL threads, without changing behavior for regular (kernel-thread) SOF builds.

Changes:

  • Introduce sof_sys_user_heap_get() (Zephyr implementation returns the LL user heap when enabled).
  • Add a new Zephyr app memory partition (sysuser_partition) plus attach helper for memory domains.
  • Add APP_SYSUSER_DATA/APP_SYSUSER_BSS macros for tagging static objects into the new partition.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
zephyr/lib/userspace_helper.c Defines sysuser_partition and adds a helper to attach it to a mem domain.
zephyr/lib/alloc.c Adds sof_sys_user_heap_get() to select the LL userspace heap when enabled.
zephyr/include/rtos/userspace_helper.h Adds APP_SYSUSER_* macros and declares the new partition attach helper.
zephyr/include/rtos/alloc.h Declares sof_sys_user_heap_get() with a new API comment block.
src/platform/library/lib/alloc.c Adds a stub implementation of sof_sys_user_heap_get() for the library/testbench platform.
posix/include/rtos/alloc.h Adds the sof_sys_user_heap_get() prototype for POSIX builds.

Comment thread zephyr/lib/userspace_helper.c
Comment thread zephyr/include/rtos/alloc.h
Comment thread zephyr/include/rtos/userspace_helper.h
Comment thread zephyr/include/rtos/userspace_helper.h
Copy link
Copy Markdown
Collaborator Author

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Responses to review comments, will upload V2.

Comment thread zephyr/include/rtos/alloc.h
Comment thread zephyr/include/rtos/userspace_helper.h
Comment thread zephyr/include/rtos/userspace_helper.h
Comment thread zephyr/lib/userspace_helper.c
kv2019i added 2 commits April 28, 2026 19:09
Add sof_sys_user_heap_get() to get heap object to use for SOF audio
application heap allocations. When SOF is built with
CONFIG_SOF_USERSPACE_LL, this will return a heap that can be
used for user-space code.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add APP_SYSUSER_BSS() and APP_SYSUSER_DATA() macros to put global
objects to a memory partition that is available to the user context
used to run main SOF application. If SOF is run in kernel space,
these are no-ops, but if CONFIG_SOF_USERSPACE_LL is set, a dedicated
memory partition is used.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented Apr 28, 2026

V2 pushed:

  • addressed copilot review comments, no change to functionality

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants