summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/psignalunblockthread.c7
-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
6 files changed, 87 insertions, 54 deletions
diff --git a/cpukit/posix/src/psignalunblockthread.c b/cpukit/posix/src/psignalunblockthread.c
index de814c13cd..36680f99a2 100644
--- a/cpukit/posix/src/psignalunblockthread.c
+++ b/cpukit/posix/src/psignalunblockthread.c
@@ -196,8 +196,6 @@ bool _POSIX_signals_Unblock_thread(
if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
if ( (the_thread->Wait.option & mask) || (api->signals_unblocked & mask) ) {
- the_thread->Wait.return_code = STATUS_INTERRUPTED;
-
the_info = (siginfo_t *) the_thread->Wait.return_argument;
if ( !info ) {
@@ -208,7 +206,7 @@ bool _POSIX_signals_Unblock_thread(
*the_info = *info;
}
- _Thread_queue_Extract_with_proxy( the_thread );
+ _Thread_Timer_remove_and_continue( the_thread, STATUS_INTERRUPTED );
return _POSIX_signals_Unblock_thread_done( the_thread, api, true );
}
@@ -238,8 +236,7 @@ bool _POSIX_signals_Unblock_thread(
*/
if ( _States_Is_interruptible_by_signal( the_thread->current_state ) ) {
- the_thread->Wait.return_code = STATUS_INTERRUPTED;
- _Thread_queue_Extract_with_proxy( the_thread );
+ _Thread_Timer_remove_and_continue( the_thread, STATUS_INTERRUPTED );
}
}
return _POSIX_signals_Unblock_thread_done( the_thread, api, false );
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 );