[PATCH] userext: Simplify configuration

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Dec 5 14:18:26 UTC 2019


Avoid the use of the workspace and use statically allocated switch
controls for the initial extensions.
---
 cpukit/include/rtems/confdefs.h          | 28 +++++++---------------------
 cpukit/include/rtems/config.h            |  6 +++---
 cpukit/include/rtems/score/userextdata.h |  7 +++++++
 cpukit/score/src/userext.c               | 20 +++++++-------------
 cpukit/score/src/userextiterate.c        |  8 +++-----
 5 files changed, 27 insertions(+), 42 deletions(-)

diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h
index 4e6b91ad2c..f04717006d 100644
--- a/cpukit/include/rtems/confdefs.h
+++ b/cpukit/include/rtems/confdefs.h
@@ -2124,7 +2124,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     defined(CONFIGURE_INITIAL_EXTENSIONS) || \
     defined(CONFIGURE_STACK_CHECKER_ENABLED) || \
     (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
-  static const rtems_extensions_table Configuration_Initial_Extensions[] = {
+  const User_extensions_Table _User_extensions_Initial_extensions[] = {
     #if CONFIGURE_RECORD_PER_PROCESSOR_ITEMS > 0 && \
       defined(CONFIGURE_RECORD_EXTENSIONS_ENABLED)
       RECORD_EXTENSION,
@@ -2143,18 +2143,18 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     #endif
   };
 
-  #define _CONFIGURE_INITIAL_EXTENSION_TABLE Configuration_Initial_Extensions
-  #define _CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS \
-    RTEMS_ARRAY_SIZE(Configuration_Initial_Extensions)
+  const size_t _User_extensions_Initial_count =
+    RTEMS_ARRAY_SIZE( _User_extensions_Initial_extensions );
+
+  User_extensions_Switch_control _User_extensions_Initial_switch_controls[
+    RTEMS_ARRAY_SIZE( _User_extensions_Initial_extensions )
+  ];
 
   RTEMS_SYSINIT_ITEM(
     _User_extensions_Handler_initialization,
     RTEMS_SYSINIT_INITIAL_EXTENSIONS,
     RTEMS_SYSINIT_ORDER_MIDDLE
   );
-#else
-  #define _CONFIGURE_INITIAL_EXTENSION_TABLE NULL
-  #define _CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS 0
 #endif
 
 #if defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY)
@@ -2486,17 +2486,6 @@ struct _reent *__getreent(void)
 #define _CONFIGURE_MEMORY_FOR_SYSTEM_OVERHEAD \
   _CONFIGURE_MEMORY_FOR_INTERNAL_TASKS
 
-/**
- * This macro reserves the memory required by the statically configured
- * user extensions.
- */
-#define _CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS \
-  (_CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS == 0 ? 0 : \
-    _Configure_From_workspace( \
-      _CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS \
-        * sizeof(User_extensions_Switch_control) \
-    ))
-
 /**
  * This calculates the memory required for the executive workspace.
  *
@@ -2517,7 +2506,6 @@ struct _reent *__getreent(void)
    _CONFIGURE_MEMORY_FOR_POSIX_SHMS( \
      CONFIGURE_MAXIMUM_POSIX_SHMS) + \
    _CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS + \
-   _CONFIGURE_MEMORY_FOR_STATIC_EXTENSIONS + \
    _CONFIGURE_MEMORY_FOR_MP + \
    CONFIGURE_MESSAGE_BUFFER_MEMORY + \
    (CONFIGURE_MEMORY_OVERHEAD * 1024) + \
@@ -2923,8 +2911,6 @@ struct _reent *__getreent(void)
         false,
       #endif
     #endif
-    _CONFIGURE_NUMBER_OF_INITIAL_EXTENSIONS,   /* number of static extensions */
-    _CONFIGURE_INITIAL_EXTENSION_TABLE,        /* pointer to static extensions */
     #if defined(RTEMS_MULTIPROCESSING)
       CONFIGURE_MULTIPROCESSING_TABLE,        /* pointer to MP config table */
     #endif
diff --git a/cpukit/include/rtems/config.h b/cpukit/include/rtems/config.h
index ae11fd9df8..c0302d96cf 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/userextdata.h>
 #include <rtems/score/watchdogticks.h>
 #include <rtems/rtems/config.h>
 #include <rtems/posix/config.h>
@@ -206,7 +207,6 @@ typedef struct {
   #endif
 
   uint32_t                       number_of_initial_extensions;
-  const rtems_extensions_table  *User_extension_table;
   #if defined(RTEMS_MULTIPROCESSING)
     rtems_multiprocessing_table   *User_multiprocessing_table;
   #endif
@@ -302,10 +302,10 @@ uint32_t rtems_configuration_get_maximum_extensions( void );
    (Configuration.do_zero_of_workspace)
 
 #define rtems_configuration_get_number_of_initial_extensions() \
-        (Configuration.number_of_initial_extensions)
+  ((uint32_t) _User_extensions_Initial_count)
 
 #define rtems_configuration_get_user_extension_table() \
-        (Configuration.User_extension_table)
+  (&_User_extensions_Initial_extensions[ 0 ])
 
 #if defined(RTEMS_MULTIPROCESSING)
   #define rtems_configuration_get_user_multiprocessing_table() \
diff --git a/cpukit/include/rtems/score/userextdata.h b/cpukit/include/rtems/score/userextdata.h
index 7b7a2eb95f..7c19d72721 100644
--- a/cpukit/include/rtems/score/userextdata.h
+++ b/cpukit/include/rtems/score/userextdata.h
@@ -53,6 +53,13 @@ typedef struct {
   User_extensions_Table          Callouts;
 }   User_extensions_Control;
 
+extern const size_t _User_extensions_Initial_count;
+
+extern const User_extensions_Table _User_extensions_Initial_extensions[];
+
+extern User_extensions_Switch_control
+  _User_extensions_Initial_switch_controls[];
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/cpukit/score/src/userext.c b/cpukit/score/src/userext.c
index a2e70dc4d3..c724d1d0fa 100644
--- a/cpukit/score/src/userext.c
+++ b/cpukit/score/src/userext.c
@@ -19,24 +19,18 @@
   #include "config.h"
 #endif
 
-#include <rtems/config.h>
 #include <rtems/score/userextimpl.h>
-#include <rtems/score/wkspace.h>
 
 void _User_extensions_Handler_initialization(void)
 {
-  User_extensions_Switch_control *initial_extension_switch_controls;
   const User_extensions_Table    *initial_table;
-  uint32_t                        n;
-  uint32_t                        i;
+  User_extensions_Switch_control *initial_switch_controls;
+  size_t                          n;
+  size_t                          i;
 
-  n = rtems_configuration_get_number_of_initial_extensions();
-
-  initial_extension_switch_controls = _Workspace_Allocate_or_fatal_error(
-    n * sizeof( *initial_extension_switch_controls )
-  );
-
-  initial_table = rtems_configuration_get_user_extension_table();
+  initial_table = _User_extensions_Initial_extensions;
+  initial_switch_controls = _User_extensions_Initial_switch_controls;
+  n = _User_extensions_Initial_count;
 
   for ( i = 0 ; i < n ; ++i ) {
     User_extensions_thread_switch_extension callout;
@@ -46,7 +40,7 @@ void _User_extensions_Handler_initialization(void)
     if ( callout != NULL ) {
       User_extensions_Switch_control *c;
 
-      c = &initial_extension_switch_controls[ i ];
+      c = &initial_switch_controls[ i ];
       c->thread_switch = callout;
       _Chain_Initialize_node( &c->Node );
       _Chain_Append_unprotected( &_User_extensions_Switches_list, &c->Node );
diff --git a/cpukit/score/src/userextiterate.c b/cpukit/score/src/userextiterate.c
index 0bd32262e9..ca010efa92 100644
--- a/cpukit/score/src/userextiterate.c
+++ b/cpukit/score/src/userextiterate.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2012, 2017 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2012, 2019 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -24,7 +24,6 @@
   #include "config.h"
 #endif
 
-#include <rtems/config.h>
 #include <rtems/score/userextimpl.h>
 
 #include <pthread.h>
@@ -164,9 +163,8 @@ void _User_extensions_Iterate(
 
   executing = _Thread_Get_executing();
 
-  initial_begin = rtems_configuration_get_user_extension_table();
-  initial_end =
-    initial_begin + rtems_configuration_get_number_of_initial_extensions();
+  initial_begin = _User_extensions_Initial_extensions;
+  initial_end = initial_begin + _User_extensions_Initial_count;
 
   if ( direction == CHAIN_ITERATOR_FORWARD ) {
     initial_current = initial_begin;
-- 
2.16.4



More information about the devel mailing list