sched_setscheduler(2) DG/UX 5.4.2 sched_setscheduler(2)
NAME
sched_setscheduler - set the scheduling policy and priority for a
process
SYNOPSIS
#include <sched.h>
int schedsetscheduler (pid, policy, *priority)
pidt pid;
int policy;
struct schedparam *priority;
DESCRIPTION
Use schedsetscheduler(2) to set a process's scheduling policy and
priority:
pid is the process id.
policy may be one of the following:
SCHED_DG_TS The default DG/UX timesharing policy (same as
SCHED_OTHER described in POSIX specifica
tions)
SCHED_FIFO First-in-first-out restricted fixed priority
SCHED_RR Round robin restricted fixed priority with a
timeslice
SCHED_DG_FIFO FIFO unrestricted fixed priority
See "Scheduling Policies" below for descriptions.
priority points to a structure containing the scheduling priority.
The POSIX-specified structure that priority points to is:
struct schedparam
{
int schedpriority;
};
If pid is 0, this call sets the scheduling policy and priority of the
calling process.
Only the superuser can change the scheduling policy, or set a prior
ity that is higher than the current priority. A priority that is
lower than or equal to the current priority may be set either by the
superuser or by a process having an effective user id matching that
of pid.
The larger the number in schedpriority, the higher the priority.
The number must be within the range for policy returned by
schedgetprioritymin(2) and schedgetprioritymax(2).
Licensed material--property of copyright holder(s) 1
sched_setscheduler(2) DG/UX 5.4.2 sched_setscheduler(2)
If this call fails, the policy and priority of pid are not changed.
The scheduling policy and priority are inherited on a fork(2).
Scheduling Priorities
The system schedules a process based on its effective priority. You
can get the effective priority of a process with ps(1) or
dgprocessinfo(2). You can get the priority of a process that was
set by this system call or by schedsetparam(2) with
schedgetparam(2).
The effective priority used by the system for scheduling is not iden
tical to the priority set by this system call. One difference is that
the numerical representations for priority are reversed. In the
scheme used internally by the system for effective priorities, a low
number represents a high priority and vice versa. In the POSIX-
designated scheme used by the scheduling system calls for priority, a
high number represents a high priority and vice versa. Thus, if you
assign a high number (i.e., high priority) to a process with this
system call and then view the process's effective priority with ps(1)
or dgprocessinfo(2), the process will have a low number (i.e., high
priority).
A second difference between effective priority and priority applies
to timesharing (SCHED_DG_TS) processes only. For a timesharing pro
cess, the system determines its effective priority dynamically as
explained below.
Scheduling Policies
The SCHED_DG_TS policy provides fair scheduling for timesharing pro
cesses. The miminum and maximum priorities available to the
SCHED_DG_TS class assure that a process created in this class will
have a lower priority than any realtime (SCHED_FIFO or SCHED_RR) pro
cess or DG/UX kernel system process. Unless specifically changed by
this call, the shell (sh or csh) belongs to the SCHED_DG_TS class.
The system dynamically calculates the effective priorities of time
sharing processes to enforce fairness. For example, the system may
decrease the effective priority of a SCHED_DG_TS process that is con
suming too much of the JP resources, or increase the effective prior
ity of a SCHED_DG_TS process that is not making sufficient progress.
The calculation is influenced by three factors:
* The priority, which may be set by this system call or by
schedsetparam(2)
* The nice level, which may be set by nice(1) or nice(2)
* The interactive level
Determined by the system, the interactive level of a process is the
ratio of its wait-time to its run-time. The higher this ratio, the
greater the interactive level. Thus, a process that continually
blocks waiting for terminal I/O is more interactive than a compute-
Licensed material--property of copyright holder(s) 2
sched_setscheduler(2) DG/UX 5.4.2 sched_setscheduler(2)
bound process.
The system assigns a higher effective priority but a smaller time
slice to a highly interactive process. The higher priority improves
the response time of the process, while the smaller time slice pre
vents the improvement from coming at the expense of competing pro
cesses. This combination works well for interactive processes
because they typically are ready to give up a JP after running for
only a short period of time.
Conversely, the system assigns a lower effective priority but a
larger time slice to a less interactive process. This combination
works well for less interactive processes because they tend to occupy
the JP for a longer period of time, usually until removed by preemp
tion.
POSIX specifies a vendor-defined policy named SCHED_OTHER. In the
DG/UX implementation, SCHED_OTHER is identical to SCHED_DG_TS.
The POSIX-specified SCHED_FIFO class provides fixed priority schedul
ing for realtime processes. The minimum and maximum priorities
available to this class assure that a process in the class will have
a higher priority than any timesharing (SCHED_DG_TS) process, but
will have a lower priority than any DG/UX kernel system process.
A SCHED_FIFO process:
* Has an infinitely long time slice. Once it starts executing on a
JP, it stays on the JP until it completes, is preempted by a
higher-priority process, is blocked by an action that it takes, or
voluntarily gives up the JP.
* When it completes, is blocked, or voluntarily gives up the JP, the
JP goes to the eligible process with the highest priority.
* If preempted, is added to the eligible list ahead of processes of
equal or lower priority.
* If blocked, is added to the eligible list behind processes of
greater or equal priority.
* If it voluntarily gives up the JP with a schedyield(2) call, is
placed in the eligible list behind processes of greater or equal
priority.
* If it changes its priority, is placed in the eligible list behind
processes of greater or equal priority. This is true even if the
process changes its priority to its current priority.
* Never has its priority changed by the system. Its priority is not
affected by its nice(2) value. However, if the nice(2) value is
changed, the new value will apply should the process change into
the timesharing (SCHED_DG_TS) scheduling class.
Licensed material--property of copyright holder(s) 3
sched_setscheduler(2) DG/UX 5.4.2 sched_setscheduler(2)
The POSIX-specified SCHED_RR (round robin) policy is identical to the
SCHED_FIFO policy except that a SCHED_RR process:
* Has a specific time slice, returned by schedrrgetinterval(2).
When a SCHED_RR process has been executing for this interval (or
longer), it gives up the JP and is added to the eligible list
behind processes of higher or equal priority.
* Upon completing its execution interval, or if blocked, is given a
new full execution interval the next time it executes.
* If preempted, is given the remainder of its previous execution
interval the next time it executes.
The SCHED_RR time slice is the value of the system variable MAXSLICE.
This value, 500 ms by default, may be changed during system configu
ration.
The SCHED_DG_FIFO class provides fixed-priority FIFO scheduling for
users whose needs are not met by the SCHED_FIFO policy. The priori
ties available to the SCHED_DG_FIFO class include the entire range of
priorities available on the system. This range includes priorities
higher than DG/UX kernel system processes and lower than timesharing
(SCHED_DG_TS) processes. Except for this unrestricted priority range,
the SCHED_DG_FIFO policy is identical to the SCHED_FIFO policy.
The SCHED_FIFO policy is sufficient for most realtime applications
and, where so, is preferable to SCHED_DG_FIFO. Use SCHED_DG_FIFO
rather than SCHED_FIFO for a realtime process that:
* Requires the best priority in the system regardless of any poten
tial consequences resulting from interference with the DG/UX ker
nel system processes.
* Needs a priority low enough to force it to compete with timeshar
ing processes.
Caution: incorrect use of SCHED_DG_FIFO may result in severe perfor
mance degradation, including the appearance of a system hang.
Note
* This routine is based on POSIX realtime extension document P1003.4
draft 12. It is therefore subject to change.
* Compilation of a source file using this routine requires that fea
ture macro _POSIX4_DRAFT_SOURCE be defined. This feature macro is
not enabled by any other feature macro, nor does it enable any
other feature macro.
* The compiled routine must be linked to library librte.a.
RETURN VALUE
If successful, schedsetscheduler returns the previous scheduling
Licensed material--property of copyright holder(s) 4
sched_setscheduler(2) DG/UX 5.4.2 sched_setscheduler(2)
policy of pid. If unsuccessful, the routine returns -1 and sets ERRNO
to one of the following:
EFAULT The address of priority is bad.
EINVAL The value of policy is invalid, or the value in
schedpriority is outside the range defined for policy.
EPERM The caller does not have permission to set the scheduling
parameters for pid.
ESRCH Process pid doesn't exist or is negative.
SEE ALSO
dgprocessinfo(2), nice(1), nice(2), ps(1), schedgetscheduler(2),
schedsetparam(2), schedgetparam(2), schedyield(2),
schedgetprioritymax(2), schedgetprioritymin(2),
schedrrgetinterval(2).
Licensed material--property of copyright holder(s) 5