8000 proposed umm_malloc improvements by mhightower83 · Pull Request #6274 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

proposed umm_malloc improvements #6274

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 27 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0af9c5e
Correct critical section with interrupt level preserving and nest s…
mhightower83 Jul 8, 2019
dc8fe13
Fixed. travis build complaint.
mhightower83 Jul 9, 2019
254259e
Merge branch 'master' into pr3
mhightower83 Jul 9, 2019
7b0a0c8
Changes for https://github.com/esp8266/Arduino/pull/6274#pullrequestr…
mhightower83 Jul 9, 2019
40c6e95
Merge branch 'pr3' of github.com:mhightower83/Arduino into pr3
mhightower83 Jul 9, 2019
472b1b4
Added requested comment and missing comment for UMM_CRITICAL_PERIOD_A…
mhightower83 Jul 10, 2019
c32d96e
Merge pull request #1 from esp8266/master
mhightower83 Jul 10, 2019
1de2ec4
Updated comments and update xt_rsil()
mhightower83 Jul 10, 2019
28c823f
Merge branch 'pr3' of github.com:mhightower83/Arduino into pr3
mhightower83 Jul 15, 2019
5e8927e
Merge branch 'master' into pr3
earlephilhower Jul 16, 2019
08cc09e
Moved xt_rsil&co (pulled in __STRINGIFY) definitions out of
mhightower83 Jul 16, 2019
2d39911
Added "#ifndef CORE_MOCK" around conflicted area.
mhightower83 Jul 16, 2019
c858f5c
Merge branch 'master' into pr3
earlephilhower Jul 19, 2019
72d5d78
Merge branch 'master' into pr3
d-a-v Jul 21, 2019
9d35f34
Moved performance measurment and ESP specific definitions to
mhightower83 Jul 22, 2019
9b69df9
Merge branch 'pr3' of github.com:mhightower83/Arduino into pr3
mhightower83 Jul 22, 2019
e69676c
Commented out umm analyze. Delay CRITICAL_SECTION_EXIT() in
mhightower83 Jul 23, 2019
ed49b3c
Missed file change. This commit has: Delay CRITICAL_SECTION_EXIT() in
mhightower83 Jul 27, 2019
a937f1e
2nd Path. Removed early release of critical section around memmove
mhightower83 Jul 27, 2019
909c6b9
improved variable name
mhightower83 Jul 27, 2019
996ac76
Resolved ISR OOM concern with `_umm_realloc()`
mhightower83 Aug 1, 2019
e86e7ca
Resolved ISR OOM concern in _umm_realloc()
mhightower83 Aug 1, 2019
b81e87f
Update to keep access to alternate printf in one file.
mhightower83 Aug 3, 2019
a41873a
Merge branch 'master' into pr3
earlephilhower Aug 3, 2019
1bf9eb0
Updated to use ISR safe versions of memmove, memcpy, and memset.
mhightower83 Aug 7, 2019
5854e29
Merge branch 'master' into pr3
earlephilhower Aug 17, 2019
5d1a95f
Update umm_malloc.cpp
devyte Aug 18, 2019
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
8000
Diff view
Prev Previous commit
Next Next commit
Updated to use ISR safe versions of memmove, memcpy, and memset.
The library versions of memmove, memcpy, and memset were in flash.
Updated to use ROM functions ets_memmove, ets_memcpy, and ets_memset.
Additional note, the library version of memmove does not appear to
have been optimized. It took almost 10x longer than the ROM version.
Renamed printf macro to DBGLOG_FUNCTION and moved to umm_malloc_cfg.h.
Changed printf macro usage to use DBGLOG_FUNCTION.
  • Loading branch information
mhightower83 committed Aug 7, 2019
commit 1bf9eb0aff1049d3575f19e648892c129dcb37ab
48 changes: 24 additions & 24 deletions cores/esp8266/umm_malloc/umm_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,12 @@

extern "C" {

#if defined(DEBUG_ESP_PORT) || defined(DEBUG_ESP_ISR)
#define printf(fmt, ...) _isr_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
#else
// Macro to place constant strings into PROGMEM and print them properly
#define printf(fmt, ...) printf(PSTR(fmt), ## __VA_ARGS__ )
#endif
#undef memcpy
#undef memmove
#undef memset
#define memcpy ets_memcpy
#define memmove ets_memmove
#define memset ets_memset

// From UMM, the last caller of a malloc/realloc/calloc which failed:
extern void *umm_last_fail_alloc_addr;
Expand Down Expand Up @@ -611,42 +611,42 @@ Changes for July 2019:
/* ------------------------------------------------------------------------- */

#if DBG_LOG_LEVEL >= 6
# define DBG_LOG_TRACE( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_TRACE( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_TRACE( format, ... )
#endif

#if DBG_LOG_LEVEL >= 5
# define DBG_LOG_DEBUG( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_DEBUG( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_DEBUG( format, ... )
#endif

#if DBG_LOG_LEVEL >= 4
# define DBG_LOG_CRITICAL( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_CRITICAL( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_CRITICAL( format, ... )
#endif

#if DBG_LOG_LEVEL >= 3
# define DBG_LOG_ERROR( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_ERROR( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_ERROR( format, ... )
#endif

#if DBG_LOG_LEVEL >= 2
# define DBG_LOG_WARNING( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_WARNING( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_WARNING( format, ... )
#endif

#if DBG_LOG_LEVEL >= 1
# define DBG_LOG_INFO( format, ... ) printf( format, ## __VA_ARGS__ )
# define DBG_LOG_INFO( format, ... ) DBGLOG_FUNCTION( format, ## __VA_ARGS__ )
#else
# define DBG_LOG_INFO( format, ... )
#endif

#define DBG_LOG_FORCE( force, format, ... ) {if(force) {printf( format, ## __VA_ARGS__ );}}
#define DBG_LOG_FORCE( force, format, ... ) {if(force) {DBGLOG_FUNCTION( format, ## __VA_ARGS__ );}}

/* }}} */

Expand Down Expand Up @@ -739,7 +739,7 @@ static int integrity_check(void) {
< 8000 br>
/* Check that next free block number is valid */
if (cur >= UMM_NUMBLOCKS) {
printf("heap integrity broken: too large next free num: %d "
DBGLOG_FUNCTION("heap integrity broken: too large next free num: %d "
"(in block %d, addr 0x%lx)\n", cur, prev,
(unsigned long)&UMM_NBLOCK(prev));
ok = 0;
Expand All @@ -752,7 +752,7 @@ static int integrity_check(void) {

/* Check if prev free block number matches */
if (UMM_PFREE(cur) != prev) {
printf("heap integrity broken: free links don't match: "
DBGLOG_FUNCTION("heap integrity broken: free links don't match: "
"%d -> %d, but %d -> %d\n",
prev, cur, cur, UMM_PFREE(cur));
ok = 0;
Expand All @@ -771,7 +771,7 @@ static int integrity_check(void) {

/* Check that next block number is valid */
if (cur >= UMM_NUMBLOCKS) {
printf("heap integrity broken: too large next block num: %d "
DBGLOG_FUNCTION("heap integrity broken: too large next block num: %d "
"(in block %d, addr 0x%lx)\n", cur, prev,
(unsigned long)&UMM_NBLOCK(prev));
ok = 0;
Expand All @@ -786,7 +786,7 @@ static int integrity_check(void) {
if ((UMM_NBLOCK(cur) & UMM_FREELIST_MASK)
!= (UMM_PBLOCK(cur) & UMM_FREELIST_MASK))
{
printf("heap integrity broken: mask wrong at addr 0x%lx: n=0x%x, p=0x%x\n",
DBGLOG_FUNCTION("heap integrity broken: mask wrong at addr 0x%lx: n=0x%x, p=0x%x\n",
(unsigned long)&UMM_NBLOCK(cur),
(UMM_NBLOCK(cur) & UMM_FREELIST_MASK),
(UMM_PBLOCK(cur) & UMM_FREELIST_MASK)
Expand All @@ -800,7 +800,7 @@ static int integrity_check(void) {

/* Check if prev block number matches */
if (UMM_PBLOCK(cur) != prev) {
printf("heap integrity broken: block links don't match: "
DBGLOG_FUNCTION("heap integrity broken: block links don't match: "
"%d -> %d, but %d -> %d\n",
prev, cur, cur, UMM_PBLOCK(cur));
ok = 0;
Expand Down Expand Up @@ -846,7 +846,7 @@ static int integrity_check(void) {
*/
static void dump_mem ( const unsigned char *ptr, size_t len ) {
while (len--) {
printf(" 0x%.2x", (unsigned int)(*ptr++));
DBGLOG_FUNCTION(" 0x%.2x", (unsigned int)(*ptr++));
}
}

Expand Down Expand Up @@ -877,11 +877,11 @@ static int check_poison( const unsigned char *ptr, size_t poison_size,
}

if (!ok) {
printf("there is no poison %s the block. "
DBGLOG_FUNCTION("there is no poison %s the block. "
"Expected poison address: 0x%lx, actual data:",
where, (unsigned long)ptr);
dump_mem(ptr, poison_size);
printf("\n");
DBGLOG_FUNCTION("\n");
}

return ok;
Expand All @@ -895,7 +895,7 @@ static int check_poison_block( umm_block *pblock ) {
int ok = 1;

if (pblock->header.used.next & UMM_FREELIST_MASK) {
printf("check_poison_block is called for free block 0x%lx\n",
DBGLOG_FUNCTION("check_poison_block is called for free block 0x%lx\n",
(unsigned long)pblock);
} else {
/* the block is used; let's check poison */
Expand All @@ -904,15 +904,15 @@ static int check_poison_block( umm_block *pblock ) {

pc_cur = pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE);
if (!check_poison(pc_cur, UMM_POISON_SIZE_BEFORE, "before")) {
printf("block start: %08x\n", pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);
DBGLOG_FUNCTION("block start: %08x\n", pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);
UMM_HEAP_CORRUPTION_CB();
ok = 0;
goto clean;
}

pc_cur = pc + *((UMM_POISONED_BLOCK_LEN_TYPE *)pc) - UMM_POISON_SIZE_AFTER;
if (!check_poison(pc_cur, UMM_POISON_SIZE_AFTER, "after")) {
printf("block start: %08x\n", pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);
DBGLOG_FUNCTION("block start: %08x\n", pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);
UMM_HEAP_CORRUPTION_CB();
ok = 0;
goto clean;
Expand Down
11 changes: 11 additions & 0 deletions cores/esp8266/umm_malloc/umm_malloc_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ extern "C" {
#include "umm_performance.h"
#include "umm_stats.h"

#undef DBGLOG_FUNCTION
#if defined(DEBUG_ESP_PORT) || defined(DEBUG_ESP_ISR)
int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
// Note, _isr_safe_printf_P will not handle additional string arguments in
// PROGMEM. Only the 1st parameter, fmt, is supported in PROGMEM.
#define DBGLOG_FUNCTION(fmt, ...) _isr_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
#else
// Macro to place constant strings into PROGMEM and print them properly
#define DBGLOG_FUNCTION(fmt, ...) printf(PSTR(fmt), ## __VA_ARGS__ )
#endif

/*
* There are a number of defines you can set at compile time that affect how
* the memory allocator will operate.
Expand Down
1 change: 1 addition & 0 deletions tools/sdk/include/ets_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ void *pvPortMalloc(size_t xWantedSize, const char* file, int line) __attribute__
void *pvPortRealloc(void* ptr, size_t xWantedSize, const char* file, int line) __attribute__((alloc_size(2)));
void vPortFree(void *ptr, const char* file, int line);
void *ets_memcpy(void *dest, const void *src, size_t n);
void *ets_memmove(void *dest, const void *src, size_t n);
void *ets_memset(void *s, int c, size_t n);
void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer);
void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg);
Expand Down
0