Quellcode durchsuchen

heap: Update the component to incorporate the new TLSF implementation

- remove tlsf_platform.h from esp-idf since the fl_index is now calculated
  based on the size of the requested heap
- update CMakeLists.txt accordingly

* based on the changes made to the TLSF in https://github.com/espressif/esp-idf/pull/7829
* contributes to fix https://github.com/espressif/esp-idf/issues/7822
Guillaume Souchere vor 3 Jahren
Ursprung
Commit
90ac786cf4

+ 0 - 5
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)

+ 8 - 9
components/heap/multi_heap.c

@@ -142,7 +142,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;
     }
@@ -150,13 +150,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;
@@ -417,7 +420,6 @@ static void multi_heap_get_info_tlsf(void* ptr, size_t size, int used, void* use
 
 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));
@@ -431,13 +433,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

+ 1 - 1
components/heap/tlsf

@@ -1 +1 @@
-Subproject commit ab17d6798d1561758827b6553d56d57f19aa4d66
+Subproject commit 13da0fff7f54623b20785dbeb466df420f52e510

+ 0 - 51
components/heap/tlsf_platform.h

@@ -1,51 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#pragma once
-
-#include <stddef.h>
-#include <stdbool.h>
-
-#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