Debian Codegraph @

upstream/debian-trixie/man3/__ppc_get_timebase.3

raw
1 .\" Copyright (c) 2012, IBM Corporation.
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH __ppc_get_timebase 3 2024-06-15 "Linux man-pages 6.9.1"
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>
15 .P
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.
25 .P
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.
35 .P
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
55 \&
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>
63 \&
64 /* Maximum value of the Time Base Register: 2\[ha]60 \- 1.
65 Source: POWER ISA. */
66 #define MAX_TB 0xFFFFFFFFFFFFFFF
67 \&
68 int
69 main(void)
70 {
71 uint64_t tb1, tb2, diff;
72 uint64_t freq;
73 \&
74 freq = __ppc_get_timebase_freq();
75 printf("Time Base frequency = %"PRIu64" Hz\[rs]n", freq);
76 \&
77 tb1 = __ppc_get_timebase();
78 \&
79 // Do some stuff...
80 \&
81 tb2 = __ppc_get_timebase();
82 \&
83 if (tb2 > tb1) {
84 diff = tb2 \- tb1;
85 } else {
86 /* Treat Time Base Register overflow. */
87 diff = (MAX_TB \- tb2) + tb1;
88 }
89 \&
90 printf("Elapsed time = %1.2f usecs\[rs]n",
91 (double) diff * 1000000 / freq);
92 \&
93 exit(EXIT_SUCCESS);
94 }
95 .EE
96 .\" SRC END
97 .SH SEE ALSO
98 .BR time (2),
99 .BR usleep (3)