1 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 2008-06-24, mtk: added some details about where jiffies come into
24 .\" play; added section on high-resolution timers.
26 .\" Japanese Version Copyright (c) 2006 Yuichi SATO
27 .\" all rights reserved.
28 .\" Translated 2006-07-23 by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v2.36
29 .\" Updated 2007-05-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.44
30 .\" Updated 2008-08-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
32 .TH TIME 7 2010-02-25 "Linux" "Linux Programmer's Manual"
36 .SS "実時間 (real time) とプロセス時間"
37 \fI実時間\fRは、特定の時点から計った時間と定義される。
39 (下記の紀元 (Epoch) とカレンダ時刻の説明を参照) や、
40 プロセスの一生における何らかの時点 (例えば、開始時) である
43 \fIプロセス時間\fRは、プロセスによって使われた総 CPU 時間と定義される。
44 多くの場合、\fIユーザ\fR時間と\fIシステム\fR時間に分けられる。
45 ユーザ CPU 時間は、コードをユーザモードで実行するのに使った時間である。
46 システム CPU 時間は、そのプロセスのために
47 カーネルがシステムモードで実行するのに使った時間である
48 (例えば、システムコールを実行するのに使った時間)。
50 コマンドはプログラムの実行に費された総 CPU 時間を計るのに使用される。
51 プログラムは、自身が費した総 CPU 時間を
57 多くのコンピュータが (電池で駆動される) ハードウェアクロックを持っている。
58 カーネルは起動時にソフトウェアクロックを初期化するために
65 .SS "ソフトウェアクロック, HZ, Jiffy"
68 .BR sigtimedwait (2))、
69 .\" semtimedop(), mq_timedwait(), io_getevents(), poll() は同じ futex であり、
70 .\" したがっって sem_timedwait() は高精度タイマを使用しているようである。
72 .BR getrusage (2)) する様々なシステムコールの精度は
74 の分解能 (resolution) に制限される。
75 ソフトウェアクロックとは、カーネルが管理する
83 の値はカーネルのバージョンとハードウェアプラットフォームで異なる。
85 2.4.x とそれより前のカーネルでは、HZ は 100 であったので、
86 jiffy の値は 0.01 秒になっていた。
87 2.6.0 以降では、HZ は 1000 に増やされたので、jiffy の値は 0.001 秒である。
88 カーネル 2.6.13 以降では、HZ の値はカーネル設定パラメータになり、
89 100, 250 (デフォルト), 1000 という値にできる。
90 それぞれ jiffy の値は 0.01, 0.004, 0.001 秒になる。
91 カーネル 2.6.20 以降では、300 も利用できるようになっている。
92 300 は一般的な映像フレームレートの公倍数である (PAL, 25HZ; NTSC, 30HZ)。
100 .I sysconf(_SC_CLK_TCK)
102 .\" glibc gets this info with a little help from the ELF loader;
103 .\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c.
106 Linux 2.6.21 より前では、タイマやスリープ関連のシステムコールの精度も
107 jiffy のサイズにより制限されていた。
109 Linux 2.6.21 以降では、Linux は高精度タイマ (high-resolution timers; HRTs)
111 .B CONFIG_HIGH_RES_TIMERS
113 高精度タイマをサポートしているシステムでは、タイマとスリープ関連のシステムコール
114 の精度はもはや jiffy に制約されることはなく、
116 (最近のハードウェアではマイクロ秒単位の精度が一般的である)。
121 内の "resolution" エントリを参照するかで判断できる。
123 高精度タイマはすべてのハードウェアアーキテクチャでサポートされている
124 訳ではない (対応しているアーキテクチャは x86, arm, powerpc である)。
127 紀元 (1970-01-01 00:00:00 +0000 (UTC)) からの秒数で表現する。
129 プログラムは \fIカレンダ時刻\fR を
132 この関数は紀元からの経過時間を (秒とマイクロ秒で) 返す。
134 は同様の情報を提供するが、最も近い秒の精度しかない。
142 この構造体は\fI要素別の時刻\fRを表し、
143 時刻の値を別々の要素 (年・月・日・時・分・秒など) に分けて格納する。
146 に記述されており、カレンダ時刻を要素別の時刻に変換する
148 要素別の時刻を表示可能な文字列に変換する関数については、
154 様々なシステムコールと関数により、指定された一定の時間、
155 プログラムはスリープ (実行を停止) することが可能である。
157 .BR clock_nanosleep (2),
161 様々なシステムコールにより、プロセスは将来のある時点で
163 またオプションとして繰り返し間隔が指定できるものもある。
166 .BR timerfd_create (2),
174 .BR clock_gettime (2),
175 .BR clock_nanosleep (2),
179 .BR gettimeofday (2),
183 .BR timer_create (2),
184 .BR timerfd_create (2),
189 .BR clock_getcpuclockid (3),
191 .BR pthread_getcpuclockid (3),