1TIME(7)                    Linux Programmer's Manual                   TIME(7)
2
3
4

NAME

6       time - overview of time and timers
7

DESCRIPTION

9   Real time and process time
10       Real  time  is  defined  as time measured from some fixed point, either
11       from a standard point in the past (see the description of the Epoch and
12       calendar  time below), or from some point (e.g., the start) in the life
13       of a process (elapsed time).
14
15       Process time is defined as the amount of CPU time used  by  a  process.
16       This  is  sometimes  divided into user and system components.  User CPU
17       time is the time spent executing code in user mode.  System CPU time is
18       the  time spent by the kernel executing in system mode on behalf of the
19       process (e.g., executing system calls).  The  time(1)  command  can  be
20       used  to determine the amount of CPU time consumed during the execution
21       of a program.  A program can determine the amount of CPU  time  it  has
22       consumed using times(2), getrusage(2), or clock(3).
23
24   The hardware clock
25       Most computers have a (battery-powered) hardware clock which the kernel
26       reads at boot time in order to initialize the software clock.  For fur‐
27       ther details, see rtc(4) and hwclock(8).
28
29   The software clock, HZ, and jiffies
30       The  accuracy  of  various  system  calls  that  set  timeouts,  (e.g.,
31       select(2), sigtimedwait(2)) and measure CPU time  (e.g.,  getrusage(2))
32       is  limited by the resolution of the software clock, a clock maintained
33       by the kernel which measures time in jiffies.  The size of a  jiffy  is
34       determined by the value of the kernel constant HZ.
35
36       The  value  of HZ varies across kernel versions and hardware platforms.
37       On i386 the situation is as follows: on kernels  up  to  and  including
38       2.4.x,  HZ was 100, giving a jiffy value of 0.01 seconds; starting with
39       2.6.0, HZ was raised to 1000, giving a jiffy of 0.001  seconds.   Since
40       kernel 2.6.13, the HZ value is a kernel configuration parameter and can
41       be 100, 250 (the default) or 1000, yielding a jiffies value of, respec‐
42       tively,  0.01, 0.004, or 0.001 seconds.  Since kernel 2.6.20, a further
43       frequency is available: 300, a number that divides evenly for the  com‐
44       mon video frame rates (PAL, 25 HZ; NTSC, 30 HZ).
45
46       The  times(2)  system  call is a special case.  It reports times with a
47       granularity defined by the kernel constant USER_HZ.  User-space  appli‐
48       cations    can   determine   the   value   of   this   constant   using
49       sysconf(_SC_CLK_TCK).
50
51   High-resolution timers
52       Before Linux 2.6.21, the accuracy of timer and sleep system calls  (see
53       below) was also limited by the size of the jiffy.
54
55       Since  Linux  2.6.21,  Linux  supports  high-resolution  timers (HRTs),
56       optionally configurable via CONFIG_HIGH_RES_TIMERS.  On a  system  that
57       supports  HRTs,  the  accuracy  of  sleep  and timer system calls is no
58       longer constrained by the jiffy, but instead can be as accurate as  the
59       hardware  allows  (microsecond accuracy is typical of modern hardware).
60       You can determine  whether  high-resolution  timers  are  supported  by
61       checking  the resolution returned by a call to clock_getres(2) or look‐
62       ing at the "resolution" entries in /proc/timer_list.
63
64       HRTs are not supported on all hardware architectures.  (Support is pro‐
65       vided on x86, arm, and powerpc, among others.)
66
67   The Epoch
68       UNIX  systems  represent  time  in  seconds since the Epoch, 1970-01-01
69       00:00:00 +0000 (UTC).
70
71       A program can determine the  calendar  time  via  the  clock_gettime(2)
72       CLOCK_REALTIME  clock,  which returns time (in seconds and nanoseconds)
73       that have elapsed since the Epoch; time(2)  provides  similar  informa‐
74       tion,  but  only  with accuracy to the nearest second.  The system time
75       can be changed using clock_settime(2).
76
77   Broken-down time
78       Certain library functions use a structure of type tm to represent  bro‐
79       ken-down time, which stores time value separated out into distinct com‐
80       ponents (year, month, day, hour, minute, second, etc.).  This structure
81       is  described  in ctime(3), which also describes functions that convert
82       between calendar time and broken-down time.  Functions  for  converting
83       between  broken-down  time  and printable string representations of the
84       time are described in ctime(3), strftime(3), and strptime(3).
85
86   Sleeping and setting timers
87       Various system calls and functions allow a program  to  sleep  (suspend
88       execution)   for   a   specified  period  of  time;  see  nanosleep(2),
89       clock_nanosleep(2), and sleep(3).
90
91       Various system calls allow a process to set a  timer  that  expires  at
92       some  point  in  the  future, and optionally at repeated intervals; see
93       alarm(2), getitimer(2), timerfd_create(2), and timer_create(2).
94
95   Timer slack
96       Since Linux 2.6.28, it is possible to control the "timer  slack"  value
97       for  a thread.  The timer slack is the length of time by which the ker‐
98       nel may delay the wake-up of certain system calls  that  block  with  a
99       timeout.   Permitting  this delay allows the kernel to coalesce wake-up
100       events, thus possibly reducing the number of system wake-ups and saving
101       power.   For  more details, see the description of PR_SET_TIMERSLACK in
102       prctl(2).
103

SEE ALSO

105       date(1), time(1), timeout(1), adjtimex(2), alarm(2), clock_gettime(2),
106       clock_nanosleep(2), getitimer(2), getrlimit(2), getrusage(2),
107       gettimeofday(2), nanosleep(2), stat(2), time(2), timer_create(2),
108       timerfd_create(2), times(2), utime(2), adjtime(3), clock(3),
109       clock_getcpuclockid(3), ctime(3), ntp_adjtime(3), ntp_gettime(3),
110       pthread_getcpuclockid(3), sleep(3), strftime(3), strptime(3),
111       timeradd(3), usleep(3), rtc(4), hwclock(8)
112

COLOPHON

114       This page is part of release 5.04 of the Linux man-pages project.  A
115       description of the project, information about reporting bugs, and the
116       latest version of this page, can be found at
117       https://www.kernel.org/doc/man-pages/.
118
119
120
121Linux                             2018-04-30                           TIME(7)
Impressum