[rtems commit] score: Add Thread_Configuration::cpu_time_budget
Sebastian Huber
sebh at rtems.org
Tue Mar 16 13:01:29 UTC 2021
Module: rtems
Branch: master
Commit: c9a41b0043e67ed7f1be98f19b5f5fda994ceb55
Changeset: http://git.rtems.org/rtems/commit/?id=c9a41b0043e67ed7f1be98f19b5f5fda994ceb55
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Mar 12 08:31:35 2021 +0100
score: Add Thread_Configuration::cpu_time_budget
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 52d462a..723b20e 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 1e7d586..d9c0779 100644
--- a/cpukit/include/rtems/score/threadimpl.h
+++ b/cpukit/include/rtems/score/threadimpl.h
@@ -164,6 +164,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.
*/
uint32_t name;
diff --git a/cpukit/posix/src/psxtransschedparam.c b/cpukit/posix/src/psxtransschedparam.c
index 6fa7a43..eba26d4 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 55ba73c..75d3c64 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 9ab543c..e9be24b 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 f11e35d..18c98c6 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;
More information about the vc
mailing list