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
ArmV7-M mpu sub region alignment #17337
Comments
@ioannisg could you please share some idea for this problem? thanks |
I am trying to understand this, @wentongwu thanks for looking at options for improvement.
Which systems are those?
|
the system is ARMv7-M, and what I mean users want to use sub region size granularity(that's power of two alignment) to do alignment to avoid large memory hole(for above example)which can be seen in the map file, sorry I have wrong description, I mean we should disable CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT in linker script, but when configure mpu, the size will be power of two alignment. For above example, if 64K granularity to do alignment in linker script, only another almost 64K will be wasted. And for the mpu configuration, 512k -> region1 and 64k -> region2 have same mpu attribute. @ioannisg |
Alright, thanks for explaining. Now, I also confused; what do you mean by sub-region? |
Ok, it is, but for example somehow we can know the size of .text section, 512k+4B, with current code and CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT enabled, the size of .text section in RAM (suppose only RAM) will be 1M.
But if with below code, the size of .text section will be 512k+64k(MPU_SUB_REGION_SIZE), that saved memory.
For MPU configuration, 512k will be in MPU region1 and 64k will be in MPU region2 as one sub region of region2 which disable all the other sub regions. And the disabled sub regions of region2 can also be part of regionN(N>2) and will be functional in regionN. |
Alright, now I understand what you want to do. So, this means that for a data region (e.g. a user thread stack, app mem partition, etc) you might need to waste 2 MPU regions at run-time, to make this work. We cannot afford this, sorry. We need to use as few regions as possible. |
But now I started thinking more of it: could we use sub-region feature to shrink the MPU regions? |
Yes, you are right. But we just use this in the linker script to avoid memory waste in linking time. For stack and memory partition, we still use CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE. |
Alright. So we are saving space in code, not SRAM, right? |
Sorry for the late response. |
@ioannisg I created a example for this alignment proposal, hope that can show my idea more. Thanks. |
when enable CONFIG_CUSTOM_SECTION_ALIGN, it need less alignment memory for image rom region. But that needs carefully configure MPU region and sub-regions(ARMv7-M) to cover this feature. Fixes: zephyrproject-rtos#17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
add custom align size for code relocation to reduce alignment memory wasting. Fixes: zephyrproject-rtos#17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
when enable CONFIG_CUSTOM_SECTION_ALIGN, it need less alignment memory for image rom region. But that needs carefully configure MPU region and sub-regions(ARMv7-M) to cover this feature. Fixes: #17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
add custom align size for code relocation to reduce alignment memory wasting. Fixes: #17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
when enable CONFIG_CUSTOM_SECTION_ALIGN, it need less alignment memory for image rom region. But that needs carefully configure MPU region and sub-regions(ARMv7-M) to cover this feature. Fixes: zephyrproject-rtos#17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
add custom align size for code relocation to reduce alignment memory wasting. Fixes: zephyrproject-rtos#17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
when enable CONFIG_CUSTOM_SECTION_ALIGN, it need less alignment memory for image rom region. But that needs carefully configure MPU region and sub-regions(ARMv7-M) to cover this feature. Fixes: #17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
add custom align size for code relocation to reduce alignment memory wasting. Fixes: #17337. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
for systems that have mpu sub region support, users want to use sub region size granularity to do alignment instead of power of two to avoid wasting much memory, for example code size is about 512K + 4Byte, if power of two alignment enabled, another almost 512K will be wasted. So for that case, we should disable CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT, and if configure CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE to mpu sub region size, the size of thread stack will be very large because of thread stack align with CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE, so my suggestion is to add one more Kconfig(like CONFIG_ARM_MPU_SUB_REGION_MIN_ALIGN_AND_SIZE) to configure mpu sub region size.
The text was updated successfully, but these errors were encountered: