Commit Graph

69 Commits

Author SHA1 Message Date
Guillaume Souchere
dd1dde5fb9 fix(heap): Tracing of all heap_caps API
This commit fixes the missing tracing on all
heap_caps_xx_prefer and heap_caps_xx_aligned
functions.
2024-04-09 13:27:45 +02:00
Guillaume Souchere
497c840172 fix(heap): Wrong size propagated in alloc fail callback
Propagate `n * size` as the size of the failed allocation
instead of just `size` when heap_caps_calloc() fails since
`n * size` is the actual number of bytes that the heap
component tried to allocate.
2024-03-26 06:48:33 +01:00
Guillaume Souchere
34fb83ffbc feat(heap): Add return value to walker callback
This return value is used by the tlsf_walk_pool
function to be notified of the need to interrupt
the ongoing traversal of the currently traversed
heap.
2024-03-20 08:33:48 +01:00
Guillaume Souchere
5cc69ce12b feat(heap): Add walker to the heap component
Introduce new APIs in essp_heap_caps.h:
- heap_caps_walk()
- heap_caps_walk_all()

Those functions are triggering a callback for all blocks
(allocated or free) of memory present in heaps meeting
the set of capabilities passed as parameter (or all heaps
for heap_caps_walk_all() function)

test_walker.c added to test the new functionality in
test_apps/heap_test/
2024-03-20 08:33:48 +01:00
Guillaume Souchere
bb9d5a8d51 feat(heap): Allow tracking of minimum free size for a given time frame
Implement a function to start tracking the minimum free size from the
moment the function is called.
Implement a function to stop tracking the minimum free size and restore
the minimum free size value calculated since startup.
Implement the tests related to this new feature.
2023-12-21 08:07:01 +01:00
Guillaume Souchere
b2cc934b94 fix(heap): Fix the use of block owner macro
In heap_caps_get_info, update the use of block owner
macros to use MULTI_HEAP_BLOCK_OWNER_SIZE() instead of
MULTI_HEAP_ADD_BLOCK_OWNER_SIZE(0).
2023-12-19 07:10:37 +01:00
Guillaume Souchere
872bc74954 fix(heap): Fix bugs in heap task tracking
Update task tracking feature to fix bugs introduced when
decoupling task tracking from heap poisoning.

Closes https://github.com/espressif/esp-idf/issues/12498
Closes https://github.com/espressif/esp-idf/issues/12493
2023-11-09 09:20:45 +01:00
Cody P Schafer
9e1e245477 fix(heap): memalign respect malloc_alwaysinternal_limit
This changes `memalign` (and `posix_memalign`) so that it uses an
allocation method with the same selection criteria (checking
`malloc_alwaysinternal_limit` and picking one of:

- always MALLOC_CAP_INTERNAL
- MALLOC_CAP_INTERNAL first with fallback
- MALLOC_CAP_SPIRAM first with fallback

`malloc_alwaysinternal_limit` is in turn set by the options
`CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL` and
`CONFIG_SPRIAM_USE_CAPS_ALLOC`.

This notably affects folks using esp-rs to build rust code for the
esp-idf, as all allocations from rust use `memalign`.

Merges https://github.com/espressif/esp-idf/pull/12375
2023-11-01 01:58:27 +08:00
Guillaume Souchere
7492c862af feat(heap): Dissociate heap poisoning from task tracking
In order to enable CONFIG_HEAP_TASK_TRACKING, some kind
of poisoning had to be enabled (!HEAP_POISONING_DISABLED).
However since those functionalities don't seem to be related
in any way, this commit decouple them by removing
MULTI_HEAP_BLOCK_OWNER from poison_head_t in multi_heap_poisoning.c
and handling the block ownership in heap_caps.c instead.

Note that handling task tracking in multi_heap.c would necessitate
updating the ROM implementation of multi_heap.c as well. For this
reason, the task tracking feature has to be handled in heap_caps.c.
2023-10-18 06:43:22 +02:00
Guillaume Souchere
110aac240d heap: Add a configuration that places all the heap component and related functionalities in flash when enabled
Add test configuration to run all tests with heap component in the flash.
Add reference to this new configuration in performance section of the documentation.
2023-04-12 08:11:24 +02:00
Guillaume Souchere
2f982107dc heap: Wrap the function hook feature under a configuration
also update heap_debug.rst and mem_alloc.rst to provide information about the feature
2023-03-23 04:50:49 +00:00
Guillaume Souchere
5a1f0cd63c heap: Make weak declaration for the alloc and free callbacks
- Fix "test get allocated size"
- Add tests for the free / alloc hooks
- Call alloc function hook on malloc/realloc/calloc base functions
- Add caps parameter to the allocation hook function
2023-03-23 04:50:49 +00:00
Chip Weinberger
1588c61c7b [Heap] new api for user heap trace callbacks 2023-03-23 04:50:49 +00:00
Zim Kalinowski
f6fc5e3c31 heap: fix and re-enable no-format warnings 2023-03-12 21:45:11 +01:00
Guillaume Souchere
a630f06132 Merge branch 'feature/verbose-alloc-failure-abort' into 'master'
heap: print size and caps when malloc fails before calling system abort

Closes IDFGH-9267

See merge request espressif/esp-idf!22192
2023-02-13 15:26:24 +08:00
Guillaume Souchere
65c946f1f2 heap: Fix priority in shex() bit shift 2023-02-10 07:43:32 +01:00
Chip Weinberger
f11256d9da [Logs] print size and caps when malloc fails 2023-02-09 06:49:34 -08:00
Guillaume Souchere
a26ecafa0d Merge branch 'fix/malloc_cap_exec_on_esp32c6' into 'master'
heap: Fix allocation issue when trying to allocate in IRAM on esp32c6

Closes IDF-6306

See merge request espressif/esp-idf!22077
2023-01-26 17:45:23 +08:00
Guillaume Souchere
fb9a7f36d4 heap: replace usage of bzero() with memset() across the component
See https://github.com/espressif/esp-idf/issues/5095
2023-01-25 09:28:56 +01:00
Guillaume Souchere
a5d6f62e7e heap: Prevent alloc from IRAM to call dram_alloc_to_iram() on esp32c6 target
Since DRAM and IRAM are superposed on esp32c6 it is not necessary to convert a freshly allocated
DRAM addr to its IRAM equivalent when MALLOC_CAP_EXEC is passed to heap_caps_malloc(). Instead,
proceed with a default allocation since the address returned by multi_heap_malloc() already belongs
to the IRAM region.

Applies for esp32c6 and every boards with superposed DRAM and IRAM addresses.
2023-01-23 07:42:20 +01:00
Guillaume Souchere
b496bab0f6 heap: fix linker issues and remove spi flash dependencies 2022-11-24 10:31:14 +01:00
Guillaume Souchere
0376e6ec79 heap: add check for usage of flash content from iram
this commits:
- adds build-time test to check that no call to flash regions are done from IRAM functions

- resolves problems related to IRAM function using content in flash memory

- update heap_caps_alloc_failed to use a default function name in DRAM
  when necessary instead of creating a function name variable in DRAM for
  each call of heap_caps_alloc_failed. This allows to save some extra bytes
  in RAM.
2022-11-24 10:31:14 +01:00
Omar Chebib
c6ddf7288c heap: add a unit test for malloc(0) and slightly optimize heap_caps_malloc_prefer 2022-08-09 10:30:36 +08:00
tgotic
ee4d15d02f fix malloc(0) and heap_caps_alloc_failed()
Don't call heap_caps_alloc_failed() for malloc(0) and calloc(0), because it is not an error.
Improve handling of malloc(0) and calloc(0).

Merges https://github.com/espressif/esp-idf/pull/9517
2022-08-08 02:55:50 +00:00
Omar Chebib
a0ca353cda Heap: heap_caps_*_prefer functions now properly call alloc_failed callback
heap_caps_*_prefer functions will now only call heaps_caps_alloc_failed
callback if all attempts to allocation memory fail (and not after each attempt
anymore).

* Closes https://github.com/espressif/esp-idf/issues/9086
2022-07-05 05:57:04 +00:00
morris
4280164be4 rmt: add more clock source caps 2022-04-21 13:59:47 +00:00
Anton Maklakov
68e5d9d585 Remove IRAM_ATTR from any function declarations
IRAM_ATTR expands to a unique section attribute. Applying it to both
declaration and definition results in a section conflict.
2022-03-22 09:58:50 +00:00
Omar Chebib
96391ef62b SPIRAM: 'Abort on allocation failure' should not trigger when there is available SPI ram 2021-11-02 05:36:18 +00:00
Angus Gratton
d6f4d99d93 core system: Fix warnings in compilation when assertions are disabled
Adds a CI config for hello world that sets this, to catch future regressions
2021-03-03 10:26:57 +11:00
jiangguangming
47f469b238 heap: support aligned_alloc for retention memory on ESP32-C3 2021-01-13 14:41:22 +08:00
morris
753a929525 global: fix sign-compare warnings 2021-01-12 14:05:08 +08:00
Angus Gratton
66fb5a29bb Whitespace: Automated whitespace fixes (large commit)
Apply the pre-commit hook whitespace fixes to all files in the repo.

(Line endings, blank lines at end of file, trailing whitespace)
2020-11-11 07:36:35 +00:00
Michael (XIAO Xufeng)
1966f00f0b soc: updates caps usage
We should define caps as 1 if true. When use the caps macros, #if and
 #if ! should be used instead of #ifdef/#ifndef.
2020-10-17 16:10:17 +08:00
Felipe Neves
3057b76a7e tests: re-add all disabled tests and all disabled configurations 2020-10-14 16:11:49 +11:00
Felipe Neves
bd9b921713 heap_tlsf: added implementation of TLSF allocator
heap: ported tlsf allocator into multi heap

heap_host_tests: added tlsf allocator into host test

heap_host_test: update freebytes after using free

heap_tests: tlsf now passing on host tests without poisoning

multi_heap: added support for memalign using tlsf implementation

heap_caps: removed heap_caps_aligned_free

heap/test: fixed broken aligned alloc test build

heap: added poisoning pattern when blocks are being merged

heap/tests: added timing tests for memory allocation

heap: reduced tlsf structure overhead

heap/tlsf: made all short functions inside of tlsf  module as inline to improve timings

heap: moved tlsf heap routines outside of flash memory

newlib: linked multiheap memalign with newlib memalign function

heap: moved block member functions to a separate file so multi_heap can use the functions

heap/test: improved the tlsf timing test

heap/test: added memalign on aligned alloc tests

heap: moved tlsf configuration constants to a separated file

heap: added random allocations test with timings

heap: modified the calculation of heap free bytes

heap: make aligned free true deprecated functions and update their documentation

heap: add extra assert after successive mallocs on small allocation host test

heap: remove legacy aligned alloc implementation.

performance: added malloc and free time performance default values
2020-10-13 23:52:03 +00:00
Felipe Neves
6f5e43e26a heap: added alloc failed hook and configuration options
heap/test: added alloc failed hook tests

docs: added alloc failed hook documentation

heap: add function to register allocation failed hook

docs: allocation failed hook docs improvements
2020-05-04 10:58:38 -03:00
Angus Gratton
d40c69375c bootloader: Add fault injection resistance to Secure Boot bootloader verification
Goal is that multiple faults would be required to bypass a boot-time signature check.

- Also strengthens some address range checks for safe app memory addresses
- Change pre-enable logic to also check the bootloader signature before enabling SBV2 on ESP32

Add some additional checks for invalid sections:

- Sections only partially in DRAM or IRAM are invalid
- If a section is in D/IRAM, allow the possibility only some is in D/IRAM
- Only pass sections that are entirely in the same type of RTC memory region
2020-02-27 14:37:19 +05:30
Felipe Neves
6a307ee70f heap: removed ptr check in diram area since aligned allocator does not support data allocated from IRAM 2020-01-10 10:15:32 -03:00
Felipe Neves
0d8a5ebec7 heap: added aligned calloc function plus tests 2020-01-10 10:05:28 -03:00
Felipe Neves
a2db437c46 heap/heap_caps: Added tests for align allocation on both internal and external ram 2020-01-10 10:05:28 -03:00
Felipe Neves
7fbf4c74d7 heap/heap_caps: added initial, top level heap_caps_aligned_alloc and heap_caps_aligned_free 2020-01-10 10:05:27 -03:00
Ivan Grokhotkov
52f8aa2adb Merge branch 'feature/heap_non_os_build' into 'master'
heap: make compatible with non-OS builds, remove target dependence

Closes IDF-1236

See merge request espressif/esp-idf!7051
2020-01-03 17:12:51 +08:00
Ivan Grokhotkov
3285ed116d heap: make compatible with non-OS builds, remove target dependence 2019-12-27 12:40:06 +01:00
Felipe Neves
4909fdfe02 heap_caps: small fixes on comments plus cleaning 2019-12-20 13:35:56 -03:00
Felipe Neves
31145f38fa heap_caps: added special case for realloc when previous area is an diram_iram ptr, this will force a malloc/copy/free 2019-12-20 13:35:56 -03:00
Felipe Neves
ce9f84fba9 heap_caps: enable check of pointer on diram_iram for both S2 and non-S2 platform 2019-12-20 13:35:56 -03:00
Felipe Neves
4a392932f1 heap/heap_caps: added special case for esp32s2 when handling memory allocated (and aliased) from IRAM 2019-12-20 13:35:56 -03:00
Angus Gratton
7ce75a42c7 Merge branch 'master' into feature/esp32s2beta_merge 2019-10-25 15:13:52 +11:00
Angus Gratton
04dbe663be Merge branch 'feature/heap_caps_get_size_free' into 'master'
add heap_caps_get_allocated_size

See merge request espressif/esp-idf!6375
2019-10-23 14:02:50 +08:00
Angus Gratton
8675a818f9 Merge branch 'master' into feature/esp32s2beta_merge 2019-10-22 13:51:49 +11:00