Skip to content

uVisor: Standardize available legacy heap and stack #3692

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

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ ENTRY(Reset_Handler)

__ram_vector_table__ = 1;

/* Heap 1/4 of ram and stack 1/8 */
__stack_size__ = 0x8000;
__heap_size__ = 0x10000;
/* With the RTOS in use, this does not affect the main stack size. The size of
* the stack where main runs is determined via the RTOS. */
__stack_size__ = 0x400;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine for mbed 5. However, in case RTOS is not used (mbed 2), this radically decreasing stack size for MCU like k64f.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, without RTOS, the stack for the main function is reduced a lot. With RTOS, having this be large is a waste of memory, as the user application can never use this RAM (the RTOS uses it for its stack).

It's almost like we need two different linker scripts, one for with RTOS and one for without, unless we can come up with a good balanced number that isn't too bad of a choice for either platform. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linker scripts already contain a conditional assignment like the following:

HEAP_SIZE  = DEFINED(__heap_size__)  ? __heap_size__  : 0x0400;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;

so we could define those symbols somewhere else. In that way we can also define them depending on RTOS being used or not. @0xc0170 do you agree? What's the best place to place those definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, doesn't the stack just start at the top of SRAM and grow down until it hits the heap? So, this would be a minimum stack size with mbed 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. So this should not be an issue @0xc0170

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so.

LGTM


/* This is the guaranteed minimum available heap size for an application. When
* uVisor is enabled, this is also the maximum available heap size. The
* HEAP_SIZE value is set by uVisor porters to balance the size of the legacy
* heap and the page heap in uVisor applications. */
__heap_size__ = 0x6000;

HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
M_VECTOR_RAM_SIZE = 0x400;

/* Heap: 1/4 of RAM. Stack: 1/8 of RAM. */
STACK_SIZE = 0x6000;
HEAP_SIZE = 0xC000;
/* With the RTOS in use, this does not affect the main stack size. The size of
* the stack where main runs is determined via the RTOS. */
STACK_SIZE = 0x400;

/* This is the guaranteed minimum available heap size for an application. When
* uVisor is enabled, this is also the maximum available heap size. The
* HEAP_SIZE value is set by uVisor porters to balance the size of the legacy
* heap and the page heap in uVisor applications. */
HEAP_SIZE = 0x6000;

/* Specify the memory areas */
MEMORY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
/* Version 4.2.0 */
/* */

/* With the RTOS in use, this does not affect the main stack size. The size of
* the stack where main runs is determined via the RTOS. */
STACK_SIZE = 0x400;
HEAP_SIZE = 0xC00;

/* This is the guaranteed minimum available heap size for an application. When
* uVisor is enabled, this is also the maximum available heap size. The
* HEAP_SIZE value is set by uVisor porters to balance the size of the legacy
* heap and the page heap in uVisor applications. */
HEAP_SIZE = 0x6000;

MEMORY
{
Expand Down