Blame man3/__ppc_get_timebase.3

Packit 7cfc04
.\" Copyright (c) 2012, IBM Corporation.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of
Packit 7cfc04
.\" this manual under the conditions for verbatim copying, provided that
Packit 7cfc04
.\" the entire resulting derived work is distributed under the terms of
Packit 7cfc04
.\" a permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume.
Packit 7cfc04
.\" no responsibility for errors or omissions, or for damages resulting.
Packit 7cfc04
.\" from the use of the information contained herein.  The author(s) may.
Packit 7cfc04
.\" not have taken the same level of care in the production of this.
Packit 7cfc04
.\" manual, which is licensed free of charge, as they might when working.
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH __PPC_GET_TIMEBASE 3 2017-09-15 "GNU C Library" "Linux Programmer's\
Packit 7cfc04
Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
__ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
Packit 7cfc04
 of the Time Base Register on Power architecture and its frequency.
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <sys/platform/ppc.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "uint64_t __ppc_get_timebase(void)"
Packit 7cfc04
.PP
Packit 7cfc04
.BI "uint64_t __ppc_get_timebase_freq(void);"
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR __ppc_get_timebase ()
Packit 7cfc04
reads the current value of the Time Base Register and returns its
Packit 7cfc04
value, while
Packit 7cfc04
.BR __ppc_get_timebase_freq ()
Packit 7cfc04
returns the frequency in which the Time Base Register is updated.
Packit 7cfc04
.PP
Packit 7cfc04
The Time Base Register is a 64-bit register provided by Power Architecture
Packit 7cfc04
processors.
Packit 7cfc04
It stores a monotonically incremented value that is updated at a
Packit 7cfc04
system-dependent frequency that may be different from the processor
Packit 7cfc04
frequency.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
.BR __ppc_get_timebase ()
Packit 7cfc04
returns a 64-bit unsigned integer that represents the current value of the
Packit 7cfc04
Time Base Register.
Packit 7cfc04
.PP
Packit 7cfc04
.BR __ppc_get_timebase_freq ()
Packit 7cfc04
returns a 64-bit unsigned integer that represents the frequency at
Packit 7cfc04
which the Time Base Register is updated.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
GNU C Library support for
Packit 7cfc04
.\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
Packit 7cfc04
.BR __ppc_get_timebase ()
Packit 7cfc04
has been provided since version 2.16 and
Packit 7cfc04
.\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
Packit 7cfc04
.BR __ppc_get_timebase_freq ()
Packit 7cfc04
has been available since version 2.17.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
Both functions are nonstandard GNU extensions.
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
The following program will calculate the time, in microseconds, spent
Packit 7cfc04
between two calls to
Packit 7cfc04
.BR __ppc_get_timebase ().
Packit 7cfc04
.SS Program source
Packit 7cfc04
\&
Packit 7cfc04
.EX
Packit 7cfc04
#include <inttypes.h>
Packit 7cfc04
#include <stdint.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <sys/platform/ppc.h>
Packit 7cfc04
Packit 7cfc04
/* Maximum value of the Time Base Register: 2^60 \- 1.
Packit 7cfc04
   Source: POWER ISA.  */
Packit 7cfc04
#define MAX_TB 0xFFFFFFFFFFFFFFF
Packit 7cfc04
Packit 7cfc04
int
Packit 7cfc04
main(void)
Packit 7cfc04
{
Packit 7cfc04
    uint64_t tb1, tb2, diff;
Packit 7cfc04
Packit 7cfc04
    uint64_t freq = __ppc_get_timebase_freq();
Packit 7cfc04
    printf("Time Base frequency = %"PRIu64" Hz\\n", freq);
Packit 7cfc04
Packit 7cfc04
    tb1 = __ppc_get_timebase();
Packit 7cfc04
Packit 7cfc04
    // Do some stuff...
Packit 7cfc04
Packit 7cfc04
    tb2 = __ppc_get_timebase();
Packit 7cfc04
Packit 7cfc04
    if (tb2 > tb1) {
Packit 7cfc04
        diff = tb2 \- tb1;
Packit 7cfc04
    } else {
Packit 7cfc04
        /* Treat Time Base Register overflow.  */
Packit 7cfc04
        diff = (MAX_TB \- tb2) + tb1;
Packit 7cfc04
    }
Packit 7cfc04
Packit 7cfc04
    printf("Elapsed time  = %1.2f usecs\\n",
Packit 7cfc04
            (double) diff * 1000000 / freq );
Packit 7cfc04
Packit 7cfc04
    exit(EXIT_SUCCESS);
Packit 7cfc04
}
Packit 7cfc04
.EE
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR time (2),
Packit 7cfc04
.BR usleep (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.