351 lines
10 KiB
HTML
351 lines
10 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of TIME</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>TIME</H1>
|
|
Section: Linux Programmer's Manual (7)<BR>Updated: 2018-04-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
time - overview of time and timers
|
|
<A NAME="lbAC"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H3>Real time and process time</H3>
|
|
|
|
<I>Real time</I>
|
|
|
|
is defined as time measured from some fixed point,
|
|
either from a standard point in the past
|
|
(see the description of the Epoch and calendar time below),
|
|
or from some point (e.g., the start) in the life of a process
|
|
(<I>elapsed time</I>).
|
|
|
|
<P>
|
|
|
|
<I>Process time</I>
|
|
|
|
is defined as the amount of CPU time used by a process.
|
|
This is sometimes divided into
|
|
<I>user</I>
|
|
|
|
and
|
|
<I>system</I>
|
|
|
|
components.
|
|
User CPU time is the time spent executing code in user mode.
|
|
System CPU time is the time spent by the kernel executing
|
|
in system mode on behalf of the process (e.g., executing system calls).
|
|
The
|
|
<B><A HREF="/cgi-bin/man/man2html?1+time">time</A></B>(1)
|
|
|
|
command can be used to determine the amount of CPU time consumed
|
|
during the execution of a program.
|
|
A program can determine the amount of CPU time it has consumed using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getrusage">getrusage</A></B>(2),
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+clock">clock</A></B>(3).
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>The hardware clock</H3>
|
|
|
|
Most computers have a (battery-powered) hardware clock which the kernel
|
|
reads at boot time in order to initialize the software clock.
|
|
For further details, see
|
|
<B><A HREF="/cgi-bin/man/man2html?4+rtc">rtc</A></B>(4)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?8+hwclock">hwclock</A></B>(8).
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>The software clock, HZ, and jiffies</H3>
|
|
|
|
The accuracy of various system calls that set timeouts,
|
|
(e.g.,
|
|
<B><A HREF="/cgi-bin/man/man2html?2+select">select</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigtimedwait">sigtimedwait</A></B>(2))
|
|
|
|
|
|
|
|
and measure CPU time (e.g.,
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getrusage">getrusage</A></B>(2))
|
|
|
|
is limited by the resolution of the
|
|
<I>software clock</I>,
|
|
|
|
a clock maintained by the kernel which measures time in
|
|
<I>jiffies</I>.
|
|
|
|
The size of a jiffy is determined by the value of the kernel constant
|
|
<I>HZ</I>.
|
|
|
|
<P>
|
|
|
|
The value of
|
|
<I>HZ</I>
|
|
|
|
varies across kernel versions and hardware platforms.
|
|
On i386 the situation is as follows:
|
|
on kernels up to and including 2.4.x, HZ was 100,
|
|
giving a jiffy value of 0.01 seconds;
|
|
starting with 2.6.0, HZ was raised to 1000, giving a jiffy of
|
|
0.001 seconds.
|
|
Since kernel 2.6.13, the HZ value is a kernel
|
|
configuration parameter and can be 100, 250 (the default) or 1000,
|
|
yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds.
|
|
Since kernel 2.6.20, a further frequency is available:
|
|
300, a number that divides evenly for the common video
|
|
frame rates (PAL, 25 HZ; NTSC, 30 HZ).
|
|
<P>
|
|
|
|
The
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2)
|
|
|
|
system call is a special case.
|
|
It reports times with a granularity defined by the kernel constant
|
|
<I>USER_HZ</I>.
|
|
|
|
User-space applications can determine the value of this constant using
|
|
<I>sysconf(_SC_CLK_TCK)</I>.
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>High-resolution timers</H3>
|
|
|
|
Before Linux 2.6.21, the accuracy of timer and sleep system calls
|
|
(see below) was also limited by the size of the jiffy.
|
|
<P>
|
|
|
|
Since Linux 2.6.21, Linux supports high-resolution timers (HRTs),
|
|
optionally configurable via
|
|
<B>CONFIG_HIGH_RES_TIMERS</B>.
|
|
|
|
On a system that supports HRTs, the accuracy of sleep and timer
|
|
system calls is no longer constrained by the jiffy,
|
|
but instead can be as accurate as the hardware allows
|
|
(microsecond accuracy is typical of modern hardware).
|
|
You can determine whether high-resolution timers are supported by
|
|
checking the resolution returned by a call to
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_getres">clock_getres</A></B>(2)
|
|
|
|
or looking at the "resolution" entries in
|
|
<I>/proc/timer_list</I>.
|
|
|
|
<P>
|
|
|
|
HRTs are not supported on all hardware architectures.
|
|
(Support is provided on x86, arm, and powerpc, among others.)
|
|
<A NAME="lbAH"> </A>
|
|
<H3>The Epoch</H3>
|
|
|
|
UNIX systems represent time in seconds since the
|
|
<I>Epoch</I>,
|
|
|
|
1970-01-01 00:00:00 +0000 (UTC).
|
|
<P>
|
|
|
|
A program can determine the
|
|
<I>calendar time</I>
|
|
|
|
via the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2)
|
|
|
|
<B>CLOCK_REALTIME</B>
|
|
|
|
clock,
|
|
which returns time (in seconds and nanoseconds) that have
|
|
elapsed since the Epoch;
|
|
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2)
|
|
|
|
provides similar information, but only with accuracy to the
|
|
nearest second.
|
|
The system time can be changed using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_settime">clock_settime</A></B>(2).
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Broken-down time</H3>
|
|
|
|
Certain library functions use a structure of
|
|
type
|
|
<I>tm</I>
|
|
|
|
to represent
|
|
<I>broken-down time</I>,
|
|
|
|
which stores time value separated out into distinct components
|
|
(year, month, day, hour, minute, second, etc.).
|
|
This structure is described in
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3),
|
|
|
|
which also describes functions that convert between calendar time and
|
|
broken-down time.
|
|
Functions for converting between broken-down time and printable
|
|
string representations of the time are described in
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strptime">strptime</A></B>(3).
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Sleeping and setting timers</H3>
|
|
|
|
Various system calls and functions allow a program to sleep
|
|
(suspend execution) for a specified period of time; see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+nanosleep">nanosleep</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_nanosleep">clock_nanosleep</A></B>(2),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sleep">sleep</A></B>(3).
|
|
|
|
<P>
|
|
|
|
Various system calls allow a process to set a timer that expires
|
|
at some point in the future, and optionally at repeated intervals;
|
|
see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+alarm">alarm</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getitimer">getitimer</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timerfd_create">timerfd_create</A></B>(2),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timer_create">timer_create</A></B>(2).
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Timer slack</H3>
|
|
|
|
Since Linux 2.6.28, it is possible to control the "timer slack"
|
|
value for a thread.
|
|
The timer slack is the length of time by
|
|
which the kernel may delay the wake-up of certain
|
|
system calls that block with a timeout.
|
|
Permitting this delay allows the kernel to coalesce wake-up events,
|
|
thus possibly reducing the number of system wake-ups and saving power.
|
|
For more details, see the description of
|
|
<B>PR_SET_TIMERSLACK</B>
|
|
|
|
in
|
|
<B><A HREF="/cgi-bin/man/man2html?2+prctl">prctl</A></B>(2).
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+date">date</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+time">time</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+timeout">timeout</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+adjtimex">adjtimex</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+alarm">alarm</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_nanosleep">clock_nanosleep</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getitimer">getitimer</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getrlimit">getrlimit</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getrusage">getrusage</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+gettimeofday">gettimeofday</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+nanosleep">nanosleep</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timer_create">timer_create</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timerfd_create">timerfd_create</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+utime">utime</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+adjtime">adjtime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+clock">clock</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+clock_getcpuclockid">clock_getcpuclockid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ntp_adjtime">ntp_adjtime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ntp_gettime">ntp_gettime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pthread_getcpuclockid">pthread_getcpuclockid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sleep">sleep</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strptime">strptime</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+timeradd">timeradd</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+usleep">usleep</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?4+rtc">rtc</A></B>(4),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+hwclock">hwclock</A></B>(8)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAD">Real time and process time</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">The hardware clock</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">The software clock, HZ, and jiffies</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">High-resolution timers</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">The Epoch</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">Broken-down time</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">Sleeping and setting timers</A><DD>
|
|
<DT id="10"><A HREF="#lbAK">Timer slack</A><DD>
|
|
</DL>
|
|
<DT id="11"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="12"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:06:10 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|