Changeset ba74ebde in rtems


Ignore:
Timestamp:
Feb 14, 2020, 6:09:56 PM (5 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
1ada3e55
Parents:
ba46b936
git-author:
Sebastian Huber <sebastian.huber@…> (02/14/20 18:09:56)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/25/20 06:18:26)
Message:

libio: Add POSIX user environment pointer to TCB

The IO library used a POSIX key to store an optional POSIX user
environment pointer. This pulled in the POSIX keys support in every
application configuration. Add a user environment pointer to the thread
control block (TCB) instead. Applications which do not need the POSIX
user environment will just get an overhead of one pointer per thread.

Close #3882.

Files:
3 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/confdefs.h

    rba46b936 rba74ebde  
    139139  #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 3
    140140#endif
    141 
    142 /*
    143  * POSIX key count used by the IO library.
    144  */
    145 #define _CONFIGURE_LIBIO_POSIX_KEYS 1
    146141
    147142#ifdef CONFIGURE_INIT
     
    20742069#endif
    20752070
    2076 /*
    2077  * This macro is calculated to specify the total number of
    2078  * POSIX API keys required by the application and configured
    2079  * system capabilities.
    2080  */
    2081 #define _CONFIGURE_POSIX_KEYS \
    2082   (CONFIGURE_MAXIMUM_POSIX_KEYS + _CONFIGURE_LIBIO_POSIX_KEYS)
    2083 
    20842071/**
    20852072 * This configuration parameter specifies the maximum number of
     
    25512538  #endif
    25522539
    2553   #if _CONFIGURE_POSIX_KEYS > 0
    2554     POSIX_KEYS_INFORMATION_DEFINE( _CONFIGURE_POSIX_KEYS );
     2540  #if CONFIGURE_MAXIMUM_POSIX_KEYS > 0
     2541    POSIX_KEYS_INFORMATION_DEFINE( CONFIGURE_MAXIMUM_POSIX_KEYS );
    25552542  #endif
    25562543
  • cpukit/include/rtems/libio_.h

    rba46b936 rba74ebde  
    337337#include <rtems/userenv.h>
    338338
    339 void rtems_libio_free_user_env( void *env );
    340 
    341 extern pthread_key_t rtems_current_user_env_key;
    342 
    343339void rtems_libio_lock( void );
    344340
  • cpukit/include/rtems/score/interr.h

    rba46b936 rba74ebde  
    198198  INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED = 32,
    199199  INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED = 33,
    200   INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34,
     200  /* INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34, */
    201201  /* INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED = 35, */
    202202  INTERNAL_ERROR_LIBIO_STDOUT_FD_OPEN_FAILED = 36,
  • cpukit/include/rtems/score/thread.h

    rba46b936 rba74ebde  
    4343#include <rtems/score/processormask.h>
    4444#endif
     45
     46struct rtems_user_env_t;
    4547
    4648struct _pthread_cleanup_context;
     
    858860
    859861  Thread_Capture_control                Capture;
     862
     863  /**
     864   * @brief Pointer to an optional thread-specific POSIX user environment.
     865   */
     866  struct rtems_user_env_t *user_environment;
    860867
    861868  /**
  • cpukit/include/rtems/sysinit.h

    rba46b936 rba74ebde  
    6969#define RTEMS_SYSINIT_IDLE_THREADS               001d00
    7070#define RTEMS_SYSINIT_LIBIO                      001e00
     71#define RTEMS_SYSINIT_USER_ENVIRONMENT           001e80
    7172#define RTEMS_SYSINIT_ROOT_FILESYSTEM            001f00
    7273#define RTEMS_SYSINIT_DRVMGR                     002000
  • cpukit/include/rtems/userenv.h

    rba46b936 rba74ebde  
    5454#endif
    5555
     56typedef struct rtems_user_env_t rtems_user_env_t;
     57
    5658/**
    5759 * @brief User environment.
    5860 */
    59 typedef struct {
     61struct rtems_user_env_t {
    6062  /**
    6163   * @brief The anchor directory for relative paths.
     
    112114   */
    113115  gid_t groups[NGROUPS];
    114 } rtems_user_env_t;
     116};
    115117
    116118extern rtems_user_env_t rtems_global_user_env;
  • cpukit/libcsupport/src/__usrenv.c

    rba46b936 rba74ebde  
    2525
    2626#include <rtems/libio_.h>
     27#include <rtems/score/percpu.h>
     28#include <rtems/score/thread.h>
    2729
    2830static int null_handler_open(
     
    250252};
    251253
    252 pthread_key_t rtems_current_user_env_key;
     254rtems_user_env_t *rtems_current_user_env_get(void)
     255{
     256  Thread_Control *executing = _Thread_Get_executing();
     257  rtems_user_env_t *env = executing->user_environment;
     258
     259  if (env == NULL) {
     260    return &rtems_global_user_env;
     261  }
     262
     263  return env;
     264}
  • cpukit/libcsupport/src/libio_init.c

    rba46b936 rba74ebde  
    5050    uint32_t i;
    5151    rtems_libio_t *iop;
    52     int eno;
    5352
    5453    if (rtems_libio_number_iops > 0)
     
    6059        rtems_libio_iop_free_tail = &iop->data1;
    6160    }
    62 
    63   /*
    64    *  Create the posix key for user environment.
    65    */
    66   eno = pthread_key_create(
    67     &rtems_current_user_env_key,
    68     rtems_libio_free_user_env
    69   );
    70   if (eno != 0) {
    71     _Internal_error( INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED );
    72   }
    7361}
    7462
  • cpukit/libcsupport/src/privateenv.c

    rba46b936 rba74ebde  
    2525#include <rtems/libio_.h>
    2626#include <rtems/score/threadimpl.h>
     27#include <rtems/score/userextimpl.h>
     28#include <rtems/sysinit.h>
    2729
    2830/**
     
    3032 */
    3133
    32 rtems_user_env_t * rtems_current_user_env_get(void)
     34static void rtems_libio_free_user_env(rtems_user_env_t *env)
    3335{
    34   void *ptr = pthread_getspecific(rtems_current_user_env_key);
    35   if (ptr == NULL) {
    36     ptr = &rtems_global_user_env;
    37   }
    38   return (rtems_user_env_t *) ptr;
    39 }
    40 
    41 void rtems_libio_free_user_env(void *arg)
    42 {
    43   rtems_user_env_t *env = arg;
    4436  bool uses_global_env = env == &rtems_global_user_env;
    4537
     
    7365          && !rtems_filesystem_global_location_is_null(new_env->current_directory)
    7466      ) {
    75         int eno = pthread_setspecific(
    76           rtems_current_user_env_key,
    77           new_env
    78         );
     67        Thread_Control *executing = _Thread_Get_executing();
    7968
    80         if (eno == 0) {
    81           rtems_libio_free_user_env(old_env);
    82         } else {
    83           sc = RTEMS_TOO_MANY;
    84         }
     69        executing->user_environment = new_env;
    8570      } else {
    8671        sc = RTEMS_UNSATISFIED;
     
    10893    Thread_Life_state life_state =
    10994      _Thread_Set_life_protection(THREAD_LIFE_PROTECTED);
     95    Thread_Control *executing;
    11096
    11197    rtems_libio_free_user_env(env);
    112     pthread_setspecific(rtems_current_user_env_key, NULL);
     98    executing = _Thread_Get_executing();
     99    executing->user_environment = NULL;
    113100
    114101    _Thread_Set_life_protection(life_state);
    115102  }
    116103}
     104
     105static void rtems_libio_env_thread_terminate(Thread_Control *the_thread)
     106{
     107  rtems_user_env_t *env = the_thread->user_environment;
     108
     109  if (env != NULL) {
     110    rtems_libio_free_user_env(env);
     111  }
     112}
     113
     114static void rtems_libio_env_thread_restart(
     115  Thread_Control *executing,
     116  Thread_Control *the_thread
     117)
     118{
     119  (void) executing;
     120  rtems_libio_env_thread_terminate( the_thread );
     121}
     122
     123static User_extensions_Control rtems_libio_env_extensions = {
     124  .Callouts = {
     125    .thread_restart = rtems_libio_env_thread_restart,
     126    .thread_terminate = rtems_libio_env_thread_terminate
     127  }
     128};
     129
     130static void rtems_libio_env_init(void)
     131{
     132  _User_extensions_Add_API_set(&rtems_libio_env_extensions);
     133}
     134
     135RTEMS_SYSINIT_ITEM(
     136  rtems_libio_env_init,
     137  RTEMS_SYSINIT_USER_ENVIRONMENT,
     138  RTEMS_SYSINIT_ORDER_MIDDLE
     139);
  • cpukit/sapi/src/sysinitverbose.c

    rba46b936 rba74ebde  
    8787SYSINIT_VERBOSE( IDLE_THREADS );
    8888SYSINIT_VERBOSE( LIBIO );
     89SYSINIT_VERBOSE( USER_ENVIRONMENT );
    8990SYSINIT_VERBOSE( ROOT_FILESYSTEM );
    9091SYSINIT_VERBOSE( DRVMGR );
     
    469470}
    470471
     472static void _Sysinit_Verbose_USER_ENVIRONMENT( void )
     473{
     474  if ( !SYSINIT_IS_ADJACENT( LIBIO, USER_ENVIRONMENT ) ) {
     475    printk( "sysinit: USER_ENVIRONMENT: done\n" );
     476  }
     477}
     478
    471479static void _Sysinit_Verbose_ROOT_FILESYSTEM( void )
    472480{
    473   if ( !SYSINIT_IS_ADJACENT( LIBIO, ROOT_FILESYSTEM ) ) {
     481  if ( !SYSINIT_IS_ADJACENT( USER_ENVIRONMENT, ROOT_FILESYSTEM ) ) {
    474482    printk( "sysinit: ROOT_FILESYSTEM: done\n" );
    475483  }
  • testsuites/fstests/fsdosfsname01/init.c

    rba46b936 rba74ebde  
    14431443#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
    14441444#define CONFIGURE_MAXIMUM_SEMAPHORES (2 * RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE)
    1445 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
    14461445#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
    14471446
  • testsuites/fstests/imfs_support/fs_support.c

    rba46b936 rba74ebde  
    4242#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
    4343#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
    44 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS  1
    4544
    4645#define CONFIGURE_INIT
  • testsuites/fstests/jffs2_support/fs_support.c

    rba46b936 rba74ebde  
    158158#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    159159
    160 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
    161 
    162160#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    163161
  • testsuites/fstests/mdosfs_support/fs_support.c

    rba46b936 rba74ebde  
    9191#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
    9292#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
    93 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS     1
    9493
    9594#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
  • testsuites/fstests/mimfs_support/fs_support.c

    rba46b936 rba74ebde  
    6464#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 40
    6565#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
    66 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS  1
    6766
    6867#define CONFIGURE_FILESYSTEM_IMFS
  • testsuites/fstests/mrfs_support/fs_support.c

    rba46b936 rba74ebde  
    7070#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
    7171#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
    72 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS     1
    7372
    7473#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
  • testsuites/libtests/ftp01/init.c

    rba46b936 rba74ebde  
    263263#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    264264
    265 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
    266 
    267265#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    268266
  • testsuites/psxtests/psxchroot01/main.c

    rba46b936 rba74ebde  
    3333#define CONFIGURE_MAXIMUM_TASKS 1
    3434
    35 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
    36 
    3735#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    3836
  • testsuites/psxtests/psxconfig01/init.c

    rba46b936 rba74ebde  
    302302  rtems_resource_snapshot_take(&snapshot);
    303303  rtems_test_assert(
    304     snapshot.active_posix_keys == _CONFIGURE_POSIX_KEYS
     304    snapshot.active_posix_keys == CONFIGURE_MAXIMUM_POSIX_KEYS
    305305  );
    306306  rtems_test_assert(
  • testsuites/psxtests/psxmount/main.c

    rba46b936 rba74ebde  
    3737#define CONFIGURE_MAXIMUM_TASKS 1
    3838
    39 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
    40 
    4139#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    4240
  • testsuites/sptests/Makefile.am

    rba46b936 rba74ebde  
    10281028spfatal26_SOURCES = spfatal26/init.c
    10291029spfatal26_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spfatal26) \
    1030         $(support_includes)
    1031 endif
    1032 
    1033 if TEST_spfatal27
    1034 sp_tests += spfatal27
    1035 sp_screens += spfatal27/spfatal27.scn
    1036 sp_docs += spfatal27/spfatal27.doc
    1037 spfatal27_SOURCES = spfatal27/init.c
    1038 spfatal27_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spfatal27) \
    10391030        $(support_includes)
    10401031endif
  • testsuites/sptests/configure.ac

    rba46b936 rba74ebde  
    153153RTEMS_TEST_CHECK([spfatal25])
    154154RTEMS_TEST_CHECK([spfatal26])
    155 RTEMS_TEST_CHECK([spfatal27])
    156155RTEMS_TEST_CHECK([spfatal28])
    157156RTEMS_TEST_CHECK([spfatal29])
  • testsuites/sptests/spprivenv01/init.c

    rba46b936 rba74ebde  
    124124#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    125125
    126 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
    127 #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
    128 
    129126#define CONFIGURE_INIT
    130127
  • testsuites/sptests/spsysinit01/init.c

    rba46b936 rba74ebde  
    126126  LIBIO_PRE,
    127127  LIBIO_POST,
     128  USER_ENVIRONMENT_PRE,
     129  USER_ENVIRONMENT_POST,
    128130  ROOT_FILESYSTEM_PRE,
    129131  ROOT_FILESYSTEM_POST,
     
    514516LAST(RTEMS_SYSINIT_POSIX_KEYS)
    515517{
    516   assert(info_is_init(&_POSIX_Keys_Information, 2));
     518  assert(info_is_init(&_POSIX_Keys_Information, 1));
    517519  next_step(POSIX_KEYS_POST);
    518520}
     
    540542  assert(rtems_libio_iop_free_head == &rtems_libio_iops[0]);
    541543  next_step(LIBIO_POST);
     544}
     545
     546static size_t user_extensions_pre_user_env;
     547
     548FIRST(RTEMS_SYSINIT_USER_ENVIRONMENT)
     549{
     550  user_extensions_pre_user_env =
     551    _Chain_Node_count_unprotected(&_User_extensions_List.Active);
     552  next_step(USER_ENVIRONMENT_PRE);
     553}
     554
     555LAST(RTEMS_SYSINIT_USER_ENVIRONMENT)
     556{
     557  assert(
     558    user_extensions_pre_user_env + 1 ==
     559      _Chain_Node_count_unprotected(&_User_extensions_List.Active)
     560  );
     561  next_step(USER_ENVIRONMENT_POST);
    542562}
    543563
     
    843863}
    844864
     865static void do_posix_key_create(void)
     866{
     867  pthread_key_t key;
     868  int eno;
     869
     870  eno = pthread_key_create(&key, NULL);
     871  rtems_test_assert(eno == 0);
     872
     873  eno = pthread_key_delete(key);
     874  rtems_test_assert(eno == 0);
     875}
     876
    845877static void do_posix_mq_open(void)
    846878{
     
    926958}
    927959
     960static void do_use_global_user_env(void)
     961{
     962  rtems_libio_use_global_env();
     963}
     964
    928965static void Init(rtems_task_argument arg)
    929966{
     
    940977  do_timer_create();
    941978  do_cleanup_push_pop();
     979  do_posix_key_create();
    942980  do_posix_mq_open();
    943981  do_posix_sem_open();
    944982  do_posix_shm_open();
    945983  do_posix_timer_create();
     984  do_use_global_user_env();
    946985  check_config();
    947986  TEST_END();
Note: See TracChangeset for help on using the changeset viewer.