Skip to content

Conversation

@softwarecki
Copy link
Collaborator

@softwarecki softwarecki commented Jul 29, 2025

This pull request introduces initial support for running SOF modules in userspace. Key changes include:

  • DP Scheduler Adaptation: Modify the DP scheduler to operate with CONFIG_USERSPACE enabled. Replace irq_lock with per-core static semaphores for non-privileged threads.

  • Userspace Context: Add userspace_context structure to manage userspace-specific data.

  • Memory Domain: Introduce common_partition memory domain to expose selected SOF components to userspace.

  • Task Allocation: Allocate DP and LL task structures from the module driver heap to ensure compatibility with userspace access.

  • Overlay Configuration: Add userspace-specific overlay config to enable building SOF in userspace mode.

  • Manifest Update: Synchronize man_module_type with reference FW to support new fields like user_mode, domain_rtos, and core_type.

These changes lay the groundwork for executing selected SOF modules in non-privileged mode.

New overlay config created to build SOF with userspace mode enabled.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Allocate task structures from the module's driver heap to enable userspace
access. This change allows the DP task to operate in userspace context.
Also update LL task allocation to use the same heap for consistency,
as the memory release logic is shared and does not differentiate between
heaps.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Copy link

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

This PR introduces initial support for running SOF modules in userspace, enabling selected modules to execute in non-privileged mode. The changes focus on adapting the DP scheduler for userspace compatibility and establishing the necessary memory management infrastructure.

  • Modifies DP scheduler to use semaphores instead of IRQ locks for userspace threads
  • Introduces userspace-specific memory domains and allocation strategies
  • Adds configuration options and overlay support for userspace mode

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
zephyr/lib/userspace_helper.c Implements userspace stack allocation and memory domain management functions
zephyr/include/rtos/userspace_helper.h Defines userspace helper APIs and memory partition macros
zephyr/Kconfig Adds USERSPACE dependencies to heap configuration options
src/schedule/zephyr_dp_schedule.c Major refactoring to support both kernel and userspace thread scheduling
src/include/sof/schedule/dp_schedule.h Updates scheduler API to include thread options parameter
src/include/sof/audio/module_adapter/library/userspace_proxy.h Defines userspace context structure
src/include/module/module/base.h Adds userspace context field to processing module
src/include/sof/audio/component_ext.h Updates component cleanup to use module heap
src/idc/idc.c Converts IDC task allocation to use module heap
src/audio/pipeline/pipeline-schedule.c Updates DP task creation with userspace support
src/audio/buffers/comp_buffer.c Adds memory partition annotations to buffer operations
app/overlays/ptl/userspace_overlay.conf Provides userspace-specific configuration overlay

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator Author

@softwarecki softwarecki left a comment

Choose a reason for hiding this comment

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

Resolved incorrect review comments generated by the AI copilot.

Copy link
Collaborator

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

No showstoppers -- minor comments inline

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

I think this is a good 1st step we can build on.

@lyakh
Copy link
Collaborator

lyakh commented Sep 9, 2025

@softwarecki do I understand it correctly that with this PR it's possible to run a DP module in user space? We really need a CI test for this...

Copy link
Collaborator

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

Bonus if you add the one ifdef USERSPACE but not a blocker.

Introduce the userspace_context structure to store data required by modules
operating in userspace.

Add the common_partition memory domain to share SOF components that need
to be accessible from userspace.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
K_USER option flag is ignored until CONFIG_USERSPACE is not set.
When set, it creates thread in non_priviledged mode.
Without proper support such thread will fail.
This change is required to run DP scheduler with CONFIG_USERSPACE
flag set.

When DP scheduler supports non-privileged modules use of irq_lock is not
allowed. Therefore for this configuration it uses static semaphores one
per core. These could be accesses from user space thread.

New created thread with K_USER option (non-privileged) must be added to
module memory domain to get access to its private memory space.
Additionally allocate scheduler data and task_memory from shared pool.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
@lgirdwood lgirdwood merged commit ae535ea into thesofproject:main Sep 15, 2025
35 of 45 checks passed
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.

6 participants