Skip to content

Compiler profiles for size optimization #2973

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

TeroJaasko
Copy link
Contributor

@TeroJaasko TeroJaasko commented Oct 10, 2016

Description

This pull request adds two new compiler profiles, one for size optimization for release builds and one for minimally optimized debug build.

Status

READY/IN DEVELOPMENT/HOLD

Migrations

If this PR changes any APIs or behaviors, give a short description of what API users should do when this PR is merged.

NO

Related PRs

List related PRs against other branches:

branch PR
other_pr_production link
other_pr_master link

Todos

Deploy notes

Steps to test or reproduce

mbed compile -m K64F -t ARM --profile mbed-os/tools/profiles/size.json
mbed compile -m K64F -t GCC_ARM --profile mbed-os/tools/profiles/debug-size.json

The default profile in mbed-os optimizes for size on GCC byt for speed
on ARMCC and IAR. Add a profile which optimizes for size on all compilers.

This file is just a copy of default.json with the different
optimization targets.

Before (ARMCC, default.json):
Total Static RAM memory (data + bss): 72112 bytes
Total RAM memory (data + bss + heap + stack): 72112 bytes
Total Flash memory (text + data + misc): 358112 bytes

After (ARMCC, size.json):
Total Static RAM memory (data + bss): 72112 bytes
Total RAM memory (data + bss + heap + stack): 72112 bytes
Total Flash memory (text + data + misc): 314359 bytes

Before (IAR, default.json):
Total Static RAM memory (data + bss): 70088 bytes
Total RAM memory (data + bss + heap + stack): 168392 bytes
Total Flash memory (text + data + misc): 309739 bytes

After (IAR, size.json)
Total Static RAM memory (data + bss): 70092 bytes
Total RAM memory (data + bss + heap + stack): 168396 bytes
Total Flash memory (text + data + misc): 290523 bytes
…bled

On some cases the mbed-os's debug profile is unusable, as it disables
all optimizations to get best possible debugging environment which
may make the code too big to actually fit into system.

This new profile is based on the debug.json, but it enables the lowest
level of compiler optimizations along with the debug flag. Debugging
with this may not be optimal, but on some cases it is actually possible
at all.

Before (GCC 5.4.1, debug.json):
Total Static RAM memory (data + bss): 74144 bytes
Total RAM memory (data + bss + heap + stack): 139684 bytes
Total Flash memory (text + data + misc): 598554 bytes

After (GCC 5.4.1, debug_size.json):
Total Static RAM memory (data + bss): 73624 bytes
Total RAM memory (data + bss + heap + stack): 139164 bytes
Total Flash memory (text + data + misc): 392197 bytes

Before (ARMCC 5.06u3, debug.json):
Total Static RAM memory (data + bss): 72100 bytes
Total RAM memory (data + bss + heap + stack): 72100 bytes
Total Flash memory (text + data + misc): 412428 bytes

After (ARMCC 5.06u3, debug_size.json):
Static RAM memory (data + bss): 72112 bytes
Total RAM memory (data + bss + heap + stack): 72112 bytes
Total Flash memory (text + data + misc): 334792 bytes

Before (IAR, debug.json):
Total Static RAM memory (data + bss): 70115 bytes
Total RAM memory (data + bss + heap + stack): 168419 bytes
Total Flash memory (text + data + misc): 407543 bytes

After (IAR, debug_size.json):
Total Static RAM memory (data + bss): 70115 bytes
Total RAM memory (data + bss + heap + stack): 168419 bytes
Total Flash memory (text + data + misc): 377093 bytes
@TeroJaasko
Copy link
Contributor Author

As a side note, the debug build compiled with ARMCC for K64F fails to load properly by gdb, but binary still does work without debugger. The same happens with stock debug.json and the cloned debug-size.json. Gdb shows this warning when it starts:
--8<---
Reading symbols from BUILD/K64F/ARM/mbed-cloud-client-example.elf...
warning: Loadable section "RW_m_data" outside of ELF segments
warning: Loadable section "RW_m_data_2" outside of ELF segments
done.
--8<---

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 11, 2016

cc @sg- @screamerbg @bridadan

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

It seems fine to me.

The only question I have is the default setting for GCC_ARM already optimizes for size. Does anyone have concerns about this causing confusion?

@sg-
Copy link
Contributor

sg- commented Oct 11, 2016

This is a good start. We need some docs about the design principles behind each one and a second set of eyes that the right settings are chosen across the toolchains. Dont want to see people flipping these back and forth. If needed local profiles can be used rather than a collection of similar but different ones. @c1728p9

@c1728p9
Copy link
Contributor

c1728p9 commented Oct 12, 2016

Something like debug-size.json might be better left as a local profile. It would be good to add a size profile though. I created #3005 which bases the small profile on the size profile here. I tried to boil it down to the 3 most common use cases. Let me know what you think.

@TeroJaasko
Copy link
Contributor Author

The debug-size kind of profile is something that we need every time a debug session is needed. IMHO, it truely should be part of mbed os, as the problem is same on many real world applications which do their best to add as much as features as ROM allows.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 13, 2016

@TeroJaasko Can you review referenced PR by @c1728p9 please? And agree if that one makes sense and this one will be an addition ? Or ?

@screamerbg
Copy link
Contributor

The profiles look good to me. Please address @c1728p9. I'm up for the size profile. Note that the more profiles we have, the more confusing it would get.
@sg- @theotherjimmy

@teetak01
Copy link
Contributor

This looks ready. Can we get this merged ?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2016

This looks ready. Can we get this merged ?

Final review by @c1728p9 and @sg- please

For me size profile +1, not certain about debug-size. A user can tweak it, we got debug already, and 3 other profiles, plus this size. So each of them should get debug?

@sg-
Copy link
Contributor

sg- commented Oct 19, 2016

@TeroJaasko @c1728p9 @teetak01

Please work together to get this and #3005 unified. Less profiles are better and local profiles should be encouraged. Profiles without docs and description statement are not helpful. Next we'll see samgro01-profile.json checked in and so on.

Also, need verification that the flags are profiles are best picked across each toolchain. Report of build output for each would be nice.

@@ -0,0 +1,44 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Size doesn't really imply big or small. Maybe rename this file to small.json or something which implies that this is smaller than the default?

Copy link
Contributor

Choose a reason for hiding this comment

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

These profiles need docs. Feel free to pull the DOCs from pr #3005.

"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
"-MMD", "-fno-delete-null-pointer-checks",
"-fomit-frame-pointer", "-O1", "-g"],
Copy link
Contributor

Choose a reason for hiding this comment

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

With -O1 the optimization level is changed from the size.json configuration. This is one more configuration to verify. I would recommend sticking with just one size profile.

"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
"-MMD", "-fno-delete-null-pointer-checks",
"-fomit-frame-pointer", "-O1", "-g"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the reason debug symbols aren't turn on in all configurations is because this increases build sizes too much for testing and the online IDE. @screamerbg, @bridadan or @0xc0170 can you confirm this? If debug symbols could be turned on/off independent of the profile the each of the profiles wouldn't need have a corresponding "debug-*" profile to add symbols. This would be especially useful if the binary output doesn't change (which it shouldn't).

Copy link
Contributor

Choose a reason for hiding this comment

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

@c1728p9 That's correct. Good catch!

@sg-
Copy link
Contributor

sg- commented Oct 25, 2016

@TeroJaasko can you please work with @c1728p9 to get comments resolved or close this out and make requests against #3005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants