]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/sysctl.c
xnu-1228.12.14.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 #include <i386/tsc.h>
35
36 static int
37 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
38 {
39 __unused struct sysctl_oid *unused_oidp = oidp;
40 i386_cpu_info_t *cpu_info = cpuid_info();
41 void *ptr = (uint8_t *)cpu_info + (uint32_t)arg1;
42 int value;
43
44 if (arg2 == -1) {
45 ptr = *(char **)ptr;
46 arg2 = 0;
47 }
48
49 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
50 return ENOENT;
51 }
52
53 if (arg2 == sizeof(uint8_t)) {
54 value = (uint32_t) *(uint8_t *)ptr;
55 ptr = &value;
56 arg2 = sizeof(uint32_t);
57 }
58 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
59 }
60
61 static int
62 hw_cpu_features SYSCTL_HANDLER_ARGS
63 {
64 __unused struct sysctl_oid *unused_oidp = oidp;
65 __unused void *unused_arg1 = arg1;
66 __unused int unused_arg2 = arg2;
67 char buf[256];
68
69 buf[0] = '\0';
70 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
71
72 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
73 }
74
75 static int
76 hw_cpu_extfeatures SYSCTL_HANDLER_ARGS
77 {
78 __unused struct sysctl_oid *unused_oidp = oidp;
79 __unused void *unused_arg1 = arg1;
80 __unused int unused_arg2 = arg2;
81 char buf[256];
82
83 buf[0] = '\0';
84 cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf));
85
86 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
87 }
88
89 static int
90 hw_cpu_logical_per_package SYSCTL_HANDLER_ARGS
91 {
92 __unused struct sysctl_oid *unused_oidp = oidp;
93 __unused void *unused_arg1 = arg1;
94 __unused int unused_arg2 = arg2;
95 i386_cpu_info_t *cpu_info = cpuid_info();
96
97 if (!(cpuid_features() & CPUID_FEATURE_HTT))
98 return ENOENT;
99
100 return SYSCTL_OUT(req, &cpu_info->cpuid_logical_per_package,
101 sizeof(cpu_info->cpuid_logical_per_package));
102 }
103
104 static int
105 hw_cpu_sysctl_nehalem SYSCTL_HANDLER_ARGS
106 {
107 i386_cpu_info_t *cpu_info = cpuid_info();
108
109 if (cpu_info->cpuid_model != 26)
110 return ENOENT;
111
112 hw_cpu_sysctl(oidp, arg1, arg2, req);
113 }
114
115 static int
116 hw_cpu_flex_ratio_desired SYSCTL_HANDLER_ARGS
117 {
118 __unused struct sysctl_oid *unused_oidp = oidp;
119 __unused void *unused_arg1 = arg1;
120 __unused int unused_arg2 = arg2;
121 i386_cpu_info_t *cpu_info = cpuid_info();
122
123 if (cpu_info->cpuid_model != 26)
124 return ENOENT;
125
126 return SYSCTL_OUT(req, &flex_ratio, sizeof(flex_ratio));
127 }
128
129 static int
130 hw_cpu_flex_ratio_min SYSCTL_HANDLER_ARGS
131 {
132 __unused struct sysctl_oid *unused_oidp = oidp;
133 __unused void *unused_arg1 = arg1;
134 __unused int unused_arg2 = arg2;
135 i386_cpu_info_t *cpu_info = cpuid_info();
136
137 if (cpu_info->cpuid_model != 26)
138 return ENOENT;
139
140 return SYSCTL_OUT(req, &flex_ratio_min, sizeof(flex_ratio_min));
141 }
142
143 static int
144 hw_cpu_flex_ratio_max SYSCTL_HANDLER_ARGS
145 {
146 __unused struct sysctl_oid *unused_oidp = oidp;
147 __unused void *unused_arg1 = arg1;
148 __unused int unused_arg2 = arg2;
149 i386_cpu_info_t *cpu_info = cpuid_info();
150
151 if (cpu_info->cpuid_model != 26)
152 return ENOENT;
153
154 return SYSCTL_OUT(req, &flex_ratio_max, sizeof(flex_ratio_max));
155 }
156
157 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
158 "CPU info");
159
160 SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD,
161 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
162 hw_cpu_sysctl, "A", "CPU vendor");
163
164 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD,
165 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
166 hw_cpu_sysctl, "A", "CPU brand string");
167
168 SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD,
169 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
170 hw_cpu_sysctl, "I", "CPU family");
171
172 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD,
173 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
174 hw_cpu_sysctl, "I", "CPU model");
175
176 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD,
177 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
178 hw_cpu_sysctl, "I", "CPU extended model");
179
180 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD,
181 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
182 hw_cpu_sysctl, "I", "CPU extended family");
183
184 SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD,
185 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
186 hw_cpu_sysctl, "I", "CPU stepping");
187
188 SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
189 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
190 hw_cpu_sysctl, "I", "CPU features");
191
192 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
193 (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
194 hw_cpu_sysctl, "I", "CPU extended features");
195
196 SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD,
197 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
198 hw_cpu_sysctl, "I", "CPU signature");
199
200 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD,
201 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
202 hw_cpu_sysctl, "I", "CPU brand");
203
204 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
205 0, 0,
206 hw_cpu_features, "A", "CPU feature names");
207
208 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
209 0, 0,
210 hw_cpu_extfeatures, "A", "CPU extended feature names");
211
212 SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
213 CTLTYPE_INT | CTLFLAG_RD,
214 0, 0,
215 hw_cpu_logical_per_package, "I", "CPU logical cpus per package");
216
217 SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
218 CTLTYPE_INT | CTLFLAG_RD,
219 (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package),
220 sizeof(uint32_t),
221 hw_cpu_sysctl, "I", "CPU cores per package");
222
223 SYSCTL_PROC(_machdep_cpu, OID_AUTO, microcode_version,
224 CTLTYPE_INT | CTLFLAG_RD,
225 (void *)offsetof(i386_cpu_info_t, cpuid_microcode_version),
226 sizeof(uint32_t),
227 hw_cpu_sysctl, "I", "Microcode version number");
228
229
230 SYSCTL_NODE(_machdep_cpu, OID_AUTO, mwait, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
231 "mwait");
232
233 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_min,
234 CTLTYPE_INT | CTLFLAG_RD,
235 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_min),
236 sizeof(uint32_t),
237 hw_cpu_sysctl, "I", "Monitor/mwait minimum line size");
238
239 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_max,
240 CTLTYPE_INT | CTLFLAG_RD,
241 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_max),
242 sizeof(uint32_t),
243 hw_cpu_sysctl, "I", "Monitor/mwait maximum line size");
244
245 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, extensions,
246 CTLTYPE_INT | CTLFLAG_RD,
247 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_extensions),
248 sizeof(uint32_t),
249 hw_cpu_sysctl, "I", "Monitor/mwait extensions");
250
251 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, sub_Cstates,
252 CTLTYPE_INT | CTLFLAG_RD,
253 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_sub_Cstates),
254 sizeof(uint32_t),
255 hw_cpu_sysctl, "I", "Monitor/mwait sub C-states");
256
257
258 SYSCTL_NODE(_machdep_cpu, OID_AUTO, thermal, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
259 "thermal");
260
261 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, sensor,
262 CTLTYPE_INT | CTLFLAG_RD,
263 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_sensor),
264 sizeof(boolean_t),
265 hw_cpu_sysctl, "I", "Thermal sensor present");
266
267 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, dynamic_acceleration,
268 CTLTYPE_INT | CTLFLAG_RD,
269 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_dynamic_acceleration),
270 sizeof(boolean_t),
271 hw_cpu_sysctl, "I", "Dynamic Acceleration Technology");
272
273 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, thresholds,
274 CTLTYPE_INT | CTLFLAG_RD,
275 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_thresholds),
276 sizeof(uint32_t),
277 hw_cpu_sysctl, "I", "Number of interrupt thresholds");
278
279 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, ACNT_MCNT,
280 CTLTYPE_INT | CTLFLAG_RD,
281 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_ACNT_MCNT),
282 sizeof(boolean_t),
283 hw_cpu_sysctl, "I", "ACNT_MCNT capability");
284
285
286 SYSCTL_NODE(_machdep_cpu, OID_AUTO, arch_perf, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
287 "arch_perf");
288
289 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, version,
290 CTLTYPE_INT | CTLFLAG_RD,
291 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_version),
292 sizeof(uint8_t),
293 hw_cpu_sysctl, "I", "Architectural Performance Version Number");
294
295 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, number,
296 CTLTYPE_INT | CTLFLAG_RD,
297 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_number),
298 sizeof(uint8_t),
299 hw_cpu_sysctl, "I", "Number of counters per logical cpu");
300
301 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, width,
302 CTLTYPE_INT | CTLFLAG_RD,
303 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_width),
304 sizeof(uint8_t),
305 hw_cpu_sysctl, "I", "Bit width of counters");
306
307 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events_number,
308 CTLTYPE_INT | CTLFLAG_RD,
309 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events_number),
310 sizeof(uint8_t),
311 hw_cpu_sysctl, "I", "Number of monitoring events");
312
313 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events,
314 CTLTYPE_INT | CTLFLAG_RD,
315 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events),
316 sizeof(uint32_t),
317 hw_cpu_sysctl, "I", "Bit vector of events");
318
319 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_number,
320 CTLTYPE_INT | CTLFLAG_RD,
321 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_number),
322 sizeof(uint8_t),
323 hw_cpu_sysctl, "I", "Number of fixed-function counters");
324
325 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_width,
326 CTLTYPE_INT | CTLFLAG_RD,
327 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_width),
328 sizeof(uint8_t),
329 hw_cpu_sysctl, "I", "Bit-width of fixed-function counters");
330
331
332 SYSCTL_NODE(_machdep_cpu, OID_AUTO, cache, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
333 "cache");
334
335 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, linesize,
336 CTLTYPE_INT | CTLFLAG_RD,
337 (void *)offsetof(i386_cpu_info_t, cpuid_cache_linesize),
338 sizeof(uint32_t),
339 hw_cpu_sysctl, "I", "Cacheline size");
340
341 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, L2_associativity,
342 CTLTYPE_INT | CTLFLAG_RD,
343 (void *)offsetof(i386_cpu_info_t, cpuid_cache_L2_associativity),
344 sizeof(uint32_t),
345 hw_cpu_sysctl, "I", "L2 cache associativity");
346
347 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, size,
348 CTLTYPE_INT | CTLFLAG_RD,
349 (void *)offsetof(i386_cpu_info_t, cpuid_cache_size),
350 sizeof(uint32_t),
351 hw_cpu_sysctl, "I", "Cache size (in Kbytes)");
352
353
354 SYSCTL_NODE(_machdep_cpu, OID_AUTO, tlb, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
355 "tlb");
356
357 SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, inst_small,
358 CTLTYPE_INT | CTLFLAG_RD,
359 (void *)offsetof(i386_cpu_info_t, cpuid_itlb_small),
360 sizeof(uint32_t),
361 hw_cpu_sysctl, "I", "Number of small page instruction TLBs");
362
363 SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, data_small,
364 CTLTYPE_INT | CTLFLAG_RD,
365 (void *)offsetof(i386_cpu_info_t, cpuid_dtlb_small),
366 sizeof(uint32_t),
367 hw_cpu_sysctl, "I", "Number of small page data TLBs");
368
369 SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, inst_large,
370 CTLTYPE_INT | CTLFLAG_RD,
371 (void *)offsetof(i386_cpu_info_t, cpuid_itlb_large),
372 sizeof(uint32_t),
373 hw_cpu_sysctl, "I", "Number of large page instruction TLBs");
374
375 SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, data_large,
376 CTLTYPE_INT | CTLFLAG_RD,
377 (void *)offsetof(i386_cpu_info_t, cpuid_dtlb_large),
378 sizeof(uint32_t),
379 hw_cpu_sysctl, "I", "Number of large page data TLBs");
380
381
382 SYSCTL_NODE(_machdep_cpu, OID_AUTO, address_bits, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
383 "address_bits");
384
385 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, physical,
386 CTLTYPE_INT | CTLFLAG_RD,
387 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_physical),
388 sizeof(uint32_t),
389 hw_cpu_sysctl, "I", "Number of physical address bits");
390
391 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, virtual,
392 CTLTYPE_INT | CTLFLAG_RD,
393 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_virtual),
394 sizeof(uint32_t),
395 hw_cpu_sysctl, "I", "Number of virtual address bits");
396
397 SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count,
398 CTLTYPE_INT | CTLFLAG_RD,
399 (void *)offsetof(i386_cpu_info_t, core_count),
400 sizeof(uint32_t),
401 hw_cpu_sysctl, "I", "Number of enabled cores per package");
402
403 SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count,
404 CTLTYPE_INT | CTLFLAG_RD,
405 (void *)offsetof(i386_cpu_info_t, thread_count),
406 sizeof(uint32_t),
407 hw_cpu_sysctl, "I", "Number of enabled threads per package");
408
409 SYSCTL_NODE(_machdep_cpu, OID_AUTO, flex_ratio, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
410 "Flex ratio");
411
412 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, desired,
413 CTLTYPE_INT | CTLFLAG_RD,
414 0, 0,
415 hw_cpu_flex_ratio_desired, "I", "Flex ratio desired (0 disabled)");
416
417 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, min,
418 CTLTYPE_INT | CTLFLAG_RD,
419 0, 0,
420 hw_cpu_flex_ratio_min, "I", "Flex ratio min (efficiency)");
421
422 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, max,
423 CTLTYPE_INT | CTLFLAG_RD,
424 0, 0,
425 hw_cpu_flex_ratio_max, "I", "Flex ratio max (non-turbo)");
426
427 uint64_t pmap_pv_hashlist_walks;
428 uint64_t pmap_pv_hashlist_cnts;
429 uint32_t pmap_pv_hashlist_max;
430
431 /*extern struct sysctl_oid_list sysctl__machdep_pmap_children;*/
432
433 SYSCTL_NODE(_machdep, OID_AUTO, pmap, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
434 "PMAP info");
435
436 SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashwalks, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_walks, "");
437 SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashcnts, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_cnts, "");
438 SYSCTL_INT (_machdep_pmap, OID_AUTO, hashmax, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_max, 0, "");