posix: Remove POSIX_API_Control::schedpolicy

Use the thread CPU budget algorithm to determine the scheduler policy.
This fixes also pthread_getschedparam() for Classic tasks.

Update #2514.
This commit is contained in:
Sebastian Huber
2017-11-08 14:37:35 +01:00
parent 8d0a0aa448
commit 7147dc43b8
9 changed files with 59 additions and 39 deletions

View File

@@ -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.
*

View File

@@ -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.
*/

View File

@@ -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,

View File

@@ -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 );
}

View File

@@ -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 =

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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( &param, -1, sizeof( param ) );
sc = pthread_getschedparam( pthread_self(), &policy, &param );
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, &param );
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;