Files
rtems/cpukit/posix/src/pthreadsetschedparam.c
Joel Sherrill 412dbff629 2007-04-05 Joel Sherrill <joel@OARcorp.com>
* posix/Makefile.am, posix/include/rtems/posix/time.h,
	posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c,
	posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c,
	posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c,
	posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c,
	posix/src/pthread.c, posix/src/pthreadcreate.c,
	posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c,
	posix/src/sched.c, posix/src/semtimedwait.c,
	posix/src/sigtimedwait.c, posix/src/ualarm.c,
	rtems/src/clocktodtoseconds.c, score/Makefile.am,
	score/preinstall.am, score/include/rtems/score/tod.h,
	score/inline/rtems/score/tod.inl, score/src/coretod.c,
	score/src/coretodget.c, score/src/coretodgetuptime.c,
	score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec
	manipulation routines in the SuperCore. Use them everywhere possible.
	This lead to significant cleanup in the API routines and eliminated
	some of the same code from the POSIX API. At this point, the
	SuperCore keeps time in POSIX timespec format properly from 1970. You
	just cannot set it before 1988 in keeping with RTEMS traditional
	behavior.
	* score/include/rtems/score/timespec.h, score/src/timespecaddto.c,
	score/src/timespecfromticks.c, score/src/timespecisvalid.c,
	score/src/timespeclessthan.c, score/src/timespecsubtract.c,
	score/src/timespectoticks.c: New files.
	* posix/src/posixintervaltotimespec.c,
	posix/src/posixtimespecsubtract.c,
	posix/src/posixtimespectointerval.c: Removed.
2007-04-05 21:17:27 +00:00

131 lines
3.2 KiB
C

/*
* 13.5.2 Dynamic Thread Scheduling Parameters Access,
* P1003.1c/Draft 10, p. 124
*/
/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <pthread.h>
#include <errno.h>
#include <rtems/system.h>
#include <rtems/posix/pthread.h>
#include <rtems/posix/priority.h>
#include <rtems/posix/time.h>
int pthread_setschedparam(
pthread_t thread,
int policy,
struct sched_param *param
)
{
register Thread_Control *the_thread;
POSIX_API_Control *api;
Thread_CPU_budget_algorithms budget_algorithm;
Thread_CPU_budget_algorithm_callout budget_callout;
Objects_Locations location;
/*
* Check all the parameters
*/
if ( !param )
return EINVAL;
if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
return EINVAL;
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
budget_callout = NULL;
switch ( policy ) {
case SCHED_OTHER:
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
break;
case SCHED_FIFO:
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
break;
case SCHED_RR:
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
break;
case SCHED_SPORADIC:
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
budget_callout = _POSIX_Threads_Sporadic_budget_callout;
if ( _Timespec_To_ticks( &param->ss_replenish_period ) <
_Timespec_To_ticks( &param->ss_initial_budget ) )
return EINVAL;
if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
return EINVAL;
break;
default:
return EINVAL;
}
/*
* Actually change the scheduling policy and parameters
*/
the_thread = _POSIX_Threads_Get( thread, &location );
switch ( location ) {
case OBJECTS_ERROR:
case OBJECTS_REMOTE:
return ESRCH;
case OBJECTS_LOCAL:
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
if ( api->schedpolicy == SCHED_SPORADIC )
(void) _Watchdog_Remove( &api->Sporadic_timer );
api->schedpolicy = policy;
api->schedparam = *param;
the_thread->budget_algorithm = budget_algorithm;
the_thread->budget_callout = budget_callout;
switch ( api->schedpolicy ) {
case SCHED_OTHER:
case SCHED_FIFO:
case SCHED_RR:
the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
the_thread->real_priority =
_POSIX_Priority_To_core( api->schedparam.sched_priority );
_Thread_Change_priority(
the_thread,
the_thread->real_priority,
TRUE
);
break;
case SCHED_SPORADIC:
api->ss_high_priority = api->schedparam.sched_priority;
_Watchdog_Remove( &api->Sporadic_timer );
_POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
break;
}
_Thread_Enable_dispatch();
return 0;
}
return POSIX_BOTTOM_REACHED();
}