mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 23:23:13 +00:00
score: Add Thread_Configuration::cpu_time_budget
Move the CPU time budget to the thread configuration. This simplifies _Thread_Initialize().
This commit is contained in:
@@ -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
|
* @param policy is the POSIX scheduling policy.
|
||||||
* SuperCore settings.
|
|
||||||
*
|
*
|
||||||
* @param[in] policy is the POSIX scheduling policy
|
* @param param is the pointer to the POSIX scheduling parameters.
|
||||||
* @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
|
|
||||||
*
|
*
|
||||||
* @retval 0 Indicates success.
|
* @param[out] config is the pointer to a thread configuration to set the
|
||||||
* @retval error_code POSIX error code indicating failure.
|
* 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 _POSIX_Thread_Translate_sched_param(
|
||||||
int policy,
|
int policy,
|
||||||
const struct sched_param *param,
|
const struct sched_param *param,
|
||||||
Thread_CPU_budget_algorithms *budget_algorithm,
|
Thread_Configuration *config
|
||||||
Thread_CPU_budget_algorithm_callout *budget_callout
|
|
||||||
);
|
);
|
||||||
|
|
||||||
RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
|
RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
|
||||||
|
|||||||
@@ -163,6 +163,11 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
Thread_CPU_budget_algorithm_callout budget_callout;
|
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.
|
* @brief 32-bit unsigned integer name of the object for the thread.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,27 +42,28 @@ int _POSIX_Thread_Translate_to_sched_policy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int _POSIX_Thread_Translate_sched_param(
|
int _POSIX_Thread_Translate_sched_param(
|
||||||
int policy,
|
int policy,
|
||||||
const struct sched_param *param,
|
const struct sched_param *param,
|
||||||
Thread_CPU_budget_algorithms *budget_algorithm,
|
Thread_Configuration *config
|
||||||
Thread_CPU_budget_algorithm_callout *budget_callout
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
*budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
|
config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
|
||||||
*budget_callout = NULL;
|
config->budget_callout = NULL;
|
||||||
|
config->cpu_time_budget = 0;
|
||||||
|
|
||||||
if ( policy == SCHED_OTHER ) {
|
if ( policy == SCHED_OTHER ) {
|
||||||
*budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
|
config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( policy == SCHED_FIFO ) {
|
if ( policy == SCHED_FIFO ) {
|
||||||
*budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
|
config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( policy == SCHED_RR ) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +81,8 @@ int _POSIX_Thread_Translate_sched_param(
|
|||||||
_Timespec_To_ticks( ¶m->sched_ss_init_budget ) )
|
_Timespec_To_ticks( ¶m->sched_ss_init_budget ) )
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
*budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
|
config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
|
||||||
*budget_callout = _POSIX_Threads_Sporadic_budget_callout;
|
config->budget_callout = _POSIX_Threads_Sporadic_budget_callout;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -171,8 +171,7 @@ int pthread_create(
|
|||||||
error = _POSIX_Thread_Translate_sched_param(
|
error = _POSIX_Thread_Translate_sched_param(
|
||||||
schedpolicy,
|
schedpolicy,
|
||||||
&schedparam,
|
&schedparam,
|
||||||
&config.budget_algorithm,
|
&config
|
||||||
&config.budget_callout
|
|
||||||
);
|
);
|
||||||
if ( error != 0 ) {
|
if ( error != 0 ) {
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <rtems/posix/pthreadimpl.h>
|
#include <rtems/posix/pthreadimpl.h>
|
||||||
@@ -32,12 +33,11 @@
|
|||||||
#include <rtems/score/schedulerimpl.h>
|
#include <rtems/score/schedulerimpl.h>
|
||||||
|
|
||||||
static int _POSIX_Set_sched_param(
|
static int _POSIX_Set_sched_param(
|
||||||
Thread_Control *the_thread,
|
Thread_Control *the_thread,
|
||||||
int policy,
|
int policy,
|
||||||
const struct sched_param *param,
|
const struct sched_param *param,
|
||||||
Thread_CPU_budget_algorithms budget_algorithm,
|
const Thread_Configuration *config,
|
||||||
Thread_CPU_budget_algorithm_callout budget_callout,
|
Thread_queue_Context *queue_context
|
||||||
Thread_queue_Context *queue_context
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const Scheduler_Control *scheduler;
|
const Scheduler_Control *scheduler;
|
||||||
@@ -103,8 +103,9 @@ static int _POSIX_Set_sched_param(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
the_thread->budget_algorithm = budget_algorithm;
|
the_thread->cpu_time_budget = config->cpu_time_budget;
|
||||||
the_thread->budget_callout = budget_callout;
|
the_thread->budget_algorithm = config->budget_algorithm;
|
||||||
|
the_thread->budget_callout = config->budget_callout;
|
||||||
|
|
||||||
#if defined(RTEMS_POSIX_API)
|
#if defined(RTEMS_POSIX_API)
|
||||||
_Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
|
_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 ) {
|
if ( policy == SCHED_SPORADIC ) {
|
||||||
_POSIX_Threads_Sporadic_timer_insert( the_thread, api );
|
_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
|
#endif
|
||||||
|
|
||||||
@@ -135,23 +131,18 @@ int pthread_setschedparam(
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Thread_CPU_budget_algorithms budget_algorithm;
|
Thread_Configuration config;
|
||||||
Thread_CPU_budget_algorithm_callout budget_callout;
|
Thread_Control *the_thread;
|
||||||
Thread_Control *the_thread;
|
Per_CPU_Control *cpu_self;
|
||||||
Per_CPU_Control *cpu_self;
|
Thread_queue_Context queue_context;
|
||||||
Thread_queue_Context queue_context;
|
int error;
|
||||||
int error;
|
|
||||||
|
|
||||||
if ( param == NULL ) {
|
if ( param == NULL ) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = _POSIX_Thread_Translate_sched_param(
|
memset( &config, 0, sizeof( config ) );
|
||||||
policy,
|
error = _POSIX_Thread_Translate_sched_param( policy, param, &config );
|
||||||
param,
|
|
||||||
&budget_algorithm,
|
|
||||||
&budget_callout
|
|
||||||
);
|
|
||||||
if ( error != 0 ) {
|
if ( error != 0 ) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -169,8 +160,7 @@ int pthread_setschedparam(
|
|||||||
the_thread,
|
the_thread,
|
||||||
policy,
|
policy,
|
||||||
param,
|
param,
|
||||||
budget_algorithm,
|
&config,
|
||||||
budget_callout,
|
|
||||||
&queue_context
|
&queue_context
|
||||||
);
|
);
|
||||||
cpu_self = _Thread_queue_Dispatch_disable( &queue_context );
|
cpu_self = _Thread_queue_Dispatch_disable( &queue_context );
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
#include <rtems/score/tls.h>
|
#include <rtems/score/tls.h>
|
||||||
#include <rtems/score/userextimpl.h>
|
#include <rtems/score/userextimpl.h>
|
||||||
#include <rtems/score/watchdogimpl.h>
|
#include <rtems/score/watchdogimpl.h>
|
||||||
#include <rtems/config.h>
|
|
||||||
|
|
||||||
void _Thread_Free(
|
void _Thread_Free(
|
||||||
Thread_Information *information,
|
Thread_Information *information,
|
||||||
@@ -176,6 +175,7 @@ static bool _Thread_Try_initialize(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
the_thread->is_fp = config->is_fp;
|
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.isr_level = config->isr_level;
|
||||||
the_thread->Start.is_preemptible = config->is_preemptible;
|
the_thread->Start.is_preemptible = config->is_preemptible;
|
||||||
the_thread->Start.budget_algorithm = config->budget_algorithm;
|
the_thread->Start.budget_algorithm = config->budget_algorithm;
|
||||||
@@ -184,22 +184,6 @@ static bool _Thread_Try_initialize(
|
|||||||
|
|
||||||
_Thread_Timer_initialize( &the_thread->Timer, cpu );
|
_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)
|
#if defined(RTEMS_SMP)
|
||||||
scheduler_node = NULL;
|
scheduler_node = NULL;
|
||||||
scheduler_node_for_index = the_thread->Scheduler.nodes;
|
scheduler_node_for_index = the_thread->Scheduler.nodes;
|
||||||
|
|||||||
Reference in New Issue
Block a user