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
kernel: userspace: aligned memory allocation for dynamic objects #30762
kernel: userspace: aligned memory allocation for dynamic objects #30762
Conversation
c93df28
to
33d439e
Compare
33d439e
to
1825b70
Compare
Looks like there is some potential conflict with #30363 which has been open for a while in preparation for dynamic pthtread stacks (#29029, which has been there for quite a long time too). @dcpleung - I wonder if this ticket could focus more on dynamic kobject creation while #30363 could focus more on allocation. Please let me know if you can think of a better alternative. |
Once your PR is merged, I can rebase this on top of your changes. |
1825b70
to
b5744e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - just a slight change request to have consistent naming. Are any additional tests required?
On Tue, 12 Jan 2021, Christopher Friedt wrote:
+ return z_dynamic_object_aligned_create(1, size);
I think elsewhere that `sizeof(void*)` is used in place of an unspecified alignment because it's a reasonable safe default alignment.
Personally, I'd prefer using 0 when no particular alignment is
necessary. The code will already take care to return memory with the
minimum alignment for all basic types for a given platform in that case.
|
Hm... |
b5744e0
to
0204c01
Compare
Updated the naming and alignment value. |
On Tue, 12 Jan 2021, Daniel Leung wrote:
Hm... `sys_heap_aligned_alloc()` with alignment `0` simply calls `sys_heap_alloc()` which has no minimal alignment (AFAIK). So probably better to pass a value over.
It sure does. sys_heap_alloc() must have minimal alignment for the
platform no matter what. And I know it does.
|
0204c01
to
d096311
Compare
Changed the value to |
On Tue, 12 Jan 2021, Daniel Leung wrote:
Changed the value to `0`. There is another issue where they reported the minimal alignment was 4, but I recalled it as 1, hence the confusion.
Thanks. There is a 1 in `z_thread_malloc()` that could be turned into a 0 as well for consistency.
|
This adds a new z_thread_aligned_alloc() to do memory allocation with required alignment. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This allows allocating dynamic kernel objects with memory alignment requirements. The first candidate is for thread objects where, on some architectures, it must be aligned for saving/restoring registers. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
x86 and x86_64 require certain alignment in the k_thread struct since the buffer to save/restore FPU/SSE registers requires strict alignment. Fixes zephyrproject-rtos#29589 Fixes zephyrproject-rtos#29629 Signed-off-by: Daniel Leung <daniel.leung@intel.com>
d096311
to
950bf7e
Compare
Changed that too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me
This allows allocating dynamic kernel objects with memory alignment
requirements. The first candidate is for thread objects for x86
and x86_64 where saving/restoring SSE/FPU registers require strict
alignment.
Fixes #29589
Fixes #29629