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

Update core with upstream umm_malloc #6438

Merged
merged 40 commits into from
Oct 29, 2019

Conversation

mhightower83
Copy link
Contributor

@mhightower83 mhightower83 commented Aug 23, 2019

upstream version of umm_malloc customized for Arduino ESP8266 Core

This updates the heap management library, umm_malloc, to the current upstream
version at https://github.com/rhempel/umm_malloc. Some reorganizing and new code
was needed to use the new version.

This is a list of noteworthy changes:

UMM_POISON - now has a lite option as well as the previous intensive check
option. The code for running the full poison test at the call of the various
alloc functions was removed in the upstream version. In this port, the missing
code was added to heap.cpp and umm_local.cpp.

  • UMM_POISON - appears to have been partially changed to UMM_POISON_CHECK,
    I treat it as deprecated and used UMM_POISON_CHECK when needed.
    However, the Arduino Core's references to UMM_POISON were replaced with
    UMM_POISON_CHECK_LITE.
  • UMM_POISON_CHECK_LITE - Less intense, it just checks poison on active
    neighboring allocations.
  • UMM_POISON_CHECK - Full heap intensive check of poison

A cautionary note, on the use of UMM_INTEGRITY_CHECK and UMM_POISON_CHECK , and
UMM_INFO_PRINT
. All of these run with IRQs disabled, for periods that can go
into 100's of us. With umm_info(NULL, true) that may go into seconds, depending
on the serial interface speed and the number of memory allocations present. Use
UMM_INTEGRITY_CHECK and UMM_POISON_CHECK , and UMM_INFO_PRINT sparingly.
If you want to see numbers for the disabled time, explore using
UMM_CRITICAL_METRICS in umm_malloc_cfg.h.

our current version w/o any edits.

Using files from:
  https://github.com/rhempel/umm_malloc/tree/master/src
  https://github.com/rhempel/c-helper-macros/tree/develop

The following file remanents from our old version were removed:
  umm_malloc.cpp, umm_performance.h, umm_performance.cpp, and umm_stats.h

This is intended to be a "compare to" for changes made to
upstream version.
See comments at the top of umm_malloc.cpp for a summary of changes so far.

Added support for integrity check and poison check to refactored heap.cpp.
@devyte devyte self-requested a review September 2, 2019 12:12
…realloc.

Updated some comments and changed method of defining _rom_putc1.
cores/esp8266/heap.cpp Outdated Show resolved Hide resolved
cores/esp8266/umm_malloc/umm_malloc_cfg_example.h Outdated Show resolved Hide resolved
cores/esp8266/umm_malloc/umm_malloc_cfg.h Show resolved Hide resolved
cores/esp8266/umm_malloc/umm_malloc_cfg.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

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

Beware changing file extensions. We migrated to compile as much as possible with g++, and that shouldn't be reverted.
Also, for new features that aren't present in upstream, try to keep them in separate cpp|h files to reduce the diffs in the main files. At least if it's reasonable to do so, there is likely code where that isn't possible or reasonable.

cores/esp8266/umm_malloc/umm_malloc.c Outdated Show resolved Hide resolved
cores/esp8266/umm_malloc/umm_malloc_cfg.h Show resolved Hide resolved
cores/esp8266/umm_malloc/umm_malloc_cfg.h Outdated Show resolved Hide resolved
allocation to include its nearest allocated neighbors in the heap.
That is to say, if the nearest neighbor is free, then the next one over
is checked. And this is done in both directions.
umm_malloc() will also checks the neighbors of the selected
allocation before use.

Merged umm_malloc.c into umm_malloc.cpp.

Added additional stats for debug build.

On going comment cleanup.

Removed #if 0 block from isr_safe_printf.

Corrected mistyped UMM_POISON_CHECK UMM_CHECK_POISON.
Corrected other conditional build issues.
Updated printing in heap.cpp to behave the way os_printf would have with regards
to system_set_os_print. ie. setDebugOutput enable/disables printing

Expanded #ifdef fenceing of .c files to prevent Arduino IDE from building them
outside of the .cpp file they are included in.

Corrected more conditional building issues.

Remaining concern - umm_info(0, true) printing - does it need an ISR safe method,
all printing is done from within a critical sectionn with rsil(15)?
Or should be have the print option disabled for non-debug builds.
ie. Debug port: "Disabled"
* R.Hempel 2019-09-07 - Separate the malloc() and free() functionality into
*                        wrappers that use critical section protection macros
*                        and static core functions that assume they are
*                        running in a protected con text. Thanks @devyte
With OOM selected w/ Debug port: "Disabled" you can now use
Serial.setDebugOutput(true); to enable OOM message displaying.
This is the behavior previously available with os_printf.

commit rev 1
cores/esp8266/umm_malloc/umm_info.c Show resolved Hide resolved
cores/esp8266/heap.cpp Outdated Show resolved Hide resolved
… for future.

umm_info(NULL, true) is now treated as a debug option that is enabled by
Arduino IDE->tools `Debug port: "Serial"`, etc. It now prints when
DEBUG_ESP_PORT or UMM_INFO_PRINT are defined.

Cleanup comments and some conditionals.
More comment cleanups
Added Status TODOs marks for upstream
…upstream

version at https://github.com/rhempel/umm_malloc. Some reorganizing and new code
was needed to use the new version.

This is a list of note worthy changes:

UMM_POISON - now has a lite option as well as the previous intensive check
option. The code for running the full poison test at the call of the various
alloc functions was removed in the upstream version. In this port the missing
code was added to heap.cpp and umm_local.cpp.
* UMM_POISON - appears to have been partially changed to UMM_POISON_CHECK,
  I treat it as depricated and used UMM_POISON_CHECK, when needed.
  However, the Arduino Core's references to UMM_POISON were replaced with
  UMM_POISON_CHECK_LITE.
* UMM_POISON_CHECK_LITE - Less intense, it just checks poison on active
  neighboring allocations.
* UMM_POISON_CHECK - Full heap intensive check of poison

UMM_INFO_PRINT - This new define makes building UMM_INFO with printing
capability, optional. When umm_info(NULL, true) is used to print a debug view of
heap information to the debug port, it has to walk the heap and print out
information, while in a critical section. This requires that the print function
be able to print w/o doing malloc calls and from an IRQ disabled context. It
also requires more IRAM to handle printing. Without this define
`umm_info(NULL, true)` will not print.
* UMM_INFO_PRINT is enabled as part of selecting `Debug port: "Serial" or
* "Serial1"`. To make available all the time use '-D UMM_INFO_PRINT`.

A cautionary note, on the use of UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and
UMM_INFO_PRINT. All of these run with IRQs disabled, for periods that can go
into 100's of us. With umm_info(NULL, true) that may go into seconds, depending
on the serial interface speed and the number of memory allocations present. Use
UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and UMM_INFO_PRINT sparingly.
If you want to see numbers for the disabled time, explore using
UMM_CRITICAL_METRICS in umm_malloc_cfg.h.
@mhightower83 mhightower83 changed the title WIP: update core with upstream umm_malloc update core with upstream umm_malloc Sep 30, 2019
…upstream

version at https://github.com/rhempel/umm_malloc. Some reorganizing and new code
was needed to use the new version.

This is a list of note worthy changes:

UMM_POISON - now has a lite option as well as the previous intensive check
option. The code for running the full poison test at the call of the various
alloc functions was removed in the upstream version. In this port the missing
code was added to heap.cpp and umm_local.cpp.
* UMM_POISON - appears to have been partially changed to UMM_POISON_CHECK,
  I treat it as depricated and used UMM_POISON_CHECK, when needed.
  However, the Arduino Core's references to UMM_POISON were replaced with
  UMM_POISON_CHECK_LITE.
* UMM_POISON_CHECK_LITE - Less intense, it just checks poison on active
  neighboring allocations.
* UMM_POISON_CHECK - Full heap intensive check of poison

UMM_INFO_PRINT - This new define makes building UMM_INFO with printing
capability, optional. When umm_info(NULL, true) is used to print a debug view of
heap information to the debug port, it has to walk the heap and print out
information, while in a critical section. This requires that the print function
be able to print w/o doing malloc calls and from an IRQ disabled context. It
also requires more IRAM to handle printing. Without this define
`umm_info(NULL, true)` will not print.
* UMM_INFO_PRINT is enabled as part of selecting `Debug port: "Serial" or
* "Serial1"`. To make available all the time use '-D UMM_INFO_PRINT`.

A cautionary note, on the use of UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and
UMM_INFO_PRINT. All of these run with IRQs disabled, for periods that can go
into 100's of us. With umm_info(NULL, true) that may go into seconds, depending
on the serial interface speed and the number of memory allocations present. Use
UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and UMM_INFO_PRINT sparingly.
If you want to see numbers for the disabled time, explore using
UMM_CRITICAL_METRICS in umm_malloc_cfg.h.
@mhightower83 mhightower83 changed the title update core with upstream umm_malloc WIP: update core with upstream umm_malloc Oct 1, 2019
@devyte devyte self-requested a review October 7, 2019 23:26
keep these comments separated from the upstream code and to avoid
getting lost. I'll expand this as I think of and remember more.
@mhightower83 mhightower83 changed the title WIP: update core with upstream umm_malloc Update core with upstream umm_malloc Oct 10, 2019
Refactored macro PTR_CHECK__LOG_LAST_FAIL.
Replaced macros __umm_... with uppercase versions.
Corrected misplaced POISON_CHECK__PANIC_FL macro in realloc.

Added debug free options for OOM and Poison to umm_malloc_cfg.h

Updated Notes.h.

Lines that start with "//C" are meant to flag reviewer's attention.
thinking behind its placement and Integrity Checks placement
with relation to the *alloc function. Just so I don't forget
again :/
Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

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

2 minor typos.
I didn't check how close this follows upstream, but I trust your judgement.

cores/esp8266/umm_malloc/Notes.h Outdated Show resolved Hide resolved
cores/esp8266/umm_malloc/README.md Outdated Show resolved Hide resolved
@devyte devyte added this to the 2.6.0 milestone Oct 29, 2019
@devyte
Copy link
Collaborator

devyte commented Oct 29, 2019

Alright, merging this one to get exposure.

@devyte devyte merged commit 7a43092 into esp8266:master Oct 29, 2019
@mhightower83 mhightower83 deleted the WIP-upstream-umm_malloc branch November 6, 2019 06:52
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.

4 participants