-
Notifications
You must be signed in to change notification settings - Fork 3k
Stack unification and test #7238
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
@SeppoTakalo fyi |
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.
Can you also add checks for the boot time stack? I believe those are the same as RTOS-less builds. For example IAR seems to define it as So if we set stack size in linker file to 4kB it is used in boot, before RTX starts, and then we allocate another 4kB for main thread and kick the kernel to run. However, RTX seems to suggest that 300 bytes should be enough: https://www.keil.com/pack/doc/CMSIS/RTOS/html/theory.html |
Or here: http://www.keil.com/support/man/docs/rlarm/rlarm_ar_technical_data.htm |
@SeppoTakalo In the test I am checking mbed-os/rtos/TARGET_CORTEX/mbed_boot.c Lines 225 to 232 in eb3d3fd
mbed-os/rtos/TARGET_CORTEX/mbed_boot.c Lines 266 to 275 in 19c795c
For example STM boards defines mbed-os/targets/TARGET_STM/mbed_rtx.h Line 136 in eb3d3fd
Now for specific mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/device/TOOLCHAIN_IAR/stm32l476xx.icf Lines 25 to 28 in eb3d3fd
GCC_ARM mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/device/TOOLCHAIN_GCC_ARM/STM32L476XX.ld Lines 158 to 165 in eb3d3fd
ARM Not defined According to the requirements I'm going to modify ISR stack for all targets to 1 kB. At least for |
Why set it to 1KB only? Some devices might need higher ISR stack can we have some good range instead? |
Below files show where ISR stack is set for ARM. Look for what is set in ISR_STACK_START for all targets. Many of them use same define "ARM_LIB_STACK" in scatter files mbed-os/targets/TARGET_NUVOTON/mbed_rtx.h Line 31 in 7b42891
mbed-os/targets/TARGET_NUVOTON/TARGET_NANO100/device/TOOLCHAIN_ARM_STD/NANO130.sct Line 13 in 0977206
|
No, this was based on my original understanding that boot time stack/main stack and ISR stacks are different. But according to Cortex-M3 User Guide Reference Material: 2.1.2. Stacks So clearly "boot" stack and ISR stacks are the same. And I tried to find, where we set that pointer, but it seems to be the first vector, so its the linker file + According the Cortex-M3 Devices Generic User Guide: Stack Pointer
So I was wrong assuming that checking ISR stack would not be enough, but those are the same. Should we actually change the name, because my understanding is now that both RTX kernel and ISR both use this "main stack" where And @deepikabhavnani why would some devices need 4kB of ISR stack? Sound like a lot compared to RTX kernel requiring only 400 bytes. Do you know some examples? At least within Mbed OS it is very limited what you can do in ISR, so the call path would be usually very short. |
@@ -40,7 +40,7 @@ export symbol __ICFEDIT_region_RAM_end__; | |||
|
|||
/*-Sizes-*/ | |||
/*Heap 1/4 of ram and stack 1/8*/ | |||
define symbol __ICFEDIT_size_cstack__ = 0x800; |
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.
That would break BLE.
@@ -11,8 +11,8 @@ define symbol __ICFEDIT_region_RAM_end__ = 0x20007FFF; | |||
export symbol __ICFEDIT_region_RAM_start__; | |||
export symbol __ICFEDIT_region_RAM_end__; | |||
/*-Sizes-*/ | |||
/*Heap 1/4 of ram and stack 1/8*/ | |||
define symbol __ICFEDIT_size_cstack__ = 0x800; |
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.
That would break BLE.
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.
IRQ Stack must be at least 2K large on Nordic targets. This is not an option to change it.
I never meant 4KB stack size as requirement. I would suggest to have a range based on analysis / input from target devices instead of hard-code 1KB. |
Thanks for all your comments. They are really helpful!
I agree that the name ("Interrupt stack") is misleading and it would be better to be consistent with the documentation and use names "main stack" (interrupt and boot time stack) and "process stack" (threads).
I also agree that setting main stack/isr stack size to 1 KB for all boards might not be a good solution. For many cases it should be ok, but for sure there are cases when it is impossible (like BLE support on NRF boards pointed by @pan). I found the following problematic cases:
mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/device/TOOLCHAIN_ARM_STD/MBRZA1H.sct Line 44 in 443e37b
mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/device/TOOLCHAIN_ARM_STD/mem_RZ_A1H.h Lines 58 to 63 in 443e37b
Lines 116 to 139 in 443e37b
mbed-os/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/device/TOOLCHAIN_IAR/MKL05Z4.icf Lines 14 to 17 in 443e37b
mbed-os/targets/TARGET_ONSEMI/TARGET_NCS36510/device/TOOLCHAIN_IAR/NCS36510.icf Lines 31 to 33 in 443e37b
mbed-os/targets/TARGET_NXP/TARGET_LPC81X/TARGET_LPC810/device/TOOLCHAIN_IAR/LPC810.icf Lines 13 to 15 in 443e37b
I'm not sure if increasing main stack/isr stack size for boards which have only 4KB or 8KB RAM is possible. @bulislaw I think we should consider changing the requirement. I still did not checked all targets, but it looks like I can not simply unify main stack/isr stack size to 1KB for all targets. At least some exceptions are needed. |
Yeah that's fair, NRF is special case due to the SoftDevices. TARGET_LPC810 and TARGET_KL05Z is not supported in mbed 5. We may also make an exception for Cortex A platform, but we need to document it well (your comment above gives nice explanation). |
d9eba95
to
a119085
Compare
@pan Can you check if current form is acceptable for NORDIC target? |
Unify ISR stack size for targets which support MBED 5 (or MBED 2 and MBED 5). MBED 5 : 3 boards ---------------- TMPM3H6 TMPM46B TMPM066 MBED 2, 5 : 0 boards ---------------- MBED 2 : 0 boards (skipped) ----------------
Unify ISR stack size for targets which support MBED 5 (or MBED 2 and MBED 5). MBED 5 : 0 boards ---------------- MBED 2, 5 : 3 boards ---------------- WIZWIKI_W7500ECO WIZWIKI_W7500P WIZWIKI_W7500 MBED 2 : 0 boards (skipped) ----------------
Unify ISR stack size for targets which support MBED 5 (or MBED 2 and MBED 5).
7cfa089
to
22399bb
Compare
Rebased. |
The following Mbed 5 boards were processed: NUCLEO_F091RC NUCLEO_F070RB NUCLEO_F072RB NUCLEO_F103RB NUCLEO_F207ZG DISCO_F303VC NUCLEO_F303ZE NUCLEO_F303RE --- only boards marked with "-" of NUCLEO_F3 family were processed UBLOX_C030_U201 MTB_UBLOX_ODIN_W2 MTB_MXCHIP_EMW3166 MBED_CONNECT_ODIN UBLOX_C030_N211 UBLOX_EVK_ODIN_W2 USI_WM_BN_BM_22 UBLOX_C030_R410M NUCLEO_F411RE NUCLEO_F413ZH DISCO_F407VG - NUCLEO_F401RE NUCLEO_F429ZI B96B_F446VE DISCO_F413ZH NUCLEO_F439ZI DISCO_F429ZI - MTS_DRAGONFLY_F411RE NUCLEO_F446ZE DISCO_F469NI NUCLEO_F446RE NUCLEO_F410RB MTS_MDOT_F411RE WIO_3G STEVAL_3DP001V1 - MTB_MTS_DRAGONFLY NUCLEO_F412ZG
Maybe should we implement proposition from #8252: if (!isdefinedsymbol(MBED_APP_HEAP_SIZE)) { |
I will have to mainly review all files again when framework for configuring boot stack size will go in (PR #8039). |
Set the ISR stack to be 1KB. ARMmbed#7238 Set the heap size to 3KB(2KB + overhead + spare) so that atleast 2KB free ram is available for testing. With dynamic heap size, explicit size is not required. IAR 7.8 supports static heap, hence the change is needed in IAR linker files.
Set the ISR stack to be 1KB. #7238 Set the heap size to 3KB(2KB + overhead + spare) so that atleast 2KB free ram is available for testing. With dynamic heap size, explicit size is not required. IAR 7.8 supports static heap, hence the change is needed in IAR linker files.
@mprse Let us know the status. We shall close it and reopen with an update? Or is there expecting completion anytime soon? |
I'm planning to continue this one when I'm done with SPI testing. Since we have new Framework added by @c1728p9 (PR #8039) I will have to go through all linker scripts again, so I think we should close this one and I'll open new one instead later. |
Sounds good to me (reference this previous work if needed any history). I'll close this one |
Description
This PR provides test which verifies stack sizes:
Additionally PR provides fixes in linker scripts for some example targets. Can someone who has more experience with linker scripts check if these changes are correct? I could then proceed with the further targets.
Pull request type