-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Add a Stack Allocation API #26999
Comments
With the updates to sys_heap this shouldn't be hard, one of my PRs needs to go in #24714 and then it should be easy. |
For cases where user mode compatibility is not needed, for a stack with requested buffer size N just allocate a blob with size Z_KERNEL_STACK_SIZE_ADJUST(N) and aligned to Z_KERNEL_STACK_OBJ_ALIGN. To get this completely working with user mode the following steps need to be taken:
|
Looking at this again, and we were just chatting about this on Slack. Some additional notes: #29064 - @andrewboie provides the I thought about adding another flag |
I don't think you should be touching anything inside the k_thread object, that is reserved for the kernel. |
That was easy - 15/20 platforms are passing as-is right now with that approach. I think that the stack size might be too small on some 64-bit architectures, so I'll have to increase the default.
I have not done that yet. Currently, I've mainly considered kernel mode threads.
Today I took a stab at the creating a For kernel threads, it should be fine to deallocate the stack with a call to @nashif - I'm hoping to finish this up in the near future. I'll need to come up with a better system than the |
|
This change adds the syscall k_alloc_thread_stack() which dynamically allocates suitably aligned and padded thread stacks. Fixes zephyrproject-rtos#26999 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change adds tests for dynamically allocated thread stacks. Fixes zephyrproject-rtos#26999 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Hello @cfriedt I would like to know the status and goals on this feature, I see you have also #44379 that is a draft PR. My understanding is actually what you have develop permits to reserve an area (looks it is a good idea !) to declare dynamically some stacks, that can be passed to The last point is annoying in my opinion, because this means using dynamic stack we need to implement a kind of controller that will check for tasks created with dynamic stack, verify if they are terminated and then release the corresponding stacks. If I refer to FreeRTOS, this is what is done: when a task is deleted, it is added to a list for termination. Then the idle task periodically check this list and free memory. So my question will be more exactly and more directly: why not having the same behavior in Zephyr, idle task checking terminated tasks to free the dynamically created stacks that are no more used ? Thanks, |
Hi @joelguittet - sorry this issue has not moved very much, but I really don't get very many opportunities to work on this feature these days. Most of this is done in my "spare time". The goal is to be able to dynamically allocate a stack. There have been many attempts with PRs that try and do this sort of thing using a pool of statically allocated stacks. That is technically quite easy. What is not as easy is using arbitrary heap memory for a thread stack. For that, we need a corresponding kernel object as well for when All of that is done in #44379 except for the MMU bits. I have not really had an opportunity to figure those out. Also, from what I understand, it may be a different procedure for different architectures (but I'm not certain of that). There is additional complexity for systems that have an MPU or PMP, because those units can sometimes have insane memory alignment requirements for thread stacks. So yes, there is the typical requirements for stack setup / tear-down, but also additional complexities. I have no ETA for when this will be finished, as it is quite low on my list of priorities at the moment. |
@cfriedt |
Relates to #24714
We want an API such that we can pass in a desired stack size, and a suitably aligned pointer to a stack object will be returned, with all reserved space, alignment, and permissions considerations taken care of.
The text was updated successfully, but these errors were encountered: