[PATCH 2/3] posix: Remove POSIX_API_Control::schedparam
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Oct 17 10:11:54 UTC 2017
Move sporadic server scheduler parameters to
POSIX_API_Control::Sporadic. Remove redundant scheduler priority
parameter.
Update #2514.
---
cpukit/posix/include/rtems/posix/pthreadattrimpl.h | 18 +++++++++++++++
cpukit/posix/include/rtems/posix/pthreadimpl.h | 4 ++--
cpukit/posix/include/rtems/posix/threadsup.h | 20 +++++++++++++---
cpukit/posix/src/pthread.c | 6 -----
cpukit/posix/src/pthreadcreate.c | 8 ++++++-
cpukit/posix/src/pthreadgetattrnp.c | 24 +++++++++++++++----
cpukit/posix/src/pthreadgetschedparam.c | 4 ++--
cpukit/posix/src/pthreadsetschedparam.c | 27 ++++++++++++----------
testsuites/psxtests/psxgetattrnp01/init.c | 6 +----
9 files changed, 81 insertions(+), 36 deletions(-)
diff --git a/cpukit/posix/include/rtems/posix/pthreadattrimpl.h b/cpukit/posix/include/rtems/posix/pthreadattrimpl.h
index a52be931a1..1e5105deab 100644
--- a/cpukit/posix/include/rtems/posix/pthreadattrimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadattrimpl.h
@@ -24,6 +24,8 @@
#include <rtems/score/basedefs.h>
#include <rtems/score/assert.h>
+#include <rtems/posix/priorityimpl.h>
+#include <rtems/posix/threadsup.h>
#ifdef __cplusplus
extern "C" {
@@ -61,6 +63,22 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
);
}
+RTEMS_INLINE_ROUTINE void _POSIX_Threads_Get_sched_param_sporadic(
+ const Thread_Control *the_thread,
+ const POSIX_API_Control *api,
+ const Scheduler_Control *scheduler,
+ struct sched_param *param
+)
+{
+ param->sched_ss_low_priority = _POSIX_Priority_From_core(
+ scheduler,
+ api->Sporadic.Low_priority.priority
+ );
+ param->sched_ss_repl_period = api->Sporadic.sched_ss_repl_period;
+ param->sched_ss_init_budget = api->Sporadic.sched_ss_init_budget;
+ param->sched_ss_max_repl = api->Sporadic.sched_ss_max_repl;
+}
+
/** @} */
#ifdef __cplusplus
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index bae9e344a0..82593d3097 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -54,12 +54,12 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
)
{
the_thread->cpu_time_budget =
- _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
+ _Timespec_To_ticks( &api->Sporadic.sched_ss_init_budget );
_Watchdog_Per_CPU_insert_ticks(
&api->Sporadic.Timer,
_Per_CPU_Get(),
- _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
+ _Timespec_To_ticks( &api->Sporadic.sched_ss_repl_period )
);
}
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index 816ef566d8..b3b3910084 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -46,9 +46,6 @@ typedef struct {
/** The scheduler policy. */
int schedpolicy;
- /** The scheduler parameters */
- struct sched_param schedparam;
-
/**
* @brief Control block for the sporadic server scheduling policy.
*/
@@ -67,6 +64,23 @@ typedef struct {
* policy.
*/
Priority_Node Low_priority;
+
+ /**
+ * @brief Replenishment period for sporadic server.
+ */
+ struct timespec sched_ss_repl_period;
+
+ /**
+ * @brief Initial budget for sporadic server.
+ */
+ struct timespec sched_ss_init_budget;
+
+ /**
+ * @brief Maximum pending replenishments.
+ *
+ * Only used by pthread_getschedparam() and pthread_getattr_np().
+ */
+ int sched_ss_max_repl;
} Sporadic;
/** This is the set of signals which are currently unblocked. */
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 291b19532d..8bd44ca03a 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -126,12 +126,6 @@ static bool _POSIX_Threads_Create_extension(
api = created->API_Extensions[ THREAD_API_POSIX ];
- /* XXX check all fields are touched */
- api->schedparam.sched_priority = _POSIX_Priority_From_core(
- _Thread_Scheduler_get_home( created ),
- _Thread_Get_priority( created )
- );
-
/*
* If the thread is not a posix thread, then all posix signals are blocked
* by default.
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index d8cafe52ce..0de566f7c2 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -241,8 +241,14 @@ int pthread_create(
api->created_with_explicit_scheduler =
( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
api->schedpolicy = the_attr->schedpolicy;
- api->schedparam = the_attr->schedparam;
+
_Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
+ api->Sporadic.sched_ss_repl_period =
+ the_attr->schedparam.sched_ss_repl_period;
+ api->Sporadic.sched_ss_init_budget =
+ the_attr->schedparam.sched_ss_init_budget;
+ api->Sporadic.sched_ss_max_repl =
+ the_attr->schedparam.sched_ss_max_repl;
if ( schedpolicy == SCHED_SPORADIC ) {
_POSIX_Threads_Sporadic_timer( &api->Sporadic.Timer );
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index d815fc8c53..bebf35e4d6 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -24,6 +24,8 @@
#include <string.h>
#include <rtems/posix/pthreadimpl.h>
+#include <rtems/posix/pthreadattrimpl.h>
+#include <rtems/posix/priorityimpl.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/threadimpl.h>
@@ -32,10 +34,11 @@ int pthread_getattr_np(
pthread_attr_t *attr
)
{
- Thread_Control *the_thread;
- ISR_lock_Context lock_context;
- POSIX_API_Control *api;
- bool ok;
+ Thread_Control *the_thread;
+ ISR_lock_Context lock_context;
+ POSIX_API_Control *api;
+ const Scheduler_Control *scheduler;
+ bool ok;
if ( attr == NULL ) {
return EINVAL;
@@ -65,7 +68,18 @@ int pthread_getattr_np(
}
attr->schedpolicy = api->schedpolicy;
- attr->schedparam = api->schedparam;
+
+ scheduler = _Thread_Scheduler_get_home( the_thread );
+ attr->schedparam.sched_priority = _POSIX_Priority_From_core(
+ scheduler,
+ _Thread_Get_priority( the_thread )
+ );
+ _POSIX_Threads_Get_sched_param_sporadic(
+ the_thread,
+ api,
+ scheduler,
+ &attr->schedparam
+ );
attr->cputime_clock_allowed = 1;
if ( _Thread_Is_joinable( the_thread ) ) {
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index f172caecd4..a5494b5922 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <rtems/posix/pthreadimpl.h>
+#include <rtems/posix/pthreadattrimpl.h>
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/threadimpl.h>
@@ -57,9 +58,8 @@ int pthread_getschedparam(
_Thread_Wait_acquire_critical( the_thread, &queue_context );
*policy = api->schedpolicy;
- *param = api->schedparam;
-
scheduler = _Thread_Scheduler_get_home( the_thread );
+ _POSIX_Threads_Get_sched_param_sporadic( the_thread, api, scheduler, param );
priority = the_thread->Real_priority.priority;
_Thread_Wait_release( the_thread, &queue_context );
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 3bd5bc4f3a..c22d4f59b1 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -41,28 +41,28 @@ static int _POSIX_Set_sched_param(
{
const Scheduler_Control *scheduler;
POSIX_API_Control *api;
+ int normal_prio;
int low_prio;
- int high_prio;
bool valid;
Priority_Control core_normal_prio;
Priority_Control core_low_prio;
- if ( policy == SCHED_SPORADIC ) {
- low_prio = param->sched_ss_low_priority;
- high_prio = param->sched_priority;
- } else {
- low_prio = param->sched_priority;
- high_prio = low_prio;
- }
+ normal_prio = param->sched_priority;
scheduler = _Thread_Scheduler_get_home( the_thread );
- core_normal_prio = _POSIX_Priority_To_core( scheduler, low_prio, &valid );
+ core_normal_prio = _POSIX_Priority_To_core( scheduler, normal_prio, &valid );
if ( !valid ) {
return EINVAL;
}
- core_low_prio = _POSIX_Priority_To_core( scheduler, high_prio, &valid );
+ if ( policy == SCHED_SPORADIC ) {
+ low_prio = param->sched_ss_low_priority;
+ } else {
+ low_prio = normal_prio;
+ }
+
+ core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio, &valid );
if ( !valid ) {
return EINVAL;
}
@@ -95,13 +95,16 @@ static int _POSIX_Set_sched_param(
}
api->schedpolicy = policy;
- api->schedparam = *param;
the_thread->budget_algorithm = budget_algorithm;
the_thread->budget_callout = budget_callout;
+ _Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
+ api->Sporadic.sched_ss_repl_period = param->sched_ss_repl_period;
+ api->Sporadic.sched_ss_init_budget = param->sched_ss_init_budget;
+ api->Sporadic.sched_ss_max_repl = param->sched_ss_max_repl;
+
if ( policy == SCHED_SPORADIC ) {
- _Priority_Node_set_priority( &api->Sporadic.Low_priority, core_low_prio );
_POSIX_Threads_Sporadic_timer_insert( the_thread, api );
} else {
the_thread->cpu_time_budget =
diff --git a/testsuites/psxtests/psxgetattrnp01/init.c b/testsuites/psxtests/psxgetattrnp01/init.c
index afde4a210e..19981573d1 100644
--- a/testsuites/psxtests/psxgetattrnp01/init.c
+++ b/testsuites/psxtests/psxgetattrnp01/init.c
@@ -62,11 +62,7 @@ static int attribute_compare(
if ( attr1->schedpolicy != attr2->schedpolicy )
return 1;
- if (memcmp(
- &attr1->schedparam,
- &attr2->schedparam,
- sizeof(struct sched_param)
- ))
+ if ( attr1->schedparam.sched_priority != attr2->schedparam.sched_priority )
return 1;
#if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
--
2.12.3
More information about the devel
mailing list