psxtests: Adjust sporadic server tests

According to POSIX priority value returned from pthread_getschedparam()
shall be the value specified by the most recent pthread_setschedparam(),
pthread_setschedprio(), or pthread_create() call affecting the target
thread.  Read this as though a temporary lower priority due to the
sporadic server policy shall not be visible through
pthread_getschedparam().  Thus, use rtems_task_set_priority() to get the
current priority of the threads.

Use a priority ceiling mutex to prevent sporadic server priority
adjustments.
This commit is contained in:
Sebastian Huber
2016-08-12 15:54:46 +02:00
parent 9c42752cac
commit 5d1fc66ce7
3 changed files with 63 additions and 98 deletions

View File

@@ -20,33 +20,22 @@
const char rtems_test_name[] = "PSX 9";
void print_schedparam(
char *prefix,
struct sched_param *schedparam
);
static int CEILING_PRIORITY;
static int HIGH_PRIORITY;
static int LOW_PRIORITY;
int HIGH_PRIORITY;
int MEDIUM_PRIORITY;
int LOW_PRIORITY;
void print_schedparam(
char *prefix,
struct sched_param *schedparam
)
static int get_current_prio( pthread_t thread )
{
printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority );
#if defined(_POSIX_SPORADIC_SERVER)
printf( "%ssched_ss_low_priority = %d\n",
prefix, schedparam->sched_ss_low_priority );
printf( "%ssched_ss_repl_period = (%" PRIdtime_t ", %ld)\n", prefix,
schedparam->sched_ss_repl_period.tv_sec,
schedparam->sched_ss_repl_period.tv_nsec );
printf( "%ssched_ss_init_budget = (%" PRIdtime_t ", %ld)\n", prefix,
schedparam->sched_ss_init_budget.tv_sec,
schedparam->sched_ss_init_budget.tv_nsec );
#else
printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix );
#endif
rtems_status_code sc;
rtems_task_priority prio;
int max;
sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
max = sched_get_priority_max( SCHED_FIFO );
return max + 1 - (int) prio;
}
static void *mutex_lock_task(void *arg)
@@ -109,6 +98,10 @@ void *POSIX_Init(
TEST_BEGIN();
CEILING_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 1;
LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
test_destroy_locked_mutex();
/* set the time of day, and print our buffer in multiple ways */
@@ -135,28 +128,25 @@ void *POSIX_Init(
schedparam.sched_ss_init_budget.tv_sec = 0;
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2;
schedparam.sched_priority = HIGH_PRIORITY;
schedparam.sched_ss_low_priority = LOW_PRIORITY;
puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
rtems_test_assert( !status );
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
/* go into a loop consuming CPU time to watch our priority change */
for ( passes=0 ; passes <= 3 ; ) {
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
int current_priority;
if ( priority != schedparam.sched_priority ) {
priority = schedparam.sched_priority;
current_priority = get_current_prio( pthread_self() );
if ( priority != current_priority ) {
priority = current_priority;
sprintf( buffer, " - new priority = %d", priority );
print_current_time( "Init: ", buffer );
passes++;
@@ -175,10 +165,6 @@ void *POSIX_Init(
schedparam.sched_ss_init_budget.tv_sec = 0;
schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */
HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC );
MEDIUM_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2;
LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 4;
schedparam.sched_priority = HIGH_PRIORITY;
schedparam.sched_ss_low_priority = LOW_PRIORITY;
@@ -190,7 +176,10 @@ void *POSIX_Init(
status = pthread_mutexattr_init( &attr );
rtems_test_assert( !status );
status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
rtems_test_assert( !status );
status = pthread_mutexattr_setprioceiling( &attr, CEILING_PRIORITY );
rtems_test_assert( !status );
puts( "Init: Creating a mutex" );
@@ -199,11 +188,7 @@ void *POSIX_Init(
printf( "status = %d\n", status );
rtems_test_assert( !status );
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
/* go into a loop consuming CPU time to watch our priority NOT lower */
@@ -216,32 +201,16 @@ void *POSIX_Init(
printf( "status = %d %s\n", status, strerror(status) );
rtems_test_assert( !status );
for ( ; ; ) {
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
do {
priority = get_current_prio( pthread_self() );
if ( schedparam.sched_priority == LOW_PRIORITY ) {
if ( priority != CEILING_PRIORITY ) {
puts( "ERROR - Init's priority lowered while holding mutex" );
rtems_test_exit(0);
}
now = time( &now );
if ( now - start > 3 )
break;
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
print_current_time( "Init: ", buffer );
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
print_current_time( "Init: ", buffer );
break;
}
} while ( now - start < 3 );
/* with this unlock we should be able to go to low priority */
@@ -251,26 +220,15 @@ void *POSIX_Init(
printf( "status = %d\n", status );
rtems_test_assert( !status );
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
for ( ; ; ) {
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
if ( schedparam.sched_priority == LOW_PRIORITY )
if ( get_current_prio( pthread_self() ) == LOW_PRIORITY )
break;
}
status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
rtems_test_assert( !status );
priority = schedparam.sched_priority;
sprintf( buffer, " - new priority = %d", priority );
sprintf( buffer, " - new priority = %d", get_current_prio( pthread_self() ) );
print_current_time( "Init: ", buffer );
TEST_END();

View File

@@ -1,22 +1,20 @@
*** POSIX TEST 9 ***
*** BEGIN OF TEST PSX 9 ***
Init's ID is 0x0b010001
Init: pthread_getschedparam - SUCCESSFUL
Init: Fri May 24 11:05:00 1996 - current priority = 2
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
Init: Fri May 24 11:05:00 1996 - new priority = 254
Init: Fri May 24 11:05:00 1996 - new priority = 252
Init: Fri May 24 11:05:00 1996 - new priority = 254
Init: Fri May 24 11:05:00 1996 - new priority = 252
Init: Fri May 24 11:05:01 1996 - new priority = 254
Init: Fri May 24 11:05:00 1996 - new priority = 253
Init: Fri May 24 11:05:00 1996 - new priority = 252
Init: Fri May 24 11:05:00 1996 - new priority = 253
Init: pthread_setschedparam - SUCCESSFUL (sporadic server)
Init: Initializing mutex attributes for priority ceiling
Init: Creating a mutex
Init: Fri May 24 11:05:01 1996 - new priority = 254
Init: Fri May 24 11:05:00 1996 - new priority = 252
Init: pthread_mutex_lock acquire the lock
Init: Fri May 24 11:05:01 1996 - new priority = 254
Init: Fri May 24 11:05:01 1996 - new priority = 254
Init: unlock mutex
Init: Fri May 24 11:05:01 1996 - new priority = 254
Init: Fri May 24 11:05:01 1996 - new priority = 250
*** END OF POSIX TEST 9 ***
Init: Fri May 24 11:05:03 1996 - new priority = 253
Init: Fri May 24 11:05:03 1996 - new priority = 252
*** END OF TEST PSX 9 **

View File

@@ -44,16 +44,25 @@ typedef struct {
static test_context test_instance;
static int get_current_prio( pthread_t thread )
{
rtems_status_code sc;
rtems_task_priority prio;
int max;
sc = rtems_task_set_priority( thread, RTEMS_CURRENT_PRIORITY, &prio );
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
max = sched_get_priority_max( SCHED_FIFO );
return max + 1 - (int) prio;
}
static void wait_for_prio( int prio )
{
int status;
int policy;
struct sched_param param;
do {
status = pthread_getschedparam( pthread_self(), &policy, &param );
rtems_test_assert( status == 0 );
} while ( prio != param.sched_priority );
while ( prio != get_current_prio( pthread_self() ) ) {
/* Wait */
}
}
static uint64_t timeval_to_us( const struct timeval *tv )