summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-01-28 11:49:57 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-02-04 10:06:34 +0100
commita49bc354a77f7710fcfa7995e18107170d32eb70 (patch)
tree55660903659862a0d481ee6db136154437c02c6f
parentscore: Add _Workspace_Allocate_aligned() (diff)
downloadrtems-a49bc354a77f7710fcfa7995e18107170d32eb70.tar.bz2
score: Add _Heap_Size_with_overhead()
-rw-r--r--cpukit/score/include/rtems/score/heap.h23
-rw-r--r--testsuites/libtests/malloctest/init.c20
-rw-r--r--testsuites/libtests/malloctest/malloctest.scn1
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 80a041ca7c..53b569af82 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 ace454f69d..0cdbe844f4 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 dcb529ddb8..ec684c6f1f 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