VxWorks Reference Manual : Libraries

schedPxLib

NAME

schedPxLib - scheduling library (POSIX)

ROUTINES

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)

DESCRIPTION

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.

INCLUDE FILES

sched.h

SEE ALSO

schedPxLib, POSIX 1003.1b document, taskLib


Libraries : Routines

sched_setparam( )

NAME

sched_setparam( ) - set a task's priority (POSIX)

SYNOPSIS

int sched_setparam
    (
    pid_t                      tid,  /* task ID */
    const struct sched_param * param /* scheduling parameter */
    )

DESCRIPTION

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 */
    }
 ...

NOTE

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.

RETURNS

0 (OK) if successful, or -1 (ERROR) on error.

ERRNO

 EINVAL
    - scheduling priority is outside valid range.
 ESRCH
    - task ID is invalid.

SEE ALSO

schedPxLib


Libraries : Routines

sched_getparam( )

NAME

sched_getparam( ) - get the scheduling parameters for a specified task (POSIX)

SYNOPSIS

int sched_getparam
    (
    pid_t                tid,  /* task ID */
    struct sched_param * param /* scheduling param to store priority */
    )

DESCRIPTION

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.

NOTE

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.

RETURNS

0 (OK) if successful, or -1 (ERROR) on error.

ERRNO

 ESRCH
    - invalid task ID.

SEE ALSO

schedPxLib


Libraries : Routines

sched_setscheduler( )

NAME

sched_setscheduler( ) - set scheduling policy and scheduling parameters (POSIX)

SYNOPSIS

int sched_setscheduler
    (
    pid_t                      tid,    /* task ID */
    int                        policy, /* scheduling policy requested */
    const struct sched_param * param   /* scheduling parameters requested */
    )

DESCRIPTION

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( ).

NOTE

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.

RETURNS

The previous scheduling policy (SCHED_FIFO or SCHED_RR), or -1 (ERROR) on error.

ERRNO

 EINVAL
    - scheduling priority is outside valid range, or it is impossible to set
      the specified scheduling policy.
 ESRCH
    - invalid task ID.

SEE ALSO

schedPxLib


Libraries : Routines

sched_getscheduler( )

NAME

sched_getscheduler( ) - get the current scheduling policy (POSIX)

SYNOPSIS

int sched_getscheduler
    (
    pid_t tid /* task ID */
    )

DESCRIPTION

This routine returns the currents scheduling policy (i.e., SCHED_FIFO or SCHED_RR).

RETURNS

Current scheduling policy (SCHED_FIFO or SCHED_RR), or -1 (ERROR) on error.

ERRNO

 ESRCH
    - invalid task ID.

SEE ALSO

schedPxLib


Libraries : Routines

sched_yield( )

NAME

sched_yield( ) - relinquish the CPU (POSIX)

SYNOPSIS


int sched_yield (void)

DESCRIPTION

This routine forces the running task to give up the CPU.

RETURNS

0 (OK) if successful, or -1 (ERROR) on error.

SEE ALSO

schedPxLib


Libraries : Routines

sched_get_priority_max( )

NAME

sched_get_priority_max( ) - get the maximum priority (POSIX)

SYNOPSIS

int sched_get_priority_max
    (
    int policy /* scheduling policy */
    )

DESCRIPTION

This routine returns the value of the highest possible task priority for a specified scheduling policy (SCHED_FIFO or SCHED_RR).

NOTE

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.

RETURNS

Maximum priority value, or -1 (ERROR) on error.

ERRNO

 EINVAL
    - invalid scheduling policy.

SEE ALSO

schedPxLib


Libraries : Routines

sched_get_priority_min( )

NAME

sched_get_priority_min( ) - get the minimum priority (POSIX)

SYNOPSIS

int sched_get_priority_min
    (
    int policy /* scheduling policy */
    )

DESCRIPTION

This routine returns the value of the lowest possible task priority for a specified scheduling policy (SCHED_FIFO or SCHED_RR).

NOTE

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.

RETURNS

Minimum priority value, or -1 (ERROR) on error.

ERRNO

 EINVAL
    - invalid scheduling policy.

SEE ALSO

schedPxLib


Libraries : Routines

sched_rr_get_interval( )

NAME

sched_rr_get_interval( ) - get the current time slice (POSIX)

SYNOPSIS

int sched_rr_get_interval
    (
    pid_t             tid,     /* task ID */
    struct timespec * interval /* struct to store time slice */
    )

DESCRIPTION

This routine sets interval to the current time slice period if round-robin scheduling is currently enabled.

RETURNS

0 (OK) if successful, -1 (ERROR) on error.

ERRNO

 EINVAL
    - round-robin scheduling is not currently enabled.
 ESRCH
    - invalid task ID.

SEE ALSO

schedPxLib