[PATCH] posix: Remove POSIX_API_Control::schedpolicy
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Nov 8 13:40:17 UTC 2017
Use the thread CPU budget algorithm to determine the scheduler policy.
This fixes also pthread_getschedparam() for Classic tasks.
Update #2514.
---
cpukit/posix/include/rtems/posix/pthreadimpl.h | 4 ++++
cpukit/posix/include/rtems/posix/threadsup.h | 3 ---
cpukit/posix/src/psxtransschedparam.c | 17 +++++++++++++++++
cpukit/posix/src/pthread.c | 6 +-----
cpukit/posix/src/pthreadcreate.c | 1 -
cpukit/posix/src/pthreadgetattrnp.c | 25 +++++++++++++++----------
cpukit/posix/src/pthreadgetschedparam.c | 14 ++++++++------
cpukit/posix/src/pthreadsetschedparam.c | 2 --
testsuites/psxtests/psxclassic01/init.c | 26 ++++++++++++++------------
9 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 82593d3097..3e2351e57e 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -77,6 +77,10 @@ void _POSIX_Threads_Sporadic_budget_callout(
Thread_Control *the_thread
);
+int _POSIX_Thread_Translate_to_sched_policy(
+ Thread_CPU_budget_algorithms budget_algorithm
+);
+
/**
* @brief Translate sched_param into SuperCore terms.
*
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index b3b3910084..4b62b19e1c 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -43,9 +43,6 @@ typedef struct {
/** Created with explicit or inherited scheduler. */
bool created_with_explicit_scheduler;
- /** The scheduler policy. */
- int schedpolicy;
-
/**
* @brief Control block for the sporadic server scheduling policy.
*/
diff --git a/cpukit/posix/src/psxtransschedparam.c b/cpukit/posix/src/psxtransschedparam.c
index fb501b0717..86d8ff0894 100644
--- a/cpukit/posix/src/psxtransschedparam.c
+++ b/cpukit/posix/src/psxtransschedparam.c
@@ -23,6 +23,23 @@
#include <rtems/posix/pthreadimpl.h>
+int _POSIX_Thread_Translate_to_sched_policy(
+ Thread_CPU_budget_algorithms budget_algorithm
+)
+{
+ 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;
+ }
+}
+
int _POSIX_Thread_Translate_sched_param(
int policy,
struct sched_param *param,
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index ba394b4924..43ed140b11 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -141,11 +141,7 @@ static void _POSIX_Threads_Terminate_extension( Thread_Control *executing )
api = executing->API_Extensions[ THREAD_API_POSIX ];
_Thread_State_acquire( executing, &lock_context );
-
- if ( api->schedpolicy == SCHED_SPORADIC ) {
- _Watchdog_Per_CPU_remove_monotonic( &api->Sporadic.Timer );
- }
-
+ _Watchdog_Per_CPU_remove_monotonic( &api->Sporadic.Timer );
_Thread_State_release( executing, &lock_context );
}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 5a8cf2d7fb..348bf68430 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -252,7 +252,6 @@ int pthread_create(
api->created_with_explicit_scheduler =
( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
- api->schedpolicy = the_attr->schedpolicy;
_Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
api->Sporadic.sched_ss_repl_period =
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index bebf35e4d6..9df5bad38f 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -34,11 +34,12 @@ int pthread_getattr_np(
pthread_attr_t *attr
)
{
- Thread_Control *the_thread;
- ISR_lock_Context lock_context;
- POSIX_API_Control *api;
- const Scheduler_Control *scheduler;
- bool ok;
+ Thread_Control *the_thread;
+ ISR_lock_Context lock_context;
+ const POSIX_API_Control *api;
+ Thread_CPU_budget_algorithms budget_algorithm;
+ const Scheduler_Control *scheduler;
+ bool ok;
if ( attr == NULL ) {
return EINVAL;
@@ -56,10 +57,8 @@ int pthread_getattr_np(
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- attr->is_initialized = true;
attr->stackaddr = the_thread->Start.Initial_stack.area;
attr->stacksize = the_thread->Start.Initial_stack.size;
- attr->contentionscope = PTHREAD_SCOPE_PROCESS;
if ( api->created_with_explicit_scheduler ) {
attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
@@ -67,8 +66,6 @@ int pthread_getattr_np(
attr->inheritsched = PTHREAD_INHERIT_SCHED;
}
- attr->schedpolicy = api->schedpolicy;
-
scheduler = _Thread_Scheduler_get_home( the_thread );
attr->schedparam.sched_priority = _POSIX_Priority_From_core(
scheduler,
@@ -80,7 +77,6 @@ int pthread_getattr_np(
scheduler,
&attr->schedparam
);
- attr->cputime_clock_allowed = 1;
if ( _Thread_Is_joinable( the_thread ) ) {
attr->detachstate = PTHREAD_CREATE_JOINABLE;
@@ -96,6 +92,15 @@ int pthread_getattr_np(
attr->affinityset
);
+ budget_algorithm = the_thread->budget_algorithm;
+
_Thread_State_release( the_thread, &lock_context );
+
+ attr->is_initialized = true;
+ attr->contentionscope = PTHREAD_SCOPE_PROCESS;
+ attr->cputime_clock_allowed = 1;
+ attr->schedpolicy =
+ _POSIX_Thread_Translate_to_sched_policy( budget_algorithm );
+
return ok ? 0 : EINVAL;
}
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index a5494b5922..25c6195967 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -36,11 +36,12 @@ int pthread_getschedparam(
struct sched_param *param
)
{
- Thread_Control *the_thread;
- Thread_queue_Context queue_context;
- POSIX_API_Control *api;
- const Scheduler_Control *scheduler;
- Priority_Control priority;
+ Thread_Control *the_thread;
+ Thread_queue_Context queue_context;
+ const POSIX_API_Control *api;
+ Thread_CPU_budget_algorithms budget_algorithm;
+ const Scheduler_Control *scheduler;
+ Priority_Control priority;
if ( policy == NULL || param == NULL ) {
return EINVAL;
@@ -57,13 +58,14 @@ int pthread_getschedparam(
_Thread_Wait_acquire_critical( the_thread, &queue_context );
- *policy = api->schedpolicy;
scheduler = _Thread_Scheduler_get_home( the_thread );
_POSIX_Threads_Get_sched_param_sporadic( the_thread, api, scheduler, param );
priority = the_thread->Real_priority.priority;
+ budget_algorithm = the_thread->budget_algorithm;
_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 );
return 0;
}
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index c22d4f59b1..77e0ecaf48 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -94,8 +94,6 @@ static int _POSIX_Set_sched_param(
);
}
- api->schedpolicy = policy;
-
the_thread->budget_algorithm = budget_algorithm;
the_thread->budget_callout = budget_callout;
diff --git a/testsuites/psxtests/psxclassic01/init.c b/testsuites/psxtests/psxclassic01/init.c
index 946dcc7e92..2a38bf186a 100644
--- a/testsuites/psxtests/psxclassic01/init.c
+++ b/testsuites/psxtests/psxclassic01/init.c
@@ -24,30 +24,26 @@
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
+#include <string.h>
+#include <sched.h>
const char rtems_test_name[] = "PSXCLASSIC 1";
-int Caught_signo = -1;
-siginfo_t Caught_siginfo = { -1, -1, };
+static int Caught_signo = -1;
+static siginfo_t Caught_siginfo = { -1, -1, };
-/* forward declarations to avoid warnings */
-rtems_task Init(rtems_task_argument arg);
-void handler(int signo);
-void handler_info(int signo, siginfo_t *info, void *context);
-rtems_task test_task(rtems_task_argument arg);
-
-void handler(int signo)
+static void handler(int signo)
{
Caught_signo = signo;
}
-void handler_info(int signo, siginfo_t *info, void *context)
+static void handler_info(int signo, siginfo_t *info, void *context)
{
Caught_signo = signo;
Caught_siginfo = *info;
}
-rtems_task test_task(rtems_task_argument arg)
+static rtems_task test_task(rtems_task_argument arg)
{
int sc;
struct sigaction new_action;
@@ -57,8 +53,14 @@ rtems_task test_task(rtems_task_argument arg)
printf("test_task starting...\n");
+ policy = -1;
+ memset( ¶m, -1, sizeof( param ) );
sc = pthread_getschedparam( pthread_self(), &policy, ¶m );
rtems_test_assert( sc == 0 );
+ rtems_test_assert( policy == SCHED_FIFO );
+ rtems_test_assert(
+ param.sched_priority == sched_get_priority_max( SCHED_FIFO )
+ );
sc = pthread_setschedparam( pthread_self(), policy, ¶m );
rtems_test_assert( sc == 0 );
@@ -132,7 +134,7 @@ static rtems_id create_task( void )
return task_id;
}
-rtems_task Init( rtems_task_argument arg )
+static rtems_task Init( rtems_task_argument arg )
{
rtems_id task_id;
int status;
--
2.12.3
More information about the devel
mailing list