-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
ARC privilege mode stacks waste memory due to alignment requirements #17755
Comments
@andrewboie it's limitted by the ARC MPUv2. For ARC MPUv3, there is no such a problem whose requirement is 32 bytes aligned. For ARC MPUv2, it's very difficult to avoid memory waste even following ARM' approach.
will become
Because
The correct address alignment should be
Then what about stk3 with a size of 16 K? In ARC's current solution ,the privileg stack or stack guard area does not affect the aligment of user stack, If user stack is aligned , the privilege stack/ stack guard is aligned. So, the better solution is improving the hardware, e.g. use MPUv3 or MPUv4 of ARC |
No, the memory sections are sorted in reverse order of object size:
This results in
Please, migrate ARC to use privilege stack generation. |
@andrewboie emm... with the help of linker, that make senses. I will take a look at it and try to catch up with zephyr 2.0 |
It's a kind of optimization. It won't corrupt the system, but a waste of memory. Lower its priority. plan to have a fix in 2.1 release |
@vonhust moved from bug to enhancement. I assume this is still an issue. |
@carlescufi this prevents us from shipping a product on ARC with user mode enabled. This should be treated as a bug. |
Thanks @andrewboie, did not realize. |
We made it much easier to generate privilege mode stacks. There is now a Kconfig option for it, @vonhust do you have time to implement this? It would be great if we could make the ARC stack layout similar to ARM for the V2 MPU. |
Any specific product/project in mind, or is this a general remark? Is the main concern indeed overhead, or a preference to align implementations over different architectures and remove the ARC optimization to dynamically combine/split the user and privilege stacks? |
Please provide detail on how this can be done.
Yes. |
@vonhust @ruuddw from my point of view, the MPU v2 implementation is unoptimized and not suitable for real-world use cases. If you don't want to fix/support it, can we remove MPU v2 support from the kernel entirely? |
The carefull stack sizing I had in mind was to minimize large stacks. I don't challenge that there's an option for optimization, but trying to understand the real-world case you are worrying about. What would be the savings from optimization in real-world cases? The MPU v2 has a minimum region size of 2k so only for user stacks of 4k and larger there would be a saving (of at most the sum of (user stack-2k) for the larger stacks). For resource constrained systems I'd expect not many stacks larger than 2k. For systems with caches & DDR, the extra memory might not be a big deal. |
@ruuddw please think about this for a moment.
What are you talking about? First of all, MPU guard regions are not used, anywhere, on any arch, for stack buffers used by user mode threads. They are not necessary. The user thread gets granted access to the stack buffer by virtue of the MPU region programmed for it. Second, on ARC the privilege mode stack is AFTER the user stack buffer, the layout is MPU guard regions are an optional feature to catch stack overflows in supervisor mode, and on ARC that's only if the CPU is lacking the built-in support for stack checking. These MPU guards are orthogonal to user mode, userspace does not and has never required them. And since the minimum MPU size on ARC is so large hardly anyone is ever going to use it since there is 2k of memory wasted per thread. |
For stacks < 2kbyte I don't see additional dead code in current implementation. The 4k per stack is fully used: 2k for user, 2k for privilege stack. |
@ruuddw privilege mode stacks do not need to be 2k. They do not require an MPU region to cover them. The default is 1024 bytes. At minimum a kilobyte is being wasted per thread. |
ok, we plan to address it for the 2.3 release. |
The current scheme for ARC stacks is as follows:
However, on ARM EM the user mode stacks must be sized and aligned to a power of two since an MPU region must cover them. Adding the privilege stack to the same area results in memory being wasted:
If we use the same privilege stack generation mechanism as ARM, then the stacks can be laid out in memory with no gaps in between:
The text was updated successfully, but these errors were encountered: