[PATCH 2/5] score: Add _Heap_Size_with_overhead()
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Jan 29 10:17:49 UTC 2014
---
cpukit/score/include/rtems/score/heap.h | 23 +++++++++++++++++++++++
testsuites/libtests/malloctest/init.c | 20 ++++++++++++++++++++
testsuites/libtests/malloctest/malloctest.scn | 1 +
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 80a041c..53b569a 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -464,6 +464,29 @@ RTEMS_INLINE_ROUTINE uintptr_t _Heap_Area_overhead(
return 2 * (page_size - 1) + HEAP_BLOCK_HEADER_SIZE;
}
+/**
+ * @brief Returns the size with administration and alignment overhead for one
+ * allocation.
+ */
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Size_with_overhead(
+ uintptr_t page_size,
+ uintptr_t size,
+ uintptr_t alignment
+)
+{
+ if ( page_size != 0 ) {
+ page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
+ } else {
+ page_size = CPU_ALIGNMENT;
+ }
+
+ if ( page_size < alignment ) {
+ page_size = alignment;
+ }
+
+ return HEAP_BLOCK_HEADER_SIZE + page_size - 1 + size;
+}
+
/** @} */
#ifdef __cplusplus
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index ace454f..0cdbe84 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -1157,6 +1157,25 @@ static void test_rtems_heap_allocate_aligned_with_boundary(void)
rtems_test_assert( p == NULL );
}
+static void test_heap_size_with_overhead(void)
+{
+ uintptr_t s;
+
+ puts( "_Heap_Size_with_overhead" );
+
+ s = _Heap_Size_with_overhead(0, 0, 0);
+ rtems_test_assert(s == HEAP_BLOCK_HEADER_SIZE + CPU_ALIGNMENT - 1);
+
+ s = _Heap_Size_with_overhead(CPU_ALIGNMENT, 0, 0);
+ rtems_test_assert(s == HEAP_BLOCK_HEADER_SIZE + CPU_ALIGNMENT - 1);
+
+ s = _Heap_Size_with_overhead(CPU_ALIGNMENT, 0, 2 * CPU_ALIGNMENT);
+ rtems_test_assert(s == HEAP_BLOCK_HEADER_SIZE + 2 * CPU_ALIGNMENT - 1);
+
+ s = _Heap_Size_with_overhead(CPU_ALIGNMENT, 123, 0);
+ rtems_test_assert(s == HEAP_BLOCK_HEADER_SIZE + CPU_ALIGNMENT - 1 + 123);
+}
+
/*
* A simple test of posix_memalign
*/
@@ -1268,6 +1287,7 @@ rtems_task Init(
test_heap_extend_allocation_order_with_empty_heap();
test_heap_no_extend();
test_heap_info();
+ test_heap_size_with_overhead();
test_protected_heap_info();
test_rtems_heap_allocate_aligned_with_boundary();
test_greedy_allocate();
diff --git a/testsuites/libtests/malloctest/malloctest.scn b/testsuites/libtests/malloctest/malloctest.scn
index dcb529d..ec684c6 100644
--- a/testsuites/libtests/malloctest/malloctest.scn
+++ b/testsuites/libtests/malloctest/malloctest.scn
@@ -59,6 +59,7 @@ malloc_info - called with NULL
malloc_info - check free space drops after malloc
malloc_info - verify free space returns to previous value
+_Heap_Size_with_overhead
_Protected_heap_Get_information - NULL heap
_Protected_heap_Get_information - NULL info
posix_memalign - NULL return pointer -- EINVAL
--
1.7.7
More information about the devel
mailing list