__ppc_get_timebase(3) — Linux manual page

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | STANDARDS | HISTORY | EXAMPLES | SEE ALSO | COLOPHON

__ppc_get_timebase(3)   Library Functions Manual   __ppc_get_timebase(3)

NAME         top

       __ppc_get_timebase, __ppc_get_timebase_freq - get the current
       value of the Time Base Register on Power architecture and its
       frequency.

LIBRARY         top

       Standard C library (libc, -lc)

SYNOPSIS         top

       #include <sys/platform/ppc.h>

       uint64_t __ppc_get_timebase(void);
       uint64_t __ppc_get_timebase_freq(void);

DESCRIPTION         top

       __ppc_get_timebase() reads the current value of the Time Base
       Register and returns its value, while __ppc_get_timebase_freq()
       returns the frequency in which the Time Base Register is updated.

       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.

RETURN VALUE         top

       __ppc_get_timebase() returns a 64-bit unsigned integer that
       represents the current value of the Time Base Register.

       __ppc_get_timebase_freq() returns a 64-bit unsigned integer that
       represents the frequency at which the Time Base Register is
       updated.

STANDARDS         top

       GNU.

HISTORY         top

       __ppc_get_timebase()
              glibc 2.16.

       __ppc_get_timebase_freq()
              glibc 2.17.

EXAMPLES         top

       The following program will calculate the time, in microseconds,
       spent between two calls to __ppc_get_timebase().

   Program source

       #include <inttypes.h>
       #include <stdint.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <sys/platform/ppc.h>

       /* Maximum value of the Time Base Register: 2^60 - 1.
          Source: POWER ISA.  */
       #define MAX_TB 0xFFFFFFFFFFFFFFF

       int
       main(void)
       {
           uint64_t tb1, tb2, diff;
           uint64_t freq;

           freq = __ppc_get_timebase_freq();
           printf("Time Base frequency = %"PRIu64" Hz\n", freq);

           tb1 = __ppc_get_timebase();

           // Do some stuff...

           tb2 = __ppc_get_timebase();

           if (tb2 > tb1) {
               diff = tb2 - tb1;
           } else {
               /* Treat Time Base Register overflow.  */
               diff = (MAX_TB - tb2) + tb1;
           }

           printf("Elapsed time  = %1.2f usecs\n",
                  (double) diff * 1000000 / freq);

           exit(EXIT_SUCCESS);
       }

SEE ALSO         top

       time(2), usleep(3)

COLOPHON         top

       This page is part of the man-pages (Linux kernel and C library
       user-space interface documentation) project.  Information about
       the project can be found at 
       ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report
       for this manual page, see
       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
       This page was obtained from the tarball man-pages-6.9.1.tar.gz
       fetched from
       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
       2024-06-26.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-
       to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not
       part of the original manual page), send a mail to
       [email protected]

Linux man-pages 6.9.1          2024-06-15          __ppc_get_timebase(3)