]>
Commit | Line | Data |
---|---|---|
42d7fb6c TMQMF |
1 | .\" Copyright (c) 2012, IBM Corporation. |
2 | .\" | |
e624ea57 | 3 | .\" %%%LICENSE_START(VERBATIM) |
42d7fb6c TMQMF |
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. | |
e624ea57 MK |
23 | .\" %%%LICENSE_END |
24 | .\" | |
4b8c67d9 | 25 | .TH __PPC_GET_TIMEBASE 3 2017-09-15 "GNU C Library" "Linux Programmer's\ |
42d7fb6c TMQMF |
26 | Manual" |
27 | .SH NAME | |
1e6e3762 TMQMF |
28 | __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value |
29 | of the Time Base Register on Power architecture and its frequency. | |
42d7fb6c TMQMF |
30 | .SH SYNOPSIS |
31 | .B #include <sys/platform/ppc.h> | |
68e4db0a | 32 | .PP |
42d7fb6c | 33 | .BI "uint64_t __ppc_get_timebase(void)" |
f90f031e | 34 | .PP |
1e6e3762 | 35 | .BI "uint64_t __ppc_get_timebase_freq(void);" |
42d7fb6c | 36 | .SH DESCRIPTION |
e624ea57 | 37 | .BR __ppc_get_timebase () |
1e6e3762 TMQMF |
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. | |
847e0d88 | 42 | .PP |
e624ea57 MK |
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 | |
42d7fb6c TMQMF |
46 | system-dependent frequency that may be different from the processor |
47 | frequency. | |
48 | .SH RETURN VALUE | |
1e6e3762 TMQMF |
49 | .BR __ppc_get_timebase () |
50 | returns a 64-bit unsigned integer that represents the current value of the | |
42d7fb6c | 51 | Time Base Register. |
847e0d88 | 52 | .PP |
1e6e3762 TMQMF |
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. | |
42d7fb6c | 56 | .SH VERSIONS |
e624ea57 MK |
57 | GNU C Library support for |
58 | .\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e | |
59 | .BR __ppc_get_timebase () | |
1e6e3762 TMQMF |
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. | |
42d7fb6c | 64 | .SH CONFORMING TO |
1e6e3762 TMQMF |
65 | Both functions are nonstandard GNU extensions. |
66 | .SH EXAMPLE | |
67 | The following program will calculate the time, in microseconds, spent | |
70a9fec7 MK |
68 | between two calls to |
69 | .BR __ppc_get_timebase (). | |
1e6e3762 TMQMF |
70 | .SS Program source |
71 | \& | |
e7d0bb47 | 72 | .EX |
1e6e3762 TMQMF |
73 | #include <inttypes.h> |
74 | #include <stdint.h> | |
75 | #include <stdio.h> | |
56aa9a95 | 76 | #include <stdlib.h> |
1e6e3762 TMQMF |
77 | #include <sys/platform/ppc.h> |
78 | ||
56aa9a95 MK |
79 | /* Maximum value of the Time Base Register: 2^60 \- 1. |
80 | Source: POWER ISA. */ | |
1e6e3762 TMQMF |
81 | #define MAX_TB 0xFFFFFFFFFFFFFFF |
82 | ||
83 | int | |
56aa9a95 | 84 | main(void) |
1e6e3762 | 85 | { |
56aa9a95 | 86 | uint64_t tb1, tb2, diff; |
1e6e3762 | 87 | |
56aa9a95 MK |
88 | uint64_t freq = __ppc_get_timebase_freq(); |
89 | printf("Time Base frequency = %"PRIu64" Hz\\n", freq); | |
1e6e3762 | 90 | |
56aa9a95 | 91 | tb1 = __ppc_get_timebase(); |
1e6e3762 | 92 | |
56aa9a95 | 93 | // Do some stuff... |
1e6e3762 | 94 | |
56aa9a95 | 95 | tb2 = __ppc_get_timebase(); |
1e6e3762 | 96 | |
56aa9a95 MK |
97 | if (tb2 > tb1) { |
98 | diff = tb2 \- tb1; | |
99 | } else { | |
100 | /* Treat Time Base Register overflow. */ | |
101 | diff = (MAX_TB \- tb2) + tb1; | |
102 | } | |
1e6e3762 | 103 | |
56aa9a95 MK |
104 | printf("Elapsed time = %1.2f usecs\\n", |
105 | (double) diff * 1000000 / freq ); | |
1e6e3762 | 106 | |
56aa9a95 | 107 | exit(EXIT_SUCCESS); |
1e6e3762 | 108 | } |
e7d0bb47 | 109 | .EE |
42d7fb6c TMQMF |
110 | .SH SEE ALSO |
111 | .BR time (2), | |
112 | .BR usleep (3) |