Changeset 69aa3349 in rtems


Ignore:
Timestamp:
Apr 8, 2014, 7:42:29 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
0712d17
Parents:
e1598a6
git-author:
Sebastian Huber <sebastian.huber@…> (04/08/14 07:42:29)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/15/14 06:37:12)
Message:

score: Simplify thread control initialization

The thread control block contains fields that point to application
configuration dependent memory areas, like the scheduler information,
the API control blocks, the user extension context table, the RTEMS
notepads and the Newlib re-entrancy support. Account for these areas in
the configuration and avoid extra workspace allocations for these areas.

This helps also to avoid heap fragementation and reduces the per thread
memory due to a reduced heap allocation overhead.

Location:
cpukit
Files:
3 deleted
22 edited

Legend:

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

    re1598a6 r69aa3349  
    8585
    8686#define __RTEMS_NEWLIB_BEGIN 0
    87 
    88 void newlib_delete_hook(
    89   rtems_tcb *current_task,
    90   rtems_tcb *deleted_task
    91 );
    9287
    9388void newlib_terminate_hook(
     
    10095  0,                      /* rtems_task_start   */ \
    10196  0,                      /* rtems_task_restart */ \
    102   newlib_delete_hook,     /* rtems_task_delete  */ \
     97  0,                      /* rtems_task_delete  */ \
    10398  0,                      /* task_switch  */ \
    10499  __RTEMS_NEWLIB_BEGIN,   /* task_begin   */ \
  • cpukit/libcsupport/src/newlibc_reent.c

    re1598a6 r69aa3349  
    3636)
    3737{
    38   struct _reent *ptr;
    39   bool ok;
    40 
    4138#if !defined(__DYNAMIC_REENT__)
    4239  if (_Thread_libc_reent == 0)
     
    4845#endif
    4946
    50   /* It is OK to allocate from the workspace because these
    51    * hooks run with thread dispatching disabled.
    52    */
    53   ptr = (struct _reent *) _Workspace_Allocate(sizeof(*ptr));
    54   creating_task->libc_reent = ptr;
    55   ok = ptr != NULL;
     47  _REENT_INIT_PTR((creating_task->libc_reent)); /* GCC extension: structure constants */
    5648
    57   if (ok) {
    58     _REENT_INIT_PTR((ptr)); /* GCC extension: structure constants */
    59   }
    60 
    61   return ok;
    62 }
    63 
    64 void newlib_delete_hook(
    65   rtems_tcb *current_task,
    66   rtems_tcb *deleted_task
    67 )
    68 {
    69   (void) current_task;
    70 
    71   _Workspace_Free(deleted_task->libc_reent);
     49  return true;
    7250}
    7351
  • cpukit/posix/src/pthread.c

    re1598a6 r69aa3349  
    191191  POSIX_API_Control *executing_api;
    192192
    193   api = _Workspace_Allocate( sizeof( POSIX_API_Control ) );
    194 
    195   if ( !api )
    196     return false;
    197 
    198   created->API_Extensions[ THREAD_API_POSIX ] = api;
     193  api = created->API_Extensions[ THREAD_API_POSIX ];
    199194
    200195  /* XXX check all fields are touched */
     
    267262}
    268263
    269 /*
    270  *  _POSIX_Threads_Delete_extension
    271  *
    272  *  This method is invoked for each thread deleted.
    273  */
    274 static void _POSIX_Threads_Delete_extension(
    275   Thread_Control *executing __attribute__((unused)),
    276   Thread_Control *deleted
    277 )
    278 {
    279   _Workspace_Free( deleted->API_Extensions[ THREAD_API_POSIX ] );
    280 }
    281 
    282264static void _POSIX_Threads_Terminate_extension(
    283265  Thread_Control *executing
     
    356338    NULL,                                     /* start */
    357339    _POSIX_Threads_Restart_extension,         /* restart */
    358     _POSIX_Threads_Delete_extension,          /* delete */
     340    NULL,                                     /* delete */
    359341    NULL,                                     /* switch */
    360342    NULL,                                     /* begin */
     
    393375    Configuration_POSIX_API.maximum_threads,
    394376                                 /* maximum objects of this class */
    395     sizeof( Thread_Control ),
    396                                  /* size of this object's control block */
     377    _Thread_Control_size,        /* size of this object's control block */
    397378    true,                        /* true if names for this object are strings */
    398379    _POSIX_PATH_MAX              /* maximum length of each object's name */
  • cpukit/rtems/include/rtems/rtems/tasks.h

    re1598a6 r69aa3349  
    575575   *  @note MUST BE LAST ENTRY.
    576576   */
    577   uint32_t                 Notepads[ RTEMS_NUMBER_NOTEPADS ];
     577  uint32_t                 Notepads[ RTEMS_ZERO_LENGTH_ARRAY ];
    578578}  RTEMS_API_Control;
    579579
  • cpukit/rtems/src/tasks.c

    re1598a6 r69aa3349  
    5151{
    5252  RTEMS_API_Control *api;
    53   int                i;
    54   size_t             to_allocate;
    55 
    56   /*
    57    *  Notepads must be the last entry in the structure and they
    58    *  can be left off if disabled in the configuration.
    59    */
    60   to_allocate = sizeof( RTEMS_API_Control );
    61   if ( !rtems_configuration_get_notepads_enabled() )
    62     to_allocate -= (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t));
    63 
    64   api = _Workspace_Allocate( to_allocate );
    65 
    66   if ( !api )
    67     return false;
    68 
    69   created->API_Extensions[ THREAD_API_RTEMS ] = api;
     53  size_t             i;
     54
     55  api = created->API_Extensions[ THREAD_API_RTEMS ];
    7056
    7157  _Event_Initialize( &api->Event );
     
    10389  _Event_Initialize( &api->Event );
    10490  _Event_Initialize( &api->System_event );
    105 }
    106 
    107 /*
    108  *  _RTEMS_tasks_Delete_extension
    109  *
    110  *  This extension routine is invoked when a task is deleted.
    111  */
    112 
    113 static void _RTEMS_tasks_Delete_extension(
    114   Thread_Control *executing,
    115   Thread_Control *deleted
    116 )
    117 {
    118   /*
    119    *  Free API specific memory
    120    */
    121 
    122   (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
    12391}
    12492
     
    205173    _RTEMS_tasks_Start_extension,             /* start */
    206174    _RTEMS_tasks_Start_extension,             /* restart */
    207     _RTEMS_tasks_Delete_extension,            /* delete */
     175    NULL,                                     /* delete */
    208176    RTEMS_TASKS_SWITCH_EXTENSION,             /* switch */
    209177    NULL,                                     /* begin */
     
    222190    Configuration_RTEMS_API.maximum_tasks,
    223191                               /* maximum objects of this class */
    224     sizeof( Thread_Control ),  /* size of this object's control block */
     192    _Thread_Control_size,      /* size of this object's control block */
    225193    false,                     /* true if the name is a string */
    226194    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
  • cpukit/sapi/include/confdefs.h

    re1598a6 r69aa3349  
    642642 *    - CONFIGURE_SCHEDULER_CONTEXT
    643643 *    - CONFIGURE_SCHEDULER_CONTROLS
    644  *    - CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER - per task memory
     644 *    - CONFIGURE_SCHEDULER_USER_PER_THREAD
    645645 */
    646646
     
    677677      RTEMS_SCHEDULER_CONTROL_PRIORITY(dflt)
    678678  #endif
    679 
    680   /**
    681    * This defines the memory used by the priority scheduler.
    682    */
    683   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
    684     _Configure_From_workspace(sizeof(Scheduler_priority_Per_thread)) )
    685679#endif
    686680
     
    700694      RTEMS_SCHEDULER_CONTROL_PRIORITY_SMP(dflt)
    701695  #endif
    702 
    703   /**
    704    * This defines the memory used by the priority scheduler.
    705    */
    706   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
    707     _Configure_From_workspace(sizeof(Scheduler_priority_Per_thread)) )
    708696#endif
    709697
     
    723711      RTEMS_SCHEDULER_CONTROL_PRIORITY_AFFINITY_SMP(dflt)
    724712  #endif
    725 
    726   /**
    727    * This defines the memory used by the priority scheduler.
    728    */
    729   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
    730     _Configure_From_workspace(sizeof(Scheduler_priority_Per_thread)) )
    731713#endif
    732714
     
    740722    #define CONFIGURE_SCHEDULER_CONTROLS RTEMS_SCHEDULER_CONTROL_SIMPLE(dflt)
    741723  #endif
    742 
    743   /**
    744    * define the memory used by the simple scheduler
    745    */
    746   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (0)
    747724#endif
    748725
     
    758735      RTEMS_SCHEDULER_CONTROL_SIMPLE_SMP(dflt)
    759736  #endif
    760 
    761   /**
    762    * Define the memory used by the Simple SMP Scheduler
    763    *
    764    * NOTE: This is the same as the Simple Scheduler
    765    */
    766   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER (0)
    767737#endif
    768738
     
    776746    #define CONFIGURE_SCHEDULER_CONTROLS RTEMS_SCHEDULER_CONTROL_EDF(dflt)
    777747  #endif
    778 
    779   /**
    780    * define the memory used by the EDF scheduler
    781    */
    782   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
    783     _Configure_From_workspace(sizeof(Scheduler_EDF_Per_thread)))
    784748#endif
    785749
     
    805769      _Scheduler_CBS_Server_list[ CONFIGURE_CBS_MAXIMUM_SERVERS ];
    806770  #endif
    807 
    808   /**
    809    * define the memory used by the CBS scheduler
    810    */
    811   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
    812     _Configure_From_workspace(sizeof(Scheduler_CBS_Per_thread)))
    813771#endif
    814772
     
    15951553  #else
    15961554    #define CONFIGURE_NOTEPADS_ENABLED           FALSE
    1597   #endif
    1598 
    1599   #ifndef CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
    1600     #define CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API \
    1601       _Configure_From_workspace( sizeof(RTEMS_API_Control) )
    1602   #else
    1603     #define CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API \
    1604       _Configure_From_workspace( sizeof(RTEMS_API_Control) - \
    1605         (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t)))
    16061555  #endif
    16071556
     
    18401789    #define CONFIGURE_MAXIMUM_POSIX_THREADS 0
    18411790  #endif
    1842 
    1843   #define CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API \
    1844     _Configure_From_workspace(sizeof(POSIX_API_Control))
    18451791
    18461792  #ifndef CONFIGURE_MAXIMUM_POSIX_MUTEXES
     
    19801926
    19811927  #define CONFIGURE_MAXIMUM_POSIX_THREADS         0
    1982   #define CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API 0
    19831928  #define CONFIGURE_MEMORY_FOR_POSIX              0
    19841929
     
    20572002#endif
    20582003
    2059 #ifndef RTEMS_SCHEDSIM
    2060 /**
    2061  * This macro specifies the amount of memory to be reserved for the
    2062  * Newlib C Library reentrancy structure -- if we are using newlib.
    2063  */
    2064 
    2065 #if (defined(RTEMS_NEWLIB) && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY))
    2066   #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB \
    2067     _Configure_From_workspace(sizeof(struct _reent))
    2068 #else
    2069   #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB 0
    2070 #endif
    2071 
    2072 #else
    2073   #define CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB 0
    2074 #endif
    2075 
    20762004/**
    20772005 * This is so we can account for tasks with stacks greater than minimum
     
    21052033#define CONFIGURE_MEMORY_FOR_TASKS(_tasks, _number_FP_tasks) \
    21062034  ( \
    2107     _Configure_Object_RAM(_tasks, sizeof(Thread_Control)) \
    2108       + _Configure_Max_Objects(_tasks) \
    2109         * ( \
    2110             CONFIGURE_MEMORY_PER_TASK_FOR_CLASSIC_API \
    2111               + CONFIGURE_MEMORY_PER_TASK_FOR_NEWLIB \
    2112               + CONFIGURE_MEMORY_PER_TASK_FOR_POSIX_API \
    2113               + CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER \
    2114               + _Configure_From_workspace( \
    2115                 (CONFIGURE_MAXIMUM_USER_EXTENSIONS + 1) * sizeof(void *) \
    2116               ) \
    2117           ) \
     2035    _Configure_Object_RAM(_tasks, sizeof(Configuration_Thread_control)) \
    21182036      + _Configure_Max_Objects(_number_FP_tasks) \
    21192037        * _Configure_From_workspace(CONTEXT_FP_SIZE) \
     
    23812299
    23822300#ifdef CONFIGURE_INIT
     2301  typedef struct {
     2302    Thread_Control Control;
     2303    #if CONFIGURE_MAXIMUM_USER_EXTENSIONS > 0
     2304      void *extensions[ CONFIGURE_MAXIMUM_USER_EXTENSIONS + 1 ];
     2305    #endif
     2306    union {
     2307      #ifdef CONFIGURE_SCHEDULER_CBS
     2308        Scheduler_CBS_Per_thread CBS;
     2309      #endif
     2310      #ifdef CONFIGURE_SCHEDULER_EDF
     2311        Scheduler_EDF_Per_thread EDF;
     2312      #endif
     2313      #if defined(CONFIGURE_SCHEDULER_PRIORITY) \
     2314        || defined(CONFIGURE_SCHEDULER_PRIORITY_SMP)
     2315        Scheduler_priority_Per_thread Priority;
     2316      #endif
     2317      #ifdef CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
     2318        Scheduler_priority_affinity_SMP_Per_thread Priority_affinity;
     2319      #endif
     2320      #ifdef CONFIGURE_SCHEDULER_USER_PER_THREAD
     2321        CONFIGURE_SCHEDULER_USER_PER_THREAD User;
     2322      #endif
     2323    } Scheduler;
     2324    RTEMS_API_Control API_RTEMS;
     2325    #ifndef CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
     2326      uint32_t Notepads[ RTEMS_NUMBER_NOTEPADS ];
     2327    #endif
     2328    #ifdef RTEMS_POSIX_API
     2329      POSIX_API_Control API_POSIX;
     2330    #endif
     2331    #if !defined(RTEMS_SCHEDSIM) \
     2332      && defined(RTEMS_NEWLIB) \
     2333      && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY)
     2334      struct _reent Newlib;
     2335    #else
     2336      struct { /* Empty */ } Newlib;
     2337    #endif
     2338  } Configuration_Thread_control;
     2339
     2340  const size_t _Thread_Control_size = sizeof( Configuration_Thread_control );
     2341
     2342  const Thread_Control_add_on _Thread_Control_add_ons[] = {
     2343    {
     2344      offsetof( Configuration_Thread_control, Control.scheduler_info ),
     2345      offsetof( Configuration_Thread_control, Scheduler )
     2346    }, {
     2347      offsetof(
     2348        Configuration_Thread_control,
     2349        Control.API_Extensions[ THREAD_API_RTEMS ]
     2350      ),
     2351      offsetof( Configuration_Thread_control, API_RTEMS )
     2352    }, {
     2353      offsetof(
     2354        Configuration_Thread_control,
     2355        Control.libc_reent
     2356      ),
     2357      offsetof( Configuration_Thread_control, Newlib )
     2358    }
     2359    #ifdef RTEMS_POSIX_API
     2360      , {
     2361        offsetof(
     2362          Configuration_Thread_control,
     2363          Control.API_Extensions[ THREAD_API_POSIX ]
     2364        ),
     2365        offsetof( Configuration_Thread_control, API_POSIX )
     2366      }
     2367    #endif
     2368  };
     2369
     2370  const size_t _Thread_Control_add_on_count =
     2371    RTEMS_ARRAY_SIZE( _Thread_Control_add_ons );
     2372
    23832373  /**
    23842374   * This is the Classic API Configuration Table.
     
    25732563    uint32_t INTERRUPT_STACK_MEMORY;
    25742564    uint32_t MEMORY_FOR_IDLE_TASK;
    2575     uint32_t MEMORY_PER_TASK_FOR_SCHEDULER;
    25762565
    25772566    /* Classic API Pieces */
     
    26292618    CONFIGURE_INTERRUPT_STACK_MEMORY,
    26302619    CONFIGURE_MEMORY_FOR_IDLE_TASK,
    2631     CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER,
    26322620
    26332621    /* Classic API Pieces */
  • cpukit/score/Makefile.am

    re1598a6 r69aa3349  
    204204## SCHEDULERPRIORITY_C_FILES
    205205libscore_a_SOURCES += src/schedulerpriority.c \
    206     src/schedulerpriorityallocate.c \
    207206    src/schedulerpriorityblock.c \
    208207    src/schedulerpriorityenqueue.c \
    209208    src/schedulerpriorityenqueuefirst.c \
    210209    src/schedulerpriorityextract.c \
    211     src/schedulerpriorityfree.c \
    212210    src/schedulerpriorityprioritycompare.c \
    213211    src/schedulerpriorityschedule.c \
     
    235233    src/scheduleredfenqueuefirst.c \
    236234    src/scheduleredfextract.c \
    237     src/scheduleredffree.c \
    238235    src/scheduleredfprioritycompare.c \
    239236    src/scheduleredfreleasejob.c \
  • cpukit/score/include/rtems/score/scheduler.h

    re1598a6 r69aa3349  
    6868
    6969  /** allocates the scheduler field of the given thread */
    70   void * ( *allocate )( const Scheduler_Control *, Thread_Control * );
     70  bool ( *allocate )( const Scheduler_Control *, Thread_Control * );
    7171
    7272  /** frees the scheduler field of the given thread */
     
    200200 * @param[in] the_thread Unused.
    201201 *
    202  * @return An arbitrary non-NULL value.
    203  */
    204 void *_Scheduler_default_Allocate(
     202 * @retval true Always.
     203 */
     204bool _Scheduler_default_Allocate(
    205205  const Scheduler_Control *scheduler,
    206206  Thread_Control          *the_thread
  • cpukit/score/include/rtems/score/schedulercbs.h

    re1598a6 r69aa3349  
    5454    _Scheduler_CBS_Unblock,          /* unblock entry point */ \
    5555    _Scheduler_CBS_Allocate,         /* allocate entry point */ \
    56     _Scheduler_EDF_Free,             /* free entry point */ \
     56    _Scheduler_default_Free,         /* free entry point */ \
    5757    _Scheduler_EDF_Update,           /* update entry point */ \
    5858    _Scheduler_EDF_Enqueue,          /* enqueue entry point */ \
     
    345345 *             management memory for.
    346346 */
    347 void *_Scheduler_CBS_Allocate(
     347bool _Scheduler_CBS_Allocate(
    348348  const Scheduler_Control *scheduler,
    349349  Thread_Control          *the_thread
  • cpukit/score/include/rtems/score/scheduleredf.h

    re1598a6 r69aa3349  
    4747    _Scheduler_EDF_Unblock,          /* unblock entry point */ \
    4848    _Scheduler_EDF_Allocate,         /* allocate entry point */ \
    49     _Scheduler_EDF_Free,             /* free entry point */ \
     49    _Scheduler_default_Free,         /* free entry point */ \
    5050    _Scheduler_EDF_Update,           /* update entry point */ \
    5151    _Scheduler_EDF_Enqueue,          /* enqueue entry point */ \
     
    151151 *             management memory for.
    152152 */
    153 void *_Scheduler_EDF_Allocate(
    154   const Scheduler_Control *scheduler,
    155   Thread_Control          *the_thread
    156 );
    157 
    158 /**
    159  *  @brief Frees EDF information of a thread.
    160  *
    161  *  This routine frees the EDF specific information of @a the_thread.
    162  *
    163  *  @param[in] the_thread is the thread whose scheduler specific information
    164  *             will be deallocated.
    165  */
    166 void _Scheduler_EDF_Free(
     153bool _Scheduler_EDF_Allocate(
    167154  const Scheduler_Control *scheduler,
    168155  Thread_Control          *the_thread
  • cpukit/score/include/rtems/score/schedulerimpl.h

    re1598a6 r69aa3349  
    125125 * This routine allocates @a the_thread->scheduler
    126126 */
    127 RTEMS_INLINE_ROUTINE void* _Scheduler_Allocate(
     127RTEMS_INLINE_ROUTINE bool _Scheduler_Allocate(
    128128  const Scheduler_Control *scheduler,
    129129  Thread_Control          *the_thread
  • cpukit/score/include/rtems/score/schedulerpriority.h

    re1598a6 r69aa3349  
    5353    _Scheduler_priority_Block,            /* block entry point */ \
    5454    _Scheduler_priority_Unblock,          /* unblock entry point */ \
    55     _Scheduler_priority_Allocate,         /* allocate entry point */ \
    56     _Scheduler_priority_Free,             /* free entry point */ \
     55    _Scheduler_default_Allocate,         /* allocate entry point */ \
     56    _Scheduler_default_Free,             /* free entry point */ \
    5757    _Scheduler_priority_Update,           /* update entry point */ \
    5858    _Scheduler_priority_Enqueue,          /* enqueue entry point */ \
     
    127127
    128128/**
    129  *  @brief Allocates @a the_thread->scheduler.
    130  *
    131  *  This routine allocates @a the_thread->scheduler.
    132  *
    133  *  @param[in] the_thread is the thread the scheduler is allocating
    134  *             management memory for
    135  */
    136 void * _Scheduler_priority_Allocate(
    137   const Scheduler_Control *scheduler,
    138   Thread_Control          *the_thread
    139 );
    140 
    141 /**
    142  *  @brief Frees @a the_thread->scheduler.
    143  *
    144  *  This routine frees @a the_thread->scheduler.
    145  *
    146  *  @param[in] the_thread is the thread whose scheduler specific information
    147  *             will be deallocated.
    148  */
    149 void _Scheduler_priority_Free(
    150   const Scheduler_Control *scheduler,
    151   Thread_Control          *the_thread
    152 );
    153 
    154 /**
    155129 *  @brief Update the scheduler priority.
    156130 *  This routine updates @a the_thread->scheduler based on @a the_scheduler
  • cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h

    re1598a6 r69aa3349  
    5656    _Scheduler_priority_SMP_Enqueue_fifo, \
    5757    _Scheduler_priority_affinity_SMP_Allocate, \
    58     _Scheduler_priority_Free, \
     58    _Scheduler_default_Free, \
    5959    _Scheduler_priority_SMP_Update, \
    6060    _Scheduler_priority_SMP_Enqueue_fifo, \
     
    7878 *             management memory for.
    7979 */
    80 void * _Scheduler_priority_affinity_SMP_Allocate(
     80bool _Scheduler_priority_affinity_SMP_Allocate(
    8181  const Scheduler_Control *scheduler,
    8282  Thread_Control          *the_thread
  • cpukit/score/include/rtems/score/schedulerprioritysmp.h

    re1598a6 r69aa3349  
    6464    _Scheduler_priority_SMP_Block, \
    6565    _Scheduler_priority_SMP_Enqueue_fifo, \
    66     _Scheduler_priority_Allocate, \
    67     _Scheduler_priority_Free, \
     66    _Scheduler_default_Allocate, \
     67    _Scheduler_default_Free, \
    6868    _Scheduler_priority_SMP_Update, \
    6969    _Scheduler_priority_SMP_Enqueue_fifo, \
  • cpukit/score/include/rtems/score/thread.h

    re1598a6 r69aa3349  
    567567  /** This array contains the API extension area pointers. */
    568568  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
    569   /** This field points to the user extension pointers. */
    570   void                                **extensions;
    571569
    572570#if !defined(RTEMS_SMP)
     
    585583
    586584  Thread_Life_control                   Life;
     585
     586  /**
     587   * @brief Variable length array of user extension pointers.
     588   *
     589   * The length is defined by the application via <rtems/confdefs.h>.
     590   */
     591  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
    587592};
    588593
     
    639644}
    640645
     646/**
     647 * @brief Thread control add-on.
     648 */
     649typedef struct {
     650  /**
     651   * @brief Offset of the pointer field in Thread_Control referencing an
     652   * application configuration dependent memory area in the thread control
     653   * block.
     654   */
     655  size_t destination_offset;
     656
     657  /**
     658   * @brief Offset relative to the thread control block begin to an application
     659   * configuration dependent memory area.
     660   */
     661  size_t source_offset;
     662} Thread_Control_add_on;
     663
     664/**
     665 * @brief Thread control add-ons.
     666 *
     667 * The thread control block contains fields that point to application
     668 * configuration dependent memory areas, like the scheduler information, the
     669 * API control blocks, the user extension context table, the RTEMS notepads and
     670 * the Newlib re-entrancy support.  Account for these areas in the
     671 * configuration and avoid extra workspace allocations for these areas.
     672 *
     673 * This array is provided via <rtems/confdefs.h>.
     674 *
     675 * @see _Thread_Control_add_on_count and _Thread_Control_size.
     676 */
     677extern const Thread_Control_add_on _Thread_Control_add_ons[];
     678
     679/**
     680 * @brief Thread control add-on count.
     681 *
     682 * Count of entries in _Thread_Control_add_ons.
     683 *
     684 * This value is provided via <rtems/confdefs.h>.
     685 */
     686extern const size_t _Thread_Control_add_on_count;
     687
     688/**
     689 * @brief Size of the thread control block of a particular application.
     690 *
     691 * This value is provided via <rtems/confdefs.h>.
     692 *
     693 * @see _Thread_Control_add_ons.
     694 */
     695extern const size_t _Thread_Control_size;
     696
    641697/**@}*/
    642698
  • cpukit/score/src/schedulercbsallocate.c

    re1598a6 r69aa3349  
    2626#include <rtems/score/wkspace.h>
    2727
    28 void *_Scheduler_CBS_Allocate(
     28bool _Scheduler_CBS_Allocate(
    2929  const Scheduler_Control *scheduler,
    30   Thread_Control          *the_thread
     30  Thread_Control    *the_thread
    3131)
    3232{
    33   void *sched;
    34   Scheduler_CBS_Per_thread *schinfo;
     33  Scheduler_CBS_Per_thread *schinfo = the_thread->scheduler_info;
    3534
    3635  (void) scheduler;
    3736
    38   sched = _Workspace_Allocate(sizeof(Scheduler_CBS_Per_thread));
    39   if ( sched ) {
    40     the_thread->scheduler_info = sched;
    41     schinfo = (Scheduler_CBS_Per_thread *)(the_thread->scheduler_info);
    42     schinfo->edf_per_thread.thread = the_thread;
    43     schinfo->edf_per_thread.queue_state = SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN;
    44     schinfo->cbs_server = NULL;
    45   }
     37  schinfo->edf_per_thread.thread = the_thread;
     38  schinfo->edf_per_thread.queue_state = SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN;
     39  schinfo->cbs_server = NULL;
    4640
    47   return sched;
     41  return true;
    4842}
  • cpukit/score/src/schedulerdefaultallocatefree.c

    re1598a6 r69aa3349  
    2222#include <rtems/score/scheduler.h>
    2323
    24 void *_Scheduler_default_Allocate(
     24bool _Scheduler_default_Allocate(
    2525  const Scheduler_Control *scheduler,
    2626  Thread_Control          *the_thread
     
    3030  ( void ) the_thread;
    3131
    32   return ( void * )-1; /* maybe pick an appropriate poison value */
     32  return true;
    3333}
    3434
  • cpukit/score/src/scheduleredfallocate.c

    re1598a6 r69aa3349  
    2525#include <rtems/score/wkspace.h>
    2626
    27 void *_Scheduler_EDF_Allocate(
     27bool _Scheduler_EDF_Allocate(
    2828  const Scheduler_Control *scheduler,
    2929  Thread_Control          *the_thread
    3030)
    3131{
    32   void *sched;
    33   Scheduler_EDF_Per_thread *schinfo;
     32  Scheduler_EDF_Per_thread *schinfo = the_thread->scheduler_info;
    3433
    3534  (void) scheduler;
    3635
    37   sched = _Workspace_Allocate( sizeof(Scheduler_EDF_Per_thread) );
     36  schinfo = (Scheduler_EDF_Per_thread *)(the_thread->scheduler_info);
     37  schinfo->thread = the_thread;
     38  schinfo->queue_state = SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN;
    3839
    39   if ( sched ) {
    40     the_thread->scheduler_info = sched;
    41     schinfo = (Scheduler_EDF_Per_thread *)(the_thread->scheduler_info);
    42     schinfo->thread = the_thread;
    43     schinfo->queue_state = SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN;
    44   }
    45 
    46   return sched;
     40  return true;
    4741}
  • cpukit/score/src/schedulerpriorityaffinitysmp.c

    re1598a6 r69aa3349  
    3232}
    3333
    34 void * _Scheduler_priority_affinity_SMP_Allocate(
     34bool _Scheduler_priority_affinity_SMP_Allocate(
    3535  const Scheduler_Control *scheduler,
    3636  Thread_Control          *the_thread
     
    3838{
    3939  Scheduler_priority_affinity_SMP_Per_thread *info =
    40     _Workspace_Allocate( sizeof( *info ) );
     40    the_thread->scheduler_info;
    4141
    4242  info->Affinity = *_CPU_set_Default();
    4343  info->Affinity.set = &info->Affinity.preallocated;
    44  
    45   the_thread->scheduler_info = info;
    4644
    47   return info;
     45  return true;
    4846}
    4947
  • cpukit/score/src/thread.c

    re1598a6 r69aa3349  
    6565    OBJECTS_INTERNAL_THREADS,
    6666    _Thread_Get_maximum_internal_threads(),
    67     sizeof( Thread_Control ),
    68                                 /* size of this object's control block */
     67    _Thread_Control_size,       /* size of this object's control block */
    6968    false,                      /* true if names for this object are strings */
    7069    8                           /* maximum length of each object's name */
  • cpukit/score/src/threadinitialize.c

    re1598a6 r69aa3349  
    4343)
    4444{
    45   size_t     actual_stack_size = 0;
    46   void      *stack = NULL;
     45  size_t                   actual_stack_size = 0;
     46  void                    *stack = NULL;
    4747  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    48     void    *fp_area;
    49   #endif
    50   void      *sched = NULL;
    51   void      *extensions_area;
    52   bool       extension_status;
    53   int        i;
     48    void                  *fp_area = NULL;
     49  #endif
     50  bool                     extension_status;
     51  size_t                   i;
     52  bool                     scheduler_allocated = false;
     53  const Scheduler_Control *scheduler;
    5454
    5555  /*
     
    6565#endif
    6666
     67  for ( i = 0 ; i < _Thread_Control_add_on_count ; ++i ) {
     68    const Thread_Control_add_on *add_on = &_Thread_Control_add_ons[ i ];
     69
     70    *(void **) ( (char *) the_thread + add_on->destination_offset ) =
     71      (char *) the_thread + add_on->source_offset;
     72  }
     73
    6774  /*
    6875   *  Initialize the Ada self pointer
     
    7279  #endif
    7380
    74   /*
    75    *  Zero out all the allocated memory fields
    76    */
    77   for ( i=0 ; i <= THREAD_API_LAST ; i++ )
    78     the_thread->API_Extensions[i] = NULL;
    79 
    80   extensions_area = NULL;
    81   the_thread->libc_reent = NULL;
    8281  the_thread->Start.tls_area = NULL;
    83 
    84   #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    85     fp_area = NULL;
    86   #endif
    8782
    8883  /*
     
    152147    _Chain_Initialize_empty(&the_thread->lock_mutex);
    153148  #endif
    154 
    155   /*
    156    *  Allocate the extensions area for this thread
    157    */
    158   if ( rtems_configuration_get_maximum_extensions() ) {
    159     extensions_area = _Workspace_Allocate(
    160       (rtems_configuration_get_maximum_extensions() + 1) * sizeof( void * )
    161     );
    162     if ( !extensions_area )
    163       goto failed;
    164   }
    165   the_thread->extensions = (void **) extensions_area;
    166149
    167150  /*
     
    216199  the_thread->real_priority           = priority;
    217200  the_thread->Start.initial_priority  = priority;
    218   sched =_Scheduler_Allocate( _Scheduler_Get( the_thread ), the_thread );
    219   if ( !sched )
     201
     202  scheduler = _Scheduler_Get( _Thread_Get_executing() );
     203  scheduler_allocated = _Scheduler_Allocate( scheduler, the_thread );
     204  if ( !scheduler_allocated ) {
    220205    goto failed;
     206  }
     207
    221208  _Thread_Set_priority( the_thread, priority );
    222209
     
    261248
    262249failed:
     250
     251  if ( scheduler_allocated ) {
     252    _Scheduler_Free( scheduler, the_thread );
     253  }
     254
    263255  _Workspace_Free( the_thread->Start.tls_area );
    264 
    265   _Workspace_Free( the_thread->libc_reent );
    266 
    267   for ( i=0 ; i <= THREAD_API_LAST ; i++ )
    268     _Workspace_Free( the_thread->API_Extensions[i] );
    269 
    270   _Workspace_Free( extensions_area );
    271256
    272257  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    273258    _Workspace_Free( fp_area );
    274259  #endif
    275 
    276    _Workspace_Free( sched );
    277260
    278261   _Thread_Stack_Free( the_thread );
  • cpukit/score/src/threadrestart.c

    re1598a6 r69aa3349  
    9191   */
    9292  _Thread_Stack_Free( the_thread );
    93 
    94   _Workspace_Free( the_thread->extensions );
    9593
    9694  _Workspace_Free( the_thread->Start.tls_area );
Note: See TracChangeset for help on using the changeset viewer.