summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-10-27 12:59:09 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-11-15 08:56:53 +0100
commit240a1f79b1fcb58b9ae7bfc393e1f890e4492683 (patch)
tree92c47fa4899b2f0a8306e32bc18d66fbbf6b216f /cpukit/posix
parentscore: Do not shadow parameter (diff)
downloadrtems-240a1f79b1fcb58b9ae7bfc393e1f890e4492683.tar.bz2
score: Introduce CPU budget operations
This patch set replaces the CPU budget algorithm enumeration with a set of CPU budget operations which implement a particular CPU budget algorithm. This helps to hide the CPU budget algorithm implementation details from the general thread handling. The CPU budget callouts are turned into CPU budget operations. This slightly reduces the size of the thread control block. All schedulers used the default scheduler tick implementation. The tick scheduler operation is removed and the CPU budget operations are directly used in _Watchdog_Tick() if the executing thread uses a CPU budget algorithm. This is performance improvement for all threads which do not use a CPU budget algorithm (default behaviour).
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/src/psxtransschedparam.c44
-rw-r--r--cpukit/posix/src/pthreadcreate.c36
-rw-r--r--cpukit/posix/src/pthreadgetattrnp.c16
-rw-r--r--cpukit/posix/src/pthreadgetschedparam.c14
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c24
5 files changed, 85 insertions, 49 deletions
diff --git a/cpukit/posix/src/psxtransschedparam.c b/cpukit/posix/src/psxtransschedparam.c
index eba26d4932..f97924e011 100644
--- a/cpukit/posix/src/psxtransschedparam.c
+++ b/cpukit/posix/src/psxtransschedparam.c
@@ -23,22 +23,27 @@
#include <errno.h>
#include <rtems/posix/pthreadimpl.h>
+#include <rtems/score/threadcpubudget.h>
int _POSIX_Thread_Translate_to_sched_policy(
- Thread_CPU_budget_algorithms budget_algorithm
+ const Thread_CPU_budget_operations *operations
)
{
- switch ( budget_algorithm ) {
- case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
- return SCHED_OTHER;
- case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
- return SCHED_RR;
- case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
- return SCHED_SPORADIC;
- default:
- _Assert( budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE );
- return SCHED_FIFO;
+ if ( operations == NULL ) {
+ return SCHED_FIFO;
}
+
+ if ( operations == &_Thread_CPU_budget_exhaust_timeslice ) {
+ return SCHED_RR;
+ }
+
+#if defined(RTEMS_POSIX_API)
+ if ( operations == &_POSIX_Threads_Sporadic_budget ) {
+ return SCHED_SPORADIC;
+ }
+#endif
+
+ return SCHED_OTHER;
}
int _POSIX_Thread_Translate_sched_param(
@@ -47,23 +52,19 @@ int _POSIX_Thread_Translate_sched_param(
Thread_Configuration *config
)
{
- config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
- config->budget_callout = NULL;
- config->cpu_time_budget = 0;
+ config->cpu_budget_operations = NULL;
- if ( policy == SCHED_OTHER ) {
- config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
+ if ( policy == SCHED_FIFO ) {
return 0;
}
- if ( policy == SCHED_FIFO ) {
- config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ if ( policy == SCHED_OTHER ) {
+ config->cpu_budget_operations = &_Thread_CPU_budget_reset_timeslice;
return 0;
}
if ( policy == SCHED_RR ) {
- config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
- config->cpu_time_budget = rtems_configuration_get_ticks_per_timeslice();
+ config->cpu_budget_operations = &_Thread_CPU_budget_exhaust_timeslice;
return 0;
}
@@ -81,8 +82,7 @@ int _POSIX_Thread_Translate_sched_param(
_Timespec_To_ticks( &param->sched_ss_init_budget ) )
return EINVAL;
- config->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
- config->budget_callout = _POSIX_Threads_Sporadic_budget_callout;
+ config->cpu_budget_operations = &_POSIX_Threads_Sporadic_budget;
return 0;
}
#endif
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 9474d07032..093ad5cfe1 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -34,9 +34,11 @@
#include <rtems/posix/pthreadimpl.h>
#include <rtems/posix/pthreadattrimpl.h>
#include <rtems/score/assert.h>
+#include <rtems/score/threadcpubudget.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/stackimpl.h>
+#include <rtems/score/statesimpl.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/userextimpl.h>
#include <rtems/sysinit.h>
@@ -348,7 +350,9 @@ void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
_Thread_Priority_update( &queue_context );
}
-void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread )
+static void _POSIX_Threads_Sporadic_budget_callout(
+ Thread_Control *the_thread
+)
{
POSIX_API_Control *api;
Thread_queue_Context queue_context;
@@ -363,7 +367,7 @@ void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread )
* This will prevent the thread from consuming its entire "budget"
* while at low priority.
*/
- the_thread->cpu_time_budget = UINT32_MAX;
+ the_thread->CPU_budget.available = UINT32_MAX;
if ( !_Priority_Node_is_active( &api->Sporadic.Low_priority ) ) {
_Thread_Priority_add(
@@ -382,6 +386,34 @@ void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread )
_Thread_Priority_update( &queue_context );
}
+static void _POSIX_Threads_Sporadic_budget_at_tick( Thread_Control *the_thread )
+{
+ uint32_t budget_available;
+
+ if ( !the_thread->is_preemptible ) {
+ return;
+ }
+
+ if ( !_States_Is_ready( the_thread->current_state ) ) {
+ return;
+ }
+
+ budget_available = the_thread->CPU_budget.available;
+
+ if ( budget_available == 1 ) {
+ the_thread->CPU_budget.available = 0;
+ _POSIX_Threads_Sporadic_budget_callout ( the_thread );
+ } else {
+ the_thread->CPU_budget.available = budget_available - 1;
+ }
+}
+
+const Thread_CPU_budget_operations _POSIX_Threads_Sporadic_budget = {
+ .at_tick = _POSIX_Threads_Sporadic_budget_at_tick,
+ .at_context_switch = _Thread_CPU_budget_do_nothing,
+ .initialize = _Thread_CPU_budget_do_nothing
+};
+
static bool _POSIX_Threads_Create_extension(
Thread_Control *executing,
Thread_Control *created
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index 5572fb98a5..aa34185264 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -37,12 +37,12 @@ int pthread_getattr_np(
pthread_attr_t *attr
)
{
- Thread_Control *the_thread;
- ISR_lock_Context lock_context;
- Thread_CPU_budget_algorithms budget_algorithm;
- const Scheduler_Control *scheduler;
- Priority_Control priority;
- Status_Control status;
+ Thread_Control *the_thread;
+ ISR_lock_Context lock_context;
+ const Thread_CPU_budget_operations *cpu_budget_operations;
+ const Scheduler_Control *scheduler;
+ Priority_Control priority;
+ Status_Control status;
if ( attr == NULL ) {
return EINVAL;
@@ -89,7 +89,7 @@ int pthread_getattr_np(
attr->affinityset
);
- budget_algorithm = the_thread->budget_algorithm;
+ cpu_budget_operations = the_thread->CPU_budget.operations;
_Thread_State_release( the_thread, &lock_context );
@@ -101,7 +101,7 @@ int pthread_getattr_np(
priority
);
attr->schedpolicy =
- _POSIX_Thread_Translate_to_sched_policy( budget_algorithm );
+ _POSIX_Thread_Translate_to_sched_policy( cpu_budget_operations );
return _POSIX_Get_error( status );
}
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index a82d79c715..406ae8e7bb 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -37,11 +37,11 @@ int pthread_getschedparam(
struct sched_param *param
)
{
- Thread_Control *the_thread;
- Thread_queue_Context queue_context;
- Thread_CPU_budget_algorithms budget_algorithm;
- const Scheduler_Control *scheduler;
- Priority_Control priority;
+ Thread_Control *the_thread;
+ Thread_queue_Context queue_context;
+ const Thread_CPU_budget_operations *cpu_budget_operations;
+ const Scheduler_Control *scheduler;
+ Priority_Control priority;
if ( policy == NULL || param == NULL ) {
return EINVAL;
@@ -59,11 +59,11 @@ int pthread_getschedparam(
scheduler = _Thread_Scheduler_get_home( the_thread );
_POSIX_Threads_Get_sched_param_sporadic( the_thread, scheduler, param );
priority = the_thread->Real_priority.priority;
- budget_algorithm = the_thread->budget_algorithm;
+ cpu_budget_operations = the_thread->CPU_budget.operations;
_Thread_Wait_release( the_thread, &queue_context );
param->sched_priority = _POSIX_Priority_From_core( scheduler, priority );
- *policy = _POSIX_Thread_Translate_to_sched_policy( budget_algorithm );
+ *policy = _POSIX_Thread_Translate_to_sched_policy( cpu_budget_operations );
return 0;
}
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 1c207e7887..165e1d86a8 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -40,14 +40,15 @@ static int _POSIX_Set_sched_param(
Thread_queue_Context *queue_context
)
{
- const Scheduler_Control *scheduler;
- int normal_prio;
- bool valid;
- Priority_Control core_normal_prio;
+ const Scheduler_Control *scheduler;
+ int normal_prio;
+ bool valid;
+ Priority_Control core_normal_prio;
+ const Thread_CPU_budget_operations *cpu_budget_operations;
#if defined(RTEMS_POSIX_API)
- POSIX_API_Control *api;
- int low_prio;
- Priority_Control core_low_prio;
+ POSIX_API_Control *api;
+ int low_prio;
+ Priority_Control core_low_prio;
#endif
normal_prio = param->sched_priority;
@@ -103,9 +104,12 @@ static int _POSIX_Set_sched_param(
}
#endif
- the_thread->cpu_time_budget = config->cpu_time_budget;
- the_thread->budget_algorithm = config->budget_algorithm;
- the_thread->budget_callout = config->budget_callout;
+ cpu_budget_operations = config->cpu_budget_operations;
+ the_thread->CPU_budget.operations = cpu_budget_operations;
+
+ if ( cpu_budget_operations != NULL ) {
+ ( *cpu_budget_operations->initialize )( the_thread );
+ }
#if defined(RTEMS_POSIX_API)
_Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );