]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/sysctl.c
xnu-1228.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <string.h>
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/sysctl.h>
33 #include <i386/cpuid.h>
34
35 static int
36 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
37 {
38 __unused struct sysctl_oid *unused_oidp = oidp;
39 i386_cpu_info_t *cpu_info = cpuid_info();
40 void *ptr = (uint8_t *)cpu_info + (uint32_t)arg1;
41 int value;
42
43 if (arg2 == -1) {
44 ptr = *(char **)ptr;
45 arg2 = 0;
46 }
47
48 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
49 return ENOENT;
50 }
51
52 if (arg2 == sizeof(uint8_t)) {
53 value = (uint32_t) *(uint8_t *)ptr;
54 ptr = &value;
55 arg2 = sizeof(uint32_t);
56 }
57 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
58 }
59
60 static int
61 hw_cpu_features SYSCTL_HANDLER_ARGS
62 {
63 __unused struct sysctl_oid *unused_oidp = oidp;
64 __unused void *unused_arg1 = arg1;
65 __unused int unused_arg2 = arg2;
66 char buf[256];
67
68 buf[0] = '\0';
69 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
70
71 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
72 }
73
74 static int
75 hw_cpu_extfeatures SYSCTL_HANDLER_ARGS
76 {
77 __unused struct sysctl_oid *unused_oidp = oidp;
78 __unused void *unused_arg1 = arg1;
79 __unused int unused_arg2 = arg2;
80 char buf[256];
81
82 buf[0] = '\0';
83 cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf));
84
85 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
86 }
87
88 static int
89 hw_cpu_logical_per_package SYSCTL_HANDLER_ARGS
90 {
91 __unused struct sysctl_oid *unused_oidp = oidp;
92 __unused void *unused_arg1 = arg1;
93 __unused int unused_arg2 = arg2;
94 i386_cpu_info_t *cpu_info = cpuid_info();
95
96 if (!(cpuid_features() & CPUID_FEATURE_HTT))
97 return ENOENT;
98
99 return SYSCTL_OUT(req, &cpu_info->cpuid_logical_per_package,
100 sizeof(cpu_info->cpuid_logical_per_package));
101 }
102
103 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
104 "CPU info");
105
106 SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD,
107 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
108 hw_cpu_sysctl, "A", "CPU vendor");
109
110 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD,
111 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
112 hw_cpu_sysctl, "A", "CPU brand string");
113
114 SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD,
115 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
116 hw_cpu_sysctl, "I", "CPU family");
117
118 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD,
119 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
120 hw_cpu_sysctl, "I", "CPU model");
121
122 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD,
123 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
124 hw_cpu_sysctl, "I", "CPU extended model");
125
126 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD,
127 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
128 hw_cpu_sysctl, "I", "CPU extended family");
129
130 SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD,
131 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
132 hw_cpu_sysctl, "I", "CPU stepping");
133
134 SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
135 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
136 hw_cpu_sysctl, "I", "CPU features");
137
138 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
139 (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
140 hw_cpu_sysctl, "I", "CPU extended features");
141
142 SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD,
143 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
144 hw_cpu_sysctl, "I", "CPU signature");
145
146 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD,
147 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
148 hw_cpu_sysctl, "I", "CPU brand");
149
150 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
151 0, 0,
152 hw_cpu_features, "A", "CPU feature names");
153
154 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
155 0, 0,
156 hw_cpu_extfeatures, "A", "CPU extended feature names");
157
158 SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
159 CTLTYPE_INT | CTLFLAG_RD,
160 0, 0,
161 hw_cpu_logical_per_package, "I", "CPU logical cpus per package");
162
163 SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
164 CTLTYPE_INT | CTLFLAG_RD,
165 (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package),
166 sizeof(uint32_t),
167 hw_cpu_sysctl, "I", "CPU cores per package");
168
169
170 SYSCTL_NODE(_machdep_cpu, OID_AUTO, mwait, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
171 "mwait");
172
173 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_min,
174 CTLTYPE_INT | CTLFLAG_RD,
175 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_min),
176 sizeof(uint32_t),
177 hw_cpu_sysctl, "I", "Monitor/mwait minimum line size");
178
179 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_max,
180 CTLTYPE_INT | CTLFLAG_RD,
181 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_max),
182 sizeof(uint32_t),
183 hw_cpu_sysctl, "I", "Monitor/mwait maximum line size");
184
185 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, extensions,
186 CTLTYPE_INT | CTLFLAG_RD,
187 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_extensions),
188 sizeof(uint32_t),
189 hw_cpu_sysctl, "I", "Monitor/mwait extensions");
190
191 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, sub_Cstates,
192 CTLTYPE_INT | CTLFLAG_RD,
193 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_sub_Cstates),
194 sizeof(uint32_t),
195 hw_cpu_sysctl, "I", "Monitor/mwait sub C-states");
196
197
198 SYSCTL_NODE(_machdep_cpu, OID_AUTO, thermal, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
199 "thermal");
200
201 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, sensor,
202 CTLTYPE_INT | CTLFLAG_RD,
203 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_sensor),
204 sizeof(boolean_t),
205 hw_cpu_sysctl, "I", "Thermal sensor present");
206
207 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, dynamic_acceleration,
208 CTLTYPE_INT | CTLFLAG_RD,
209 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_dynamic_acceleration),
210 sizeof(boolean_t),
211 hw_cpu_sysctl, "I", "Dynamic Acceleration Technology");
212
213 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, thresholds,
214 CTLTYPE_INT | CTLFLAG_RD,
215 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_thresholds),
216 sizeof(uint32_t),
217 hw_cpu_sysctl, "I", "Number of interrupt thresholds");
218
219 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, ACNT_MCNT,
220 CTLTYPE_INT | CTLFLAG_RD,
221 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_ACNT_MCNT),
222 sizeof(boolean_t),
223 hw_cpu_sysctl, "I", "ACNT_MCNT capability");
224
225
226 SYSCTL_NODE(_machdep_cpu, OID_AUTO, arch_perf, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
227 "arch_perf");
228
229 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, version,
230 CTLTYPE_INT | CTLFLAG_RD,
231 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_version),
232 sizeof(uint8_t),
233 hw_cpu_sysctl, "I", "Architectural Performance Version Number");
234
235 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, number,
236 CTLTYPE_INT | CTLFLAG_RD,
237 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_number),
238 sizeof(uint8_t),
239 hw_cpu_sysctl, "I", "Number of counters per logical cpu");
240
241 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, width,
242 CTLTYPE_INT | CTLFLAG_RD,
243 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_width),
244 sizeof(uint8_t),
245 hw_cpu_sysctl, "I", "Bit width of counters");
246
247 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events_number,
248 CTLTYPE_INT | CTLFLAG_RD,
249 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events_number),
250 sizeof(uint8_t),
251 hw_cpu_sysctl, "I", "Number of monitoring events");
252
253 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events,
254 CTLTYPE_INT | CTLFLAG_RD,
255 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events),
256 sizeof(uint32_t),
257 hw_cpu_sysctl, "I", "Bit vector of events");
258
259 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_number,
260 CTLTYPE_INT | CTLFLAG_RD,
261 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_number),
262 sizeof(uint8_t),
263 hw_cpu_sysctl, "I", "Number of fixed-function counters");
264
265 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_width,
266 CTLTYPE_INT | CTLFLAG_RD,
267 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_width),
268 sizeof(uint8_t),
269 hw_cpu_sysctl, "I", "Bit-width of fixed-function counters");
270
271
272 SYSCTL_NODE(_machdep_cpu, OID_AUTO, cache, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
273 "cache");
274
275 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, linesize,
276 CTLTYPE_INT | CTLFLAG_RD,
277 (void *)offsetof(i386_cpu_info_t, cpuid_cache_linesize),
278 sizeof(uint32_t),
279 hw_cpu_sysctl, "I", "Cacheline size");
280
281 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, L2_associativity,
282 CTLTYPE_INT | CTLFLAG_RD,
283 (void *)offsetof(i386_cpu_info_t, cpuid_cache_L2_associativity),
284 sizeof(uint32_t),
285 hw_cpu_sysctl, "I", "L2 cache associativity");
286
287 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, size,
288 CTLTYPE_INT | CTLFLAG_RD,
289 (void *)offsetof(i386_cpu_info_t, cpuid_cache_size),
290 sizeof(uint32_t),
291 hw_cpu_sysctl, "I", "Cache size (in Kbytes)");
292
293
294 SYSCTL_NODE(_machdep_cpu, OID_AUTO, address_bits, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
295 "address_bits");
296
297 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, physical,
298 CTLTYPE_INT | CTLFLAG_RD,
299 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_physical),
300 sizeof(uint32_t),
301 hw_cpu_sysctl, "I", "Number of physical address bits");
302
303 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, virtual,
304 CTLTYPE_INT | CTLFLAG_RD,
305 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_virtual),
306 sizeof(uint32_t),
307 hw_cpu_sysctl, "I", "Number of virtual address bits");
308
309 uint64_t pmap_pv_hashlist_walks;
310 uint64_t pmap_pv_hashlist_cnts;
311 uint32_t pmap_pv_hashlist_max;
312
313 /*extern struct sysctl_oid_list sysctl__machdep_pmap_children;*/
314
315 SYSCTL_NODE(_machdep, OID_AUTO, pmap, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
316 "PMAP info");
317
318 SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashwalks, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_walks, "");
319 SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashcnts, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_cnts, "");
320 SYSCTL_INT (_machdep_pmap, OID_AUTO, hashmax, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_max, 0, "");