1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 2003 Nick Clifford (zaf@nrc.co.nz), Jan 25, 2003
4 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl), Aug 24, 2003
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" 2003-08-23 Martin Schulze <joey@infodrom.org> improvements
27 .\" 2003-08-24 aeb, large parts rewritten
28 .\" 2004-08-06 Christoph Lameter <clameter@sgi.com>, SMP note
30 .\" Japanese Version Copyright (c) 2004-2005 Yuichi SATO
31 .\" all rights reserved.
32 .\" Translated 2004-07-19, Yuichi SATO <ysato444@yahoo.co.jp>
33 .\" Updated & Modified 2005-01-10, Yuichi SATO
34 .\" Updated 2010-04-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
36 .TH CLOCK_GETRES 2 2010-02-03 "" "Linux Programmer's Manual"
39 .\"O clock_getres, clock_gettime, clock_settime \- clock and time functions
40 clock_getres, clock_gettime, clock_settime \- ¥¯¥í¥Ã¥¯¤È»þ´Ö¤Î´Ø¿ô
45 .BI "int clock_getres(clockid_t " clk_id ", struct timespec *" res );
47 .BI "int clock_gettime(clockid_t " clk_id ", struct timespec *" tp );
49 .BI "int clock_settime(clockid_t " clk_id ", const struct timespec *" tp );
51 .\"O Link with \fI\-lrt\fP.
52 \fI\-lrt\fP ¤È¥ê¥ó¥¯¤¹¤ë¡£
55 .\"O Feature Test Macro Requirements for glibc (see
56 .\"O .BR feature_test_macros (7)):
57 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
58 .RB ( feature_test_macros (7)
66 _POSIX_C_SOURCE\ >=\ 199309L
71 .\"O .BR clock_getres ()
72 .\"O finds the resolution (precision) of the specified clock
76 .\"O is non-NULL, stores it in the \fIstruct timespec\fP pointed to by
83 ¤Îʬ²òǽ (ÀºÅÙ) ¤òõ¤·½Ð¤¹¡£
85 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢¤½¤Îʬ²òǽ¤ò
87 ¤Ç»Ø¤µ¤ì¤ë \fIstruct timespec\fP ¤Ë³ÊǼ¤¹¤ë¡£
88 .\"O The resolution of clocks depends on the implementation and cannot be
89 .\"O configured by a particular process.
90 ¥¯¥í¥Ã¥¯¤Îʬ²òǽ¤Ï¼ÂÁõ¤Ë°Í¸¤·¡¢
91 ÆÃÄê¤Î¥×¥í¥»¥¹¤Ë¤è¤Ã¤ÆÀßÄꤹ¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
92 .\"O If the time value pointed to by the argument
95 .\"O .BR clock_settime ()
96 .\"O is not a multiple of
98 .\"O then it is truncated to a multiple of
107 ¤ÎÇÜ¿ô¤ËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£
110 .\"O .BR clock_gettime ()
112 .\"O .BR clock_settime ()
113 .\"O retrieve and set the time of the specified clock
119 ¤Ï¡¢»ØÄꤵ¤ì¤¿¥¯¥í¥Ã¥¯
121 ¤Î»þ´Ö¤ò¼èÆÀ¤Þ¤¿¤ÏÀßÄꤹ¤ë¡£
129 .\"O structures, as specified in
138 ¤Ç°Ê²¼¤Î¤è¤¦¤Ëµ¬Äꤵ¤ì¤Æ¤¤¤ë:
143 time_t tv_sec; /* seconds */
144 long tv_nsec; /* nanoseconds */
151 .\"O argument is the identifier of the particular clock on which to act.
153 °ú¤¿ô¤ÏÆÃÄê¤Î¥¯¥í¥Ã¥¯¤Î¼±Ê̻ҤǤ¢¤ê¡¢¤½¤Î¥¯¥í¥Ã¥¯¤ÇÆ°ºî¤¹¤ë¡£
154 .\"O A clock may be system-wide and hence visible for all processes, or
155 .\"O per-process if it measures time only within a single process.
156 ¥¯¥í¥Ã¥¯¤Ï¥·¥¹¥Æ¥àÁ´ÂΤËŬÍѤ¹¤ë¤³¤È¤â¤Ç¤¡¢
157 ¤½¤Î¾ì¹ç¤ÏÁ´¤Æ¤Î¥×¥í¥»¥¹¤«¤é¸«¤ë¤³¤È¤¬¤Ç¤¤ë¡£
158 ¤Þ¤¿ 1 ¤Ä¤Î¥×¥í¥»¥¹Æâ¤Ç¤Î¤ß»þ´Ö¤ò·×¬¤¹¤ë¾ì¹ç¤Ï¡¢
159 ¥×¥í¥»¥¹Ëè¤ËŬÍѤ¹¤ë¤³¤È¤â¤Ç¤¤ë¡£
161 .\"O All implementations support the system-wide real-time clock,
162 .\"O which is identified by
163 .\"O .BR CLOCK_REALTIME .
164 Á´¤Æ¤Î¼ÂÁõ¤Ë¤ª¤¤¤Æ¥·¥¹¥Æ¥àÁ´ÂΤΥꥢ¥ë¥¿¥¤¥à¥¯¥í¥Ã¥¯¤¬¥µ¥Ý¡¼¥È¤µ¤ì¡¢
167 .\"O Its time represents seconds and nanoseconds since the Epoch.
168 »þ´Ö¤Ïµª¸µ (the Epoch) ¤«¤é¤ÎÉäȥʥÎÉäÇɽ¤µ¤ì¤ë¡£
169 .\"O When its time is changed, timers for a relative interval are
170 .\"O unaffected, but timers for an absolute point in time are affected.
171 »þ´Ö¤¬Êѹ¹¤µ¤ì¤¿¾ì¹ç¡¢ÁêÂÐŪ¤Ê»þ´Ö´Ö³Ö¤Î¥¿¥¤¥Þ¤Ï±Æ¶Á¤ò¼õ¤±¤Ê¤¤¤¬¡¢
172 ÀäÂÐŪ¤Ê»þÅÀ¤Î¥¿¥¤¥Þ¤Ï±Æ¶Á¤ò¼õ¤±¤ë¡£
174 .\"O More clocks may be implemented.
175 .\"O The interpretation of the
176 .\"O corresponding time values and the effect on timers is unspecified.
177 ¤µ¤é¤Ë¤¤¤¯¤Ä¤«¤Î¥¯¥í¥Ã¥¯¤¬¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
178 Âбþ¤¹¤ë»þ´Ö¤ÎÃͤò²ò¼á¤¹¤ëÊýË¡¤È¥¿¥¤¥Þ¤Ø¤Î±Æ¶Á¤Ï¡¢Äê¤á¤é¤ì¤Æ¤¤¤Ê¤¤¡£
180 .\"O Sufficiently recent versions of glibc and the Linux kernel
181 .\"O support the following clocks:
182 glibc ¤È Linux ¥«¡¼¥Í¥ë¤ÎºÇ¿·¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¡¢
183 °Ê²¼¤Î¤è¤¦¤Ê½½Ê¬¤Ê¥¯¥í¥Ã¥¯¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£
186 .\"O System-wide real-time clock.
187 ¥·¥¹¥Æ¥àÁ´ÂΤΥꥢ¥ë¥¿¥¤¥à¥¯¥í¥Ã¥¯¡£
188 .\"O Setting this clock requires appropriate privileges.
189 ¤³¤Î¥¯¥í¥Ã¥¯¤òÀßÄꤹ¤ë¤Ë¤ÏŬÀÚ¤ÊÆø¢¤¬É¬ÍפǤ¢¤ë¡£
192 .\"O Clock that cannot be set and represents monotonic time since
193 .\"O some unspecified starting point.
194 ¤¤¤¯¤Ä¤«¤Î³«»ÏÅÀ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¤¿¤á¡¢
195 ¥¯¥í¥Ã¥¯¤¬¥â¥Î¥È¥Ë¥Ã¥¯¥¿¥¤¥à¤òÀßÄꤷ¤¿¤êɽ¸½¤·¤¿¤ê¤Ç¤¤Ê¤¤¡£
197 .\"O .BR CLOCK_MONOTONIC_RAW " (since Linux 2.6.28; Linux-specific)"
198 .BR CLOCK_MONOTONIC_RAW " (Linux 2.6.28 °Ê¹ß; Linux ÆÃÍ)"
199 .\" Added in commit 2d42244ae71d6c7b0884b5664cf2eda30fb2ae68, John Stultz
201 .\"O .BR CLOCK_MONOTONIC ,
202 .\"O but provides access to a raw hardware-based time
203 .\"O that is not subject to NTP adjustments.
205 ¤ÈƱÍͤÀ¤¬¡¢NTP ¤Ë¤è¤ëÄ´À°¤Î±Æ¶Á¤ò¼õ¤±¤Ê¤¤¡¢¥Ï¡¼¥É¥¦¥§¥¢¤Ë¤è¤ë
206 À¸¤Î»þ¹ï¤Ø¤Î¥¢¥¯¥»¥¹¤¬¤Ç¤¤ë¡£
208 .B CLOCK_PROCESS_CPUTIME_ID
209 .\"O High-resolution per-process timer from the CPU.
210 CPU ¤Ë¤è¤ë¹âʬ²òǽ¤Î¥×¥í¥»¥¹Ëè¤Î¥¿¥¤¥Þ¡£
212 .B CLOCK_THREAD_CPUTIME_ID
213 .\"O Thread-specific CPU-time clock.
214 ¥¹¥ì¥Ã¥É¸ÇͤΠCPU ¥¿¥¤¥à¥¯¥í¥Ã¥¯¡£
215 .\"O .SH "RETURN VALUE"
217 .\"O .BR clock_gettime (),
218 .\"O .BR clock_settime ()
220 .\"O .BR clock_getres ()
221 .\"O return 0 for success, or \-1 for failure (in which case
223 .\"O is set appropriately).
224 .BR clock_gettime (),
225 .BR clock_settime (),
227 ¤ÏÀ®¸ù¤·¤¿¾ì¹ç¤Ë 0 ¤òÊÖ¤·¡¢¼ºÇÔ¤·¤¿¾ì¹ç¤Ë \-1 ¤òÊÖ¤¹
230 ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë)¡£
236 .\"O points outside the accessible address space.
238 ¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤ò»Ø¤·¤¿¡£
243 .\"O specified is not supported on this system.
244 .\" Linux also gives this error on attempts to set CLOCK_PROCESS_CPUTIME_ID
245 .\" and CLOCK_THREAD_CPUTIME_ID, when probably the proper error should be
249 ¤¬¤³¤Î¥·¥¹¥Æ¥à¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
252 .\"O .BR clock_settime ()
253 .\"O does not have permission to set the clock indicated.
254 »Ø¼¨¤µ¤ì¤¿¥¯¥í¥Ã¥¯¤òÀßÄꤹ¤ë¸¢¸Â¤¬
257 .\"O .SH "CONFORMING TO"
260 .\"O .SH AVAILABILITY
262 .\"O On POSIX systems on which these functions are available, the symbol
263 .\"O .B _POSIX_TIMERS
264 .\"O is defined in \fI<unistd.h>\fP to a value greater than 0.
265 ¤³¤ì¤é¤Î´Ø¿ô¤¬ÍøÍѲÄǽ¤Ê POSIX ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢\fI<unistd.h>\fP ¤Ë¤ª¤¤¤Æ¥·¥ó¥Ü¥ë
267 ¤¬ 0 ¤è¤êÂ礤¤ÃͤËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
269 .\"O .BR _POSIX_MONOTONIC_CLOCK ,
270 .\"O .BR _POSIX_CPUTIME ,
271 .\"O .B _POSIX_THREAD_CPUTIME
273 .\"O .BR CLOCK_MONOTONIC ,
274 .\"O .BR CLOCK_PROCESS_CPUTIME_ID ,
275 .\"O .B CLOCK_THREAD_CPUTIME_ID
278 .BR _POSIX_MONOTONIC_CLOCK ,
280 .B _POSIX_THREAD_CPUTIME
282 .BR CLOCK_MONOTONIC ,
283 .BR CLOCK_PROCESS_CPUTIME_ID ,
284 .B CLOCK_THREAD_CPUTIME_ID
285 ¤¬ÍøÍѲÄǽ¤Ê¤³¤È¤ò¼¨¤¹¡£
287 .\"O .BR sysconf (3).)
292 .\"O .SS Note for SMP systems
293 .SS "SMP ¥·¥¹¥Æ¥à¤Ë¤Ä¤¤¤Æ¤ÎÃí°Õ"
295 .\"O .B CLOCK_PROCESS_CPUTIME_ID
297 .\"O .B CLOCK_THREAD_CPUTIME_ID
298 .\"O clocks are realized on many platforms using timers from the CPUs
299 .\"O (TSC on i386, AR.ITC on Itanium).
300 .B CLOCK_PROCESS_CPUTIME_ID
302 .B CLOCK_THREAD_CPUTIME_ID
303 ¥¯¥í¥Ã¥¯¤Ï¡¢CPU ¤«¤é¤Î¥¿¥¤¥Þ
304 (i386 ¾å¤Î TSC¡¢Itanium ¾å¤Î AR.ITC) ¤òÍѤ¤¤Æ¼Â¸½¤µ¤ì¤Æ¤¤¤ë¡£
305 .\"O These registers may differ between CPUs and as a consequence
306 .\"O these clocks may return
307 .\"O .B bogus results
308 .\"O if a process is migrated to another CPU.
309 ¤³¤ì¤é¤Î¥ì¥¸¥¹¥¿¤Ï CPU ´Ö¤Ç°Û¤Ê¤ë²ÄǽÀ¤¬¤¢¤ê¡¢
310 ¥×¥í¥»¥¹¤¬Â¾¤Î CPU ¤Ë°ÜÆ°¤µ¤»¤é¤ì¤¿¾ì¹ç¡¢
311 ·ë²Ì¤È¤·¤Æ¤³¤ì¤é¤Î¥¯¥í¥Ã¥¯¤¬\fBµ¶¤Î·ë²Ì\fR
312 (bogus results) ¤òÊÖ¤¹¤«¤â¤·¤ì¤Ê¤¤¡£
314 .\"O If the CPUs in an SMP system have different clock sources then
315 .\"O there is no way to maintain a correlation between the timer registers since
316 .\"O each CPU will run at a slightly different frequency.
317 .\"O If that is the case then
318 .\"O .I clock_getcpuclockid(0)
321 .\"O to signify this condition.
322 .\"O The two clocks will then only be useful if it
323 .\"O can be ensured that a process stays on a certain CPU.
324 SMP ¥·¥¹¥Æ¥à¤Î³Æ CPU ¤¬ÊÌ¡¹¤Î¥¯¥í¥Ã¥¯¸»¤ò»ý¤Ä¾ì¹ç¡¢
325 ¥¿¥¤¥Þ¥ì¥¸¥¹¥¿´Ö¤ÎÁê¸ß´Ø·¸¤ò´ÉÍý¤¹¤ëÊýË¡¤Ï¤Ê¤¤¡£
326 ¤³¤ì¤Ï³Æ CPU ¤¬Èù̯¤Ë°Û¤Ê¤ë¼þÇÈ¿ô¤ÇÆ°ºî¤¹¤ë¤¿¤á¤Ç¤¢¤ë¡£
327 ¤³¤ì¤¬¿¿¼Â¤Î¾ì¹ç (ÌõÃð: ³Æ CPU ¤¬ÊÌ¡¹¤Î¥¯¥í¥Ã¥¯¸»¤ò»ý¤Ä¾ì¹ç)¡¢
328 .I clock_getcpuclockid(0)
331 ¤òÊÖ¤·¤Æ¡¢¤½¤Î¾õ¶·¤òɽ¤¹¡£
332 2 ¤Ä¤Î¥¯¥í¥Ã¥¯¤Ï¡¢¥×¥í¥»¥¹¤¬ÆÃÄê¤Î CPU ¾å¤Ëα¤Þ¤Ã¤Æ¤¤¤ë¤³¤È¤¬
333 ÊݾڤǤ¤ë¾ì¹ç¤Ë¤Î¤ß͸ú¤Ç¤¢¤ë¡£
335 .\"O The processors in an SMP system do not start all at exactly the same
336 .\"O time and therefore the timer registers are typically running at an offset.
337 SMP ¥·¥¹¥Æ¥à¤Î³Æ¥×¥í¥»¥Ã¥µ¤ÏÁ´¤¯Æ±¤¸»þ¹ï¤Ëµ¯Æ°¤¹¤ëÌõ¤Ç¤Ï¤Ê¤¤¤Î¤Ç¡¢
338 ³Æ¥¿¥¤¥Þ¥ì¥¸¥¹¥¿¤ÏÄ̾ï¤Ï¤¢¤ë¥ª¥Õ¥»¥Ã¥È¤ÇÆ°ºî¤·¤Æ¤¤¤ë¡£
339 .\"O Some architectures include code that attempts to limit these offsets on bootup.
340 ¥ª¥Õ¥»¥Ã¥È¤ò¥Ö¡¼¥È»þ¤ËÀ©¸Â¤¹¤ë¥³¡¼¥É¤¬´Þ¤Þ¤ì¤ë¥¢¡¼¥¥Æ¥¯¥Á¥ã¤â¤¢¤ë¡£
341 .\"O However, the code cannot guarantee to accurately tune the offsets.
342 ¤·¤«¤·¡¢¤³¤Î¥³¡¼¥É¤¬¥ª¥Õ¥»¥Ã¥È¤òÀµ³Î¤ËÄ´À°¤¹¤ë¤³¤È¤ÏÊݾڤǤ¤Ê¤¤¡£
343 .\"O Glibc contains no provisions to deal with these offsets (unlike the Linux
345 .\"O Typically these offsets are small and therefore the effects may be
346 .\"O negligible in most cases.
347 glibc ¤Ï (Linux ¥«¡¼¥Í¥ë¤È¤Ï°Û¤Ê¤ê) ¥ª¥Õ¥»¥Ã¥È¤ò°·¤¦¤¿¤á¤Î¥³¡¼¥É¤òÄ󶡤·¤Ê¤¤¡£
348 Ä̾ï¤Ï¤³¤ì¤é¤Î¥ª¥Õ¥»¥Ã¥È¤¬¾®¤µ¤¤¤Î¤Ç¡¢Â¿¤¯¤Î¾ì¹ç¤Ç¤½¤Î±Æ¶Á¤Ï̵»ë¤Ç¤¤ë¡£
351 .\"O According to POSIX.1-2001, a process with "appropriate privileges" may set the
352 .\"O .B CLOCK_PROCESS_CPUTIME_ID
354 .\"O .B CLOCK_THREAD_CPUTIME_ID
356 .\"O .BR clock_settime ().
357 .\"O On Linux, these clocks are not settable
358 .\"O (i.e., no process has "appropriate privileges").
360 ¡ÖŬÀÚ¤ÊÆø¢ (appropriate privileges)¡×¤ò»ý¤Ã¤¿¥×¥í¥»¥¹¤Ï¡¢
363 .B CLOCK_PROCESS_CPUTIME_ID
365 .B CLOCK_THREAD_CPUTIME_ID
366 ¤òÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¤È¤µ¤ì¤Æ¤¤¤ë¡£
367 Linux ¤Ç¤Ï¡¢¤³¤ì¤é¤Î¥¯¥í¥Ã¥¯¤ÏÀßÄê²Äǽ¤Ç¤Ï¤Ê¤¤
368 (¤¹¤Ê¤ï¤Á¡¢¤É¤Î¥×¥í¥»¥¹¤â¡ÖŬÀÚ¤ÊÆø¢¡×¤ò»ý¤¿¤Ê¤¤)¡£
369 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=11972
374 .BR gettimeofday (2),
375 .BR settimeofday (2),
377 .BR clock_getcpuclockid (3),
380 .BR pthread_getcpuclockid (3),