fix(stdlib): fix issues when using LVGL TLSF memory pool to manage more than 4 GiB of memory (#5720)
This commit is contained in:
committed by
GitHub
parent
f5ca15b321
commit
10f9d98419
@@ -78,7 +78,7 @@ static void obj_test_task_cb(lv_timer_t * tmr)
|
|||||||
|
|
||||||
if(mem_free_start == 0) mem_free_start = mon.free_size;
|
if(mem_free_start == 0) mem_free_start = mon.free_size;
|
||||||
|
|
||||||
LV_LOG_USER("mem leak since start: %" LV_PRIu32 ", frag: %3d %%", mem_free_start - mon.free_size, mon.frag_pct);
|
LV_LOG_USER("mem leak since start: %zu, frag: %3d %%", mem_free_start - mon.free_size, mon.frag_pct);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@@ -92,13 +92,13 @@ void lv_example_table_2(void)
|
|||||||
lv_mem_monitor_t mon2;
|
lv_mem_monitor_t mon2;
|
||||||
lv_mem_monitor(&mon2);
|
lv_mem_monitor(&mon2);
|
||||||
|
|
||||||
uint32_t mem_used = mon1.free_size - mon2.free_size;
|
size_t mem_used = mon1.free_size - mon2.free_size;
|
||||||
|
|
||||||
uint32_t elaps = lv_tick_elaps(t);
|
uint32_t elaps = lv_tick_elaps(t);
|
||||||
|
|
||||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||||
lv_label_set_text_fmt(label, "%"LV_PRIu32" items were created in %"LV_PRIu32" ms\n"
|
lv_label_set_text_fmt(label, "%"LV_PRIu32" items were created in %"LV_PRIu32" ms\n"
|
||||||
"using %"LV_PRIu32" bytes of memory",
|
"using %zu bytes of memory",
|
||||||
(uint32_t)ITEM_CNT, elaps, mem_used);
|
(uint32_t)ITEM_CNT, elaps, mem_used);
|
||||||
|
|
||||||
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -10);
|
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -10);
|
||||||
|
|||||||
@@ -268,14 +268,14 @@ static void mem_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
|||||||
lv_obj_t * label = lv_observer_get_target(observer);
|
lv_obj_t * label = lv_observer_get_target(observer);
|
||||||
const lv_mem_monitor_t * mon = lv_subject_get_pointer(subject);
|
const lv_mem_monitor_t * mon = lv_subject_get_pointer(subject);
|
||||||
|
|
||||||
uint32_t used_size = mon->total_size - mon->free_size;;
|
size_t used_size = mon->total_size - mon->free_size;;
|
||||||
uint32_t used_kb = used_size / 1024;
|
size_t used_kb = used_size / 1024;
|
||||||
uint32_t used_kb_tenth = (used_size - (used_kb * 1024)) / 102;
|
size_t used_kb_tenth = (used_size - (used_kb * 1024)) / 102;
|
||||||
uint32_t max_used_kb = mon->max_used / 1024;
|
size_t max_used_kb = mon->max_used / 1024;
|
||||||
uint32_t max_used_kb_tenth = (mon->max_used - (max_used_kb * 1024)) / 102;
|
size_t max_used_kb_tenth = (mon->max_used - (max_used_kb * 1024)) / 102;
|
||||||
lv_label_set_text_fmt(label,
|
lv_label_set_text_fmt(label,
|
||||||
"%"LV_PRIu32 ".%"LV_PRIu32 " kB (%d%%)\n"
|
"%zu.%zu kB (%d%%)\n"
|
||||||
"%"LV_PRIu32 ".%"LV_PRIu32 " kB max, %d%% frag.",
|
"%zu.%zu kB max, %d%% frag.",
|
||||||
used_kb, used_kb_tenth, mon->used_pct,
|
used_kb, used_kb_tenth, mon->used_pct,
|
||||||
max_used_kb, max_used_kb_tenth,
|
max_used_kb, max_used_kb_tenth,
|
||||||
mon->frag_pct);
|
mon->frag_pct);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../../lv_conf_internal.h"
|
#include "../../lv_conf_internal.h"
|
||||||
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||||
|
|
||||||
#ifndef LV_TLSF_H
|
#ifndef LV_TLSF_H
|
||||||
@@ -60,8 +60,8 @@ typedef struct {
|
|||||||
lv_mutex_t mutex;
|
lv_mutex_t mutex;
|
||||||
#endif
|
#endif
|
||||||
lv_tlsf_t tlsf;
|
lv_tlsf_t tlsf;
|
||||||
uint32_t cur_used;
|
size_t cur_used;
|
||||||
uint32_t max_used;
|
size_t max_used;
|
||||||
lv_ll_t pool_ll;
|
lv_ll_t pool_ll;
|
||||||
} lv_tlsf_state_t;
|
} lv_tlsf_state_t;
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ void * lv_malloc(size_t size)
|
|||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
||||||
lv_mem_monitor_t mon;
|
lv_mem_monitor_t mon;
|
||||||
lv_mem_monitor(&mon);
|
lv_mem_monitor(&mon);
|
||||||
LV_LOG_INFO("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
|
LV_LOG_INFO("used: %zu (%3d %%), frag: %3d %%, biggest free: %zu",
|
||||||
(int)(mon.total_size - mon.free_size), mon.used_pct, mon.frag_pct,
|
mon.total_size - mon.free_size, mon.used_pct, mon.frag_pct,
|
||||||
(int)mon.free_biggest_size);
|
mon.free_biggest_size);
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -103,9 +103,9 @@ void * lv_malloc_zeroed(size_t size)
|
|||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
||||||
lv_mem_monitor_t mon;
|
lv_mem_monitor_t mon;
|
||||||
lv_mem_monitor(&mon);
|
lv_mem_monitor(&mon);
|
||||||
LV_LOG_INFO("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
|
LV_LOG_INFO("used: %zu (%3d %%), frag: %3d %%, biggest free: %zu",
|
||||||
(int)(mon.total_size - mon.free_size), mon.used_pct, mon.frag_pct,
|
mon.total_size - mon.free_size, mon.used_pct, mon.frag_pct,
|
||||||
(int)mon.free_biggest_size);
|
mon.free_biggest_size);
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* @file lv_mem.h
|
* @file lv_mem.h
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -35,12 +35,12 @@ typedef void * lv_mem_pool_t;
|
|||||||
* Heap information structure.
|
* Heap information structure.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t total_size; /**< Total heap size*/
|
size_t total_size; /**< Total heap size*/
|
||||||
uint32_t free_cnt;
|
size_t free_cnt;
|
||||||
uint32_t free_size; /**< Size of available memory*/
|
size_t free_size; /**< Size of available memory*/
|
||||||
uint32_t free_biggest_size;
|
size_t free_biggest_size;
|
||||||
uint32_t used_cnt;
|
size_t used_cnt;
|
||||||
uint32_t max_used; /**< Max size of Heap memory used*/
|
size_t max_used; /**< Max size of Heap memory used*/
|
||||||
uint8_t used_pct; /**< Percentage used*/
|
uint8_t used_pct; /**< Percentage used*/
|
||||||
uint8_t frag_pct; /**< Amount of fragmentation*/
|
uint8_t frag_pct; /**< Amount of fragmentation*/
|
||||||
} lv_mem_monitor_t;
|
} lv_mem_monitor_t;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#else
|
#else
|
||||||
#define LV_HEAP_CHECK(x) x
|
#define LV_HEAP_CHECK(x) x
|
||||||
|
|
||||||
static inline uint32_t lv_test_get_free_mem(void)
|
static inline size_t lv_test_get_free_mem(void)
|
||||||
{
|
{
|
||||||
lv_mem_monitor_t m1;
|
lv_mem_monitor_t m1;
|
||||||
lv_mem_monitor(&m1);
|
lv_mem_monitor(&m1);
|
||||||
|
|||||||
2
tests/src/test_cases/cache/test_cache.c
vendored
2
tests/src/test_cases/cache/test_cache.c
vendored
@@ -127,7 +127,7 @@ void test_cache_1(void)
|
|||||||
* Now drop the cache {key1 = 32, key2 = 33}. However, this entry is acquired once without release, so `drop`
|
* Now drop the cache {key1 = 32, key2 = 33}. However, this entry is acquired once without release, so `drop`
|
||||||
* will not release the memory allocated by this entry.
|
* will not release the memory allocated by this entry.
|
||||||
*/
|
*/
|
||||||
uint32_t mem_curr_free = lv_test_get_free_mem();
|
size_t mem_curr_free = lv_test_get_free_mem();
|
||||||
lv_cache_drop(cache, &search_key32, NULL);
|
lv_cache_drop(cache, &search_key32, NULL);
|
||||||
/*
|
/*
|
||||||
* Though it doesn't release the data, the entry and other structure has been freed.
|
* Though it doesn't release the data, the entry and other structure has been freed.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void test_jpg_2(void)
|
|||||||
|
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_2.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_2.png");
|
||||||
|
|
||||||
uint32_t mem_before = lv_test_get_free_mem();
|
size_t mem_before = lv_test_get_free_mem();
|
||||||
for(uint32_t i = 0; i < 20; i++) {
|
for(uint32_t i = 0; i < 20; i++) {
|
||||||
create_images();
|
create_images();
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void test_libpng_1(void)
|
|||||||
|
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_2.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_2.png");
|
||||||
|
|
||||||
uint32_t mem_before = lv_test_get_free_mem();
|
size_t mem_before = lv_test_get_free_mem();
|
||||||
for(uint32_t i = 0; i < 20; i++) {
|
for(uint32_t i = 0; i < 20; i++) {
|
||||||
create_images();
|
create_images();
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void test_lodepng_1(void)
|
|||||||
|
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_1.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("libs/png_1.png");
|
||||||
|
|
||||||
uint32_t mem_before = lv_test_get_free_mem();
|
size_t mem_before = lv_test_get_free_mem();
|
||||||
for(uint32_t i = 0; i < 20; i++) {
|
for(uint32_t i = 0; i < 20; i++) {
|
||||||
create_images();
|
create_images();
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void test_tjpgd_1(void)
|
|||||||
|
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_1.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_1.png");
|
||||||
|
|
||||||
uint32_t mem_before = lv_test_get_free_mem();
|
size_t mem_before = lv_test_get_free_mem();
|
||||||
for(uint32_t i = 0; i < 20; i++) {
|
for(uint32_t i = 0; i < 20; i++) {
|
||||||
create_images();
|
create_images();
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void test_demo_stress(void)
|
|||||||
#endif
|
#endif
|
||||||
/* loop once to allow objects to be created */
|
/* loop once to allow objects to be created */
|
||||||
loop_through_stress_test();
|
loop_through_stress_test();
|
||||||
uint32_t mem_before = lv_test_get_free_mem();
|
size_t mem_before = lv_test_get_free_mem();
|
||||||
/* loop 5 more times */
|
/* loop 5 more times */
|
||||||
for(uint32_t i = 0; i < 5; i++) {
|
for(uint32_t i = 0; i < 5; i++) {
|
||||||
loop_through_stress_test();
|
loop_through_stress_test();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void test_event_should_not_memory_lean(void)
|
|||||||
lv_mem_monitor_t monitor;
|
lv_mem_monitor_t monitor;
|
||||||
lv_mem_monitor(&monitor);
|
lv_mem_monitor(&monitor);
|
||||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||||
uint32_t initial_free_size = monitor.free_size;
|
size_t initial_free_size = monitor.free_size;
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < 10; i++) {
|
||||||
lv_obj_add_event_cb(obj, NULL, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(obj, NULL, LV_EVENT_ALL, NULL);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
void test_snapshot_should_not_leak_memory(void)
|
void test_snapshot_should_not_leak_memory(void)
|
||||||
{
|
{
|
||||||
uint32_t idx = 0;
|
uint32_t idx = 0;
|
||||||
uint32_t initial_available_memory = 0;
|
size_t initial_available_memory = 0;
|
||||||
uint32_t final_available_memory = 0;
|
size_t final_available_memory = 0;
|
||||||
lv_mem_monitor_t monitor;
|
lv_mem_monitor_t monitor;
|
||||||
|
|
||||||
lv_draw_buf_t * snapshots[NUM_SNAPSHOTS] = {NULL};
|
lv_draw_buf_t * snapshots[NUM_SNAPSHOTS] = {NULL};
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void test_checkbox_should_return_dynamically_allocated_text(void)
|
|||||||
|
|
||||||
void test_checkbox_should_allocate_memory_for_static_text(void)
|
void test_checkbox_should_allocate_memory_for_static_text(void)
|
||||||
{
|
{
|
||||||
uint32_t initial_available_memory = 0;
|
size_t initial_available_memory = 0;
|
||||||
const char * static_text = "Keep me while you exist";
|
const char * static_text = "Keep me while you exist";
|
||||||
|
|
||||||
lv_mem_monitor_t m1;
|
lv_mem_monitor_t m1;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void test_dropdown_set_options(void)
|
|||||||
|
|
||||||
lv_mem_monitor_t m2;
|
lv_mem_monitor_t m2;
|
||||||
lv_mem_monitor(&m2);
|
lv_mem_monitor(&m2);
|
||||||
TEST_ASSERT_UINT32_WITHIN(48, m1.free_size, m2.free_size);
|
TEST_ASSERT_UINT_WITHIN(48, m1.free_size, m2.free_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_dropdown_select(void)
|
void test_dropdown_select(void)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ void test_switch_should_have_default_state_after_being_created(void)
|
|||||||
void test_switch_should_not_leak_memory_after_deletion(void)
|
void test_switch_should_not_leak_memory_after_deletion(void)
|
||||||
{
|
{
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
uint32_t initial_available_memory = 0;
|
size_t initial_available_memory = 0;
|
||||||
lv_obj_t * switches[SWITCHES_CNT] = {NULL};
|
lv_obj_t * switches[SWITCHES_CNT] = {NULL};
|
||||||
|
|
||||||
initial_available_memory = lv_test_get_free_mem();
|
initial_available_memory = lv_test_get_free_mem();
|
||||||
|
|||||||
Reference in New Issue
Block a user