[rtems commit] score: Fix workspace size estimate for TLS

Sebastian Huber sebh at rtems.org
Wed Apr 9 13:28:50 UTC 2014


Module:    rtems
Branch:    master
Commit:    6cf45cbeef58697af3349299f3fd717133eae5ed
Changeset: http://git.rtems.org/rtems/commit/?id=6cf45cbeef58697af3349299f3fd717133eae5ed

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Apr  7 16:50:13 2014 +0200

score: Fix workspace size estimate for TLS

---

 cpukit/score/include/rtems/score/heap.h |    5 +++++
 cpukit/score/src/heap.c                 |    3 ++-
 cpukit/score/src/wkspace.c              |   13 ++++++++++---
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 1ca840d..0120a2b 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -449,6 +449,11 @@ RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_up(
   }
 }
 
+RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min_block_size( uintptr_t page_size )
+{
+  return _Heap_Align_up( sizeof( Heap_Block ), page_size );
+}
+
 /**
  * @brief Returns the worst case overhead to manage a memory area.
  */
diff --git a/cpukit/score/src/heap.c b/cpukit/score/src/heap.c
index 949e963..1550c4c 100644
--- a/cpukit/score/src/heap.c
+++ b/cpukit/score/src/heap.c
@@ -228,7 +228,8 @@ uintptr_t _Heap_Initialize(
       return 0;
     }
   }
-  min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
+
+  min_block_size = _Heap_Min_block_size( page_size );
 
   area_ok = _Heap_Get_first_and_last_block(
     heap_area_begin,
diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c
index 071c178..20e2563 100644
--- a/cpukit/score/src/wkspace.c
+++ b/cpukit/score/src/wkspace.c
@@ -67,11 +67,18 @@ void _Workspace_Handler_initialization(
   size_t i;
 
   if ( tls_size > 0 ) {
-    uintptr_t tls_alignment = (uintptr_t) _TLS_Alignment;
-    uintptr_t tls_alloc = _TLS_Get_allocation_size( tls_size, tls_alignment );
+    uintptr_t tls_align = _TLS_Heap_align_up( (uintptr_t) _TLS_Alignment );
+    uintptr_t tls_alloc = _TLS_Get_allocation_size( tls_size, tls_align );
+
+    /*
+     * Memory allocated with an alignment constraint is allocated from the end
+     * of a free block.  The last allocation may need one free block of minimum
+     * size.
+     */
+    remaining += _Heap_Min_block_size( page_size );
 
     remaining += _Get_maximum_thread_count()
-      * _Heap_Size_with_overhead( page_size, tls_alloc, tls_alignment );
+      * _Heap_Size_with_overhead( page_size, tls_alloc, tls_align );
   }
 
   for (i = 0; i < area_count; ++i) {




More information about the vc mailing list