lvgl heap: Align addresses & sizes to cache line size

This commit is contained in:
CTCaer 2019-12-04 19:04:11 +02:00
parent ec10b572d1
commit b61b212218

View file

@ -34,13 +34,14 @@
#if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/
/*The size of this union must be 4 bytes (uint32_t)*/
/*The size of this union must be 32 bytes (uint32_t * 8)*/
typedef union {
struct {
MEM_UNIT used: 1; //1: if the entry is used
MEM_UNIT d_size: 31; //Size off the data (1 means 4 bytes)
};
MEM_UNIT header; //The header (used + d_size)
uint32_t align[7]; //Align header size to 32 bytes
} lv_mem_header_t;
typedef struct {
@ -109,19 +110,12 @@ void * lv_mem_alloc(uint32_t size)
return &zero_mem;
}
#ifdef LV_MEM_ENV64
/*Round the size up to 8*/
if(size & 0x7) {
size = size & (~0x7);
size += 8;
/*Round the size up to 32*/
if(size & 0x1F) {
size = size & (~0x1F);
size += 0x20;
}
#else
/*Round the size up to 4*/
if(size & 0x3) {
size = size & (~0x3);
size += 4;
}
#endif
void * alloc = NULL;
#if LV_MEM_CUSTOM == 0 /*Use the allocation from dyn_mem*/
@ -339,7 +333,7 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p)
e = ent_get_next(e);
}
mon_p->total_size = LV_MEM_SIZE;
mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size;
mon_p->used_pct = 100 - ((uint64_t)100U * mon_p->free_size) / mon_p->total_size;
mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size;
mon_p->frag_pct = 100 - mon_p->frag_pct;
#endif
@ -430,19 +424,12 @@ static void * ent_alloc(lv_mem_ent_t * e, uint32_t size)
*/
static void ent_trunc(lv_mem_ent_t * e, uint32_t size)
{
#ifdef LV_MEM_ENV64
/*Round the size up to 8*/
if(size & 0x7) {
size = size & (~0x7);
size += 8;
/*Round the size up to 32*/
if(size & 0x1F) {
size = size & (~0x1F);
size += 0x20;
}
#else
/*Round the size up to 4*/
if(size & 0x3) {
size = size & (~0x3);
size += 4;
}
#endif
/*Don't let empty space only for a header without data*/
if(e->header.d_size == size + sizeof(lv_mem_header_t)) {