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
This commit is contained in:
Felipe Neves
2020-01-16 15:37:19 -03:00
committed by bot
parent a3c90bf59a
commit bd9b921713
23 changed files with 1604 additions and 734 deletions
+10 -8
View File
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <sys/param.h>
#include <string.h>
#include <malloc.h>
TEST_CASE("Capabilities aligned allocator test", "[heap]")
{
@@ -19,7 +20,7 @@ TEST_CASE("Capabilities aligned allocator test", "[heap]")
printf("[ALIGNED_ALLOC] Allocating from default CAP: \n");
for(;alignments <= 1024; alignments++) {
uint8_t *buf = (uint8_t *)heap_caps_aligned_alloc(alignments, (alignments + 137), MALLOC_CAP_DEFAULT);
uint8_t *buf = (uint8_t *)memalign(alignments, (alignments + 137));
if(((alignments & (alignments - 1)) != 0) || (!alignments)) {
TEST_ASSERT( buf == NULL );
//printf("[ALIGNED_ALLOC] alignment: %u is not a power of two, don't allow allocation \n", aligments);
@@ -28,7 +29,6 @@ TEST_CASE("Capabilities aligned allocator test", "[heap]")
printf("[ALIGNED_ALLOC] alignment required: %u \n", alignments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
if((alignments & 0x03) == 0) {
//Alignment is a multiple of four:
TEST_ASSERT(((intptr_t)buf & 0x03) == 0);
@@ -41,7 +41,7 @@ TEST_CASE("Capabilities aligned allocator test", "[heap]")
//canary verification will fail:
memset(buf, 0xA5, (alignments + 137));
heap_caps_aligned_free(buf);
free(buf);
}
}
@@ -71,10 +71,12 @@ TEST_CASE("Capabilities aligned allocator test", "[heap]")
//Exotic alignments:
TEST_ASSERT(((intptr_t)buf & (alignments - 1)) == 0);
}
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (10*1024));
heap_caps_aligned_free(buf);
heap_caps_free(buf);
}
}
#endif
@@ -109,7 +111,7 @@ TEST_CASE("Capabilities aligned calloc test", "[heap]")
//canary verification will fail:
memset(buf, 0xA5, (alignments + 137));
heap_caps_aligned_free(buf);
heap_caps_free(buf);
}
}
@@ -118,12 +120,12 @@ TEST_CASE("Capabilities aligned calloc test", "[heap]")
memset(&byte_array, 0, sizeof(byte_array));
uint8_t *buf = (uint8_t *)heap_caps_aligned_calloc(1024, 1, 1024, MALLOC_CAP_DEFAULT);
TEST_ASSERT(memcmp(byte_array, buf, sizeof(byte_array)) == 0);
heap_caps_aligned_free(buf);
heap_caps_free(buf);
//Same size, but different chunk:
buf = (uint8_t *)heap_caps_aligned_calloc(1024, 1024, 1, MALLOC_CAP_DEFAULT);
TEST_ASSERT(memcmp(byte_array, buf, sizeof(byte_array)) == 0);
heap_caps_aligned_free(buf);
heap_caps_free(buf);
//Alloc from a non permitted area:
uint32_t *not_permitted_buf = (uint32_t *)heap_caps_aligned_calloc(alignments, 1, (alignments + 137), MALLOC_CAP_32BIT);
@@ -154,7 +156,7 @@ TEST_CASE("Capabilities aligned calloc test", "[heap]")
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (10*1024));
heap_caps_aligned_free(buf);
heap_caps_free(buf);
}
}
#endif