looks good
On Fri, Mar 12, 2021 at 12:34 AM Sebastian Huber <sebastian.hu...@embedded-brains.de> wrote: > > Move the CPU time budget to the thread configuration. This simplifies > _Thread_Initialize(). > --- > cpukit/include/rtems/posix/pthreadimpl.h | 26 +++++++------- > cpukit/include/rtems/score/threadimpl.h | 5 +++ > cpukit/posix/src/psxtransschedparam.c | 23 +++++++------ > cpukit/posix/src/pthreadcreate.c | 3 +- > cpukit/posix/src/pthreadsetschedparam.c | 44 +++++++++--------------- > cpukit/score/src/threadinitialize.c | 18 +--------- > 6 files changed, 49 insertions(+), 70 deletions(-) > > diff --git a/cpukit/include/rtems/posix/pthreadimpl.h > b/cpukit/include/rtems/posix/pthreadimpl.h > index 52d462ab6f..723b20e8d2 100644 > --- a/cpukit/include/rtems/posix/pthreadimpl.h > +++ b/cpukit/include/rtems/posix/pthreadimpl.h > @@ -77,24 +77,24 @@ int _POSIX_Thread_Translate_to_sched_policy( > ); > > /** > - * @brief Translate sched_param into SuperCore terms. > + * @brief Translates the POSIX scheduling policy and parameters to parts of > the > + * thread configuration. > * > - * This method translates the POSIX API sched_param into the corresponding > - * SuperCore settings. > + * @param policy is the POSIX scheduling policy. > * > - * @param[in] policy is the POSIX scheduling policy > - * @param[in] param points to the scheduling parameter structure > - * @param[in] budget_algorithm points to the output CPU Budget algorithm > - * @param[in] budget_callout points to the output CPU Callout > + * @param param is the pointer to the POSIX scheduling parameters. > * > - * @retval 0 Indicates success. > - * @retval error_code POSIX error code indicating failure. > + * @param[out] config is the pointer to a thread configuration to set the > + * budget algorithm, callout, and CPU time budget. > + * > + * @retval 0 The operation was successful. > + * > + * @retval EINVAL The POSIX scheduling policy or parameters were invalid. > */ > int _POSIX_Thread_Translate_sched_param( > - int policy, > - const struct sched_param *param, > - Thread_CPU_budget_algorithms *budget_algorithm, > - Thread_CPU_budget_algorithm_callout *budget_callout > + int policy, > + const struct sched_param *param, > + Thread_Configuration *config > ); > > RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void) > diff --git a/cpukit/include/rtems/score/threadimpl.h > b/cpukit/include/rtems/score/threadimpl.h > index 1e7d58609f..d9c0779b08 100644 > --- a/cpukit/include/rtems/score/threadimpl.h > +++ b/cpukit/include/rtems/score/threadimpl.h > @@ -163,6 +163,11 @@ typedef struct { > */ > Thread_CPU_budget_algorithm_callout budget_callout; > > + /** > + * @brief The thread's initial CPU time budget. > + */ > + uint32_t cpu_time_budget; > + > /** > * @brief 32-bit unsigned integer name of the object for the thread. > */ > diff --git a/cpukit/posix/src/psxtransschedparam.c > b/cpukit/posix/src/psxtransschedparam.c > index 6fa7a43886..eba26d4932 100644 > --- a/cpukit/posix/src/psxtransschedparam.c > +++ b/cpukit/posix/src/psxtransschedparam.c > @@ -42,27 +42,28 @@ int _POSIX_Thread_Translate_to_sched_policy( > } > > int _POSIX_Thread_Translate_sched_param( > - int policy, > - const struct sched_param *param, > - Thread_CPU_budget_algorithms *budget_algorithm, > - Thread_CPU_budget_algorithm_callout *budget_callout > + int policy, > + const struct sched_param *param, > + Thread_Configuration *config > ) > { > - *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; > - *budget_callout = NULL; > + config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; > + config->budget_callout = NULL; > + config->cpu_time_budget = 0; > > if ( policy == SCHED_OTHER ) { > - *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; > + config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; > return 0; > } > > if ( policy == SCHED_FIFO ) { > - *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; > + config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; > return 0; > } > > if ( policy == SCHED_RR ) { > - *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE; > + config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE; > + config->cpu_time_budget = rtems_configuration_get_ticks_per_timeslice(); > return 0; > } > > @@ -80,8 +81,8 @@ int _POSIX_Thread_Translate_sched_param( > _Timespec_To_ticks( ¶m->sched_ss_init_budget ) ) > return EINVAL; > > - *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT; > - *budget_callout = _POSIX_Threads_Sporadic_budget_callout; > + config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT; > + config->budget_callout = _POSIX_Threads_Sporadic_budget_callout; > return 0; > } > #endif > diff --git a/cpukit/posix/src/pthreadcreate.c > b/cpukit/posix/src/pthreadcreate.c > index 55ba73c8b4..75d3c64676 100644 > --- a/cpukit/posix/src/pthreadcreate.c > +++ b/cpukit/posix/src/pthreadcreate.c > @@ -171,8 +171,7 @@ int pthread_create( > error = _POSIX_Thread_Translate_sched_param( > schedpolicy, > &schedparam, > - &config.budget_algorithm, > - &config.budget_callout > + &config > ); > if ( error != 0 ) { > return error; > diff --git a/cpukit/posix/src/pthreadsetschedparam.c > b/cpukit/posix/src/pthreadsetschedparam.c > index 9ab543cd31..e9be24b417 100644 > --- a/cpukit/posix/src/pthreadsetschedparam.c > +++ b/cpukit/posix/src/pthreadsetschedparam.c > @@ -24,6 +24,7 @@ > #endif > > #include <pthread.h> > +#include <string.h> > #include <errno.h> > > #include <rtems/posix/pthreadimpl.h> > @@ -32,12 +33,11 @@ > #include <rtems/score/schedulerimpl.h> > > static int _POSIX_Set_sched_param( > - Thread_Control *the_thread, > - int policy, > - const struct sched_param *param, > - Thread_CPU_budget_algorithms budget_algorithm, > - Thread_CPU_budget_algorithm_callout budget_callout, > - Thread_queue_Context *queue_context > + Thread_Control *the_thread, > + int policy, > + const struct sched_param *param, > + const Thread_Configuration *config, > + Thread_queue_Context *queue_context > ) > { > const Scheduler_Control *scheduler; > @@ -103,8 +103,9 @@ static int _POSIX_Set_sched_param( > } > #endif > > - the_thread->budget_algorithm = budget_algorithm; > - the_thread->budget_callout = budget_callout; > + the_thread->cpu_time_budget = config->cpu_time_budget; > + the_thread->budget_algorithm = config->budget_algorithm; > + the_thread->budget_callout = config->budget_callout; > > #if defined(RTEMS_POSIX_API) > _Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio ); > @@ -114,11 +115,6 @@ static int _POSIX_Set_sched_param( > > if ( policy == SCHED_SPORADIC ) { > _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); > - } else { > -#endif > - the_thread->cpu_time_budget = > - rtems_configuration_get_ticks_per_timeslice(); > -#if defined(RTEMS_POSIX_API) > } > #endif > > @@ -135,23 +131,18 @@ int pthread_setschedparam( > #endif > ) > { > - Thread_CPU_budget_algorithms budget_algorithm; > - Thread_CPU_budget_algorithm_callout budget_callout; > - Thread_Control *the_thread; > - Per_CPU_Control *cpu_self; > - Thread_queue_Context queue_context; > - int error; > + Thread_Configuration config; > + Thread_Control *the_thread; > + Per_CPU_Control *cpu_self; > + Thread_queue_Context queue_context; > + int error; > > if ( param == NULL ) { > return EINVAL; > } > > - error = _POSIX_Thread_Translate_sched_param( > - policy, > - param, > - &budget_algorithm, > - &budget_callout > - ); > + memset( &config, 0, sizeof( config ) ); > + error = _POSIX_Thread_Translate_sched_param( policy, param, &config ); > if ( error != 0 ) { > return error; > } > @@ -169,8 +160,7 @@ int pthread_setschedparam( > the_thread, > policy, > param, > - budget_algorithm, > - budget_callout, > + &config, > &queue_context > ); > cpu_self = _Thread_queue_Dispatch_disable( &queue_context ); > diff --git a/cpukit/score/src/threadinitialize.c > b/cpukit/score/src/threadinitialize.c > index f11e35dcf3..18c98c6995 100644 > --- a/cpukit/score/src/threadinitialize.c > +++ b/cpukit/score/src/threadinitialize.c > @@ -27,7 +27,6 @@ > #include <rtems/score/tls.h> > #include <rtems/score/userextimpl.h> > #include <rtems/score/watchdogimpl.h> > -#include <rtems/config.h> > > void _Thread_Free( > Thread_Information *information, > @@ -176,6 +175,7 @@ static bool _Thread_Try_initialize( > */ > > the_thread->is_fp = config->is_fp; > + the_thread->cpu_time_budget = config->cpu_time_budget; > the_thread->Start.isr_level = config->isr_level; > the_thread->Start.is_preemptible = config->is_preemptible; > the_thread->Start.budget_algorithm = config->budget_algorithm; > @@ -184,22 +184,6 @@ static bool _Thread_Try_initialize( > > _Thread_Timer_initialize( &the_thread->Timer, cpu ); > > - switch ( config->budget_algorithm ) { > - case THREAD_CPU_BUDGET_ALGORITHM_NONE: > - case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: > - break; > - #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) > - case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: > - the_thread->cpu_time_budget = > - rtems_configuration_get_ticks_per_timeslice(); > - break; > - #endif > - #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) > - case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: > - break; > - #endif > - } > - > #if defined(RTEMS_SMP) > scheduler_node = NULL; > scheduler_node_for_index = the_thread->Scheduler.nodes; > -- > 2.26.2 > > _______________________________________________ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel