1__PPC_GET_TIMEBASE(3) Linux Programmer'sManual __PPC_GET_TIMEBASE(3)
2
3
4
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
10 #include <sys/platform/ppc.h>
11
12 uint64_t __ppc_get_timebase(void)
13
14 uint64_t __ppc_get_timebase_freq(void);
15
17 __ppc_get_timebase() reads the current value of the Time Base Register
18 and returns its value, while __ppc_get_timebase_freq() returns the fre‐
19 quency in which the Time Base Register is updated.
20
21 The Time Base Register is a 64-bit register provided by Power Architec‐
22 ture processors. It stores a monotonically incremented value that is
23 updated at a system-dependent frequency that may be different from the
24 processor frequency.
25
27 __ppc_get_timebase() returns a 64-bit unsigned integer that represents
28 the current value of the Time Base Register.
29
30 __ppc_get_timebase_freq() returns a 64-bit unsigned integer that repre‐
31 sents the frequency at which the Time Base Register is updated.
32
34 GNU C Library support for __ppc_get_timebase() has been provided since
35 version 2.16 and __ppc_get_timebase_freq() has been available since
36 version 2.17.
37
39 Both functions are nonstandard GNU extensions.
40
42 The following program will calculate the time, in microseconds, spent
43 between two calls to __ppc_get_timebase().
44
45 Program source
46
47 #include <inttypes.h>
48 #include <stdint.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <sys/platform/ppc.h>
52
53 /* Maximum value of the Time Base Register: 2^60 - 1.
54 Source: POWER ISA. */
55 #define MAX_TB 0xFFFFFFFFFFFFFFF
56
57 int
58 main(void)
59 {
60 uint64_t tb1, tb2, diff;
61
62 uint64_t freq = __ppc_get_timebase_freq();
63 printf("Time Base frequency = %"PRIu64" Hz\n", freq);
64
65 tb1 = __ppc_get_timebase();
66
67 // Do some stuff...
68
69 tb2 = __ppc_get_timebase();
70
71 if (tb2 > tb1) {
72 diff = tb2 - tb1;
73 } else {
74 /* Treat Time Base Register overflow. */
75 diff = (MAX_TB - tb2) + tb1;
76 }
77
78 printf("Elapsed time = %1.2f usecs\n",
79 (double) diff * 1000000 / freq );
80
81 exit(EXIT_SUCCESS);
82 }
83
85 time(2), usleep(3)
86
88 This page is part of release 5.07 of the Linux man-pages project. A
89 description of the project, information about reporting bugs, and the
90 latest version of this page, can be found at
91 https://www.kernel.org/doc/man-pages/.
92
93
94
95GNU C Library 2020-06-09 __PPC_GET_TIMEBASE(3)