Skip to content

EFM32GG: Fix heap size formula in scatter files #14129

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
Jan 11, 2021

Conversation

hugueskamba
Copy link
Collaborator

Summary of changes

The heap size was incorrectly calculated.
This fixes it by subtracting the Stack size, any memory chunks allocated
before the start of the application (for vectors and/or crash report), and
finally the size of the application from the total RAM size.

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


The heap size was incorrectly calculated.
This fixes it by subtracting the Stack size, any memory chunks allocated
before the start of the application (for vectors and/or crash report), and
finally the size of the application from the total RAM size.
@hugueskamba hugueskamba requested a review from a team January 8, 2021 18:39
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jan 8, 2021
@ciarmcom ciarmcom requested a review from a team January 8, 2021 19:00
@ciarmcom
Copy link
Member

ciarmcom commented Jan 8, 2021

@hugueskamba, thank you for your changes.
@ARMmbed/team-silabs @ARMmbed/mbed-os-maintainers please review.

@mergify mergify bot added needs: CI and removed needs: review labels Jan 11, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Jan 11, 2021

CI started

.ANY (+RW +ZI)
}

ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_SIZE-RAM_FIXED_SIZE+MBED_RAM_START-AlignExpr(ImageLimit(RW_IRAM1), 16) - MBED_CONF_TARGET_BOOT_STACK_SIZE) {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_SIZE-RAM_FIXED_SIZE+MBED_RAM1_START-AlignExpr(ImageLimit(RW_IRAM1), 16)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is convoluted to the point I can't really visualise it (and I think that's how the error wasn't spotted in the first place).

I think it's correct now - "heap size = total RAM size - fixed size - IRAM1 used space", with the used space being "AlignExpr(ImageLimit(RW_IRAM1, 16)) - MBED_RAM1_START", but the sign flippery confuses that.

Last time I touched this on a branch, I went with

(MBED_RAM_START+MBED_RAM_SIZE-MBED_BOOT_STACK_SIZE)-AlignExpr(ImageLimit(RW_IRAM1), 16)

or "heap size = Stack start address - IRAM1 end address".

Actually, we can just say that more simply:

ImageBase(ARM_LIB_STACK) - AlignExpr(ImageLimit(RW_IRAM1), 16)

although I guess you'd have to reorder the sections to decare stack first. Kind of makes sense though - you're laying out the fixed things and finally heap is what's left.

Or the original size-based formula could be somewhat simplified the same way:

MBED_RAM_SIZE-RAM_FIXED_SIZE-AlignExpr(ImageLength(RW_IRAM1), 16)

But I think it's clearest to denote the heap by its direct boundaries (end of IRAM1, start of stack).

It would help if you could just set the limit as an absolute address rather than a size, then we could just say ImageBase(ARM_LIB_STACK) for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Completely agree. ImageLength() looks useful, so we don't need to do image start - ImageLimit().

Also, some of the terms we put in RAM_FIXED_SIZE's definition eventually get cancelled out in the maths of the heap size. But this PR is to make as small change as possible, so keeping the existing logic is fine.

@mbed-ci
Copy link

mbed-ci commented Jan 11, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 11, 2021

Thanks @kjbracey-arm for details. I'll merge this as it is. We can work on simplifying it in a separate issue.

@0xc0170 0xc0170 merged commit d3d02eb into ARMmbed:master Jan 11, 2021
@mergify mergify bot removed the ready for merge label Jan 11, 2021
@hugueskamba hugueskamba deleted the hk_heap_size_fix_silabs branch January 11, 2021 16:23
@mbedmain mbedmain added release-version: 6.7.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jan 25, 2021
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.

7 participants