[rtems commit] score: Split stack allocator configuration

Sebastian Huber sebh at rtems.org
Wed Feb 12 15:11:59 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Dec 16 14:32:47 2019 +0100

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(-)

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 303c0af..06e98c3 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 7fc1cf9..00303de 100644
--- a/cpukit/include/rtems/confdefs.h
+++ b/cpukit/include/rtems/confdefs.h
@@ -1203,34 +1203,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 725f45d..c1d735f 100644
--- a/cpukit/include/rtems/config.h
+++ b/cpukit/include/rtems/config.h
@@ -30,6 +30,7 @@
 #include <rtems/score/object.h>
 #include <rtems/score/isr.h>
 #include <rtems/score/memory.h>
+#include <rtems/score/stack.h>
 #include <rtems/score/userextdata.h>
 #include <rtems/score/watchdogticks.h>
 #include <rtems/rtems/config.h>
@@ -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
@@ -130,21 +122,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.
    *
    * If this element is @a true, then the RTEMS Workspace and the C Program
@@ -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 2ad362a..df1df74 100644
--- a/cpukit/include/rtems/score/stack.h
+++ b/cpukit/include/rtems/score/stack.h
@@ -58,6 +58,30 @@ typedef struct {
 }   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.
  *
  * Application provided via <rtems/confdefs.h>.
@@ -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 0000000..d13874e
--- /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;



More information about the vc mailing list