man-pages/man3/__ppc_get_timebase.3.html
2021-03-31 01:06:50 +01:00

166 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of __PPC_GET_TIMEBASE</TITLE>
</HEAD><BODY>
<H1>__PPC_GET_TIMEBASE</H1>
Section: Linux Programmer'sManual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
__ppc_get_timebase, __ppc_get_timebase_freq - get the current value
<BR>&nbsp;of&nbsp;the&nbsp;Time&nbsp;Base&nbsp;Register&nbsp;on&nbsp;Power&nbsp;architecture&nbsp;and&nbsp;its&nbsp;frequency.
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/platform/ppc.h">sys/platform/ppc.h</A>&gt;</B>
<P>
<B>uint64_t __ppc_get_timebase(void)</B>
<P>
<B>uint64_t __ppc_get_timebase_freq(void);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>__ppc_get_timebase</B>()
reads the current value of the Time Base Register and returns its
value, while
<B>__ppc_get_timebase_freq</B>()
returns the frequency in which the Time Base Register is updated.
<P>
The Time Base Register is a 64-bit register provided by Power Architecture
processors.
It stores a monotonically incremented value that is updated at a
system-dependent frequency that may be different from the processor
frequency.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>__ppc_get_timebase</B>()
returns a 64-bit unsigned integer that represents the current value of the
Time Base Register.
<P>
<B>__ppc_get_timebase_freq</B>()
returns a 64-bit unsigned integer that represents the frequency at
which the Time Base Register is updated.
<A NAME="lbAF">&nbsp;</A>
<H2>VERSIONS</H2>
GNU C Library support for
<B>__ppc_get_timebase</B>()
has been provided since version 2.16 and
<B>__ppc_get_timebase_freq</B>()
has been available since version 2.17.
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
Both functions are nonstandard GNU extensions.
<A NAME="lbAH">&nbsp;</A>
<H2>EXAMPLE</H2>
The following program will calculate the time, in microseconds, spent
between two calls to
<B>__ppc_get_timebase</B>().
<A NAME="lbAI">&nbsp;</A>
<H3>Program source</H3>
#include &lt;<A HREF="file:///usr/include/inttypes.h">inttypes.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdint.h">stdint.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/sys/platform/ppc.h">sys/platform/ppc.h</A>&gt;
<P>
/* Maximum value of the Time Base Register: 2^60 - 1.
<BR>&nbsp;&nbsp;&nbsp;Source:&nbsp;POWER&nbsp;ISA.&nbsp;&nbsp;*/
#define MAX_TB 0xFFFFFFFFFFFFFFF
<P>
int
main(void)
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint64_t&nbsp;tb1,&nbsp;tb2,&nbsp;diff;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint64_t&nbsp;freq&nbsp;=&nbsp;__ppc_get_timebase_freq();
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Time&nbsp;Base&nbsp;frequency&nbsp;=&nbsp;%&quot;PRIu64&quot;&nbsp;Hz\n&quot;,&nbsp;freq);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;tb1&nbsp;=&nbsp;__ppc_get_timebase();
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Do&nbsp;some&nbsp;stuff...
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;tb2&nbsp;=&nbsp;__ppc_get_timebase();
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(tb2&nbsp;&gt;&nbsp;tb1)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;diff&nbsp;=&nbsp;tb2&nbsp;-&nbsp;tb1;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Treat&nbsp;Time&nbsp;Base&nbsp;Register&nbsp;overflow.&nbsp;&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;diff&nbsp;=&nbsp;(MAX_TB&nbsp;-&nbsp;tb2)&nbsp;+&nbsp;tb1;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Elapsed&nbsp;time&nbsp;&nbsp;=&nbsp;%1.2f&nbsp;usecs\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(double)&nbsp;diff&nbsp;*&nbsp;1000000&nbsp;/&nbsp;freq&nbsp;);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+usleep">usleep</A></B>(3)
<A NAME="lbAK">&nbsp;</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">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">VERSIONS</A><DD>
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="7"><A HREF="#lbAH">EXAMPLE</A><DD>
<DL>
<DT id="8"><A HREF="#lbAI">Program source</A><DD>
</DL>
<DT id="9"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="10"><A HREF="#lbAK">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:05:52 GMT, March 31, 2021
</BODY>
</HTML>