wait.2: Add ESRCH for when pid == INT_MIN
[man-pages.git] / man3 / __ppc_get_timebase.3
blob618ca74dcfaf3e6d12c92cc1d25e8f73c9019b30
1 .\" Copyright (c) 2012, IBM Corporation.
2 .\"
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.
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.
23 .\" %%%LICENSE_END
24 .\"
25 .TH __PPC_GET_TIMEBASE 3 2021-03-22 "GNU C Library" "Linux Programmer's\
26 Manual"
27 .SH NAME
28 __ppc_get_timebase, __ppc_get_timebase_freq \- get the current value
29  of the Time Base Register on Power architecture and its frequency.
30 .SH SYNOPSIS
31 .nf
32 .B #include <sys/platform/ppc.h>
33 .PP
34 .BI "uint64_t __ppc_get_timebase(void);"
35 .BI "uint64_t __ppc_get_timebase_freq(void);"
36 .fi
37 .SH DESCRIPTION
38 .BR __ppc_get_timebase ()
39 reads the current value of the Time Base Register and returns its
40 value, while
41 .BR __ppc_get_timebase_freq ()
42 returns the frequency in which the Time Base Register is updated.
43 .PP
44 The Time Base Register is a 64-bit register provided by Power Architecture
45 processors.
46 It stores a monotonically incremented value that is updated at a
47 system-dependent frequency that may be different from the processor
48 frequency.
49 .SH RETURN VALUE
50 .BR __ppc_get_timebase ()
51 returns a 64-bit unsigned integer that represents the current value of the
52 Time Base Register.
53 .PP
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.
57 .SH VERSIONS
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.
65 .SH CONFORMING TO
66 Both functions are nonstandard GNU extensions.
67 .SH EXAMPLES
68 The following program will calculate the time, in microseconds, spent
69 between two calls to
70 .BR __ppc_get_timebase ().
71 .SS Program source
73 .EX
74 #include <inttypes.h>
75 #include <stdint.h>
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <sys/platform/ppc.h>
80 /* Maximum value of the Time Base Register: 2\(ha60 \- 1.
81    Source: POWER ISA.  */
82 #define MAX_TB 0xFFFFFFFFFFFFFFF
84 int
85 main(void)
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();
94     // Do some stuff...
96     tb2 = __ppc_get_timebase();
98     if (tb2 > tb1) {
99         diff = tb2 \- tb1;
100     } else {
101         /* Treat Time Base Register overflow.  */
102         diff = (MAX_TB \- tb2) + tb1;
103     }
105     printf("Elapsed time  = %1.2f usecs\en",
106             (double) diff * 1000000 / freq );
108     exit(EXIT_SUCCESS);
111 .SH SEE ALSO
112 .BR time (2),
113 .BR usleep (3)