]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libkvm/kvm_getpcpu.3
Remove never implemented sbrk and sstk syscalls
[FreeBSD/FreeBSD.git] / lib / libkvm / kvm_getpcpu.3
1 .\" Copyright (c) 2008 Yahoo!, Inc.
2 .\" All rights reserved.
3 .\" Written by: John Baldwin <jhb@FreeBSD.org>
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. Neither the name of the author nor the names of any co-contributors
14 .\"    may be used to endorse or promote products derived from this software
15 .\"    without specific prior written permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .Dd March 15, 2017
30 .Dt KVM_GETPCPU 3
31 .Os
32 .Sh NAME
33 .Nm kvm_dpcpu_setcpu ,
34 .Nm kvm_getmaxcpu ,
35 .Nm kvm_getpcpu
36 .Nd access per-CPU data
37 .Sh LIBRARY
38 .Lb libkvm
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/pcpu.h
42 .In sys/sysctl.h
43 .In kvm.h
44 .Ft int
45 .Fn kvm_dpcpu_setcpu "kvm_t *kd" "u_int cpu"
46 .Ft int
47 .Fn kvm_getmaxcpu "kvm_t *kd"
48 .Ft int
49 .Fn kvm_getncpus "kvm_t *kd"
50 .Ft void *
51 .Fn kvm_getpcpu "kvm_t *kd" "int cpu"
52 .Ft ssize_t
53 .Fn kvm_read_zpcpu "kvm_t *kd" "u_long base" "void *buf" "size_t size" "int cpu"
54 .Ft uint64_t
55 .Fn kvm_counter_u64_fetch "kvm_t *kd" "u_long base"
56 .Sh DESCRIPTION
57 The
58 .Fn kvm_dpcpu_setcpu ,
59 .Fn kvm_getmaxcpu ,
60 and
61 .Fn kvm_getpcpu
62 functions are used to access the per-CPU data of active processors in the
63 kernel indicated by
64 .Fa kd .
65 Per-CPU storage comes in two flavours: data stored directly in a
66 .Vt "struct pcpu"
67 associated with each CPU, and dynamic per-CPU storage (DPCPU), in which a
68 single kernel symbol refers to different data depending on what CPU it is
69 accessed from.
70 .Pp
71 The
72 .Fn kvm_getmaxcpu
73 function returns the maximum number of CPUs supported by the kernel.
74 .Pp
75 The
76 .Fn kvm_getncpus
77 function returns the current number of CPUs in the kernel.
78 .Pp
79 The
80 .Fn kvm_getpcpu
81 function returns a buffer holding the per-CPU data for a single CPU.
82 This buffer is described by the
83 .Vt "struct pcpu"
84 type.
85 The caller is responsible for releasing the buffer via a call to
86 .Xr free 3
87 when it is no longer needed.
88 If
89 .Fa cpu
90 is not active, then
91 .Dv NULL
92 is returned instead.
93 .Pp
94 The
95 .Fn kvm_read_zpcpu
96 function is used to obtain private per-CPU copy from a
97 .Dv UMA_ZONE_PCPU
98 .Xr zone 9 .
99 It takes
100 .Fa base
101 argument as base address of an allocation and copyies
102 .Fa size
103 bytes into
104 .Fa buf
105 from the part of allocation that is private to
106 .Fa cpu .
107 .Pp
108 The
109 .Fn kvm_counter_u64_fetch
110 function fetches value of a
111 .Xr counter 9
112 pointed by
113 .Fa base
114 address.
115 .Pp
116 Symbols for dynamic per-CPU data are accessed via
117 .Xr kvm_nlist 3
118 as with other symbols.
119 .Nm libkvm
120 maintains a notion of the "current CPU", set by
121 .Fn kvm_dpcpu_setcpu ,
122 which defaults to 0.
123 Once another CPU is selected,
124 .Xr kvm_nlist 3
125 will return pointers to that data on the appropriate CPU.
126 .Sh CACHING
127 .Fn kvm_getmaxcpu
128 and
129 .Fn kvm_getpcpu
130 cache the nlist values for various kernel variables which are
131 reused in successive calls.
132 You may call either function with
133 .Fa kd
134 set to
135 .Dv NULL
136 to clear this cache.
137 .Sh RETURN VALUES
138 On success, the
139 .Fn kvm_getmaxcpu
140 function returns the maximum number of CPUs supported by the kernel.
141 If an error occurs,
142 it returns -1 instead.
143 .Pp
144 On success, the
145 .Fn kvm_getpcpu
146 function returns a pointer to an allocated buffer or
147 .Dv NULL .
148 If an error occurs,
149 it returns -1 instead.
150 .Pp
151 On success, the
152 .Fn kvm_dpcpu_setcpu
153 call returns 0; if an error occurs, it returns -1 instead.
154 .Pp
155 On success, the
156 .Fn kvm_read_zpcpu
157 function returns number of bytes copied.
158 If an error occurs, it returns -1 instead.
159 .Pp
160 If any function encounters an error,
161 then an error message may be retrieved via
162 .Xr kvm_geterr 3 .
163 .Sh SEE ALSO
164 .Xr free 3 ,
165 .Xr kvm 3 ,
166 .Xr counter 9 ,
167 .Xr zone 9