1 .\" Copyright (c) 2012, IBM Corporation.
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH __ppc_get_timebase 3 (date) "Linux man-pages (unreleased)"
7 __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
8 of the Time Base Register on Power architecture and its frequency.
11 .RI ( libc ", " \-lc )
14 .B #include <sys/platform/ppc.h>
16 .B uint64_t __ppc_get_timebase(void);
17 .B uint64_t __ppc_get_timebase_freq(void);
20 .BR __ppc_get_timebase ()
21 reads the current value of the Time Base Register and returns its
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
28 It stores a monotonically incremented value that is updated at a
29 system-dependent frequency that may be different from the processor
32 .BR __ppc_get_timebase ()
33 returns a 64-bit unsigned integer that represents the current value of the
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.
43 .BR __ppc_get_timebase ()
44 .\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
47 .BR __ppc_get_timebase_freq ()
48 .\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
51 The following program will calculate the time, in microseconds, spent
53 .BR __ppc_get_timebase ().
56 .\" SRC BEGIN (__ppc_get_timebase.c)
62 #include <sys/platform/ppc.h>
64 /* Maximum value of the Time Base Register: 2\[ha]60 \- 1.
66 #define MAX_TB 0xFFFFFFFFFFFFFFF
71 uint64_t tb1, tb2, diff;
74 freq = __ppc_get_timebase_freq();
75 printf("Time Base frequency = %"PRIu64" Hz\en", freq);
77 tb1 = __ppc_get_timebase();
81 tb2 = __ppc_get_timebase();
86 /* Treat Time Base Register overflow. */
87 diff = (MAX_TB \- tb2) + tb1;
90 printf("Elapsed time = %1.2f usecs\en",
91 (double) diff * 1000000 / freq);