From 6cf45cbeef58697af3349299f3fd717133eae5ed Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 7 Apr 2014 16:50:13 +0200 Subject: 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 1ca840d4a0..0120a2bb14 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 949e963070..1550c4ce1c 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 071c178758..20e2563287 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) { -- cgit v1.2.3