Skip to content

kernel: dynamic: Dynamic userspace stacks improvements #90803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

softwarecki
Copy link
Collaborator

@softwarecki softwarecki commented May 29, 2025

Optimize stack pool usage by add the flags parameter to the z_thread_stack_alloc_pool function and determine the maximum possible stack size based on the size of the reserved memory for stack and the thread type (flags).

The stack size that can be used by a thread depend on its type (kerner/user). For the same stack size, the macros K_KERNEL_STACK_DECLARE and K_THREAD_STACK_DEFINE may reserve different amount of memory. The actual memory required by the user thread stack may be larger than the user-specified size, as it can include additional reserved space.

Fix dynamic user stack allocation by use the K_THREAD_STACK_LEN macro to determine the size of the memory that need to by allocated for the user stack.

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

Minor nit - otherwise, LGTM

@cfriedt
Copy link
Member

cfriedt commented May 30, 2025

@softwarecki - can you please rebase?

Copy link

peter-mitsis
peter-mitsis previously approved these changes Jun 5, 2025
@peter-mitsis
Copy link
Collaborator

I should have checked out the failing checks first before hitting approve.

Add the flags parameter to the z_thread_stack_alloc_pool function.
Determine the maximum possible stack size based on the size of the reserved
memory for stack and the thread type (flags).

The stack size that can be used by a thread depend on its type
(kerner/user). For the same stack size, the macros K_KERNEL_STACK_DECLARE
and K_THREAD_STACK_DEFINE may reserve different amount of memory.

Signed-off-by: Adrian Warecki <[email protected]>
Copy link

sonarqubecloud bot commented Jul 7, 2025

@softwarecki softwarecki requested a review from peter-mitsis July 7, 2025 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants