Changeset c8a10609 in rtems


Ignore:
Timestamp:
Oct 1, 2021, 7:56:34 PM (2 months ago)
Author:
Joel Sherrill <joel@…>
Branches:
5
Children:
d5649e2
Parents:
99698fb
git-author:
Joel Sherrill <joel@…> (10/01/21 19:56:34)
git-committer:
Joel Sherrill <joel@…> (10/07/21 15:31:38)
Message:

Add support for IDLE Thread stack allocator

Add a stack allocator hook specifically for allocation of IDLE thread stacks.
This allows the user to decide if IDLE thread stacks are statically allocated
or handled by the same custom allocator mechanism as other thread stacks.

Closes #4520.

Files:
7 added
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    r99698fb rc8a10609  
    931931librtemscpu_a_SOURCES += score/src/schedulercbsunblock.c
    932932librtemscpu_a_SOURCES += score/src/stackallocator.c
     933librtemscpu_a_SOURCES += score/src/stackallocatorforidle.c
    933934librtemscpu_a_SOURCES += score/src/pheapallocate.c
    934935librtemscpu_a_SOURCES += score/src/pheapextend.c
  • cpukit/include/rtems/confdefs/percpu.h

    r99698fb rc8a10609  
    134134const size_t _Thread_Idle_stack_size = CONFIGURE_IDLE_TASK_STACK_SIZE;
    135135
    136 char _Thread_Idle_stacks[
    137   _CONFIGURE_MAXIMUM_PROCESSORS
    138     * ( CONFIGURE_IDLE_TASK_STACK_SIZE + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE )
    139 ] RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
    140 RTEMS_SECTION( ".rtemsstack.idle" );
     136/*
     137 * If the user provides a custom idle stack allocator, then we do not need
     138 * memory reserved for the stacks but the symbol is still referenced in
     139 * threadcreateidle.c. The code path just never uses it. Make it minimal
     140 * size to proceed.
     141 */
     142#ifndef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
     143  char _Thread_Idle_stacks[
     144    _CONFIGURE_MAXIMUM_PROCESSORS
     145      * ( CONFIGURE_IDLE_TASK_STACK_SIZE + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE )
     146  ] RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
     147  RTEMS_SECTION( ".rtemsstack.idle" );
     148#endif
    141149
    142150#if defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION) && \
  • cpukit/include/rtems/confdefs/wkspace.h

    r99698fb rc8a10609  
    133133#if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
    134134  && defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
     135  /* Custom allocator may or may not use the work space. */
    135136  #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
    136137    const bool _Stack_Allocator_avoids_workspace = true;
     
    139140  #endif
    140141
     142  /* Custom allocator may or may not need initialization. */
    141143  #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT
    142144    const Stack_Allocator_initialize _Stack_Allocator_initialize =
     
    146148  #endif
    147149
     150  /* Custom allocator must include allocate and free */
    148151  const Stack_Allocator_allocate _Stack_Allocator_allocate =
    149152    CONFIGURE_TASK_STACK_ALLOCATOR;
     
    151154  const Stack_Allocator_free _Stack_Allocator_free =
    152155    CONFIGURE_TASK_STACK_DEALLOCATOR;
     156
     157/*
     158 * Must provide both a custom stack allocator and deallocator
     159 */
    153160#elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
    154161  || defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
    155162  #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined"
     163#endif
     164
     165/*
     166 * Custom IDLE thread stacks allocator. If this is provided, it is assumed
     167 * that the allocator is providing its own memory for these stacks.
     168 */
     169#ifdef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
     170  const Stack_Allocator_allocate_for_idle _Stack_Allocator_allocate_for_idle =
     171    CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE;
    156172#endif
    157173
  • cpukit/include/rtems/config.h

    r99698fb rc8a10609  
    130130  (_Stack_Allocator_free)
    131131
     132#define rtems_configuration_get_stack_allocate_for_idle_hook() \
     133  (_Stack_Allocator_allocate_for_idle)
     134
    132135 /**
    133136  * This macro assists in accessing the field which indicates whether
  • cpukit/include/rtems/score/stack.h

    r99698fb rc8a10609  
    8383
    8484/**
     85 * @brief Stack allocator allocate for idle handler.
     86 *
     87 * The allocate for idle handler is optional even when the user thread stack
     88 * allocator and deallocator are configured.
     89 *
     90 * @param cpu Index of the CPU for the IDLE thread using this stack
     91 * @param stack_size The size of the stack area to allocate in bytes.
     92 *
     93 * @retval NULL Not enough memory.
     94 * @retval other Pointer to begin of stack area.
     95 */
     96typedef void *( *Stack_Allocator_allocate_for_idle )(
     97  uint32_t  cpu,
     98  size_t    stack_size
     99);
     100
     101/**
    85102 * @brief The minimum stack size.
    86103 *
     
    125142
    126143/** @} */
     144/**
     145 * @brief The stack allocator allocate stack for idle thread handler.
     146 *
     147 * Application provided via <rtems/confdefs.h>.
     148 */
     149extern const Stack_Allocator_allocate_for_idle
     150  _Stack_Allocator_allocate_for_idle;
    127151
    128152#ifdef __cplusplus
  • cpukit/score/src/threadcreateidle.c

    r99698fb rc8a10609  
    5454  config.stack_size = _Thread_Idle_stack_size
    5555    + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE;
    56   config.stack_area = &_Thread_Idle_stacks[
    57     _Per_CPU_Get_index( cpu ) * config.stack_size
    58   ];
     56
     57  /*
     58   * The IDLE thread stacks may be statically allocated or there may be a
     59   * custom allocator provided just as with user threads.
     60   */
     61  config.stack_area = (*_Stack_Allocator_allocate_for_idle)(
     62    _Per_CPU_Get_index( cpu ),
     63    config.stack_size
     64  );
    5965
    6066  /*
  • testsuites/sptests/Makefile.am

    r99698fb rc8a10609  
    17841784endif
    17851785
     1786if TEST_spstkalloc03
     1787sp_tests += spstkalloc03
     1788sp_screens += spstkalloc03/spstkalloc03.scn
     1789sp_docs += spstkalloc03/spstkalloc03.doc
     1790spstkalloc03_SOURCES = spstkalloc03/init.c
     1791spstkalloc03_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spstkalloc03) \
     1792        $(support_includes)
     1793endif
     1794
     1795if TEST_spstkalloc04
     1796sp_tests += spstkalloc04
     1797sp_screens += spstkalloc04/spstkalloc04.scn
     1798sp_docs += spstkalloc04/spstkalloc04.doc
     1799spstkalloc04_SOURCES = spstkalloc04/init.c
     1800spstkalloc04_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spstkalloc04) \
     1801        $(support_includes)
     1802endif
     1803
    17861804if TEST_spsysinit01
    17871805sp_tests += spsysinit01
  • testsuites/sptests/configure.ac

    r99698fb rc8a10609  
    229229RTEMS_TEST_CHECK([spstkalloc])
    230230RTEMS_TEST_CHECK([spstkalloc02])
     231RTEMS_TEST_CHECK([spstkalloc03])
     232RTEMS_TEST_CHECK([spstkalloc04])
    231233RTEMS_TEST_CHECK([spsysinit01])
    232234RTEMS_TEST_CHECK([spsyslock01])
Note: See TracChangeset for help on using the changeset viewer.