]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/__ppc_get_timebase.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / __ppc_get_timebase.3
CommitLineData
42d7fb6c
TMQMF
1.\" Copyright (c) 2012, IBM Corporation.
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
e624ea57 4.\"
4c1c5274 5.TH __ppc_get_timebase 3 (date) "Linux man-pages (unreleased)"
42d7fb6c 6.SH NAME
1e6e3762 7__ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
1ae6b2c7 8of the Time Base Register on Power architecture and its frequency.
1133a86a
AC
9.SH LIBRARY
10Standard C library
8fc3b2cf 11.RI ( libc ", " \-lc )
42d7fb6c 12.SH SYNOPSIS
15d65653 13.nf
42d7fb6c 14.B #include <sys/platform/ppc.h>
68e4db0a 15.PP
1ae6b2c7
AC
16.B uint64_t __ppc_get_timebase(void);
17.B uint64_t __ppc_get_timebase_freq(void);
15d65653 18.fi
42d7fb6c 19.SH DESCRIPTION
e624ea57 20.BR __ppc_get_timebase ()
1e6e3762
TMQMF
21reads the current value of the Time Base Register and returns its
22value, while
23.BR __ppc_get_timebase_freq ()
24returns the frequency in which the Time Base Register is updated.
847e0d88 25.PP
e624ea57
MK
26The Time Base Register is a 64-bit register provided by Power Architecture
27processors.
28It stores a monotonically incremented value that is updated at a
42d7fb6c
TMQMF
29system-dependent frequency that may be different from the processor
30frequency.
31.SH RETURN VALUE
1e6e3762
TMQMF
32.BR __ppc_get_timebase ()
33returns a 64-bit unsigned integer that represents the current value of the
42d7fb6c 34Time Base Register.
847e0d88 35.PP
1e6e3762
TMQMF
36.BR __ppc_get_timebase_freq ()
37returns a 64-bit unsigned integer that represents the frequency at
38which the Time Base Register is updated.
42d7fb6c 39.SH VERSIONS
e624ea57
MK
40GNU C Library support for
41.\" commit d9dc34cd569bcfe714fe8c708e58c028106e8b2e
42.BR __ppc_get_timebase ()
1e6e3762
TMQMF
43has been provided since version 2.16 and
44.\" commit 8ad11b9a9cf1de82bd7771306b42070b91417c11
45.BR __ppc_get_timebase_freq ()
46has been available since version 2.17.
3113c7f3 47.SH STANDARDS
1e6e3762 48Both functions are nonstandard GNU extensions.
a14af333 49.SH EXAMPLES
1e6e3762 50The following program will calculate the time, in microseconds, spent
70a9fec7
MK
51between two calls to
52.BR __ppc_get_timebase ().
1e6e3762
TMQMF
53.SS Program source
54\&
b0b6ab4e 55.\" SRC BEGIN (__ppc_get_timebase.c)
e7d0bb47 56.EX
1e6e3762
TMQMF
57#include <inttypes.h>
58#include <stdint.h>
59#include <stdio.h>
56aa9a95 60#include <stdlib.h>
1e6e3762
TMQMF
61#include <sys/platform/ppc.h>
62
9ca13180 63/* Maximum value of the Time Base Register: 2\(ha60 \- 1.
56aa9a95 64 Source: POWER ISA. */
1e6e3762
TMQMF
65#define MAX_TB 0xFFFFFFFFFFFFFFF
66
67int
56aa9a95 68main(void)
1e6e3762 69{
56aa9a95 70 uint64_t tb1, tb2, diff;
0f6f10d5 71 uint64_t freq;
1e6e3762 72
0f6f10d5 73 freq = __ppc_get_timebase_freq();
d1a71985 74 printf("Time Base frequency = %"PRIu64" Hz\en", freq);
1e6e3762 75
56aa9a95 76 tb1 = __ppc_get_timebase();
1e6e3762 77
56aa9a95 78 // Do some stuff...
1e6e3762 79
56aa9a95 80 tb2 = __ppc_get_timebase();
1e6e3762 81
56aa9a95
MK
82 if (tb2 > tb1) {
83 diff = tb2 \- tb1;
84 } else {
85 /* Treat Time Base Register overflow. */
86 diff = (MAX_TB \- tb2) + tb1;
87 }
1e6e3762 88
d1a71985 89 printf("Elapsed time = %1.2f usecs\en",
96a4746d 90 (double) diff * 1000000 / freq);
1e6e3762 91
56aa9a95 92 exit(EXIT_SUCCESS);
1e6e3762 93}
e7d0bb47 94.EE
b0b6ab4e 95.\" SRC END
42d7fb6c
TMQMF
96.SH SEE ALSO
97.BR time (2),
98.BR usleep (3)