[PATCH 07/21] score: Split stack allocator configuration

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 16 14:28:12 UTC 2019


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

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 3ced5bdd4d..33b10be42a 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -919,6 +919,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 069666abda..a5728e9868 100644
--- a/cpukit/include/rtems/confdefs.h
+++ b/cpukit/include/rtems/confdefs.h
@@ -1199,34 +1199,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
  */
@@ -2793,6 +2765,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.
    */
@@ -2803,22 +2800,12 @@ 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 */
     CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY,   /* true to clear memory */
     #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 6e3fa39a5f..923569338f 100644
--- a/cpukit/include/rtems/config.h
+++ b/cpukit/include/rtems/config.h
@@ -29,6 +29,7 @@
 
 #include <rtems/score/object.h>
 #include <rtems/score/isr.h>
+#include <rtems/score/stack.h>
 #include <rtems/score/userextdata.h>
 #include <rtems/score/watchdogticks.h>
 #include <rtems/rtems/config.h>
@@ -54,28 +55,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
@@ -128,21 +120,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;
-
   /** 
    * If this element is TRUE, then RTEMS will zero the Executive Workspace.
    * When this element is FALSE, it is assumed that the BSP or invoking
@@ -159,15 +136,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
@@ -190,8 +158,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 );
 
@@ -222,13 +199,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 <rtems/confdefs.h>.
+ */
+extern const bool _Stack_Allocator_avoids_workspace;
+
+/**
+ * @brief The stack allocator initialization handler.
+ *
+ * Application provided via <rtems/confdefs.h>.
+ */
+extern const Stack_Allocator_initialize _Stack_Allocator_initialize;
+
+/**
+ * @brief The stack allocator allocate handler.
+ *
+ * Application provided via <rtems/confdefs.h>.
+ */
+extern const Stack_Allocator_allocate _Stack_Allocator_allocate;
+
+/**
+ * @brief The stack allocator free handler.
+ *
+ * Application provided via <rtems/confdefs.h>.
+ */
+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 <rtems/score/stack.h>
+#include <rtems/score/wkspace.h>
+
+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;
-- 
2.16.4



More information about the devel mailing list