Skip to content

schedule: allocate the scheduler objects with sof_heap_alloc()#10821

Open
kv2019i wants to merge 2 commits into
thesofproject:mainfrom
kv2019i:202605-schedulers-use-heap-alloc
Open

schedule: allocate the scheduler objects with sof_heap_alloc()#10821
kv2019i wants to merge 2 commits into
thesofproject:mainfrom
kv2019i:202605-schedulers-use-heap-alloc

Conversation

@kv2019i

@kv2019i kv2019i commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Ensure the scheduler objects and lists of schedulers are allocated such that they can be used with both kernel and user-space LL scheduler implementations.

The SOF_MEM_FLAG_KERNEL flag is remevod. This flag has been a no-op for a while, and given scheduler list is not always in kernel anymore, it would be highly confusing to keep it.

When CONFIG_SOF_USERSPACE_LL is set, the context of all schedulers is managed in the LL user-space domain.

@kv2019i

kv2019i commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

For context, 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 updates scheduler object allocation so scheduler state can reside in the appropriate heap for both kernel and userspace LL scheduler configurations.

Changes:

  • Replaces rzalloc(SOF_MEM_FLAG_KERNEL, ...) with sof_heap_alloc(...).
  • Selects the LL userspace heap when CONFIG_SOF_USERSPACE_LL is enabled.
  • Adds explicit zero-initialization after allocation to preserve previous rzalloc() behavior.

Comment thread src/schedule/schedule.c Outdated
struct k_heap *heap = NULL;

#ifdef CONFIG_SOF_USERSPACE_LL
heap = sof_sys_user_heap_get();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

whats the split between kernel/user memory for scheduler APIs for LL user ?

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.

@lgirdwood The idea here is the audio schedulers (i.e. SOF schedule.h) are owned by the system LL thread (that can be now in user-space). This means we move other audio schedulers (DP, EDF) also to user-space. Only initial setup (and cleanup) is done from kernel.

Comment thread src/schedule/schedule.c
/* init schedulers list */
*sch = rzalloc(SOF_MEM_FLAG_KERNEL,
sizeof(**sch));
*sch = sof_heap_alloc(heap, 0, sizeof(**sch), 0);

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.

this would mean, that userspace code now effectively has access to all schedulers, also kernel ones

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.

Ack. This does leave a gap with EDF currently, so this is not safe yet for production use. So in short, generic scheduler logic (Zephyr scheduling) in kernel, audio task scheduling in user-space (if SOF built for LL userspace).

@kv2019i kv2019i marked this pull request as draft June 1, 2026 10:59
@kv2019i

kv2019i commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Back to draft. I'll refactor this to follow a more conservative/opt-in approach where scheduler type can be moved (or not moved) one-by-one to user-space.

kv2019i added 2 commits June 22, 2026 14:57
Add support for registering user-space LL tasks, and ability to use
the task scheduling functions from user-space.

The implementation splits scheduler list into kernel and user
portions if SOF is built with CONFIG_SOF_USERSPACE_LL. A scheduler
type can be either maintained in kernel or user, never both. With
this patch, the SOF_SCHEDULE_LL_TIMER is moved to user managed
if CONFIG_SOF_USERSPACE_LL is used.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Ensure the scheduler objects and lists of schedulers are allocated
such that they can be used with both kernel and user-space LL
scheduler implementations.

The SOF_MEM_FLAG_KERNEL flag is removed. This flag has been a no-op
for a while, and given scheduler list is not always in kernel anymore,
it would be highly confusing to keep it.

When CONFIG_SOF_USERSPACE_LL is set, the context of all schedulers
is managed in the LL user-space domain.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i kv2019i force-pushed the 202605-schedulers-use-heap-alloc branch from 1f2b5c4 to 8892eb0 Compare June 22, 2026 11:58
@kv2019i

kv2019i commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

V2:

  • split scheduler state into kernel and user schedulers, allowing to move only LL to userspace and keep EDF still in kernel
  • marking again as ready for review

@kv2019i kv2019i marked this pull request as ready for review June 22, 2026 11:59
Comment thread zephyr/schedule.c
* either holds all or subset of scheduler types.
* Not accessible from user-space threads.
*/
static struct schedulers *_schedulers[CONFIG_CORE_COUNT];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick, we could put a k/u in the names if we have some static objects that are always kernel or always user, just to make sure we can visualize their usage better.

@lyakh lyakh left a comment

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.

so does this mean now, that we don't need to access the global scheduler list from the userspace? Only respective individual schedulers?
But please check if those tiny functions can be inlined, would be much better that way.


assert(schedulers);
assert(task && task->sch);
sch = task->sch;

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.

...at some point would be good to have all these converted to

const struct scheduler_ops *ops = task->sch->ops;

if (ops->x)
    return ops->x(...);

just to reduce the number of arrows that we carry around

Comment thread src/schedule/schedule.c
}

#ifdef CONFIG_SOF_USERSPACE_LL
if (scheduler_is_user(type))

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.

can we use if (IS_ENABLED(CONFIG_SOF_USERSPACE_LL) && scheduler_is_user(type)) here?

Comment thread zephyr/schedule.c
return NULL;
#endif
}
EXPORT_SYMBOL(arch_user_schedulers_get_for_core);

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.

can these be made static inline which would also avoid having to export them?

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