VxWorks Reference Manual : Libraries
schedPxLib - scheduling library (POSIX)
sched_setparam( ) - set a task's priority (POSIX)
sched_getparam( ) - get the scheduling parameters for a specified task (POSIX)
sched_setscheduler( ) - set scheduling policy and scheduling parameters (POSIX)
sched_getscheduler( ) - get the current scheduling policy (POSIX)
sched_yield( ) - relinquish the CPU (POSIX)
sched_get_priority_max( ) - get the maximum priority (POSIX)
sched_get_priority_min( ) - get the minimum priority (POSIX)
sched_rr_get_interval( ) - get the current time slice (POSIX)
This library provides POSIX-compliance scheduling routines. The routines in this library allow the user to get and set priorities and scheduling schemes, get maximum and minimum priority values, and get the time slice if round-robin scheduling is enabled.
The POSIX standard specifies a priority numbering scheme in which higher priorities are indicated by larger numbers. The VxWorks native numbering scheme is the reverse of this, with higher priorities indicated by smaller numbers. For example, in the VxWorks native priority numbering scheme, the highest priority task has a priority of 0.
In VxWorks, POSIX scheduling interfaces are implemented using the POSIX priority numbering scheme. This means that the priority numbers used by this library do not match those reported and used in all the other VxWorks components. It is possible to change the priority numbering scheme used by this library by setting the global variable posixPriorityNumbering. If this variable is set to FALSE, the VxWorks native numbering scheme (small number = high priority) is used, and priority numbers used by this library will match those used by the other portions of VxWorks.
The routines in this library are compliant with POSIX 1003.1b. In particular, task priorities are set and reported through the structure sched_setparam, which has a single member:
struct sched_param /* Scheduling parameter structure */ { int sched_priority; /* scheduling priority */ };POSIX 1003.1b specifies this indirection to permit future extensions through the same calling interface. For example, because sched_setparam( ) takes this structure as an argument (rather than using the priority value directly) its type signature need not change if future schedulers require other parameters.
sched.h
schedPxLib, POSIX 1003.1b document, taskLib
sched_setparam( ) - set a task's priority (POSIX)
int sched_setparam ( pid_t tid, /* task ID */ const struct sched_param * param /* scheduling parameter */ )
This routine sets the priority of a specified task, tid. If tid is 0, it sets the priority of the calling task. Valid priority numbers are 0 through 255.
The param argument is a structure whose member sched_priority is the integer priority value. For example, the following program fragment sets the calling task's priority to 13 using POSIX interfaces:
#include "sched.h" ... struct sched_param AppSchedPrio; ... AppSchedPrio.sched_priority = 13; if ( sched_setparam (0, &AppSchedPrio) != OK ) { ... /* recovery attempt or abort message */ } ...
If the global variable posixPriorityNumbering is FALSE, the VxWorks native priority numbering scheme is used, in which higher priorities are indicated by smaller numbers. This is different than the priority numbering scheme specified by POSIX, in which higher priorities are indicated by larger numbers.
0 (OK) if successful, or -1 (ERROR) on error.
EINVAL
- scheduling priority is outside valid range.
ESRCH
- task ID is invalid.
sched_getparam( ) - get the scheduling parameters for a specified task (POSIX)
int sched_getparam ( pid_t tid, /* task ID */ struct sched_param * param /* scheduling param to store priority */ )
This routine gets the scheduling priority for a specified task, tid. If tid is 0, it gets the priority of the calling task. The task's priority is copied to the sched_param structure pointed to by param.
If the global variable posixPriorityNumbering is FALSE, the VxWorks native priority numbering scheme is used, in which higher priorities are indicated by smaller numbers. This is different than the priority numbering scheme specified by POSIX, in which higher priorities are indicated by larger numbers.
0 (OK) if successful, or -1 (ERROR) on error.
ESRCH
- invalid task ID.
sched_setscheduler( ) - set scheduling policy and scheduling parameters (POSIX)
int sched_setscheduler ( pid_t tid, /* task ID */ int policy, /* scheduling policy requested */ const struct sched_param * param /* scheduling parameters requested */ )
This routine sets the scheduling policy and scheduling parameters for a specified task, tid. If tid is 0, it sets the scheduling policy and scheduling parameters for the calling task.
Because VxWorks does not set scheduling policies (e.g., round-robin scheduling) on a task-by-task basis, setting a scheduling policy that conflicts with the current system policy simply fails and errno is set to EINVAL. If the requested scheduling policy is the same as the current system policy, then this routine acts just like sched_setparam( ).
If the global variable posixPriorityNumbering is FALSE, the VxWorks native priority numbering scheme is used, in which higher priorities are indicated by smaller numbers. This is different than the priority numbering scheme specified by POSIX, in which higher priorities are indicated by larger numbers.
The previous scheduling policy (SCHED_FIFO or SCHED_RR), or -1 (ERROR) on error.
EINVAL
- scheduling priority is outside valid range, or it is impossible to set
the specified scheduling policy.
ESRCH
- invalid task ID.
sched_getscheduler( ) - get the current scheduling policy (POSIX)
int sched_getscheduler ( pid_t tid /* task ID */ )
This routine returns the currents scheduling policy (i.e., SCHED_FIFO or SCHED_RR).
Current scheduling policy (SCHED_FIFO or SCHED_RR), or -1 (ERROR) on error.
ESRCH
- invalid task ID.
sched_yield( ) - relinquish the CPU (POSIX)
int sched_yield (void)
This routine forces the running task to give up the CPU.
0 (OK) if successful, or -1 (ERROR) on error.
sched_get_priority_max( ) - get the maximum priority (POSIX)
int sched_get_priority_max ( int policy /* scheduling policy */ )
This routine returns the value of the highest possible task priority for a specified scheduling policy (SCHED_FIFO or SCHED_RR).
If the global variable posixPriorityNumbering is FALSE, the VxWorks native priority numbering scheme is used, in which higher priorities are indicated by smaller numbers. This is different than the priority numbering scheme specified by POSIX, in which higher priorities are indicated by larger numbers.
Maximum priority value, or -1 (ERROR) on error.
EINVAL
- invalid scheduling policy.
sched_get_priority_min( ) - get the minimum priority (POSIX)
int sched_get_priority_min ( int policy /* scheduling policy */ )
This routine returns the value of the lowest possible task priority for a specified scheduling policy (SCHED_FIFO or SCHED_RR).
If the global variable posixPriorityNumbering is FALSE, the VxWorks native priority numbering scheme is used, in which higher priorities are indicated by smaller numbers. This is different than the priority numbering scheme specified by POSIX, in which higher priorities are indicated by larger numbers.
Minimum priority value, or -1 (ERROR) on error.
EINVAL
- invalid scheduling policy.
sched_rr_get_interval( ) - get the current time slice (POSIX)
int sched_rr_get_interval ( pid_t tid, /* task ID */ struct timespec * interval /* struct to store time slice */ )
This routine sets interval to the current time slice period if round-robin scheduling is currently enabled.
0 (OK) if successful, -1 (ERROR) on error.
EINVAL
- round-robin scheduling is not currently enabled.
ESRCH
- invalid task ID.