Skip to content

[Userspace LL] zephyr: cpu: turn cpu_get_id() into a system call - #11079

Open
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202608-cpugetid-syscall
Open

[Userspace LL] zephyr: cpu: turn cpu_get_id() into a system call#11079
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202608-cpugetid-syscall

Conversation

@kv2019i

@kv2019i kv2019i commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

cpu_get_id() ultimately reads a privileged special register via arch_proc_id() (e.g. the Xtensa PRID register). When low-atency pipelines run in user-space threads (CONFIG_SOF_USERSPACE_LL), this read is issued from user mode and faults. While many direct usages of cpu_get_id() have been removed from SOF codebase, multiple usages remain. As the remaining usages are mostly on less frequently used code paths (most via cpu_is_me() call, which is used in IPC handling), opt to keep the remaining cpu_get_id() calls and make the function available as a system call.

The system call machinery is gated on CONFIG_SOF_FULL_ZEPHYR_APPLICATION so unit-test builds keep the plain inline definition.

cpu_get_id() ultimately reads a privileged special register via
arch_proc_id() (e.g. the Xtensa PRID register). When low-atency
pipelines run in user-space threads (CONFIG_SOF_USERSPACE_LL), this read
is issued from user mode and faults. While many direct usages of
cpu_get_id() have been removed from SOF codebase, multiple usages
remain. As the remaining usages are mostly on less frequently used code
paths (most via cpu_is_me() call, which is used in IPC handling), opt to
keep the remaining cpu_get_id() calls and make the function available as
a system call.

The system call machinery is gated on CONFIG_SOF_FULL_ZEPHYR_APPLICATION
so unit-test builds keep the plain inline definition.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:33
@kv2019i

kv2019i commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

For context, this is part of #10558

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 makes cpu_get_id() available as a Zephyr system call so user-mode threads (notably CONFIG_SOF_USERSPACE_LL low-latency pipelines) can safely read the current core ID without faulting on privileged register access, while keeping unit-test builds on the existing plain inline implementation via CONFIG_SOF_FULL_ZEPHYR_APPLICATION.

Changes:

  • Adds a userspace verification/marshalling entrypoint for cpu_get_id() (z_vrfy_cpu_get_id() + mrsh include).
  • Updates the Zephyr-side sof/lib/cpu.h to expose cpu_get_id() as __syscall and provide z_impl_cpu_get_id() inline implementations.
  • Hooks the syscall header generation and syscall source into the Zephyr build.

Reviewed changes

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

File Description
zephyr/syscall/cpu.c Adds the syscall verification wrapper for cpu_get_id() and includes the generated marshalling code.
zephyr/include/sof/lib/cpu.h Converts cpu_get_id() into a Zephyr syscall (when CONFIG_SOF_FULL_ZEPHYR_APPLICATION is enabled) and supplies z_impl_cpu_get_id() implementations.
zephyr/CMakeLists.txt Registers the syscall header for generation and compiles the syscall handler when userspace is enabled.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants