From 45ee958552ca35b6834985718ecd59b27fc52f86 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 30 Sep 2022 08:06:18 +0200 Subject: config: Add CONFIGURE_IDLE_TASK_STORAGE_SIZE By default, allocate the IDLE task storage areas from the RTEMS Workspace. This avoids having to estimate the thread-local storage size in the default configuration. Add the application configuration option CONFIGURE_IDLE_TASK_STORAGE_SIZE to request a static allocation of the task storage area for IDLE tasks. Update #3835. Update #4524. --- cpukit/score/src/stackallocatorforidle.c | 43 ++++++++---------- cpukit/score/src/stackallocatorforidlewkspace.c | 60 +++++++++++++++++++++++++ cpukit/score/src/threadcreateidle.c | 23 +++++++--- 3 files changed, 95 insertions(+), 31 deletions(-) create mode 100644 cpukit/score/src/stackallocatorforidlewkspace.c (limited to 'cpukit/score') diff --git a/cpukit/score/src/stackallocatorforidle.c b/cpukit/score/src/stackallocatorforidle.c index c97dde030f..c8c8c0b766 100644 --- a/cpukit/score/src/stackallocatorforidle.c +++ b/cpukit/score/src/stackallocatorforidle.c @@ -1,6 +1,15 @@ -/* - * SPDX-License-Identifier: BSD-2-Clause +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSScoreStack * + * @brief This source file contains the implementation of + * _Stack_Allocator_allocate_for_idle_static(). + */ + +/* * Copyright (C) 2021 On-Line Applications Research Corporation (OAR) * * Redistribution and use in source and binary forms, with or without @@ -30,35 +39,21 @@ #endif #include -#include #include -/** - * @brief Default stack allocator allocate for IDLE threads. - * - * The default allocator for IDLE thread stacks gets the memory from a - * statically allocated area provided via confdefs.h. - * - * @param cpu is the index of the CPU for the IDLE thread using this stack. - * - * @param stack_size[in] is pointer to a size_t object. On function - * entry, the object contains the size of the stack area to allocate in - * bytes. - * - * @return Returns the pointer to begin of the allocated stack area. - */ -static void *_Stack_Allocator_allocate_for_idle_default( +void *_Stack_Allocator_allocate_for_idle_static( uint32_t cpu_index, - size_t *stack_size + size_t *storage_size ) { + size_t size; + + size = _Stack_Allocator_allocate_for_idle_storage_size; + *storage_size = size; #if defined(RTEMS_SMP) - return &_Thread_Idle_stacks[ cpu_index * ( *stack_size ) ]; + return &_Stack_Allocator_allocate_for_idle_storage_areas[ cpu_index * size ]; #else _Assert( cpu_index == 0 ); - return &_Thread_Idle_stacks[ 0 ]; + return &_Stack_Allocator_allocate_for_idle_storage_areas[ 0 ]; #endif } - -const Stack_Allocator_allocate_for_idle _Stack_Allocator_allocate_for_idle = - _Stack_Allocator_allocate_for_idle_default; diff --git a/cpukit/score/src/stackallocatorforidlewkspace.c b/cpukit/score/src/stackallocatorforidlewkspace.c new file mode 100644 index 0000000000..0864271f07 --- /dev/null +++ b/cpukit/score/src/stackallocatorforidlewkspace.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSScoreStack + * + * @brief This source file contains the implementation of + * _Stack_Allocator_allocate_for_idle_workspace(). + */ + +/* + * Copyright (C) 2022 embedded brains GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +void *_Stack_Allocator_allocate_for_idle_workspace( + uint32_t unused, + size_t *storage_size +) +{ + void *area; + + (void) unused; + area = _Workspace_Allocate( *storage_size ); + + if ( area == NULL ) { + _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_IDLE_TASK_STORAGE ); + } + + return area; +} diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c index d2037b36f0..04565f910b 100644 --- a/cpukit/score/src/threadcreateidle.c +++ b/cpukit/score/src/threadcreateidle.c @@ -53,7 +53,10 @@ #include -static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu ) +static void _Thread_Create_idle_for_CPU( + Per_CPU_Control *cpu, + uintptr_t storage_size +) { Thread_Configuration config; Thread_Control *idle; @@ -70,8 +73,7 @@ static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu ) config.is_fp = CPU_IDLE_TASK_IS_FP; config.is_preemptible = true; config.stack_free = _Objects_Free_nothing; - config.stack_size = _Thread_Idle_stack_size - + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE; + config.stack_size = storage_size; /* * The IDLE thread stacks may be statically allocated or there may be a @@ -118,21 +120,28 @@ static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu ) void _Thread_Create_idle( void ) { + uintptr_t storage_size; #if defined(RTEMS_SMP) - uint32_t cpu_max; - uint32_t cpu_index; + uint32_t cpu_max; + uint32_t cpu_index; +#endif + + storage_size = _TLS_Get_allocation_size() + + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE + + _Thread_Idle_stack_size; +#if defined(RTEMS_SMP) cpu_max = _SMP_Get_processor_maximum(); for ( cpu_index = 0 ; cpu_index < cpu_max ; ++cpu_index ) { Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); if ( _Per_CPU_Is_processor_online( cpu ) ) { - _Thread_Create_idle_for_CPU( cpu ); + _Thread_Create_idle_for_CPU( cpu, storage_size ); } } #else - _Thread_Create_idle_for_CPU( _Per_CPU_Get() ); + _Thread_Create_idle_for_CPU( _Per_CPU_Get(), storage_size ); #endif _CPU_Use_thread_local_storage( -- cgit v1.2.3