]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - lib/libkvm/kvm_getpcpu.3
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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 .\" $FreeBSD$
30 .\"
31 .Dd February 12, 2014
32 .Dt KVM_GETPCPU 3
33 .Os
34 .Sh NAME
35 .Nm kvm_dpcpu_setcpu
36 .Nm kvm_getmaxcpu ,
37 .Nm kvm_getpcpu
38 .Nd access per-CPU data
39 .Sh LIBRARY
40 .Lb libkvm
41 .Sh SYNOPSIS
42 .In sys/param.h
43 .In sys/pcpu.h
44 .In sys/sysctl.h
45 .In kvm.h
46 .Ft int
47 .Fn kvm_dpcpu_setcpu "kvm_t *kd" "u_int cpu"
48 .Ft int
49 .Fn kvm_getmaxcpu "kvm_t *kd"
50 .Ft int
51 .Fn kvm_getncpus "kvm_t *kd"
52 .Ft void *
53 .Fn kvm_getpcpu "kvm_t *kd" "int cpu"
54 .Ft ssize_t
55 .Fn kvm_read_zpcpu "kvm_t *kd" "u_long base" "void *buf" "size_t size" "int cpu"
56 .Ft uint64_t
57 .Fn kvm_counter_u64_fetch "kvm_t *kd" "u_long base"
58 .Sh DESCRIPTION
59 The
60 .Fn kvm_dpcpu_setcpu ,
61 .Fn kvm_getmaxcpu ,
62 and
63 .Fn kvm_getpcpu
64 functions are used to access the per-CPU data of active processors in the
65 kernel indicated by
66 .Fa kd .
67 Per-CPU storage comes in two flavours: data stored directly in a
68 .Vt "struct pcpu"
69 associated with each CPU, and dynamic per-CPU storage (DPCPU), in which a
70 single kernel symbol refers to different data depending on what CPU it is
71 accessed from.
72 .Pp
73 The
74 .Fn kvm_getmaxcpu
75 function returns the maximum number of CPUs supported by the kernel.
76 .Pp
77 The
78 .Fn kvm_getncpus
79 function returns the current number of CPUs in the kernel.
80 .Pp
81 The
82 .Fn kvm_getpcpu
83 function returns a buffer holding the per-CPU data for a single CPU.
84 This buffer is described by the
85 .Vt "struct pcpu"
86 type.
87 The caller is responsible for releasing the buffer via a call to
88 .Xr free 3
89 when it is no longer needed.
90 If
91 .Fa cpu
92 is not active, then
93 .Dv NULL
94 is returned instead.
95 .Pp
96 The
97 .Fn kvm_read_zpcpu
98 function is used to obtain private per-CPU copy from a
99 .Dv UMA_ZONE_PCPU
100 .Xr zone 9 .
101 It takes
102 .Fa base
103 argument as base address of an allocation and copyies
104 .Fa size
105 bytes into
106 .Fa buf
107 from the part of allocation that is private to
108 .Fa cpu .
109 .Pp
110 The
111 .Fn kvm_counter_u64_fetch
112 function fetches value of a
113 .Xr counter 9
114 pointed by
115 .Fa base
116 address.
117 .Pp
118 Symbols for dynamic per-CPU data are accessed via
119 .Xr kvm_nlist 3
120 as with other symbols.
121 .Nm libkvm
122 maintains a notion of the "current CPU", set by
123 .Xr kvm_dpcpu_setcpu ,
124 which defaults to 0.
125 Once another CPU is selected,
126 .Xr kvm_nlist 3
127 will return pointers to that data on the appropriate CPU.
128 .Sh CACHING
129 .Fn kvm_getmaxcpu
130 and
131 .Fn kvm_getpcpu
132 cache the nlist values for various kernel variables which are
133 reused in successive calls.
134 You may call either function with
135 .Fa kd
136 set to
137 .Dv NULL
138 to clear this cache.
139 .Sh RETURN VALUES
140 On success, the
141 .Fn kvm_getmaxcpu
142 function returns the maximum number of CPUs supported by the kernel.
143 If an error occurs,
144 it returns -1 instead.
145 .Pp
146 On success, the
147 .Fn kvm_getpcpu
148 function returns a pointer to an allocated buffer or
149 .Dv NULL .
150 If an error occurs,
151 it returns -1 instead.
152 .Pp
153 On success, the
154 .Fn kvm_dpcpu_setcpu
155 call returns 0; if an error occurs, it returns -1 instead.
156 .Pp
157 On success, the
158 .Fn kvm_read_zpcpu
159 function returns number of bytes copied.
160 If an error occurs, it returns -1 instead.
161 .Pp
162 If any function encounters an error,
163 then an error message may be retrieved via
164 .Xr kvm_geterr 3 .
165 .Sh SEE ALSO
166 .Xr free 3 ,
167 .Xr kvm 3 ,
168 .Xr counter 9 ,
169 .Xr zone 9