| 1 |
.\" Copyright 2012, International Business Machines Corp. |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH __ppc_get_timebase 3 2026-02-16 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
__ppc_get_timebase, __ppc_get_timebase_freq \- get the current value |
| 9 |
of the Time Base Register on Power architecture and its frequency. |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <sys/platform/ppc.h> |
| 16 |
.P |
| 17 |
.B uint64_t __ppc_get_timebase(void); |
| 18 |
.B uint64_t __ppc_get_timebase_freq(void); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
.BR __ppc_get_timebase () |
| 22 |
reads the current value of the Time Base Register and returns its |
| 23 |
value, while |
| 24 |
.BR __ppc_get_timebase_freq () |
| 25 |
returns the frequency in which the Time Base Register is updated. |
| 26 |
.P |
| 27 |
The Time Base Register is a 64-bit register provided by Power Architecture |
| 28 |
processors. |
| 29 |
It stores a monotonically incremented value that is updated at a |
| 30 |
system-dependent frequency that may be different from the processor |
| 31 |
frequency. |
| 32 |
.SH RETURN VALUE |
| 33 |
.BR __ppc_get_timebase () |
| 34 |
returns a 64-bit unsigned integer that represents the current value of the |
| 35 |
Time Base Register. |
| 36 |
.P |
| 37 |
.BR __ppc_get_timebase_freq () |
| 38 |
returns a 64-bit unsigned integer that represents the frequency at |
| 39 |
which the Time Base Register is updated. |
| 40 |
.SH STANDARDS |
| 41 |
GNU. |
| 42 |
.SH HISTORY |
| 43 |
.TP |
| 44 |
.BR __ppc_get_timebase () |
| 45 |
.\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e |
| 46 |
glibc 2.16. |
| 47 |
.TP |
| 48 |
.BR __ppc_get_timebase_freq () |
| 49 |
.\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11 |
| 50 |
glibc 2.17. |
| 51 |
.SH EXAMPLES |
| 52 |
The following program will calculate the time, in microseconds, spent |
| 53 |
between two calls to |
| 54 |
.BR __ppc_get_timebase (). |
| 55 |
.SS Program source |
| 56 |
\& |
| 57 |
.\" SRC BEGIN (__ppc_get_timebase.c) |
| 58 |
.EX |
| 59 |
#include <inttypes.h> |
| 60 |
#include <stdint.h> |
| 61 |
#include <stdio.h> |
| 62 |
#include <stdlib.h> |
| 63 |
#include <sys/platform/ppc.h> |
| 64 |
\& |
| 65 |
/* Maximum value of the Time Base Register: 2\[ha]60 \- 1. |
| 66 |
Source: POWER ISA. */ |
| 67 |
#define MAX_TB 0xFFFFFFFFFFFFFFF |
| 68 |
\& |
| 69 |
int |
| 70 |
main(void) |
| 71 |
{ |
| 72 |
uint64_t tb1, tb2, diff; |
| 73 |
uint64_t freq; |
| 74 |
\& |
| 75 |
freq = __ppc_get_timebase_freq(); |
| 76 |
printf("Time Base frequency = %w64u Hz\[rs]n", freq); |
| 77 |
\& |
| 78 |
tb1 = __ppc_get_timebase(); |
| 79 |
\& |
| 80 |
// Do some stuff... |
| 81 |
\& |
| 82 |
tb2 = __ppc_get_timebase(); |
| 83 |
\& |
| 84 |
if (tb2 > tb1) { |
| 85 |
diff = tb2 \- tb1; |
| 86 |
} else { |
| 87 |
/* Treat Time Base Register overflow. */ |
| 88 |
diff = (MAX_TB \- tb2) + tb1; |
| 89 |
} |
| 90 |
\& |
| 91 |
printf("Elapsed time = %1.2f usecs\[rs]n", |
| 92 |
(double) diff * 1000000 / freq); |
| 93 |
\& |
| 94 |
exit(EXIT_SUCCESS); |
| 95 |
} |
| 96 |
.EE |
| 97 |
.\" SRC END |
| 98 |
.SH SEE ALSO |
| 99 |
.BR time (2), |
| 100 |
.BR usleep (3) |