]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/sysctl.c
xnu-1228.9.59.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
CommitLineData
55e303ae 1/*
5d5c5d0d
A
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55e303ae 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
55e303ae
A
27 */
28
91447636 29#include <string.h>
55e303ae
A
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/sysctl.h>
33#include <i386/cpuid.h>
593a1d5f 34#include <i386/tsc.h>
55e303ae
A
35
36static int
37hw_cpu_sysctl SYSCTL_HANDLER_ARGS
38{
91447636
A
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;
55e303ae
A
42 int value;
43
91447636
A
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 }
55e303ae
A
52
53 if (arg2 == sizeof(uint8_t)) {
54 value = (uint32_t) *(uint8_t *)ptr;
55 ptr = &value;
56 arg2 = sizeof(uint32_t);
57 }
91447636 58 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
55e303ae
A
59}
60
61static int
62hw_cpu_features SYSCTL_HANDLER_ARGS
63{
91447636
A
64 __unused struct sysctl_oid *unused_oidp = oidp;
65 __unused void *unused_arg1 = arg1;
66 __unused int unused_arg2 = arg2;
55e303ae 67 char buf[256];
55e303ae 68
55e303ae 69 buf[0] = '\0';
91447636 70 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
55e303ae
A
71
72 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
73}
74
0c530ab8
A
75static int
76hw_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
2d21ac55
A
89static int
90hw_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
104SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
55e303ae
A
105 "CPU info");
106
107SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD,
108 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
109 hw_cpu_sysctl, "A", "CPU vendor");
110
111SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD,
112 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
113 hw_cpu_sysctl, "A", "CPU brand string");
114
55e303ae
A
115SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD,
116 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
117 hw_cpu_sysctl, "I", "CPU family");
118
119SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD,
120 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
121 hw_cpu_sysctl, "I", "CPU model");
122
123SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD,
124 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
125 hw_cpu_sysctl, "I", "CPU extended model");
126
127SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD,
128 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
129 hw_cpu_sysctl, "I", "CPU extended family");
130
131SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD,
132 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
133 hw_cpu_sysctl, "I", "CPU stepping");
134
0c530ab8
A
135SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
136 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
55e303ae
A
137 hw_cpu_sysctl, "I", "CPU features");
138
0c530ab8
A
139SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
140 (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
141 hw_cpu_sysctl, "I", "CPU extended features");
142
55e303ae
A
143SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD,
144 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
145 hw_cpu_sysctl, "I", "CPU signature");
146
147SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD,
148 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
149 hw_cpu_sysctl, "I", "CPU brand");
150
55e303ae
A
151SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
152 0, 0,
153 hw_cpu_features, "A", "CPU feature names");
154
0c530ab8
A
155SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
156 0, 0,
157 hw_cpu_extfeatures, "A", "CPU extended feature names");
158
159SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
160 CTLTYPE_INT | CTLFLAG_RD,
2d21ac55
A
161 0, 0,
162 hw_cpu_logical_per_package, "I", "CPU logical cpus per package");
0c530ab8
A
163
164SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
165 CTLTYPE_INT | CTLFLAG_RD,
166 (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package),
167 sizeof(uint32_t),
168 hw_cpu_sysctl, "I", "CPU cores per package");
169
593a1d5f
A
170SYSCTL_PROC(_machdep_cpu, OID_AUTO, microcode_version,
171 CTLTYPE_INT | CTLFLAG_RD,
172 (void *)offsetof(i386_cpu_info_t, cpuid_microcode_version),
173 sizeof(uint32_t),
174 hw_cpu_sysctl, "I", "Microcode version number");
175
55e303ae 176
2d21ac55
A
177SYSCTL_NODE(_machdep_cpu, OID_AUTO, mwait, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
178 "mwait");
179
180SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_min,
181 CTLTYPE_INT | CTLFLAG_RD,
182 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_min),
183 sizeof(uint32_t),
184 hw_cpu_sysctl, "I", "Monitor/mwait minimum line size");
185
186SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_max,
187 CTLTYPE_INT | CTLFLAG_RD,
188 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_linesize_max),
189 sizeof(uint32_t),
190 hw_cpu_sysctl, "I", "Monitor/mwait maximum line size");
191
192SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, extensions,
193 CTLTYPE_INT | CTLFLAG_RD,
194 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_extensions),
195 sizeof(uint32_t),
196 hw_cpu_sysctl, "I", "Monitor/mwait extensions");
197
198SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, sub_Cstates,
199 CTLTYPE_INT | CTLFLAG_RD,
200 (void *)offsetof(i386_cpu_info_t, cpuid_mwait_sub_Cstates),
201 sizeof(uint32_t),
202 hw_cpu_sysctl, "I", "Monitor/mwait sub C-states");
203
204
205SYSCTL_NODE(_machdep_cpu, OID_AUTO, thermal, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
206 "thermal");
207
208SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, sensor,
209 CTLTYPE_INT | CTLFLAG_RD,
210 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_sensor),
211 sizeof(boolean_t),
212 hw_cpu_sysctl, "I", "Thermal sensor present");
213
214SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, dynamic_acceleration,
215 CTLTYPE_INT | CTLFLAG_RD,
216 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_dynamic_acceleration),
217 sizeof(boolean_t),
218 hw_cpu_sysctl, "I", "Dynamic Acceleration Technology");
219
220SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, thresholds,
221 CTLTYPE_INT | CTLFLAG_RD,
222 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_thresholds),
223 sizeof(uint32_t),
224 hw_cpu_sysctl, "I", "Number of interrupt thresholds");
225
226SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, ACNT_MCNT,
227 CTLTYPE_INT | CTLFLAG_RD,
228 (void *)offsetof(i386_cpu_info_t, cpuid_thermal_ACNT_MCNT),
229 sizeof(boolean_t),
230 hw_cpu_sysctl, "I", "ACNT_MCNT capability");
231
232
233SYSCTL_NODE(_machdep_cpu, OID_AUTO, arch_perf, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
234 "arch_perf");
235
236SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, version,
237 CTLTYPE_INT | CTLFLAG_RD,
238 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_version),
239 sizeof(uint8_t),
240 hw_cpu_sysctl, "I", "Architectural Performance Version Number");
241
242SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, number,
243 CTLTYPE_INT | CTLFLAG_RD,
244 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_number),
245 sizeof(uint8_t),
246 hw_cpu_sysctl, "I", "Number of counters per logical cpu");
247
248SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, width,
249 CTLTYPE_INT | CTLFLAG_RD,
250 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_width),
251 sizeof(uint8_t),
252 hw_cpu_sysctl, "I", "Bit width of counters");
253
254SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events_number,
255 CTLTYPE_INT | CTLFLAG_RD,
256 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events_number),
257 sizeof(uint8_t),
258 hw_cpu_sysctl, "I", "Number of monitoring events");
259
260SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events,
261 CTLTYPE_INT | CTLFLAG_RD,
262 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_events),
263 sizeof(uint32_t),
264 hw_cpu_sysctl, "I", "Bit vector of events");
265
266SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_number,
267 CTLTYPE_INT | CTLFLAG_RD,
268 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_number),
269 sizeof(uint8_t),
270 hw_cpu_sysctl, "I", "Number of fixed-function counters");
271
272SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_width,
273 CTLTYPE_INT | CTLFLAG_RD,
274 (void *)offsetof(i386_cpu_info_t, cpuid_arch_perf_fixed_width),
275 sizeof(uint8_t),
276 hw_cpu_sysctl, "I", "Bit-width of fixed-function counters");
277
278
279SYSCTL_NODE(_machdep_cpu, OID_AUTO, cache, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
280 "cache");
281
282SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, linesize,
283 CTLTYPE_INT | CTLFLAG_RD,
284 (void *)offsetof(i386_cpu_info_t, cpuid_cache_linesize),
285 sizeof(uint32_t),
286 hw_cpu_sysctl, "I", "Cacheline size");
287
288SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, L2_associativity,
289 CTLTYPE_INT | CTLFLAG_RD,
290 (void *)offsetof(i386_cpu_info_t, cpuid_cache_L2_associativity),
291 sizeof(uint32_t),
292 hw_cpu_sysctl, "I", "L2 cache associativity");
293
294SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, size,
295 CTLTYPE_INT | CTLFLAG_RD,
296 (void *)offsetof(i386_cpu_info_t, cpuid_cache_size),
297 sizeof(uint32_t),
298 hw_cpu_sysctl, "I", "Cache size (in Kbytes)");
299
300
593a1d5f
A
301SYSCTL_NODE(_machdep_cpu, OID_AUTO, tlb, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
302 "tlb");
303
304SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, inst_small,
305 CTLTYPE_INT | CTLFLAG_RD,
306 (void *)offsetof(i386_cpu_info_t, cpuid_itlb_small),
307 sizeof(uint32_t),
308 hw_cpu_sysctl, "I", "Number of small page instruction TLBs");
309
310SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, data_small,
311 CTLTYPE_INT | CTLFLAG_RD,
312 (void *)offsetof(i386_cpu_info_t, cpuid_dtlb_small),
313 sizeof(uint32_t),
314 hw_cpu_sysctl, "I", "Number of small page data TLBs");
315
316SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, inst_large,
317 CTLTYPE_INT | CTLFLAG_RD,
318 (void *)offsetof(i386_cpu_info_t, cpuid_itlb_large),
319 sizeof(uint32_t),
320 hw_cpu_sysctl, "I", "Number of large page instruction TLBs");
321
322SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, data_large,
323 CTLTYPE_INT | CTLFLAG_RD,
324 (void *)offsetof(i386_cpu_info_t, cpuid_dtlb_large),
325 sizeof(uint32_t),
326 hw_cpu_sysctl, "I", "Number of large page data TLBs");
327
328
2d21ac55
A
329SYSCTL_NODE(_machdep_cpu, OID_AUTO, address_bits, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
330 "address_bits");
331
332SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, physical,
333 CTLTYPE_INT | CTLFLAG_RD,
334 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_physical),
335 sizeof(uint32_t),
336 hw_cpu_sysctl, "I", "Number of physical address bits");
337
338SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, virtual,
339 CTLTYPE_INT | CTLFLAG_RD,
340 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_virtual),
341 sizeof(uint32_t),
342 hw_cpu_sysctl, "I", "Number of virtual address bits");
343
593a1d5f
A
344SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count,
345 CTLTYPE_INT | CTLFLAG_RD,
346 (void *)offsetof(i386_cpu_info_t, core_count),
347 sizeof(uint32_t),
348 hw_cpu_sysctl, "I", "Number of enabled cores per package");
349
350SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count,
351 CTLTYPE_INT | CTLFLAG_RD,
352 (void *)offsetof(i386_cpu_info_t, thread_count),
353 sizeof(uint32_t),
354 hw_cpu_sysctl, "I", "Number of enabled threads per package");
355
356
2d21ac55
A
357uint64_t pmap_pv_hashlist_walks;
358uint64_t pmap_pv_hashlist_cnts;
359uint32_t pmap_pv_hashlist_max;
360
361/*extern struct sysctl_oid_list sysctl__machdep_pmap_children;*/
362
363SYSCTL_NODE(_machdep, OID_AUTO, pmap, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
364 "PMAP info");
55e303ae 365
2d21ac55
A
366SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashwalks, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_walks, "");
367SYSCTL_QUAD (_machdep_pmap, OID_AUTO, hashcnts, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_cnts, "");
368SYSCTL_INT (_machdep_pmap, OID_AUTO, hashmax, CTLFLAG_RD | CTLFLAG_KERN, &pmap_pv_hashlist_max, 0, "");