From c48e0ee2b8fd565f8bcb45074a3d33cb7ec1428f Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 4 Jun 1996 16:15:59 +0000 Subject: added interpretation of scheduling policy and parameter information to pthread_create initial implementation of get/set id routines better argument checking on scheduler functions. --- c/src/exec/posix/src/pthread.c | 35 ++++++++++++++++++++++++----- c/src/exec/posix/src/sched.c | 40 ++++++++++++++++++++++++--------- c/src/exec/posix/src/types.c | 51 +++++++++++++++++++++++++++++++----------- 3 files changed, 98 insertions(+), 28 deletions(-) (limited to 'c/src/exec/posix/src') diff --git a/c/src/exec/posix/src/pthread.c b/c/src/exec/posix/src/pthread.c index 3ce80144d7..c855ae9c2a 100644 --- a/c/src/exec/posix/src/pthread.c +++ b/c/src/exec/posix/src/pthread.c @@ -582,11 +582,14 @@ int pthread_create( { const pthread_attr_t *attrp; Priority_Control core_priority; + boolean is_timesliced; boolean is_fp; boolean status; Thread_Control *the_thread; char *default_name = "psx"; POSIX_API_Control *api; + int schedpolicy = SCHED_RR; + struct sched_param schedparams; attrp = (attr) ? attr : &_POSIX_Threads_Default_attributes; @@ -600,14 +603,12 @@ int pthread_create( #if 0 int contentionscope; - int inheritsched; int schedpolicy; struct sched_param schedparam; #if defined(_POSIX_THREAD_CPUTIME) int cputime_clock_allowed; /* see time.h */ #endif - int detachstate; #endif /* @@ -621,20 +622,44 @@ int pthread_create( switch ( attrp->inheritsched ) { case PTHREAD_INHERIT_SCHED: + api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + schedpolicy = api->schedpolicy; + schedparams = api->Schedule; break; case PTHREAD_EXPLICIT_SCHED: + schedpolicy = attrp->schedpolicy; + schedparams = attrp->schedparam; break; } /* - * Validate the RTEMS API priority and convert it to the core priority range. + * Interpret the scheduling parameters. */ - + + is_timesliced = FALSE; + if ( !_POSIX_Priority_Is_valid( attrp->schedparam.sched_priority ) ) return EINVAL; core_priority = _POSIX_Priority_To_core( attrp->schedparam.sched_priority ); + switch ( schedpolicy ) { + case SCHED_OTHER: + case SCHED_FIFO: + break; + case SCHED_RR: + is_timesliced = TRUE; + break; + case SCHED_SPORADIC: + /* XXX interpret the following parameters */ +#if 0 + ss_low_priority; /* Low scheduling priority for sporadic */ + ss_replenish_period; /* Replenishment period for sporadic server */ + ss_initial_budget; /* Initial budget for sporadic server */ +#endif + break; + } + /* * Currently all POSIX threads are floating point if the hardware * supports it. @@ -673,7 +698,7 @@ int pthread_create( is_fp, core_priority, TRUE, /* preemptible */ - TRUE, /* timesliced */ + is_timesliced, /* timesliced */ 0, /* isr level */ &default_name /* posix threads don't have a name */ ); diff --git a/c/src/exec/posix/src/sched.c b/c/src/exec/posix/src/sched.c index 1a9a9fe38b..2cee1fc07d 100644 --- a/c/src/exec/posix/src/sched.c +++ b/c/src/exec/posix/src/sched.c @@ -85,7 +85,18 @@ int sched_get_priority_max( int policy ) { - /* XXX error check the policy */ + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + case SCHED_SPORADIC: + break; + + default: + errno = EINVAL; + return -1; + } + return POSIX_SCHEDULER_MAXIMUM_PRIORITY; } @@ -98,7 +109,18 @@ int sched_get_priority_min( int policy ) { - /* XXX error check the policy */ + switch ( policy ) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + case SCHED_SPORADIC: + break; + + default: + errno = EINVAL; + return -1; + } + return POSIX_SCHEDULER_MINIMUM_PRIORITY; } @@ -114,18 +136,16 @@ int sched_rr_get_interval( { time_t us_per_quantum; - /* XXX eventually should support different time quantums per thread */ + /* XXX do we need to support different time quantums per thread */ - /* XXX should get for errors? (bad pid) */ + /* + * Only supported for the "calling process" (i.e. this node). + */ - /* XXX some of the time routines also convert usecs to a timespec -- */ - /* XXX should this be a common routine? */ + assert( pid == getpid() ); - us_per_quantum = _TOD_Microseconds_per_tick * _Thread_Ticks_per_timeslice; - interval->tv_sec = us_per_quantum / TOD_MICROSECONDS_PER_SECOND; - interval->tv_nsec = (us_per_quantum % TOD_MICROSECONDS_PER_SECOND) * - TOD_NANOSECONDS_PER_MICROSECOND; + _POSIX_Interval_to_timespec( _Thread_Ticks_per_timeslice, interval ); return 0; } diff --git a/c/src/exec/posix/src/types.c b/c/src/exec/posix/src/types.c index c1e1c8c708..17c83c4641 100644 --- a/c/src/exec/posix/src/types.c +++ b/c/src/exec/posix/src/types.c @@ -2,11 +2,20 @@ * $Id$ */ +#include +#include +#include #include #include #include +pid_t _POSIX_types_Ppid = 0; +uid_t _POSIX_types_Uid = 0; +uid_t _POSIX_types_Euid = 0; +gid_t _POSIX_types_Gid = 0; +gid_t _POSIX_types_Egid = 0; + /*PAGE * * 4.1.1 Get Process and Parent Process IDs, P1003.1b-1993, p. 83 @@ -24,7 +33,7 @@ pid_t getpid( void ) pid_t getppid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _POSIX_types_Ppid; } /*PAGE @@ -35,7 +44,7 @@ pid_t getppid( void ) uid_t getuid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _POSIX_types_Uid; } /*PAGE @@ -46,7 +55,7 @@ uid_t getuid( void ) uid_t geteuid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _POSIX_types_Euid; } /*PAGE @@ -57,7 +66,7 @@ uid_t geteuid( void ) gid_t getgid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _POSIX_types_Gid; } /*PAGE @@ -68,7 +77,7 @@ gid_t getgid( void ) gid_t getegid( void ) { - return POSIX_NOT_IMPLEMENTED(); + return _POSIX_types_Egid; } /*PAGE @@ -80,7 +89,8 @@ int setuid( uid_t uid ) { - return POSIX_NOT_IMPLEMENTED(); + _POSIX_types_Uid = uid; + return 0; } /*PAGE @@ -92,7 +102,8 @@ int setgid( gid_t gid ) { - return POSIX_NOT_IMPLEMENTED(); + _POSIX_types_Gid = gid; + return 0; } /*PAGE @@ -105,7 +116,7 @@ int getgroups( gid_t grouplist[] ) { - return POSIX_NOT_IMPLEMENTED(); + return 0; /* no supplemental group ids */ } /*PAGE @@ -115,9 +126,12 @@ int getgroups( * NOTE: P1003.1c/D10, p. 49 adds getlogin_r(). */ +static char _POSIX_types_Getlogin_buffer[ LOGIN_NAME_MAX ]; + char *getlogin( void ) { - return (char *) POSIX_NOT_IMPLEMENTED(); + (void) getlogin_r( _POSIX_types_Getlogin_buffer, LOGIN_NAME_MAX ); + return _POSIX_types_Getlogin_buffer; } /*PAGE @@ -132,7 +146,11 @@ int getlogin_r( size_t namesize ) { - return POSIX_NOT_IMPLEMENTED(); + if ( namesize < LOGIN_NAME_MAX ) + return ERANGE; + + strcpy( name, "posixapp" ); + return 0; } /*PAGE @@ -142,7 +160,12 @@ int getlogin_r( pid_t getpgrp( void ) { - return POSIX_NOT_IMPLEMENTED(); + /* + * This always succeeds and returns the process group id. For rtems, + * this will always be the local node; + */ + + return _Objects_Local_node; } /*PAGE @@ -152,7 +175,8 @@ pid_t getpgrp( void ) pid_t setsid( void ) { - return POSIX_NOT_IMPLEMENTED(); + errno = ENOSYS; + return -1; } /*PAGE @@ -165,7 +189,8 @@ int setpgid( pid_t pgid ) { - return POSIX_NOT_IMPLEMENTED(); + errno = ENOSYS; + return -1; } /* -- cgit v1.2.3