]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/__ppc_get_timebase.3
CPU_SET.3, INFINITY.3, __ppc_get_timebase.3, __ppc_set_ppr_med.3, __ppc_yield.3,...
[thirdparty/man-pages.git] / man3 / __ppc_get_timebase.3
1 .\" Copyright (c) 2012, IBM Corporation.
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of
9 .\" this manual under the conditions for verbatim copying, provided that
10 .\" the entire resulting derived work is distributed under the terms of
11 .\" a permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume.
15 .\" no responsibility for errors or omissions, or for damages resulting.
16 .\" from the use of the information contained herein. The author(s) may.
17 .\" not have taken the same level of care in the production of this.
18 .\" manual, which is licensed free of charge, as they might when working.
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH __PPC_GET_TIMEBASE 3 2015-07-23 "GNU C Library" "Linux Programmer's\
26 Manual"
27 .SH NAME
28 __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
29 of the Time Base Register on Power architecture and its frequency.
30 .SH SYNOPSIS
31 .B #include <sys/platform/ppc.h>
32 .PP
33 .BI "uint64_t __ppc_get_timebase(void)"
34 .PP
35 .BI "uint64_t __ppc_get_timebase_freq(void);"
36 .SH DESCRIPTION
37 .BR __ppc_get_timebase ()
38 reads the current value of the Time Base Register and returns its
39 value, while
40 .BR __ppc_get_timebase_freq ()
41 returns the frequency in which the Time Base Register is updated.
42 .PP
43 The Time Base Register is a 64-bit register provided by Power Architecture
44 processors.
45 It stores a monotonically incremented value that is updated at a
46 system-dependent frequency that may be different from the processor
47 frequency.
48 .SH RETURN VALUE
49 .BR __ppc_get_timebase ()
50 returns a 64-bit unsigned integer that represents the current value of the
51 Time Base Register.
52 .PP
53 .BR __ppc_get_timebase_freq ()
54 returns a 64-bit unsigned integer that represents the frequency at
55 which the Time Base Register is updated.
56 .SH VERSIONS
57 GNU C Library support for
58 .\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
59 .BR __ppc_get_timebase ()
60 has been provided since version 2.16 and
61 .\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
62 .BR __ppc_get_timebase_freq ()
63 has been available since version 2.17.
64 .SH CONFORMING TO
65 Both functions are nonstandard GNU extensions.
66 .SH EXAMPLE
67 The following program will calculate the time, in microseconds, spent
68 between two calls to
69 .BR __ppc_get_timebase ().
70 .SS Program source
71 \&
72 .nf
73 #include <inttypes.h>
74 #include <stdint.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <sys/platform/ppc.h>
78
79 /* Maximum value of the Time Base Register: 2^60 \- 1.
80 Source: POWER ISA. */
81 #define MAX_TB 0xFFFFFFFFFFFFFFF
82
83 int
84 main(void)
85 {
86 uint64_t tb1, tb2, diff;
87
88 uint64_t freq = __ppc_get_timebase_freq();
89 printf("Time Base frequency = %"PRIu64" Hz\\n", freq);
90
91 tb1 = __ppc_get_timebase();
92
93 // Do some stuff...
94
95 tb2 = __ppc_get_timebase();
96
97 if (tb2 > tb1) {
98 diff = tb2 \- tb1;
99 } else {
100 /* Treat Time Base Register overflow. */
101 diff = (MAX_TB \- tb2) + tb1;
102 }
103
104 printf("Elapsed time = %1.2f usecs\\n",
105 (double) diff * 1000000 / freq );
106
107 exit(EXIT_SUCCESS);
108 }
109 .fi
110 .SH SEE ALSO
111 .BR time (2),
112 .BR usleep (3)