mount_setattr.2: Remove some unnecessary intermediate variables
[man-pages.git] / man7 / time.7
blob830da7ea8896fe095cfdd6dd6ff45338ec9379e9
1 .\" Copyright (c) 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2008-06-24, mtk: added some details about where jiffies come into
26 .\"     play; added section on high-resolution timers.
27 .\"
28 .TH TIME 7 2020-04-11 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 time \- overview of time and timers
31 .SH DESCRIPTION
32 .SS Real time and process time
33 .I "Real time"
34 is defined as time measured from some fixed point,
35 either from a standard point in the past
36 (see the description of the Epoch and calendar time below),
37 or from some point (e.g., the start) in the life of a process
38 .RI ( "elapsed time" ).
39 .PP
40 .I "Process time"
41 is defined as the amount of CPU time used by a process.
42 This is sometimes divided into
43 .I user
44 and
45 .I system
46 components.
47 User CPU time is the time spent executing code in user mode.
48 System CPU time is the time spent by the kernel executing
49 in system mode on behalf of the process (e.g., executing system calls).
50 The
51 .BR time (1)
52 command can be used to determine the amount of CPU time consumed
53 during the execution of a program.
54 A program can determine the amount of CPU time it has consumed using
55 .BR times (2),
56 .BR getrusage (2),
58 .BR clock (3).
59 .SS The hardware clock
60 Most computers have a (battery-powered) hardware clock which the kernel
61 reads at boot time in order to initialize the software clock.
62 For further details, see
63 .BR rtc (4)
64 and
65 .BR hwclock (8).
66 .SS The software clock, HZ, and jiffies
67 The accuracy of various system calls that set timeouts,
68 (e.g.,
69 .BR select (2),
70 .BR sigtimedwait (2))
71 .\" semtimedop(), mq_timedwait(), io_getevents(), poll() are the same
72 .\" futexes and thus sem_timedwait() seem to use high-res timers.
73 and measure CPU time (e.g.,
74 .BR getrusage (2))
75 is limited by the resolution of the
76 .IR "software clock" ,
77 a clock maintained by the kernel which measures time in
78 .IR jiffies .
79 The size of a jiffy is determined by the value of the kernel constant
80 .IR HZ .
81 .PP
82 The value of
83 .I HZ
84 varies across kernel versions and hardware platforms.
85 On i386 the situation is as follows:
86 on kernels up to and including 2.4.x, HZ was 100,
87 giving a jiffy value of 0.01 seconds;
88 starting with 2.6.0, HZ was raised to 1000, giving a jiffy of
89 0.001 seconds.
90 Since kernel 2.6.13, the HZ value is a kernel
91 configuration parameter and can be 100, 250 (the default) or 1000,
92 yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds.
93 Since kernel 2.6.20, a further frequency is available:
94 300, a number that divides evenly for the common video
95 frame rates (PAL, 25 HZ; NTSC, 30 HZ).
96 .PP
97 The
98 .BR times (2)
99 system call is a special case.
100 It reports times with a granularity defined by the kernel constant
101 .IR USER_HZ .
102 User-space applications can determine the value of this constant using
103 .IR sysconf(_SC_CLK_TCK) .
104 .\" glibc gets this info with a little help from the ELF loader;
105 .\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c.
107 .SS System and process clocks; time namespaces
108 The kernel supports a range of clocks that measure various kinds of
109 elapsed and virtual (i.e., consumed CPU) time.
110 These clocks are described in
111 .BR clock_gettime (2).
112 A few of the clocks are settable using
113 .BR clock_settime (2).
114 The values of certain clocks are virtualized by time namespaces; see
115 .BR time_namespaces (7).
117 .SS High-resolution timers
118 Before Linux 2.6.21, the accuracy of timer and sleep system calls
119 (see below) was also limited by the size of the jiffy.
121 Since Linux 2.6.21, Linux supports high-resolution timers (HRTs),
122 optionally configurable via
123 .BR CONFIG_HIGH_RES_TIMERS .
124 On a system that supports HRTs, the accuracy of sleep and timer
125 system calls is no longer constrained by the jiffy,
126 but instead can be as accurate as the hardware allows
127 (microsecond accuracy is typical of modern hardware).
128 You can determine whether high-resolution timers are supported by
129 checking the resolution returned by a call to
130 .BR clock_getres (2)
131 or looking at the "resolution" entries in
132 .IR /proc/timer_list .
134 HRTs are not supported on all hardware architectures.
135 (Support is provided on x86, arm, and powerpc, among others.)
136 .SS The Epoch
137 UNIX systems represent time in seconds since the
138 .IR Epoch ,
139 1970-01-01 00:00:00 +0000 (UTC).
141 A program can determine the
142 .I "calendar time"
143 via the
144 .BR clock_gettime (2)
145 .BR CLOCK_REALTIME
146 clock,
147 which returns time (in seconds and nanoseconds) that have
148 elapsed since the Epoch;
149 .BR time (2)
150 provides similar information, but only with accuracy to the
151 nearest second.
152 The system time can be changed using
153 .BR clock_settime (2).
155 .SS Broken-down time
156 Certain library functions use a structure of
157 type
158 .I tm
159 to represent
160 .IR "broken-down time" ,
161 which stores time value separated out into distinct components
162 (year, month, day, hour, minute, second, etc.).
163 This structure is described in
164 .BR ctime (3),
165 which also describes functions that convert between calendar time and
166 broken-down time.
167 Functions for converting between broken-down time and printable
168 string representations of the time are described in
169 .BR ctime (3),
170 .BR strftime (3),
172 .BR strptime (3).
173 .SS Sleeping and setting timers
174 Various system calls and functions allow a program to sleep
175 (suspend execution) for a specified period of time; see
176 .BR nanosleep (2),
177 .BR clock_nanosleep (2),
179 .BR sleep (3).
181 Various system calls allow a process to set a timer that expires
182 at some point in the future, and optionally at repeated intervals;
184 .BR alarm (2),
185 .BR getitimer (2),
186 .BR timerfd_create (2),
188 .BR timer_create (2).
189 .SS Timer slack
190 Since Linux 2.6.28, it is possible to control the "timer slack"
191 value for a thread.
192 The timer slack is the length of time by
193 which the kernel may delay the wake-up of certain
194 system calls that block with a timeout.
195 Permitting this delay allows the kernel to coalesce wake-up events,
196 thus possibly reducing the number of system wake-ups and saving power.
197 For more details, see the description of
198 .B PR_SET_TIMERSLACK
200 .BR prctl (2).
201 .SH SEE ALSO
202 .ad l
204 .BR date (1),
205 .BR time (1),
206 .BR timeout (1),
207 .BR adjtimex (2),
208 .BR alarm (2),
209 .BR clock_gettime (2),
210 .BR clock_nanosleep (2),
211 .BR getitimer (2),
212 .BR getrlimit (2),
213 .BR getrusage (2),
214 .BR gettimeofday (2),
215 .BR nanosleep (2),
216 .BR stat (2),
217 .BR time (2),
218 .BR timer_create (2),
219 .BR timerfd_create (2),
220 .BR times (2),
221 .BR utime (2),
222 .BR adjtime (3),
223 .BR clock (3),
224 .BR clock_getcpuclockid (3),
225 .BR ctime (3),
226 .BR ntp_adjtime (3),
227 .BR ntp_gettime (3),
228 .BR pthread_getcpuclockid (3),
229 .BR sleep (3),
230 .BR strftime (3),
231 .BR strptime (3),
232 .BR timeradd (3),
233 .BR usleep (3),
234 .BR rtc (4),
235 .BR time_namespaces (7),
236 .BR hwclock (8)