1 .\" Copyright (c) 2012, IBM Corporation.
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.
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.
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.
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH __PPC_GET_TIMEBASE 3 2021-03-22 "GNU C Library" "Linux Programmer's\
28 __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
29 of the Time Base Register on Power architecture and its frequency.
32 .B #include <sys/platform/ppc.h>
34 .BI "uint64_t __ppc_get_timebase(void);"
35 .BI "uint64_t __ppc_get_timebase_freq(void);"
38 .BR __ppc_get_timebase ()
39 reads the current value of the Time Base Register and returns its
41 .BR __ppc_get_timebase_freq ()
42 returns the frequency in which the Time Base Register is updated.
44 The Time Base Register is a 64-bit register provided by Power Architecture
46 It stores a monotonically incremented value that is updated at a
47 system-dependent frequency that may be different from the processor
50 .BR __ppc_get_timebase ()
51 returns a 64-bit unsigned integer that represents the current value of the
54 .BR __ppc_get_timebase_freq ()
55 returns a 64-bit unsigned integer that represents the frequency at
56 which the Time Base Register is updated.
58 GNU C Library support for
59 .\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
60 .BR __ppc_get_timebase ()
61 has been provided since version 2.16 and
62 .\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
63 .BR __ppc_get_timebase_freq ()
64 has been available since version 2.17.
66 Both functions are nonstandard GNU extensions.
68 The following program will calculate the time, in microseconds, spent
70 .BR __ppc_get_timebase ().
78 #include <sys/platform/ppc.h>
80 /* Maximum value of the Time Base Register: 2\(ha60 \- 1.
82 #define MAX_TB 0xFFFFFFFFFFFFFFF
87 uint64_t tb1, tb2, diff;
89 uint64_t freq = __ppc_get_timebase_freq();
90 printf("Time Base frequency = %"PRIu64" Hz\en", freq);
92 tb1 = __ppc_get_timebase();
96 tb2 = __ppc_get_timebase();
101 /* Treat Time Base Register overflow. */
102 diff = (MAX_TB \- tb2) + tb1;
105 printf("Elapsed time = %1.2f usecs\en",
106 (double) diff * 1000000 / freq );