sched_setschedulerのヘルプ・マニュアル
日本語 英語
sched_setscheduler --help
man sched_setscheduler
SCHED_SETSCHEDULER(2) Linux Programmer’s Manual SCHED_SETSCHEDULER(2)
名前
sched_setscheduler, sched_getscheduler - スケジューリング・ポリシーとパ
ラメータを設定/取得する
書式
#include
int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param);
int sched_getscheduler(pid_t pid);
struct sched_param {
...
int sched_priority;
...
};
説明
sched_setscheduler() は pid で指定された ID を持つプロセスのスケジュ ー
リング・ポリシーやそれに関連するパラメータを設定する。pid が 0 の場合は
呼び出したプロセスのスケジューリング・ポリシーとパラメータが設定され る
。引き数 param の解釈は選択されたポリシーによる。現在のところ、Linux で
は以下に示す「通常」(リアルタイムでない) スケジューリング・ポリシーがサ
ポートされている。
SCHED_OTHER 標準の、ラウンドロビンによる時分割型のスケジューリング・
ポリシー。
SCHED_BATCH 「バッチ」形式でのプロセスの実行用。
SCHED_IDLE 「非常に」低い優先度で動作するバックグラウンド・ジョブ 用
。
ど の実行可能プロセスを選択するかについて、より正確な制御を必要とする時
間の制約が厳しい特別なアプリケーション用として、以下の「リアルタイム 」
ポリシーもサポートされている。
SCHED_FIFO ファーストイン、ファーストアウト型のポリシー。
SCHED_RR ラウンドロビン型のポリシー。
これらのポリシーのそれぞれの動作については以下で説明する。
sched_getscheduler() は pid で識別されるプロセスに現在適用されているス
ケジューリング・ポリシーを尋ねる。pid が 0 ならば、呼び出したプロセス自
身のスケジューリング・ポリシーが返される。
スケジューリング・ポリシー (scheduling policy)
ス ケジューラ (scheduler) とはカーネルの構成要素で、次に CPU で実行され
る実行可能なプロセスを決定するものである。各々のプロセスには、スケジ ュ
ー リング・ポリシーと「静的」なスケジューリング優先度 sched_priority が
対応付けられ、これらの設定は sched_setscheduler() で変更できる。スケ ジ
ュ ーラは、システム上の全プロセスのスケジューリング・ポリシーと静的優先
度に関する知識に基づいて決定を行う。
通常のスケジューリング・ポリシー (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH)
の 下でスケジューリングされるプロセスでは、 sched_priority はスケジュー
リングの決定に使用されない (sched_priority には 0 を指定しなければな ら
ない)。
リ アルタイム・スケジューリング・ポリシー (SCHED_FIFO, SCHED_RR) の下で
スケジューリングされるプロセスは、 sched_priority の値は 1 (最低) か ら
99 (最高) の範囲となる (数字から分かるように、リアルタイム・プロセスは
常に通常のプロセスよりも高い優先度を持つ)。ここで注意 す べ き な の は
、POSIX.1-2001 が要求しているのは、リアルタイム・ポリシーの実装において
最低 32 種類の異なる優先度レベルがサポートされることだけであり、いく つ
か のシステムではこの最低限の数の優先度しか提供されていない、ということ
である。移植性が必要なプログラムでは 、 sched_get_priority_min(2) と
sched_get_priority_max(2) を使って、あるポリシーがサポートする優先度の
範囲を調べるべきである。
概念としては、スケジューラはその sched_priority の値それぞれに対して 実
行 可能なプロセスのリストを管理している。どのプロセスを次に実行するかを
決定するために、スケジューラは静的優先度の最も高い空でないリストを探 し
て、そのリストの先頭のプロセスを選択する。
各 プロセスのスケジューリング・ポリシーは、そのプロセスが同じ静的優先度
を持つプロセスのリストの中のどこに挿入され、このリストの中をどのよう に
移動するかを決定する。
全 てのスケジューリングはプリエンプティブ (preemptive) である: より高い
優先度のプロセスが実行可能になると、現在実行中のプロセスは実行権を取 り
上 げられ (preempted)、そのプロセスの静的優先度レベルの待ちリストに戻さ
れる。スケジューリング・ポリシーは同じ静的優先度を持つ実行可能なプロ セ
スのリストの中で順番のみを決定する。
SCHED_FIFO: ファーストイン・ファーストアウト・スケジューリング
SCHED_FIFO は 0 より大きな静的優先度でのみ使用できる。このポリシーでは
、 SCHED_FIFO プロセスが実行可能になっ た 場 合 、 そ の ポ リ シ ー が
SCHED_OTHER、 SCHED_BATCH、 SCHED_IDLE の現在実行中のプロセスは直ちに実
行権を取り上げられる。 SCHED_FIFO は時分割のない単純なスケジューリン グ
・ アルゴリズムである。 SCHED_FIFO ポリシーでスケジューリングされている
プロセスには以下のルールが適用される:
* より高い優先度の他のプロセスによって取って代わられた SCHED_FIFO プロ
セスはその優先度のリストの先頭に留まり続け、より高い優先度のプロセス
全てが停止 (block) した場合に実行を再開する。
* SCHED_FIFO プロセスが実行可能になった時、その優先度のリストの最後 に
挿入される。
* sched_setscheduler() や sched_setparam(2) は pid で指定された
SCHED_FIFO (または SCHED_RR) プロセスが実行可能な場合、リストの最 初
に置く。結果として、もし優先度が同じだった場合、現在実行中のプロセス
に先んじるかもしれない。 (POSIX.1-2001 ではプロセスはリストの最後 に
行くべきと規定されている。)
* sched_yield(2) を呼び出したプロセスはリストの最後に置かれる。
そ の他のイベントによって SCHED_FIFO ポリシーでスケジューリングされるプ
ロセスが同じ優先度の実行可能なプロセスの待ちリストの中を移動すること は
ない。
SCHED_FIFO プロセスは I/O 要求によって停止するか、より高い優先度のプロ
セスによって置きかえられるか、 sched_yield(2) を呼び出すまで実行を続 け
る。
SCHED_RR: ラウンド・ロビン (round robin) ・スケジューリング
SCHED_RR は SCHED_FIFO の単純な拡張である。上述された SCHED_FIFO に関す
る記述は全て SCHED_RR に適用できる。異なるのはそれぞれのプロセスは最 大
時間単位までしか実行できないということである。SCHED_RR プロセスが時間単
位と同じかそれより長い時間実行されると、その優先度のリストの最後に置 か
れ る。より高い優先度のプロセスによって置きかえられ、その後実行を再開し
た SCHED_RR プロセスは、そのラウンド・ロビン時間単位を完全に使い切る ま
で 実行される。その時間単位の長さは sched_rr_get_interval(2) を使って取
得できる。
SCHED_OTHER: Linux のデフォルトの時分割スケジューリング
SCHED_OTHER は静的優先度 0 でのみ使用できる。 SCHED_OTHER は Linux 標準
の 時分割スケジューラで、特別なリアルタイム機構を必要としていない全ての
プロセスで使用される。実行するプロセスは、静的優先度 0 のリストから、こ
の リストの中だけで決定される「動的な」優先度 (dynamic priority) に基い
て決定される。動的な優先度は (nice(2) や setpriority(2) により設定さ れ
る) nice 値に基づいて決定されるもので、単位時間毎に、プロセスが実行可能
だが、スケジューラにより実行が拒否された場合にインクリメントされる。 こ
れにより、全ての SCHED_OTHER プロセスでの公平性が保証される。
SCHED_BATCH: バッチプロセスのスケジューリング
(Linux 2.6.16 以降) SCHED_BATCH は静的優先度 0 でのみ使用できる。このポ
リシーは (nice 値に基づく) 動的な優先度にしたがってプロセスのスケジュー
リ ングが行われるという点で、SCHED_OTHER に似ている。異なるのは、このポ
リシーでは、プロセスが常に CPU に負荷のかかる (CPU-intensive) 処理を 行
う と、スケジューラが仮定する点である。スケジューラはプロセスを呼び起こ
す毎にそのプロセスにスケジューリング上のペナルティを少し課し、その結 果
、このプロセスはスケジューリングの決定で若干冷遇されるようになる。
こ のポリシーは、非対話的な処理だがその nice 値を下げたくない処理や、 (
処理のタスク間で) 余計なタスクの置き換えの原因とある対話的な処理なし で
確定的な (deterministic) スケジューリング・ポリシーを適用したい処理に対
して有効である。
SCHED_IDLE: 非常に優先度の低いジョブのスケジューリング
(Linux 2.6.23 以降) SCHED_IDLE は静的優先度 0 でのみ使用できる。この ポ
リシーではプロセスの nice 値はスケジューリングに影響を与えない。
非 常に低い優先度でのジョブの実行を目的としたものである (非常に低い優先
度とは、ポリシー SCHED_OTHER か SCHED_BATCH での nice 値 +19 よりさらに
低い優先度である)。
特権とリソース制限
2.6.12 よ り 前 の バ ー ジ ョ ン の Linux カーネルでは、特権プロセス
(CAP_SYS_NICE ケーパビリティを持つプロセス) だけが 0 以外の静的優先度を
設定する (すなわち、リアルタイム・スケジューリング・ポリシーを設定する)
ことができる。非特権プロセスができる変更は SCHED_OTHER ポリシーを設定す
る ことだけであり、さらにこの変更を行えるのは sched_setscheduler() の呼
び出し元の実効ユーザ ID がポリシーの変更対象プロセス (pid で指定され た
プロセス) の実ユーザ ID か実効ユーザ ID と一致する場合だけである。
Linux 2.6.12 以降では、リソース制限 RLIMIT_RTPRIO が定義されており、ス
ケジューリング・ポリシーが SCHED_RR と SCHED_FIFO の場合の、非特権プ ロ
セ スの静的優先度の上限を定めている。スケジューリング・ポリシーと優先度
を変更する際のルールは以下の通りである。
* 非特権プロセスに 0 以外の RLIMIT_RTPRIO ソフト・リミットが設定され て
い る場合、非特権プロセスはそのプロセスのスケジューリング・ポリシーと
優先度を変更できるが、優先度を現在の自身の優先度と RLIMIT_RTPRIO ソフ
ト ・リミットの大きい方よりも高い値に設定できないという制限が課される
。
* RLIMIT_RTPRIO ソフト・リミットが 0 の場合、優先度を下げるか、リアルタ
イムでないポリシーへ切り替えるかの変更だけが許可される。
* ある非特権プロセスが別のプロセスに対してこれらの変更を行う際にも、同
じルールが適用される。変更を行えるのは、変更を行おうとするプロセス の
実 効ユーザ ID が変更対象のプロセスの実ユーザ ID か実効ユーザ ID と一
致している場合に限られる。
* SCHED_IDLE には特別なルールが適用され、このポリシーの下で動作する非特
権プロセスは、リソース制限 RLIMIT_RTPRIO の値にかかわらず自身のポリシ
ーを変更することができない。
特権プロセス (CAP_SYS_NICE ケーパビリティを持つプロセ ス) の 場 合 、
RLIMIT_RTPRIO の制限は無視される; 古いカーネルと同じように、スケジュー
リング・ポリシーと優先度に対し任意の変 更 を 行 う こ と が で き る 。
RLIMIT_RTPRIO に関するもっと詳しい情報は getrlimit(2) を参照のこと。
応答時間 (response time)
I/O 待ちで停止したより高い優先度のプロセスは再びスケジューリングされる
前にいくらかの応答時間がかかる。デバイス・ドライバーを書 く 場 合 に は
"slow interrupt" 割り込みハンドラーを使用することでこの応答時間を劇的に
減少させることができる。
その他
子プロセスは fork(2) の際に親プロセスのスケジューリング・ポリシーとパラ
メータを継承する。 execve(2) の前後で、スケジューリング・ポリシーとパラ
メータは保持される。
リアルタイム・プロセスは大抵、ページングの待ち時間 を 避 け る た め に
mlock(2) や mlockall(2) を使ってメモリ・ロックをしなければならない。
SCHED_FIFO や SCHED_RR でスケジューリングされるプロセスが停止せずに無限
ループに陥ると、他の全てのより低い優先度のプロセスを永久に停止 (block)
さ せてしまうので、ソフトウェア開発者はコンソールのシェルの静的優先度を
テストするアプリケーションよりも常に高く保つべきである。これによって 期
待 通りに停止したり終了したりしないリアルタイム・アプリケーションを緊急
終了させることが可能になる。 getrlimit(2) のリソース制限 RLIMIT_RTTIME
の説明も参照のこと。
POSIX システムでは に _POSIX_PRIORITY_SCHEDULING が定義され
ている場合にのみ sched_setscheduler() と sched_getscheduler() が使用 で
きる。
返り値
成 功 し た 場 合 、 sched_setscheduler() は 0 を返す。成功した場合、
sched_getscheduler() は現在のそのプロセスのポリシー (非負の整数) を返す
。エラーの場合、-1 が返され、 errno が適切に設定される。
エラー
EINVAL スケジューリング・ポリシー policy が間違っているか、 param がそ
のポリシーでは意味をなさない。
EPERM 呼び出したプロセスが適切な特権を持っていない。
ESRCH IDが pid のプロセスが見つからない。
準拠
POSIX.1-2001 (但し、下記のバグの節も参照)。 SCHED_BATCH と SCHED_IDLE
ポリシーは Linux 固有である。
注意
POSIX.1 は、非特権プロセスが sched_setscheduler() を呼び出すために必要
な権限の詳細を規定しておらず、詳細はシステムにより 異 な る 。 例 え ば
、Solaris 7 のマニュアルページでは、呼び出し元プロセスの実ユーザ ID ま
たは実効ユーザ ID が設定対象のプロセスの実ユーザ ID か保存 (save) set-
user-ID と一致していなければならない、となっている。
もともとは、標準の Linux は一般目的のオペレーティングシステムとして設計
されており、バックグラウンド・プロセスや対話的アプリケーション、リア ル
タ イム性の要求が厳しくないリアルタイム・アプリケーション (普通はタイミ
ングの応答期限 (deadline) を満たす必要があるアプリケーション) を扱う こ
と ができた。 Linux カーネル 2.6 では、カーネルのプリエンプション (タス
クの置き換え) が可能であり、新たに導入された O(1) スケジューラにより 、
ア クティブなタスクの数に関わらずスケジューリングに必要な時間は固定で確
定的 (deterministic) であることが保証されている。それにも関わらず、カー
ネ ル 2.6.17 までは真のリアルタイム・コンピューティングは実現できなかっ
た。
本流の Linux カーネルでのリアルタイム機能
カーネル 2.6.18 から現在まで、 Linux は徐々にリアルタイム機能を備えつつ
あるが、これらの機能のほとんどは、 Ingo Molnar, Thomas Gleixner, Steven
Rostedt らによって開発された、以前の realtime-preempt パッチからのも の
で ある。これらのパッチが本流のカーネルに完全にマージされるまでは (マー
ジの完了はカーネル 2.6.30 あたりの予定)、最高のリアルタイム性能を達成す
る には realtime-preempt パッチを組み込まなければならない。これらのパッ
チは
patch-kernelversion-rtpatchversion
という名前で、 http://www.kernel.org/pub/linux/kernel/projects/rt/ から
ダウンロードできる。
こ のパッチが適用されず、かつパッチの内容の本流のカーネルへのマージが完
了するまでは、カーネルの 設 定 で は CONFIG_PREEMPT_NONE, CONFIG_PRE-
EMPT_VOLUNTARY, CONFIG_PREEMPT_DESKTOP の 3つのプリエンプション・クラス
(preemption class) だけが提供される。これらのクラスでは、最悪の場合のス
ケジューリング遅延がそれぞれ全く減らない、いくらか減る、かなり減る。
パ ッチが適用された場合、またはパッチの内容の本流のカーネルへのマージが
完了した後では、上記に加えて設定項目として CONFIG_PREEMPT_RT が利用可能
になる。この項目を選択すると、 Linux は通常のリアルタイム・オペレーティ
ングシステムに変身する。この場合には、 sched_setscheduler() で選択で き
る FIFO と RR のスケジューリング・ポリシーは、真のリアルタイム優先度を
持つプロセスを最悪の場合のスケジューリング遅延が最小となる環境で動作 さ
せるために使われることになる。
バグ
POSIX では、成功時に sched_setscheduler() は直前のスケジューリング・ポ
リシーを返すべきとされている。 Linux の sched_setscheduler() はこの要求
仕様に準拠しておらず、成功時には常に 0 を返す。
関連項目
getpriority(2), mlock(2), mlockall(2), munlock(2), munlockall(2),
nice(2), sched_get_priority_max(2), sched_get_priority_min(2),
sched_getaffinity(2), sched_getparam(2), sched_rr_get_interval(2),
sched_setaffinity(2), sched_setparam(2), sched_yield(2), setprior-
ity(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
カーネル・ソース内のファイル Documentation/scheduler/sched-rt-group.txt
(カーネル 2.6.25 以降)
Linux 2008-11-06 SCHED_SETSCHEDULER(2)
SCHED_SETSCHEDULER(2) Linux Programmer’s Manual SCHED_SETSCHEDULER(2)
NAME
sched_setscheduler, sched_getscheduler - set and get scheduling pol-
icy/parameters
SYNOPSIS
#include
int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param);
int sched_getscheduler(pid_t pid);
struct sched_param {
...
int sched_priority;
...
};
DESCRIPTION
sched_setscheduler() 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:
SCHED_OTHER the standard round-robin time-sharing policy;
SCHED_BATCH for "batch" style execution of processes; and
SCHED_IDLE 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:
SCHED_FIFO a first-in, first-out policy; and
SCHED_RR a round-robin policy.
The semantics of each of these policies are detailed below.
sched_getscheduler() 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 pro-
cess will be executed by the CPU next. Each process has an associated
scheduling policy and a static scheduling priority, sched_priority;
these are the settings that are modified by sched_setscheduler(). The
scheduler makes it decisions based on knowledge of the scheduling pol-
icy and static priority of all processes on the system.
For processes scheduled under one of the normal scheduling policies
(SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used in
scheduling decisions (it must be specified as 0).
Processes scheduled under one of the real-time policies (SCHED_FIFO,
SCHED_RR) have a sched_priority 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 only requires
an implementation to support a minimum 32 distinct priority levels for
the real-time policies, and some systems supply just this minimum.
Portable programs should use sched_get_priority_min(2) and
sched_get_priority_max(2) to find the range of priorities supported for
a particular policy.
Conceptually, the scheduler maintains a list of runnable processes for
each possible sched_priority value. In order to determine which pro-
cess runs next, the scheduler looks for the non-empty 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 only determines the ordering within the list of
runnable processes with equal static priority.
SCHED_FIFO: First In-First Out scheduling
SCHED_FIFO can only be used with static priorities higher than 0, which
means that when a SCHED_FIFO processes becomes runnable, it will always
immediately preempt any currently running SCHED_OTHER, SCHED_BATCH, or
SCHED_IDLE process. SCHED_FIFO is a simple scheduling algorithm with-
out time slicing. For processes scheduled under the SCHED_FIFO policy,
the following rules apply:
* A SCHED_FIFO 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 SCHED_FIFO process becomes runnable, it will be inserted at
the end of the list for its priority.
* A call to sched_setscheduler() or sched_setparam(2) will put the
SCHED_FIFO (or SCHED_RR) 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 sched_yield(2) will be put at the end of the list.
No other events will move a process scheduled under the SCHED_FIFO pol-
icy in the wait list of runnable processes with equal static priority.
A SCHED_FIFO process runs until either it is blocked by an I/O request,
it is preempted by a higher priority process, or it calls
sched_yield(2).
SCHED_RR: Round Robin scheduling
SCHED_RR is a simple enhancement of SCHED_FIFO. Everything described
above for SCHED_FIFO also applies to SCHED_RR, except that each process
is only allowed to run for a maximum time quantum. If a SCHED_RR pro-
cess 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 SCHED_RR 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 sched_rr_get_interval(2).
SCHED_OTHER: Default Linux time-sharing scheduling
SCHED_OTHER can only be used at static priority 0. SCHED_OTHER is the
standard Linux time-sharing scheduler that is intended for all
processes 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
SCHED_OTHER processes.
SCHED_BATCH: Scheduling batch processes
(Since Linux 2.6.16.) SCHED_BATCH can only be used at static priority
0. This policy is similar to SCHED_OTHER in that it schedules the pro-
cess 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 non-interactive, but do
not want to lower their nice value, and for workloads that want a
deterministic scheduling policy without interactivity causing extra
preemptions (between the workload’s tasks).
SCHED_IDLE: Scheduling very low priority jobs
(Since Linux 2.6.23.) SCHED_IDLE can only be used 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 SCHED_OTHER or SCHED_BATCH
policies).
Privileges and resource limits
In Linux kernels before 2.6.12, only privileged (CAP_SYS_NICE) pro-
cesses can set a non-zero static priority (i.e., set a real-time
scheduling policy). The only change that an unprivileged process can
make is to set the SCHED_OTHER policy, and this can only be done if the
effective user ID of the caller of sched_setscheduler() 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 RLIMIT_RTPRIO resource limit defines a ceiling
on an unprivileged process’s static priority for the SCHED_RR and
SCHED_FIFO policies. The rules for changing scheduling policy and pri-
ority are as follows:
* If an unprivileged process has a non-zero RLIMIT_RTPRIO 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 RLIMIT_RTPRIO soft limit.
* If the RLIMIT_RTPRIO 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 target pro-
cess.
* Special rules apply for the SCHED_IDLE: an unprivileged process oper-
ating under this policy cannot change its policy, regardless of the
value of its RLIMIT_RTPRIO resource limit.
Privileged (CAP_SYS_NICE) processes ignore the RLIMIT_RTPRIO limit; as
with older kernels, they can make arbitrary changes to scheduling pol-
icy and priority. See getrlimit(2) for further information on
RLIMIT_RTPRIO.
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 non-blocking infinite loop in a process scheduled under
SCHED_FIFO or SCHED_RR 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 RLIMIT_RTTIME resource limit in getrlimit(2).
POSIX systems on which sched_setscheduler() and sched_getscheduler()
are available define _POSIX_PRIORITY_SCHEDULING in .
RETURN VALUE
On success, sched_setscheduler() returns zero. On success,
sched_getscheduler() returns the policy for the process (a non-negative
integer). On error, -1 is returned, and errno is set appropriately.
ERRORS
EINVAL The scheduling policy is not one of the recognized policies, 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 SCHED_BATCH and SCHED_IDLE
policies are Linux-specific.
NOTES
POSIX.1 does not detail the permissions that an unprivileged process
requires in order to call sched_setscheduler(), 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.
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 onwards, however, Linux is gradually becom-
ing 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 completely 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/ker-
nel/projects/rt/.
Without the patches and prior to their full inclusion into the mainline
kernel, the kernel configuration offers only the three preemption
classes CONFIG_PREEMPT_NONE, CONFIG_PREEMPT_VOLUNTARY, and CONFIG_PRE-
EMPT_DESKTOP 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 CONFIG_PREEMPT_RT
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 sched_setscheduler() 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, sched_setscheduler() should return the pre-
vious scheduling policy. Linux sched_setscheduler() does not conform
to this requirement, since it always returns 0 on success.
SEE ALSO
getpriority(2), mlock(2), mlockall(2), munlock(2), munlockall(2),
nice(2), sched_get_priority_max(2), sched_get_priority_min(2),
sched_getaffinity(2), sched_getparam(2), sched_rr_get_interval(2),
sched_setaffinity(2), sched_setparam(2), sched_yield(2), setprior-
ity(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 kernel source file Documentation/scheduler/sched-rt-group.txt
(since kernel 2.6.25).
COLOPHON
This page is part of release 3.22 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 2008-11-06 SCHED_SETSCHEDULER(2)