Manual Pages for Linux CentOS command on man sched_setscheduler
MyWebUniversity

Manual Pages for Linux CentOS command on man sched_setscheduler

SCHEDSETSCHEDULER(2) Linux Programmer's Manual SCHEDSETSCHEDULER(2)

NAME

schedsetscheduler, schedgetscheduler - set and get scheduling pol‐ icy/parameters SYNOPSIS

#include int schedsetscheduler(pidt pid, int policy, const struct schedparam *param); int schedgetscheduler(pidt pid); struct schedparam { ... int schedpriority; ... }; DESCRIPTION schedsetscheduler() sets both the scheduling policy and the associated parameters for the process whose ID is specified in pid. If pid equals zero, the scheduling policy and parameters of the calling process will be set. The interpretation of the argument param depends on the selected policy. Currently, Linux supports the following "normal"

(i.e., non-real-time) scheduling policies:

SCHEDOTHER the standard round-robin time-sharing policy; SCHEDBATCH for "batch" style execution of processes; and SCHEDIDLE for running very low priority background jobs.

The following "real-time" policies are also supported, for special

time-critical applications that need precise control over the way in which runnable processes are selected for execution:

SCHEDFIFO a first-in, first-out policy; and

SCHEDRR a round-robin policy. The semantics of each of these policies are detailed below. schedgetscheduler() queries the scheduling policy currently applied to the process identified by pid. If pid equals zero, the policy of the calling process will be retrieved. Scheduling policies The scheduler is the kernel component that decides which runnable process will be executed by the CPU next. Each process has an associ‐ ated scheduling policy and a static scheduling priority, schedprior‐ ity; these are the settings that are modified by schedsetscheduler(). The scheduler makes it decisions based on knowledge of the scheduling policy and static priority of all processes on the system. For processes scheduled under one of the normal scheduling policies (SCHEDOTHER, SCHEDIDLE, SCHEDBATCH), schedpriority is not used in scheduling decisions (it must be specified as 0).

Processes scheduled under one of the real-time policies (SCHEDFIFO, SCHEDRR) have a schedpriority value in the range 1 (low) to 99

(high). (As the numbers imply, real-time processes always have higher

priority than normal processes.) Note well: POSIX.1-2001 requires an implementation to support only a minimum 32 distinct priority levels

for the real-time policies, and some systems supply just this minimum. Portable programs should use schedgetprioritymin(2) and schedgetprioritymax(2) to find the range of priorities supported for a particular policy. Conceptually, the scheduler maintains a list of runnable processes for each possible schedpriority value. In order to determine which process runs next, the scheduler looks for the nonempty list with the highest static priority and selects the process at the head of this list. A process's scheduling policy determines where it will be inserted into the list of processes with equal static priority and how it will move inside this list. All scheduling is preemptive: if a process with a higher static prior‐ ity becomes ready to run, the currently running process will be pre‐ empted and returned to the wait list for its static priority level. The scheduling policy determines the ordering only within the list of runnable processes with equal static priority.

SCHEDFIFO: First in-first out scheduling SCHEDFIFO can be used only with static priorities higher than 0, which means that when a SCHEDFIFO processes becomes runnable, it will always immediately preempt any currently running SCHEDOTHER, SCHEDBATCH, or SCHEDIDLE process. SCHEDFIFO is a simple scheduling algorithm with‐ out time slicing. For processes scheduled under the SCHEDFIFO policy, the following rules apply: * A SCHEDFIFO process that has been preempted by another process of higher priority will stay at the head of the list for its priority and will resume execution as soon as all processes of higher prior‐ ity are blocked again. * When a SCHEDFIFO process becomes runnable, it will be inserted at the end of the list for its priority. * A call to schedsetscheduler() or schedsetparam(2) will put the SCHEDFIFO (or SCHEDRR) process identified by pid at the start of the list if it was runnable. As a consequence, it may preempt the currently running process if it has the same priority.

(POSIX.1-2001 specifies that the process should go to the end of the list.) * A process calling schedyield(2) will be put at the end of the list. No other events will move a process scheduled under the SCHEDFIFO pol‐ icy in the wait list of runnable processes with equal static priority. A SCHEDFIFO process runs until either it is blocked by an I/O request, it is preempted by a higher priority process, or it calls schedyield(2).

SCHEDRR: Round-robin scheduling SCHEDRR is a simple enhancement of SCHEDFIFO. Everything described above for SCHEDFIFO also applies to SCHEDRR, except that each process is allowed to run only for a maximum time quantum. If a SCHEDRR process has been running for a time period equal to or longer than the time quantum, it will be put at the end of the list for its priority. A SCHEDRR process that has been preempted by a higher priority process and subsequently resumes execution as a running process will complete

the unexpired portion of its round-robin time quantum. The length of the time quantum can be retrieved using schedrrgetinterval(2).

SCHEDOTHER: Default Linux time-sharing scheduling SCHEDOTHER can be used at only static priority 0. SCHEDOTHER is the

standard Linux time-sharing scheduler that is intended for all pro‐

cesses that do not require the special real-time mechanisms. The process to run is chosen from the static priority 0 list based on a dynamic priority that is determined only inside this list. The dynamic priority is based on the nice value (set by nice(2) or setpriority(2)) and increased for each time quantum the process is ready to run, but denied to run by the scheduler. This ensures fair progress among all SCHEDOTHER processes. SCHEDBATCH: Scheduling batch processes (Since Linux 2.6.16.) SCHEDBATCH can be used only at static priority 0. This policy is similar to SCHEDOTHER in that it schedules the process according to its dynamic priority (based on the nice value). The difference is that this policy will cause the scheduler to always

assume that the process is CPU-intensive. Consequently, the scheduler will apply a small scheduling penalty with respect to wakeup behaviour, so that this process is mildly disfavored in scheduling decisions. This policy is useful for workloads that are noninteractive, but do not want to lower their nice value, and for workloads that want a determin‐ istic scheduling policy without interactivity causing extra preemptions (between the workload's tasks). SCHEDIDLE: Scheduling very low priority jobs (Since Linux 2.6.23.) SCHEDIDLE can be used only at static priority 0; the process nice value has no influence for this policy. This policy is intended for running jobs at extremely low priority (lower even than a +19 nice value with the SCHEDOTHER or SCHEDBATCH policies). Resetting scheduling policy for child processes Since Linux 2.6.32, the SCHEDRESETONFORK flag can be ORed in policy when calling schedsetscheduler(). As a result of including this flag, children created by fork(2) do not inherit privileged scheduling poli‐

cies. This feature is intended for media-playback applications, and can be used to prevent applications evading the RLIMITRTTIME resource limit (see getrlimit(2)) by creating multiple child processes. More precisely, if the SCHEDRESETONFORK flag is specified, the fol‐ lowing rules apply for subsequently created children: * If the calling process has a scheduling policy of SCHEDFIFO or SCHEDRR, the policy is reset to SCHEDOTHER in child processes. * If the calling process has a negative nice value, the nice value is reset to zero in child processes. After the SCHEDRESETONFORK flag has been enabled, it can be reset only if the process has the CAPSYSNICE capability. This flag is dis‐ abled in child processes created by fork(2). The SCHEDRESETONFORK flag is visible in the policy value returned by schedgetscheduler() Privileges and resource limits In Linux kernels before 2.6.12, only privileged (CAPSYSNICE) pro‐

cesses can set a nonzero static priority (i.e., set a real-time sched‐ uling policy). The only change that an unprivileged process can make is to set the SCHEDOTHER policy, and this can be done only if the effective user ID of the caller of schedsetscheduler() matches the real or effective user ID of the target process (i.e., the process specified by pid) whose policy is being changed. Since Linux 2.6.12, the RLIMITRTPRIO resource limit defines a ceiling on an unprivileged process's static priority for the SCHEDRR and SCHEDFIFO policies. The rules for changing scheduling policy and pri‐ ority are as follows: * If an unprivileged process has a nonzero RLIMITRTPRIO soft limit, then it can change its scheduling policy and priority, subject to the restriction that the priority cannot be set to a value higher than the maximum of its current priority and its RLIMITRTPRIO soft limit. * If the RLIMITRTPRIO soft limit is 0, then the only permitted

changes are to lower the priority, or to switch to a non-real-time policy. * Subject to the same rules, another unprivileged process can also make these changes, as long as the effective user ID of the process making the change matches the real or effective user ID of the tar‐ get process. * Special rules apply for the SCHEDIDLE. In Linux kernels before 2.6.39, an unprivileged process operating under this policy cannot change its policy, regardless of the value of its RLIMITRTPRIO resource limit. In Linux kernels since 2.6.39, an unprivileged process can switch to either the SCHEDBATCH or the SCHEDNORMAL policy so long as its nice value falls within the range permitted by its RLIMITNICE resource limit (see getrlimit(2)). Privileged (CAPSYSNICE) processes ignore the RLIMITRTPRIO limit; as with older kernels, they can make arbitrary changes to scheduling pol‐ icy and priority. See getrlimit(2) for further information on RLIMITRTPRIO. Response time A blocked high priority process waiting for the I/O has a certain response time before it is scheduled again. The device driver writer can greatly reduce this response time by using a "slow interrupt" interrupt handler. Miscellaneous Child processes inherit the scheduling policy and parameters across a fork(2). The scheduling policy and parameters are preserved across execve(2).

Memory locking is usually needed for real-time processes to avoid pag‐ ing delays; this can be done with mlock(2) or mlockall(2). Since a nonblocking infinite loop in a process scheduled under SCHEDFIFO or SCHEDRR will block all processes with lower priority forever, a software developer should always keep available on the con‐ sole a shell scheduled under a higher static priority than the tested

application. This will allow an emergency kill of tested real-time applications that do not block or terminate as expected. See also the description of the RLIMITRTTIME resource limit in getrlimit(2). POSIX systems on which schedsetscheduler() and schedgetscheduler() are available define POSIXPRIORITYSCHEDULING in . RETURN VALUE On success, schedsetscheduler() returns zero. On success, schedgetscheduler() returns the policy for the process (a nonnegative

integer). On error, -1 is returned, and errno is set appropriately. ERRORS EINVAL The scheduling policy is not one of the recognized policies, param is NULL, or param does not make sense for the policy. EPERM The calling process does not have appropriate privileges. ESRCH The process whose ID is pid could not be found. CONFORMING TO

POSIX.1-2001 (but see BUGS below). The SCHEDBATCH and SCHEDIDLE

policies are Linux-specific. NOTES POSIX.1 does not detail the permissions that an unprivileged process requires in order to call schedsetscheduler(), and details vary across systems. For example, the Solaris 7 manual page says that the real or effective user ID of the calling process must match the real user ID or

the save set-user-ID of the target process.

The scheduling policy and parameters are in fact per-thread attributes on Linux. The value returned from a call to gettid(2) can be passed in the argument pid. Specifying pid as 0 will operate on the attribute for the calling thread, and passing the value returned from a call to getpid(2) will operate on the attribute for the main thread of the thread group. (If you are using the POSIX threads API, then use pthreadsetschedparam(3), pthreadgetschedparam(3), and pthreadsetschedprio(3), instead of the sched*(2) system calls.)

Originally, Standard Linux was intended as a general-purpose operating system being able to handle background processes, interactive applica‐

tions, and less demanding real-time applications (applications that need to usually meet timing deadlines). Although the Linux kernel 2.6 allowed for kernel preemption and the newly introduced O(1) scheduler ensures that the time needed to schedule is fixed and deterministic

irrespective of the number of active tasks, true real-time computing was not possible up to kernel version 2.6.17.

Real-time features in the mainline Linux kernel From kernel version 2.6.18 onward, however, Linux is gradually becoming

equipped with real-time capabilities, most of which are derived from

the former realtime-preempt patches developed by Ingo Molnar, Thomas Gleixner, Steven Rostedt, and others. Until the patches have been com‐ pletely merged into the mainline kernel (this is expected to be around kernel version 2.6.30), they must be installed to achieve the best

real-time performance. These patches are named:

patch-kernelversion-rtpatchversion and can be downloaded from ⟨http://www.kernel.org/pub/linux/kernel /projects/rt/⟩. Without the patches and prior to their full inclusion into the mainline kernel, the kernel configuration offers only the three preemption classes CONFIGPREEMPTNONE, CONFIGPREEMPTVOLUNTARY, and CONFIGPRE‐ EMPTDESKTOP which respectively provide no, some, and considerable

reduction of the worst-case scheduling latency. With the patches applied or after their full inclusion into the main‐ line kernel, the additional configuration item CONFIGPREEMPTRT becomes available. If this is selected, Linux is transformed into a

regular real-time operating system. The FIFO and RR scheduling poli‐ cies that can be selected using schedsetscheduler() are then used to

run a process with true real-time priority and a minimum worst-case scheduling latency. BUGS POSIX says that on success, schedsetscheduler() should return the pre‐ vious scheduling policy. Linux schedsetscheduler() does not conform to this requirement, since it always returns 0 on success. SEE ALSO chrt(1), getpriority(2), mlock(2), mlockall(2), munlock(2), munlockall(2), nice(2), schedgetprioritymax(2), schedgetprioritymin(2), schedgetaffinity(2), schedgetparam(2), schedrrgetinterval(2), schedsetaffinity(2), schedsetparam(2), schedyield(2), setpriority(2), capabilities(7), cpuset(7)

Programming for the real world - POSIX.4 by Bill O. Gallmeister,

O'Reilly & Associates, Inc., ISBN 1-56592-074-0.

The Linux kernel source file Documentation/scheduler/sched-rt-group.txt COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2013-02-12 SCHEDSETSCHEDULER(2)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™