Skip to content

schedule: zephyr_ll: implement user/kernel split with init_context()#10818

Open
kv2019i wants to merge 3 commits into
thesofproject:mainfrom
kv2019i:202605-llsched-userkernel-split
Open

schedule: zephyr_ll: implement user/kernel split with init_context()#10818
kv2019i wants to merge 3 commits into
thesofproject:mainfrom
kv2019i:202605-llsched-userkernel-split

Conversation

@kv2019i
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i commented May 28, 2026

A set of changes to SOF schedule.h to allow implementation of clean user/kernel split of the scheduler interface towards the user-space (option build feature) audio pipeline thread.

No functional impact to non-userspace builds.

kv2019i added 3 commits May 28, 2026 15:35
Add an optional method that allow the schedule.h user to get
access to the thread context that will be used for scheduling.
This is critical when the callbacks are run in user-space context
and schedule.h client needs to grant access to objects like locks
to the callback thread.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add new domain ops that are called from privileged context and
are used to set up resources like threads and initialize other
kernel objects.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Use the new scheduler_init_context() and domain_thread_init/free()
interfaces to separate LL scheduler logic into privileged and
unprivileged parts. The latter can be used by the audio pipeline to add,
remove and schedule tasks from the user-space audio thread.

The privileged interfaces are used to set up the scheduler during
firmware boot.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i requested review from Copilot, jsarha and lyakh May 28, 2026 12:48
@kv2019i kv2019i requested a review from softwarecki May 28, 2026 12:49
@kv2019i kv2019i requested review from abonislawski and wjablon1 May 28, 2026 12:49
@kv2019i kv2019i changed the title schedule: zephyr_ll: implement user/kernel split with init_context( schedule: zephyr_ll: implement user/kernel split with init_context() May 28, 2026
@kv2019i
Copy link
Copy Markdown
Collaborator Author

kv2019i commented May 28, 2026

For context, 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

This PR refactors the userspace LL scheduler/domain to introduce a clean kernel/user split. Privileged setup (thread creation, timer init, kernel-object access grants) is moved out of the user-callable domain_register() path into a new kernel-context scheduler_init_context()domain_thread_init() flow, with a matching domain_thread_free() for teardown. Non-userspace builds are unaffected.

Changes:

  • Add optional scheduler_init_context() operation and helper in schedule.h, plus userspace-only domain_thread_init/domain_thread_free ops and inline wrappers in ll_schedule_domain.h.
  • Split zephyr_domain_register_user() into zephyr_domain_thread_init() (privileged setup) and a bookkeeping-only register; move thread teardown/timer stop/watchdog disable into a new zephyr_domain_thread_free(); guard the thread-fn handler invocation against NULL.
  • Implement zephyr_ll_init_context() to drive domain_thread_init() and the mutex grant; call domain_thread_free() from zephyr_ll_scheduler_free(); drop in-line access grants from the schedule hot path.

Reviewed changes

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

File Description
src/include/sof/schedule/schedule.h New optional scheduler_init_context op and dispatch helper.
src/include/sof/schedule/ll_schedule_domain.h New userspace-only domain_thread_init/domain_thread_free ops and wrappers.
src/schedule/zephyr_domain.c Split user register into privileged init + bookkeeping; add thread_free; NULL-handler guard.
src/schedule/zephyr_ll.c Implement zephyr_ll_init_context, wire new ops, call domain_thread_free on scheduler free, drop in-path grants.

Comment thread src/schedule/zephyr_ll.c
tr_err(&ll_tr, "%u tasks are still active!",
sch->n_tasks);

#if CONFIG_SOF_USERSPACE_LL
Comment on lines +449 to +450
int core = cpu_get_id();
struct zephyr_domain_thread *dt = zephyr_domain->domain_thread + core;
Comment thread src/schedule/zephyr_ll.c
Comment on lines 361 to 365
ret = domain_register(sch->ll_domain, task, &schedule_ll_callback, sch);
if (ret < 0)
tr_err(&ll_tr, "cannot register domain %d",
ret);

#if CONFIG_SOF_USERSPACE_LL
k_thread_access_grant(zephyr_domain_thread_tid(sch->ll_domain), sch->lock);

tr_dbg(&ll_tr, "granting access to lock %p for thread %p", sch->lock,
zephyr_domain_thread_tid(sch->ll_domain));
tr_dbg(&ll_tr, "granting access to domain lock %p for thread %p", &sch->ll_domain->lock,
zephyr_domain_thread_tid(sch->ll_domain));
#endif
tr_err(&ll_tr, "cannot register domain %d", ret);

return 0;
Copy link
Copy Markdown
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.

LGTM, some opens from copilot

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.

4 participants