-
Notifications
You must be signed in to change notification settings - Fork 3k
Update to 2-region model for HEAP and Stack Memory #9571
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
Conversation
@mprse, thank you for your changes. |
Adding @ARMmbed/team-nuvoton and @ARMmbed/team-renesas for review |
platform/mbed_retarget.cpp
Outdated
@@ -904,21 +904,68 @@ extern "C" long PREFIX(_flen)(FILEHANDLE fh) | |||
return size; | |||
} | |||
|
|||
extern "C" char Image$$RW_IRAM1$$ZI$$Limit[]; | |||
#if defined(TARGET_NUMAKER_IOT_M487) || defined(TARGET_NUMAKER_PFM_M2351) || defined(TARGET_NUMAKER_PFM_M453) || defined(TARGET_NUMAKER_PFM_M487) || defined(TARGET_NUMAKER_PFM_NANO130) || defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_GR_LYCHEE) || defined(TARGET_RZ_A1H) || defined(TARGET_RZ_A1XX) |
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.
All Nuvoton targets adopt two-region model, so this list of Nuvoton target defines can simplify to TARGET_NUVOTON
.
platform/mbed_retarget.cpp
Outdated
r.heap_base = zi_limit; | ||
r.heap_limit = sp_limit; | ||
r.heap_base = (uint32_t)HEAP_BASE; | ||
r.heap_limit = (uint32_t)STACK_BASE; |
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.
Why assign STACK_BASE
to r.heap_limit
rather than e.g. Image$$ARM_LIB_HEAP$$ZI$$Limit
? Heap and stack may arrange non-consecutive or stack in lower memory/heap in higher memory (like Nuvoton targets)? The same question to $Sub$$__rt_lib_init
.
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.
So yeah it looks strange. The problem is that currently on most targets ARM_LIB_HEAP
is not defined, but ARM_LIB_STACK
is. This should be changed in the future.
Since it is misleading I think I add another macro HEAP_LIMIT
.
434794f
to
57dd1f4
Compare
platform/mbed_retarget.cpp
Outdated
#if defined(TARGET_NUVOTON) || defined(TARGET_RZ_A1XX) | ||
extern char Image$$ARM_LIB_HEAP$$Base[]; | ||
extern char Image$$ARM_LIB_STACK$$Base[]; | ||
extern char Image$$ARM_LIB_HEAP$$Limit[]; |
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.
According to Image$$ execution region symbols, Image$$ARM_LIB_HEAP$$Limit
doesn't include ZI section. Change to Image$$ARM_LIB_HEAP$$ZI$$Limit
?
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.
Fixed.
1f22408
to
d2d91d5
Compare
platform/mbed_retarget.cpp
Outdated
|
||
extern "C" __value_in_regs struct __argc_argv $Sub$$__rt_lib_init(unsigned heapbase, unsigned heaptop) | ||
{ | ||
return $Super$$__rt_lib_init((unsigned)HEAP_BASE, (unsigned)STACK_BASE); |
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.
Change STACK_BASE
to HEAP_LIMIT
?
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.
Missed that. Sorry. Should be fixed now.
52bee5b
to
ec86ee1
Compare
Thanks @ccli8 for review ! |
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.
Design and docs changes are needed for new memory model, I will add them next week.
@mprse - I cannot add my commits to this PR, please cherry pick below listed commits, else I can create another PR (if that is preferred). https://github.com/deepikabhavnani/mbed-os/commits/2-region |
platform/mbed_retarget.cpp
Outdated
#endif | ||
|
||
#if !defined(HEAP_START) | ||
#if defined(Image$$ARM_LIB_HEAP$$ZI$$Base) && defined(Image$$ARM_LIB_HEAP$$ZI$$Length) |
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.
@deepikabhavnani Image$$ARM_LIB_HEAP$$ZI$$Base
and Image$$ARM_LIB_HEAP$$ZI$$Length
are linker-generated symbols. Can they be used for preprocessor defines?
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.
I have not tested it, yes you are right linker symbols will not be valid during pre-processing step... will have to find another condition or define heap_start in target specific file mbed_rtx.h as it was done earlier
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.
Sorry for the delay of the review. I have no problem with that.
And thanks @ccli8. Your code was helpful.
|
||
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; | ||
|
||
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[]; |
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.
Currently ARM_LIB_HEAP
is specified only for few targets (ARM_LIB_STACK
for all), this means that the following change will cause build failure for most of the targets.
To fully move to the 2 region memory model we need to specify ARM_LIB_HEAP
in all scatter files and __HeapLimit
for GCC linker scripts. Then we will be able to completely remove ISR_STACK_SIZE, ISR_STACK_START, ISR_HEAP_SIZE, ISR_HEAP_START
macros and relay only on the linker script symbols to define heap and stack.
I already tried that, but I took a step back since there was too much changes and we have discussed this here (and few next posts):
#9092 (comment)
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.
Agree on __HeapLimit, will be needed for all GCC linker files, for now exploring the options to not have ARM_LIB_HEAP in all targets, moving it to mbed_rtx.h back seems reasonable.
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.
Also I will not remove existing symbols for HEAP and Stack, since we have few targets who use completely different ram bank for heap, or want to expand heap to multiple banks. Symbols will be needed for those cases.
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.
Added __HeapLimit for all targets in GCC linker scripts.
7319b2f
to
70c6057
Compare
@c1728p9 - Please review |
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 for MultiTech.
@deepikabhavnani @mprse please remember to update handbook, there's a page about memory layout (not 100% sure it needs updating, but that needs to be confirmed) |
Also this change was in works for longer time did you guys remembered to update the new targets like PSoC6 based ones? |
@mprse Can you please verify all targets on master are covered? I'll review now any outstanding targets in PRs to follow this as well. |
I'll check if all targets are covered. |
I checked all ARM_STD scatter files and GCC linker scripts and it looks like all are ok. Do we have successful CI run on master after this has been merged? |
I've referenced this one to all current opened PR for new targets. See above
I can't access logs for the latest nightly. One job was triggered now, so might have results later today afternoon. |
I did check the linker scripts of PSoC6 and they were compatible. Also Musca was checked and I did shared the updated linker scripts with Musca |
@bulislaw Bootstrap document is updated, please review ARMmbed/mbed-os-5-docs#951 |
@AnotherButler - Do we have any other doc in handbook describing memory layout (apart from one updated in ARMmbed/mbed-os-5-docs#951) |
All, We have not changed the location of stack and heap, just separated them so the memory model is still the same. @AnotherButler - Thanks, I have another concern related to bootstrap.md - This document is updated by this is not visible on mbed.com website. |
It's not this one? https://os.mbed.com/docs/mbed-os/v5.11/porting/porting-bootstrap.html |
👍 |
Has this been tested with uARM toolchain ?
whereas this works ok with ARM tc ... |
Description
The following commits: #8039, #9092 added Boot/ISR stack definition to all scatter files (ARM_LIB_STACK).
This has changed memory model for RTOS-less builds to 2-region memory model and caused failure in case of rtos less builds.
This PR defines valid heap/stack regions for rtos-less builds.
Verified that blinky example works on rtos-less build with this fix.
Pull request type
Reviewers
@deepikabhavnani Please review.
Release Notes
RAM memory model is updated to 2-region model. RTOS and non-RTOS versions of Mbed OS across all targets and toolchains will have separate stack and heap sections.
ISR stack size is unified across all targets and is set as 1K for Mbed OS with RTOS. In case of no RTOS, stack size is also the main thread size and is set as 4K.