1__PPC_GET_TIMEBASE(3)      Linux Programmer'sManual      __PPC_GET_TIMEBASE(3)
2
3
4

NAME

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

SYNOPSIS

10       #include <sys/platform/ppc.h>
11
12       uint64_t __ppc_get_timebase(void);
13       uint64_t __ppc_get_timebase_freq(void);
14

DESCRIPTION

16       __ppc_get_timebase()  reads the current value of the Time Base Register
17       and returns its value, while __ppc_get_timebase_freq() returns the fre‐
18       quency in which the Time Base Register is updated.
19
20       The Time Base Register is a 64-bit register provided by Power Architec‐
21       ture processors.  It stores a monotonically incremented value  that  is
22       updated  at a system-dependent frequency that may be different from the
23       processor frequency.
24

RETURN VALUE

26       __ppc_get_timebase() returns a 64-bit unsigned integer that  represents
27       the current value of the Time Base Register.
28
29       __ppc_get_timebase_freq() returns a 64-bit unsigned integer that repre‐
30       sents the frequency at which the Time Base Register is updated.
31

VERSIONS

33       GNU C Library support for __ppc_get_timebase() has been provided  since
34       version  2.16  and  __ppc_get_timebase_freq()  has been available since
35       version 2.17.
36

CONFORMING TO

38       Both functions are nonstandard GNU extensions.
39

EXAMPLES

41       The following program will calculate the time, in  microseconds,  spent
42       between two calls to __ppc_get_timebase().
43
44   Program source
45
46       #include <inttypes.h>
47       #include <stdint.h>
48       #include <stdio.h>
49       #include <stdlib.h>
50       #include <sys/platform/ppc.h>
51
52       /* Maximum value of the Time Base Register: 2^60 - 1.
53          Source: POWER ISA.  */
54       #define MAX_TB 0xFFFFFFFFFFFFFFF
55
56       int
57       main(void)
58       {
59           uint64_t tb1, tb2, diff;
60
61           uint64_t freq = __ppc_get_timebase_freq();
62           printf("Time Base frequency = %"PRIu64" Hz\n", freq);
63
64           tb1 = __ppc_get_timebase();
65
66           // Do some stuff...
67
68           tb2 = __ppc_get_timebase();
69
70           if (tb2 > tb1) {
71               diff = tb2 - tb1;
72           } else {
73               /* Treat Time Base Register overflow.  */
74               diff = (MAX_TB - tb2) + tb1;
75           }
76
77           printf("Elapsed time  = %1.2f usecs\n",
78                   (double) diff * 1000000 / freq );
79
80           exit(EXIT_SUCCESS);
81       }
82

SEE ALSO

84       time(2), usleep(3)
85

COLOPHON

87       This  page  is  part of release 5.12 of the Linux man-pages project.  A
88       description of the project, information about reporting bugs,  and  the
89       latest     version     of     this    page,    can    be    found    at
90       https://www.kernel.org/doc/man-pages/.
91
92
93
94GNU C Library                     2021-03-22             __PPC_GET_TIMEBASE(3)
Impressum