Skip to content
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

perf(Other): Use FreeRTOS Heap Allocation Scheme 4, Allow Changing FreeRTOS Heap Allocation Scheme #1052

Merged

Conversation

Brandon-Hurst
Copy link
Contributor

@Brandon-Hurst Brandon-Hurst commented Jun 21, 2024

Description

FreeRTOS gives some flexibility in the memory allocation scheme used to allow optimizing size/speed/heap fragmentation risk. The FreeRTOS documentation indicates that heap_2.c is considered outdated, and that applications should at a minimum use heap_4 as an alternative. Heap 4 uses a smarter allocation algorithm for avoiding heap fragmentation (first-fit algorithm + aggregates free RAM segments).

Sources for info:
https://www.freertos.org/a00111.html
https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch03.md

Summary of Changes

  • Changed default FreeRTOS heap allocation to heap_4.c -heap_4 is recommended by FreeRTOS as an updated alternate to heap_2 for avoiding heap fragmentation
  • Added FREERTOS_HEAP_TYPE compile time macro to select the heap allocation method
    • Default value is 4, but can be 1-5. Error message is included if invalid input is given.
  • Added an entry for FREERTOS_HEAP_TYPE in MAX78000's FreeRTOSDemo project.mk

This would (positively) affect the way FreeRTOS builds for all supported MCUs.

Tests

Tested library builds with all 5 different heap types using FreeRTOSDemo for MAX78000 as the test source code. Example builds with the appropriate heap files based on the new FREERTOS_HEAP_TYPE macro. If the macro is not defined in project.mk, the library builds with heap_4.c by default.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

…mmended by FreeRTOS as an updated alternate to heap_2 for avoiding heap fragmentation -Added FREERTOS_HEAP_TYPE compile time macro to select the heap allocation method. -Added an entry for FREERTOS_HEAP_TYPE in MAX78000's FreeRTOSDemo project.mk
@github-actions github-actions bot added the MAX78000 Related to the MAX78000 (AI85) label Jun 21, 2024
Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Just one change request for the documentation

@@ -16,6 +16,11 @@ DEBUG=1

LIB_FREERTOS = 1

# Can provide a value for the FREERTOS heap allocation scheme
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of documenting this here, you can add some info to the UG.

See here for an example for the SDHC library.

The FreeRTOS lib hasn't had any options before, so I'd suggest adding a similar table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I'll update once this has been added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be good now 👍

@Jake-Carter Jake-Carter changed the title perf(Other): Change to updated heap allocation scheme for FreeRTOS perf(Other): Use FreeRTOS Heap Allocation Scheme 4, Allow Changing FreeRTOS Heap Allocation Scheme Jul 1, 2024
@Jake-Carter Jake-Carter merged commit 76fcf09 into analogdevicesinc:main Jul 1, 2024
10 checks passed
EricB-ADI pushed a commit that referenced this pull request Aug 21, 2024
…nging FreeRTOS Heap Allocation Scheme (#1052)"

This reverts commit 76fcf09.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MAX78000 Related to the MAX78000 (AI85)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants