diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt index a05c1bc4db..61cb81219a 100644 --- a/components/heap/CMakeLists.txt +++ b/components/heap/CMakeLists.txt @@ -8,11 +8,6 @@ set(includes "include") if(NOT CONFIG_HEAP_TLSF_USE_ROM_IMPL) set(priv_includes "tlsf") list(APPEND srcs "tlsf/tlsf.c") - if(NOT CMAKE_BUILD_EARLY_EXPANSION) - set_source_files_properties(tlsf/tlsf.c - PROPERTIES COMPILE_FLAGS - "-include ../tlsf_platform.h") - endif() endif() if(NOT CONFIG_HEAP_POISONING_DISABLED) diff --git a/components/heap/multi_heap.c b/components/heap/multi_heap.c index 63cce03f08..e167b3b357 100644 --- a/components/heap/multi_heap.c +++ b/components/heap/multi_heap.c @@ -129,7 +129,7 @@ size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p) multi_heap_handle_t multi_heap_register_impl(void *start_ptr, size_t size) { assert(start_ptr); - if(size < (tlsf_size() + tlsf_block_size_min() + sizeof(heap_t))) { + if(size < (tlsf_size(NULL) + tlsf_block_size_min() + sizeof(heap_t))) { //Region too small to be a heap. return NULL; } @@ -137,13 +137,16 @@ multi_heap_handle_t multi_heap_register_impl(void *start_ptr, size_t size) heap_t *result = (heap_t *)start_ptr; size -= sizeof(heap_t); - result->heap_data = tlsf_create_with_pool(start_ptr + sizeof(heap_t), size); + /* Do not specify any maximum size for the allocations so that the default configuration is used */ + const size_t max_bytes = 0; + + result->heap_data = tlsf_create_with_pool(start_ptr + sizeof(heap_t), size, max_bytes); if(!result->heap_data) { return NULL; } result->lock = NULL; - result->free_bytes = size - tlsf_size(); + result->free_bytes = size - tlsf_size(result->heap_data); result->pool_size = size; result->minimum_free_bytes = result->free_bytes; return result; @@ -404,7 +407,6 @@ __attribute__((noinline)) static void multi_heap_get_info_tlsf(void* ptr, size_t void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info) { - uint32_t sl_interval; uint32_t overhead; memset(info, 0, sizeof(multi_heap_info_t)); @@ -418,13 +420,10 @@ void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info) /* TLSF has an overhead per block. Calculate the total amount of overhead, it shall not be * part of the allocated bytes */ overhead = info->allocated_blocks * tlsf_alloc_overhead(); - info->total_allocated_bytes = (heap->pool_size - tlsf_size()) - heap->free_bytes - overhead; + info->total_allocated_bytes = (heap->pool_size - tlsf_size(heap->heap_data)) - heap->free_bytes - overhead; info->minimum_free_bytes = heap->minimum_free_bytes; info->total_free_bytes = heap->free_bytes; - if (info->largest_free_block) { - sl_interval = (1 << (31 - __builtin_clz(info->largest_free_block))) / SL_INDEX_COUNT; - info->largest_free_block = info->largest_free_block & ~(sl_interval - 1); - } + info->largest_free_block = tlsf_fit_size(heap->heap_data, info->largest_free_block); multi_heap_internal_unlock(heap); } #endif diff --git a/components/heap/tlsf_platform.h b/components/heap/tlsf_platform.h deleted file mode 100644 index f40e0ca0f9..0000000000 --- a/components/heap/tlsf_platform.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef ESP_PLATFORM -#include "soc/soc.h" - -#if !CONFIG_SPIRAM -#define TLSF_MAX_POOL_SIZE (SOC_DIRAM_DRAM_HIGH - SOC_DIRAM_DRAM_LOW) -#else -#define TLSF_MAX_POOL_SIZE SOC_EXTRAM_DATA_SIZE -#endif -#endif - -#if (TLSF_MAX_POOL_SIZE <= (256 * 1024)) -#define FL_INDEX_MAX_PLATFORM 18 //Each pool can have up 256KB -#elif (TLSF_MAX_POOL_SIZE <= (512 * 1024)) -#define FL_INDEX_MAX_PLATFORM 19 //Each pool can have up 512KB -#elif (TLSF_MAX_POOL_SIZE <= (1 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 20 //Each pool can have up 1MB -#elif (TLSF_MAX_POOL_SIZE <= (2 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 21 //Each pool can have up 2MB -#elif (TLSF_MAX_POOL_SIZE <= (4 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 22 //Each pool can have up 4MB -#elif (TLSF_MAX_POOL_SIZE <= (8 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 23 //Each pool can have up 8MB -#elif (TLSF_MAX_POOL_SIZE <= (16 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 24 //Each pool can have up 16MB -#elif (TLSF_MAX_POOL_SIZE <= (32 * 1024 * 1024)) -#define FL_INDEX_MAX_PLATFORM 25 //Each pool can have up 32MB -#else -#error "Higher TLSF pool sizes should be added for this new config" -#endif - -/* Include from the TLSF submodule to force TLSF_INDEX_MAX_PLATFORM to be defined - * when the TLSF repository is compiled in the IDF environment. */ -#include "tlsf_common.h" - -#ifdef __cplusplus -} -#endif