From 00c7ad4cab30aba80639ace29526c1efc2779074 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 16 Dec 2019 14:32:47 +0100 Subject: score: Split stack allocator configuration This allows the linker garbage collection to perform its work. Update #3835. --- cpukit/Makefile.am | 1 + cpukit/include/rtems/confdefs.h | 63 +++++++++++++++----------------------- cpukit/include/rtems/config.h | 63 ++++++++++++-------------------------- cpukit/include/rtems/score/stack.h | 52 +++++++++++++++++++++++++++++++ cpukit/score/src/stackallocator.c | 41 +++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 81 deletions(-) create mode 100644 cpukit/score/src/stackallocator.c (limited to 'cpukit') diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index 303c0afe9a..06e98c31ff 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -922,6 +922,7 @@ librtemscpu_a_SOURCES += score/src/schedulercbsgetserverid.c librtemscpu_a_SOURCES += score/src/schedulercbssetparameters.c librtemscpu_a_SOURCES += score/src/schedulercbsreleasejob.c librtemscpu_a_SOURCES += score/src/schedulercbsunblock.c +librtemscpu_a_SOURCES += score/src/stackallocator.c librtemscpu_a_SOURCES += score/src/pheapallocate.c librtemscpu_a_SOURCES += score/src/pheapextend.c librtemscpu_a_SOURCES += score/src/pheapfree.c diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h index 7fc1cf97de..00303de049 100644 --- a/cpukit/include/rtems/confdefs.h +++ b/cpukit/include/rtems/confdefs.h @@ -1202,34 +1202,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; ); #endif -/** - * Configure the very much optional task stack allocator initialization - */ -#ifndef CONFIGURE_TASK_STACK_ALLOCATOR_INIT - #define CONFIGURE_TASK_STACK_ALLOCATOR_INIT NULL -#endif - -/* - * Configure the very much optional task stack allocator and deallocator. - */ -#if !defined(CONFIGURE_TASK_STACK_ALLOCATOR) \ - && !defined(CONFIGURE_TASK_STACK_DEALLOCATOR) - /** - * This specifies the task stack allocator method. - */ - #define CONFIGURE_TASK_STACK_ALLOCATOR _Workspace_Allocate - /** - * This specifies the task stack deallocator method. - */ - #define CONFIGURE_TASK_STACK_DEALLOCATOR _Workspace_Free -#elif (defined(CONFIGURE_TASK_STACK_ALLOCATOR) \ - && !defined(CONFIGURE_TASK_STACK_DEALLOCATOR)) \ - || (!defined(CONFIGURE_TASK_STACK_ALLOCATOR) \ - && defined(CONFIGURE_TASK_STACK_DEALLOCATOR)) - #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined" -#endif -/**@}*/ /* end of thread/interrupt stack configuration */ - /** * @addtogroup Configuration */ @@ -2728,6 +2700,31 @@ struct _reent *__getreent(void) const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE; + #if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \ + && defined(CONFIGURE_TASK_STACK_DEALLOCATOR) + #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE + const bool _Stack_Allocator_avoids_workspace = true; + #else + const bool _Stack_Allocator_avoids_workspace = false; + #endif + + #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT + const Stack_Allocator_initialize _Stack_Allocator_initialize = + CONFIGURE_TASK_STACK_ALLOCATOR_INIT; + #else + const Stack_Allocator_initialize _Stack_Allocator_initialize = NULL; + #endif + + const Stack_Allocator_allocate _Stack_Allocator_allocate = + CONFIGURE_TASK_STACK_ALLOCATOR; + + const Stack_Allocator_free _Stack_Allocator_free = + CONFIGURE_TASK_STACK_DEALLOCATOR; + #elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \ + || defined(CONFIGURE_TASK_STACK_DEALLOCATOR) + #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined" + #endif + /** * This is the primary Configuration Table for this application. */ @@ -2738,21 +2735,11 @@ struct _reent *__getreent(void) CONFIGURE_TICKS_PER_TIMESLICE, /* ticks per timeslice quantum */ CONFIGURE_IDLE_TASK_BODY, /* user's IDLE task */ CONFIGURE_IDLE_TASK_STACK_SIZE, /* IDLE task stack size */ - CONFIGURE_TASK_STACK_ALLOCATOR_INIT, /* stack allocator init */ - CONFIGURE_TASK_STACK_ALLOCATOR, /* stack allocator */ - CONFIGURE_TASK_STACK_DEALLOCATOR, /* stack deallocator */ #ifdef CONFIGURE_UNIFIED_WORK_AREAS /* true for unified work areas */ true, #else false, #endif - #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE /* true to avoid - work space for thread stack - allocation */ - true, - #else - false, - #endif #ifdef RTEMS_SMP #ifdef _CONFIGURE_SMP_APPLICATION true, diff --git a/cpukit/include/rtems/config.h b/cpukit/include/rtems/config.h index 725f45d140..c1d735f587 100644 --- a/cpukit/include/rtems/config.h +++ b/cpukit/include/rtems/config.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -55,28 +56,19 @@ extern "C" { _Objects_Maximum_per_allocation(resource) /** - * @brief Task stack allocator initialization hook. - * - * @param[in] stack_space_size is the size of the stack space in bytes. + * @copydoc Stack_Allocator_initialize */ -typedef void (*rtems_stack_allocate_init_hook)( size_t stack_space_size ); +typedef Stack_Allocator_initialize rtems_stack_allocate_init_hook; /** - * @brief Task stack allocator hook. - * - * @param[in] stack_size is the Size of the task stack in bytes. - * - * @retval NULL Not enough memory. - * @retval other Pointer to task stack. + * @copydoc Stack_Allocator_allocate */ -typedef void *(*rtems_stack_allocate_hook)( size_t stack_size ); +typedef Stack_Allocator_allocate rtems_stack_allocate_hook; /** - * @brief Task stack deallocator hook. - * - * @param[in] addr is a pointer to previously allocated task stack. + * @copydoc Stack_Allocator_free */ -typedef void (*rtems_stack_free_hook)( void *addr ); +typedef Stack_Allocator_free rtems_stack_free_hook; /* * The following records define the Configuration Table. The @@ -129,21 +121,6 @@ typedef struct { */ uint32_t idle_task_stack_size; - /** - * @brief Optional task stack allocator initialization hook. - */ - rtems_stack_allocate_init_hook stack_allocate_init_hook; - - /** - * @brief Optional task stack allocator hook. - */ - rtems_stack_allocate_hook stack_allocate_hook; - - /** - * @brief Optional task stack free hook. - */ - rtems_stack_free_hook stack_free_hook; - /** * @brief Specifies if a unified work area is used or not. * @@ -152,15 +129,6 @@ typedef struct { */ bool unified_work_area; - /** - * @brief Specifies if the stack allocator avoids the work space. - * - * If this element is @a true, then the stack allocator must not allocate the - * thread stacks from the RTEMS Workspace, otherwise it should allocate the - * thread stacks from the RTEMS Workspace. - */ - bool stack_allocator_avoids_work_space; - #ifdef RTEMS_SMP bool smp_enabled; #endif @@ -183,8 +151,17 @@ extern const rtems_configuration_table Configuration; #define rtems_configuration_get_unified_work_area() \ (Configuration.unified_work_area) +/** + * @brief Return if the stack allocator avoids the work space. + * + * @retval true The stack allocator must not allocate the thread stacks from the + * RTEMS Workspace + * + * @retval false The stack allocator should allocate the thread stacks from the + * RTEMS Workspace. + */ #define rtems_configuration_get_stack_allocator_avoids_work_space() \ - (Configuration.stack_allocator_avoids_work_space) + (_Stack_Allocator_avoids_workspace) uintptr_t rtems_configuration_get_stack_space_size( void ); @@ -215,13 +192,13 @@ uint32_t rtems_configuration_get_maximum_extensions( void ); ((size_t) _ISR_Stack_size) #define rtems_configuration_get_stack_allocate_init_hook() \ - (Configuration.stack_allocate_init_hook) + (_Stack_Allocator_initialize) #define rtems_configuration_get_stack_allocate_hook() \ - (Configuration.stack_allocate_hook) + (_Stack_Allocator_allocate) #define rtems_configuration_get_stack_free_hook() \ - (Configuration.stack_free_hook) + (_Stack_Allocator_free) /** * This macro assists in accessing the field which indicates whether diff --git a/cpukit/include/rtems/score/stack.h b/cpukit/include/rtems/score/stack.h index 2ad362abd2..df1df74867 100644 --- a/cpukit/include/rtems/score/stack.h +++ b/cpukit/include/rtems/score/stack.h @@ -57,6 +57,30 @@ typedef struct { void *area; } Stack_Control; +/** + * @brief The stack allocator initialization handler. + * + * @param stack_space_size The size of the stack space in bytes. + */ +typedef void ( *Stack_Allocator_initialize )( size_t stack_space_size ); + +/** + * @brief Stack allocator allocate handler. + * + * @param stack_size The size of the stack area to allocate in bytes. + * + * @retval NULL Not enough memory. + * @retval other Pointer to begin of stack area. + */ +typedef void *( *Stack_Allocator_allocate )( size_t stack_size ); + +/** + * @brief Stack allocator free handler. + * + * @param] addr A pointer to previously allocated stack area or NULL. + */ +typedef void ( *Stack_Allocator_free )( void *addr ); + /** * @brief The minimum stack size. * @@ -71,6 +95,34 @@ extern uint32_t rtems_minimum_stack_size; */ extern const uintptr_t _Stack_Space_size; +/** + * @brief Indicates if the stack allocator avoids the workspace. + * + * Application provided via . + */ +extern const bool _Stack_Allocator_avoids_workspace; + +/** + * @brief The stack allocator initialization handler. + * + * Application provided via . + */ +extern const Stack_Allocator_initialize _Stack_Allocator_initialize; + +/** + * @brief The stack allocator allocate handler. + * + * Application provided via . + */ +extern const Stack_Allocator_allocate _Stack_Allocator_allocate; + +/** + * @brief The stack allocator free handler. + * + * Application provided via . + */ +extern const Stack_Allocator_free _Stack_Allocator_free; + /** @} */ #ifdef __cplusplus diff --git a/cpukit/score/src/stackallocator.c b/cpukit/score/src/stackallocator.c new file mode 100644 index 0000000000..d13874ee94 --- /dev/null +++ b/cpukit/score/src/stackallocator.c @@ -0,0 +1,41 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2019 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +const bool _Stack_Allocator_avoids_workspace = false; + +const Stack_Allocator_initialize _Stack_Allocator_initialize = NULL; + +const Stack_Allocator_allocate _Stack_Allocator_allocate = _Workspace_Allocate; + +const Stack_Allocator_free _Stack_Allocator_free = _Workspace_Free; -- cgit v1.2.3