mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +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
|
||||
* 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)
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user