share/mk/: Fix includes
[man-pages.git] / man3 / __ppc_get_timebase.3
blobee922c13097da47dc7d51a92f8b5a3d320c9d4e1
1 .\" Copyright (c) 2012, IBM Corporation.
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH __ppc_get_timebase 3 (date) "Linux man-pages (unreleased)"
6 .SH NAME
7 __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
8 of the Time Base Register on Power architecture and its frequency.
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/platform/ppc.h>
16 .B uint64_t __ppc_get_timebase(void);
17 .B uint64_t __ppc_get_timebase_freq(void);
18 .fi
19 .SH DESCRIPTION
20 .BR __ppc_get_timebase ()
21 reads the current value of the Time Base Register and returns its
22 value, while
23 .BR __ppc_get_timebase_freq ()
24 returns the frequency in which the Time Base Register is updated.
26 The Time Base Register is a 64-bit register provided by Power Architecture
27 processors.
28 It stores a monotonically incremented value that is updated at a
29 system-dependent frequency that may be different from the processor
30 frequency.
31 .SH RETURN VALUE
32 .BR __ppc_get_timebase ()
33 returns a 64-bit unsigned integer that represents the current value of the
34 Time Base Register.
36 .BR __ppc_get_timebase_freq ()
37 returns a 64-bit unsigned integer that represents the frequency at
38 which the Time Base Register is updated.
39 .SH STANDARDS
40 GNU.
41 .SH HISTORY
42 .TP
43 .BR __ppc_get_timebase ()
44 .\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
45 glibc 2.16.
46 .TP
47 .BR __ppc_get_timebase_freq ()
48 .\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
49 glibc 2.17.
50 .SH EXAMPLES
51 The following program will calculate the time, in microseconds, spent
52 between two calls to
53 .BR __ppc_get_timebase ().
54 .SS Program source
56 .\" SRC BEGIN (__ppc_get_timebase.c)
57 .EX
58 #include <inttypes.h>
59 #include <stdint.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <sys/platform/ppc.h>
64 /* Maximum value of the Time Base Register: 2\[ha]60 \- 1.
65    Source: POWER ISA.  */
66 #define MAX_TB 0xFFFFFFFFFFFFFFF
68 int
69 main(void)
71     uint64_t tb1, tb2, diff;
72     uint64_t freq;
74     freq = __ppc_get_timebase_freq();
75     printf("Time Base frequency = %"PRIu64" Hz\en", freq);
77     tb1 = __ppc_get_timebase();
79     // Do some stuff...
81     tb2 = __ppc_get_timebase();
83     if (tb2 > tb1) {
84         diff = tb2 \- tb1;
85     } else {
86         /* Treat Time Base Register overflow.  */
87         diff = (MAX_TB \- tb2) + tb1;
88     }
90     printf("Elapsed time  = %1.2f usecs\en",
91            (double) diff * 1000000 / freq);
93     exit(EXIT_SUCCESS);
95 .EE
96 .\" SRC END
97 .SH SEE ALSO
98 .BR time (2),
99 .BR usleep (3)