mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 14:18:20 +00:00
added interpretation of scheduling policy and parameter information to
pthread_create initial implementation of get/set id routines better argument checking on scheduler functions.
This commit is contained in:
@@ -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 */
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/object.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user