1 /*
2 * Copyright (c) 2003-2020 Apple 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 #include <i386/rtclock_protos.h>
36 #include <i386/machine_routines.h>
37 #include <i386/pal_routines.h>
38 #include <i386/ucode.h>
39 #include <kern/clock.h>
40 #include <libkern/libkern.h>
41 #include <i386/lapic.h>
42 #include <i386/mp.h>
43 #include <kern/kalloc.h>
44 #include <i386/pmap.h>
45
46
47 static int
48 _i386_cpu_info SYSCTL_HANDLER_ARGS
49 {
50 __unused struct sysctl_oid *unused_oidp = oidp;
51 void *ptr = arg1;
52 int value;
53
54 if (arg2 == -1) {
55 ptr = *(void **)ptr;
56 arg2 = 0;
57 }
58
59 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
60 return ENOENT;
61 }
62
63 if (arg2 == sizeof(uint8_t)) {
64 value = (uint32_t) *(uint8_t *)ptr;
65 ptr = &value;
66 arg2 = sizeof(uint32_t);
67 }
68 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr) + 1);
69 }
70
71 static int
72 i386_cpu_info SYSCTL_HANDLER_ARGS
73 {
74 void *ptr = (uint8_t *)cpuid_info() + (uintptr_t)arg1;
75 return _i386_cpu_info(oidp, ptr, arg2, req);
76 }
77
78 static int
79 i386_cpu_info_nonzero SYSCTL_HANDLER_ARGS
80 {
81 void *ptr = (uint8_t *)cpuid_info() + (uintptr_t)arg1;
82 int value = *(uint32_t *)ptr;
83
84 if (value == 0) {
85 return ENOENT;
86 }
87
88 return _i386_cpu_info(oidp, ptr, arg2, req);
89 }
90 static int
91 cpu_mwait SYSCTL_HANDLER_ARGS
92 {
93 i386_cpu_info_t *cpu_info = cpuid_info();
94 void *ptr = (uint8_t *)cpu_info->cpuid_mwait_leafp + (uintptr_t)arg1;
95 if (cpu_info->cpuid_mwait_leafp == NULL) {
96 return ENOENT;
97 }
98 return _i386_cpu_info(oidp, ptr, arg2, req);
99 }
100
101 static int
102 cpu_thermal SYSCTL_HANDLER_ARGS
103 {
104 i386_cpu_info_t *cpu_info = cpuid_info();
105 void *ptr = (uint8_t *)cpu_info->cpuid_thermal_leafp + (uintptr_t)arg1;
106 if (cpu_info->cpuid_thermal_leafp == NULL) {
107 return ENOENT;
108 }
109 return _i386_cpu_info(oidp, ptr, arg2, req);
110 }
111
112 static int
113 cpu_arch_perf SYSCTL_HANDLER_ARGS
114 {
115 i386_cpu_info_t *cpu_info = cpuid_info();
116 void *ptr = (uint8_t *)cpu_info->cpuid_arch_perf_leafp + (uintptr_t)arg1;
117 if (cpu_info->cpuid_arch_perf_leafp == NULL) {
118 return ENOENT;
119 }
120 return _i386_cpu_info(oidp, ptr, arg2, req);
121 }
122
123 static int
124 cpu_xsave SYSCTL_HANDLER_ARGS
125 {
126 i386_cpu_info_t *cpu_info = cpuid_info();
127 void *ptr = (uint8_t *)cpu_info->cpuid_xsave_leafp + (uintptr_t)arg1;
128 if (cpu_info->cpuid_xsave_leafp == NULL) {
129 return ENOENT;
130 }
131 return _i386_cpu_info(oidp, ptr, arg2, req);
132 }
133
134
135 static int
136 cpu_features SYSCTL_HANDLER_ARGS
137 {
138 __unused struct sysctl_oid *unused_oidp = oidp;
139 __unused void *unused_arg1 = arg1;
140 __unused int unused_arg2 = arg2;
141 char buf[512];
142
143 buf[0] = '\0';
144 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
145
146 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
147 }
148
149 static int
150 cpu_extfeatures SYSCTL_HANDLER_ARGS
151 {
152 __unused struct sysctl_oid *unused_oidp = oidp;
153 __unused void *unused_arg1 = arg1;
154 __unused int unused_arg2 = arg2;
155 char buf[512];
156
157 buf[0] = '\0';
158 cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf));
159
160 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
161 }
162
163 static int
164 cpu_leaf7_features SYSCTL_HANDLER_ARGS
165 {
166 __unused struct sysctl_oid *unused_oidp = oidp;
167 __unused void *unused_arg1 = arg1;
168 __unused int unused_arg2 = arg2;
169 char buf[512];
170
171 uint64_t leaf7_features = cpuid_info()->cpuid_leaf7_features;
172 uint64_t leaf7_extfeatures = cpuid_info()->cpuid_leaf7_extfeatures;
173 if (leaf7_features == 0 && leaf7_extfeatures == 0) {
174 return ENOENT;
175 }
176
177 buf[0] = '\0';
178 cpuid_get_leaf7_feature_names(leaf7_features, buf, sizeof(buf));
179 if (leaf7_extfeatures != 0) {
180 strlcat(buf, " ", sizeof(buf));
181 cpuid_get_leaf7_extfeature_names(leaf7_extfeatures, buf + strlen(buf),
182 (unsigned int)(sizeof(buf) - strlen(buf)));
183 }
184
185 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
186 }
187
188 static int
189 cpu_logical_per_package SYSCTL_HANDLER_ARGS
190 {
191 __unused struct sysctl_oid *unused_oidp = oidp;
192 __unused void *unused_arg1 = arg1;
193 __unused int unused_arg2 = arg2;
194 i386_cpu_info_t *cpu_info = cpuid_info();
195
196 if (!(cpuid_features() & CPUID_FEATURE_HTT)) {
197 return ENOENT;
198 }
199
200 return SYSCTL_OUT(req, &cpu_info->cpuid_logical_per_package,
201 sizeof(cpu_info->cpuid_logical_per_package));
202 }
203
204 static int
205 cpu_flex_ratio_desired SYSCTL_HANDLER_ARGS
206 {
207 __unused struct sysctl_oid *unused_oidp = oidp;
208 __unused void *unused_arg1 = arg1;
209 __unused int unused_arg2 = arg2;
210 i386_cpu_info_t *cpu_info = cpuid_info();
211
212 if (cpu_info->cpuid_model != 26) {
213 return ENOENT;
214 }
215
216 return SYSCTL_OUT(req, &flex_ratio, sizeof(flex_ratio));
217 }
218
219 static int
220 cpu_flex_ratio_min SYSCTL_HANDLER_ARGS
221 {
222 __unused struct sysctl_oid *unused_oidp = oidp;
223 __unused void *unused_arg1 = arg1;
224 __unused int unused_arg2 = arg2;
225 i386_cpu_info_t *cpu_info = cpuid_info();
226
227 if (cpu_info->cpuid_model != 26) {
228 return ENOENT;
229 }
230
231 return SYSCTL_OUT(req, &flex_ratio_min, sizeof(flex_ratio_min));
232 }
233
234 static int
235 cpu_flex_ratio_max SYSCTL_HANDLER_ARGS
236 {
237 __unused struct sysctl_oid *unused_oidp = oidp;
238 __unused void *unused_arg1 = arg1;
239 __unused int unused_arg2 = arg2;
240 i386_cpu_info_t *cpu_info = cpuid_info();
241
242 if (cpu_info->cpuid_model != 26) {
243 return ENOENT;
244 }
245
246 return SYSCTL_OUT(req, &flex_ratio_max, sizeof(flex_ratio_max));
247 }
248
249 static int
250 cpu_ucode_update SYSCTL_HANDLER_ARGS
251 {
252 #pragma unused(oidp, arg1, arg2)
253 uint64_t addr;
254 int error;
255
256 /* Can't update microcode from within a VM. */
257
258 if (cpuid_features() & CPUID_FEATURE_VMM) {
259 return ENODEV;
260 }
261
262 if (req->newptr == USER_ADDR_NULL) {
263 return EINVAL;
264 }
265
266 error = SYSCTL_IN(req, &addr, sizeof(addr));
267 if (error) {
268 return error;
269 }
270
271 return ucode_interface(addr);
272 }
273
274 extern uint64_t panic_restart_timeout;
275 static int
panic_set_restart_timeout(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)276 panic_set_restart_timeout(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
277 {
278 int new_value = 0, old_value = 0, changed = 0, error;
279 uint64_t nstime;
280
281 if (panic_restart_timeout) {
282 absolutetime_to_nanoseconds(panic_restart_timeout, &nstime);
283 old_value = (int)MIN(nstime / NSEC_PER_SEC, INT_MAX);
284 }
285
286 error = sysctl_io_number(req, old_value, sizeof(old_value), &new_value, &changed);
287 if (error == 0 && changed) {
288 if (new_value >= 0) {
289 nanoseconds_to_absolutetime(((uint64_t)new_value) * NSEC_PER_SEC, &panic_restart_timeout);
290 } else {
291 error = EDOM;
292 }
293 }
294 return error;
295 }
296
297 /*
298 * Populates the {CPU, vector, latency} triple for the maximum observed primary
299 * interrupt latency
300 */
301 static int
misc_interrupt_latency_max(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)302 misc_interrupt_latency_max(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
303 {
304 int changed = 0, error;
305 char buf[128];
306 buf[0] = '\0';
307
308 interrupt_populate_latency_stats(buf, sizeof(buf));
309
310 error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed);
311
312 if (error == 0 && changed) {
313 interrupt_reset_latency_stats();
314 }
315
316 return error;
317 }
318
319 #if DEVELOPMENT || DEBUG
320 /*
321 * Populates a string with each CPU's tsc synch delta.
322 */
323 static int
x86_cpu_tsc_deltas(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)324 x86_cpu_tsc_deltas(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
325 {
326 int err;
327 uint32_t ncpus = ml_wait_max_cpus();
328 uint32_t buflen = (2 /* hex digits */ * sizeof(uint64_t) + 3 /* for "0x" + " " */) * ncpus + 1;
329 char *buf = (char *)kalloc_data(buflen, Z_WAITOK);
330
331 cpu_data_tsc_sync_deltas_string(buf, buflen, 0, ncpus - 1);
332
333 err = sysctl_io_string(req, buf, buflen, 0, 0);
334
335 kfree_data(buf, buflen);
336
337 return err;
338 }
339
340 /*
341 * Triggers a machine-check exception - for a suitably configured kernel only.
342 */
343 extern void mca_exception_panic(void);
344 static int
misc_machine_check_panic(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)345 misc_machine_check_panic(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
346 {
347 int changed = 0, error;
348 char buf[128];
349 buf[0] = '\0';
350
351 error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed);
352
353 if (error == 0 && changed) {
354 mca_exception_panic();
355 }
356 return error;
357 }
358
359 /*
360 * Triggers a non-responsive processor timeout panic - for a suitably configured kernel only.
361 */
362 static uint64_t kernel_timeout_spin = 0;
363 static int
misc_kernel_timeout_spin(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)364 misc_kernel_timeout_spin(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
365 {
366 uint64_t old_value;
367 uint64_t new_value;
368 int changed = 0, error;
369 char buf[128];
370 buf[0] = '\0';
371
372 absolutetime_to_nanoseconds(kernel_timeout_spin, &old_value);
373
374 error = sysctl_io_number(req, old_value, sizeof(uint64_t), &new_value, &changed);
375 if (error == 0 && changed) {
376 nanoseconds_to_absolutetime(((uint64_t)new_value), &kernel_timeout_spin);
377 kernel_spin(kernel_timeout_spin);
378 }
379 return error;
380 }
381 #endif /* DEVELOPMENT || DEBUG */
382
383
384 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
385 "CPU info");
386
387 SYSCTL_PROC(_machdep_cpu, OID_AUTO, max_basic, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
388 (void *)offsetof(i386_cpu_info_t, cpuid_max_basic), sizeof(uint32_t),
389 i386_cpu_info, "IU", "Max Basic Information value");
390
391 SYSCTL_PROC(_machdep_cpu, OID_AUTO, max_ext, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
392 (void *)offsetof(i386_cpu_info_t, cpuid_max_ext), sizeof(uint32_t),
393 i386_cpu_info, "IU", "Max Extended Function Information value");
394
395 SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
396 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
397 i386_cpu_info, "A", "CPU vendor");
398
399 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
400 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
401 i386_cpu_info, "A", "CPU brand string");
402
403 SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
404 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
405 i386_cpu_info, "I", "CPU family");
406
407 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
408 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
409 i386_cpu_info, "I", "CPU model");
410
411 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
412 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
413 i386_cpu_info, "I", "CPU extended model");
414
415 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
416 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
417 i386_cpu_info, "I", "CPU extended family");
418
419 SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
420 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
421 i386_cpu_info, "I", "CPU stepping");
422
423 SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED,
424 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
425 i386_cpu_info, "IU", "CPU features");
426
427 SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_feature_bits,
428 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
429 (void *)offsetof(i386_cpu_info_t, cpuid_leaf7_features),
430 sizeof(uint64_t),
431 i386_cpu_info_nonzero, "IU", "CPU Leaf7 features [EBX ECX]");
432
433 SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_feature_bits_edx,
434 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
435 (void *)offsetof(i386_cpu_info_t, cpuid_leaf7_extfeatures),
436 sizeof(uint32_t),
437 i386_cpu_info_nonzero, "IU", "CPU Leaf7 features [EDX]");
438
439 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED,
440 (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
441 i386_cpu_info, "IU", "CPU extended features");
442
443 SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
444 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
445 i386_cpu_info, "I", "CPU signature");
446
447 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
448 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
449 i386_cpu_info, "I", "CPU brand");
450
451 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
452 0, 0,
453 cpu_features, "A", "CPU feature names");
454
455 SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_features,
456 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
457 0, 0,
458 cpu_leaf7_features, "A", "CPU Leaf7 feature names");
459
460 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
461 0, 0,
462 cpu_extfeatures, "A", "CPU extended feature names");
463
464 SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
465 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
466 0, 0,
467 cpu_logical_per_package, "I", "CPU logical cpus per package");
468
469 SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
470 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
471 (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package),
472 sizeof(uint32_t),
473 i386_cpu_info, "I", "CPU cores per package");
474
475 SYSCTL_PROC(_machdep_cpu, OID_AUTO, microcode_version,
476 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
477 (void *)offsetof(i386_cpu_info_t, cpuid_microcode_version),
478 sizeof(uint32_t),
479 i386_cpu_info, "I", "Microcode version number");
480
481 SYSCTL_PROC(_machdep_cpu, OID_AUTO, processor_flag,
482 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
483 (void *)offsetof(i386_cpu_info_t, cpuid_processor_flag),
484 sizeof(uint32_t),
485 i386_cpu_info, "I", "CPU processor flag");
486
487
488 SYSCTL_NODE(_machdep_cpu, OID_AUTO, mwait, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
489 "mwait");
490
491 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_min,
492 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
493 (void *)offsetof(cpuid_mwait_leaf_t, linesize_min),
494 sizeof(uint32_t),
495 cpu_mwait, "I", "Monitor/mwait minimum line size");
496
497 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, linesize_max,
498 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
499 (void *)offsetof(cpuid_mwait_leaf_t, linesize_max),
500 sizeof(uint32_t),
501 cpu_mwait, "I", "Monitor/mwait maximum line size");
502
503 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, extensions,
504 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
505 (void *)offsetof(cpuid_mwait_leaf_t, extensions),
506 sizeof(uint32_t),
507 cpu_mwait, "I", "Monitor/mwait extensions");
508
509 SYSCTL_PROC(_machdep_cpu_mwait, OID_AUTO, sub_Cstates,
510 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
511 (void *)offsetof(cpuid_mwait_leaf_t, sub_Cstates),
512 sizeof(uint32_t),
513 cpu_mwait, "I", "Monitor/mwait sub C-states");
514
515
516 SYSCTL_NODE(_machdep_cpu, OID_AUTO, thermal, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
517 "thermal");
518
519 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, sensor,
520 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
521 (void *)offsetof(cpuid_thermal_leaf_t, sensor),
522 sizeof(boolean_t),
523 cpu_thermal, "I", "Thermal sensor present");
524
525 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, dynamic_acceleration,
526 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
527 (void *)offsetof(cpuid_thermal_leaf_t, dynamic_acceleration),
528 sizeof(boolean_t),
529 cpu_thermal, "I", "Dynamic Acceleration Technology (Turbo Mode)");
530
531 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, invariant_APIC_timer,
532 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
533 (void *)offsetof(cpuid_thermal_leaf_t, invariant_APIC_timer),
534 sizeof(boolean_t),
535 cpu_thermal, "I", "Invariant APIC Timer");
536
537 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, thresholds,
538 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
539 (void *)offsetof(cpuid_thermal_leaf_t, thresholds),
540 sizeof(uint32_t),
541 cpu_thermal, "I", "Number of interrupt thresholds");
542
543 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, ACNT_MCNT,
544 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
545 (void *)offsetof(cpuid_thermal_leaf_t, ACNT_MCNT),
546 sizeof(boolean_t),
547 cpu_thermal, "I", "ACNT_MCNT capability");
548
549 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, core_power_limits,
550 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
551 (void *)offsetof(cpuid_thermal_leaf_t, core_power_limits),
552 sizeof(boolean_t),
553 cpu_thermal, "I", "Power Limit Notifications at a Core Level");
554
555 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, fine_grain_clock_mod,
556 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
557 (void *)offsetof(cpuid_thermal_leaf_t, fine_grain_clock_mod),
558 sizeof(boolean_t),
559 cpu_thermal, "I", "Fine Grain Clock Modulation");
560
561 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, package_thermal_intr,
562 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
563 (void *)offsetof(cpuid_thermal_leaf_t, package_thermal_intr),
564 sizeof(boolean_t),
565 cpu_thermal, "I", "Package Thermal interrupt and Status");
566
567 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, hardware_feedback,
568 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
569 (void *)offsetof(cpuid_thermal_leaf_t, hardware_feedback),
570 sizeof(boolean_t),
571 cpu_thermal, "I", "Hardware Coordination Feedback");
572
573 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, energy_policy,
574 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
575 (void *)offsetof(cpuid_thermal_leaf_t, energy_policy),
576 sizeof(boolean_t),
577 cpu_thermal, "I", "Energy Efficient Policy Support");
578
579 SYSCTL_NODE(_machdep_cpu, OID_AUTO, xsave, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
580 "xsave");
581
582 SYSCTL_PROC(_machdep_cpu_xsave, OID_AUTO, extended_state,
583 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
584 (void *) 0,
585 sizeof(cpuid_xsave_leaf_t),
586 cpu_xsave, "IU", "XSAVE Extended State Main Leaf");
587
588 SYSCTL_PROC(_machdep_cpu_xsave, OID_AUTO, extended_state1,
589 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
590 (void *) sizeof(cpuid_xsave_leaf_t),
591 sizeof(cpuid_xsave_leaf_t),
592 cpu_xsave, "IU", "XSAVE Extended State Sub-leaf 1");
593
594
595 SYSCTL_NODE(_machdep_cpu, OID_AUTO, arch_perf, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
596 "arch_perf");
597
598 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, version,
599 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
600 (void *)offsetof(cpuid_arch_perf_leaf_t, version),
601 sizeof(uint8_t),
602 cpu_arch_perf, "I", "Architectural Performance Version Number");
603
604 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, number,
605 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
606 (void *)offsetof(cpuid_arch_perf_leaf_t, number),
607 sizeof(uint8_t),
608 cpu_arch_perf, "I", "Number of counters per logical cpu");
609
610 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, width,
611 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
612 (void *)offsetof(cpuid_arch_perf_leaf_t, width),
613 sizeof(uint8_t),
614 cpu_arch_perf, "I", "Bit width of counters");
615
616 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events_number,
617 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
618 (void *)offsetof(cpuid_arch_perf_leaf_t, events_number),
619 sizeof(uint8_t),
620 cpu_arch_perf, "I", "Number of monitoring events");
621
622 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, events,
623 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
624 (void *)offsetof(cpuid_arch_perf_leaf_t, events),
625 sizeof(uint32_t),
626 cpu_arch_perf, "I", "Bit vector of events");
627
628 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_number,
629 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
630 (void *)offsetof(cpuid_arch_perf_leaf_t, fixed_number),
631 sizeof(uint8_t),
632 cpu_arch_perf, "I", "Number of fixed-function counters");
633
634 SYSCTL_PROC(_machdep_cpu_arch_perf, OID_AUTO, fixed_width,
635 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
636 (void *)offsetof(cpuid_arch_perf_leaf_t, fixed_width),
637 sizeof(uint8_t),
638 cpu_arch_perf, "I", "Bit-width of fixed-function counters");
639
640
641 SYSCTL_NODE(_machdep_cpu, OID_AUTO, cache, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
642 "cache");
643
644 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, linesize,
645 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
646 (void *)offsetof(i386_cpu_info_t, cpuid_cache_linesize),
647 sizeof(uint32_t),
648 i386_cpu_info, "I", "Cacheline size");
649
650 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, L2_associativity,
651 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
652 (void *)offsetof(i386_cpu_info_t, cpuid_cache_L2_associativity),
653 sizeof(uint32_t),
654 i386_cpu_info, "I", "L2 cache associativity");
655
656 SYSCTL_PROC(_machdep_cpu_cache, OID_AUTO, size,
657 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
658 (void *)offsetof(i386_cpu_info_t, cpuid_cache_size),
659 sizeof(uint32_t),
660 i386_cpu_info, "I", "Cache size (in Kbytes)");
661
662
663 SYSCTL_NODE(_machdep_cpu, OID_AUTO, tlb, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
664 "tlb");
665 SYSCTL_NODE(_machdep_cpu_tlb, OID_AUTO, inst, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
666 "inst");
667 SYSCTL_NODE(_machdep_cpu_tlb, OID_AUTO, data, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
668 "data");
669
670 SYSCTL_PROC(_machdep_cpu_tlb_inst, OID_AUTO, small,
671 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
672 (void *)offsetof(i386_cpu_info_t,
673 cpuid_tlb[TLB_INST][TLB_SMALL][0]),
674 sizeof(uint32_t),
675 i386_cpu_info_nonzero, "I",
676 "Number of small page instruction TLBs");
677
678 SYSCTL_PROC(_machdep_cpu_tlb_data, OID_AUTO, small,
679 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
680 (void *)offsetof(i386_cpu_info_t,
681 cpuid_tlb[TLB_DATA][TLB_SMALL][0]),
682 sizeof(uint32_t),
683 i386_cpu_info_nonzero, "I",
684 "Number of small page data TLBs (1st level)");
685
686 SYSCTL_PROC(_machdep_cpu_tlb_data, OID_AUTO, small_level1,
687 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
688 (void *)offsetof(i386_cpu_info_t,
689 cpuid_tlb[TLB_DATA][TLB_SMALL][1]),
690 sizeof(uint32_t),
691 i386_cpu_info_nonzero, "I",
692 "Number of small page data TLBs (2nd level)");
693
694 SYSCTL_PROC(_machdep_cpu_tlb_inst, OID_AUTO, large,
695 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
696 (void *)offsetof(i386_cpu_info_t,
697 cpuid_tlb[TLB_INST][TLB_LARGE][0]),
698 sizeof(uint32_t),
699 i386_cpu_info_nonzero, "I",
700 "Number of large page instruction TLBs");
701
702 SYSCTL_PROC(_machdep_cpu_tlb_data, OID_AUTO, large,
703 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
704 (void *)offsetof(i386_cpu_info_t,
705 cpuid_tlb[TLB_DATA][TLB_LARGE][0]),
706 sizeof(uint32_t),
707 i386_cpu_info_nonzero, "I",
708 "Number of large page data TLBs (1st level)");
709
710 SYSCTL_PROC(_machdep_cpu_tlb_data, OID_AUTO, large_level1,
711 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
712 (void *)offsetof(i386_cpu_info_t,
713 cpuid_tlb[TLB_DATA][TLB_LARGE][1]),
714 sizeof(uint32_t),
715 i386_cpu_info_nonzero, "I",
716 "Number of large page data TLBs (2nd level)");
717
718 SYSCTL_PROC(_machdep_cpu_tlb, OID_AUTO, shared,
719 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
720 (void *)offsetof(i386_cpu_info_t, cpuid_stlb),
721 sizeof(uint32_t),
722 i386_cpu_info_nonzero, "I",
723 "Number of shared TLBs");
724
725
726 SYSCTL_NODE(_machdep_cpu, OID_AUTO, address_bits, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
727 "address_bits");
728
729 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, physical,
730 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
731 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_physical),
732 sizeof(uint32_t),
733 i386_cpu_info, "I", "Number of physical address bits");
734
735 SYSCTL_PROC(_machdep_cpu_address_bits, OID_AUTO, virtual,
736 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
737 (void *)offsetof(i386_cpu_info_t, cpuid_address_bits_virtual),
738 sizeof(uint32_t),
739 i386_cpu_info, "I", "Number of virtual address bits");
740
741
742 SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count,
743 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
744 (void *)offsetof(i386_cpu_info_t, core_count),
745 sizeof(uint32_t),
746 i386_cpu_info, "I", "Number of enabled cores per package");
747
748 SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count,
749 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
750 (void *)offsetof(i386_cpu_info_t, thread_count),
751 sizeof(uint32_t),
752 i386_cpu_info, "I", "Number of enabled threads per package");
753
754 SYSCTL_NODE(_machdep_cpu, OID_AUTO, flex_ratio, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
755 "Flex ratio");
756
757 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, desired,
758 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
759 0, 0,
760 cpu_flex_ratio_desired, "I", "Flex ratio desired (0 disabled)");
761
762 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, min,
763 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
764 0, 0,
765 cpu_flex_ratio_min, "I", "Flex ratio min (efficiency)");
766
767 SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, max,
768 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
769 0, 0,
770 cpu_flex_ratio_max, "I", "Flex ratio max (non-turbo)");
771
772 SYSCTL_PROC(_machdep_cpu, OID_AUTO, ucupdate,
773 CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_LOCKED, 0, 0,
774 cpu_ucode_update, "S", "Microcode update interface");
775
776 SYSCTL_NODE(_machdep_cpu, OID_AUTO, tsc_ccc, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
777 "TSC/CCC frequency information");
778
779 SYSCTL_PROC(_machdep_cpu_tsc_ccc, OID_AUTO, numerator,
780 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
781 (void *)offsetof(i386_cpu_info_t, cpuid_tsc_leaf.numerator),
782 sizeof(uint32_t),
783 i386_cpu_info, "I", "Numerator of TSC/CCC ratio");
784
785 SYSCTL_PROC(_machdep_cpu_tsc_ccc, OID_AUTO, denominator,
786 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
787 (void *)offsetof(i386_cpu_info_t, cpuid_tsc_leaf.denominator),
788 sizeof(uint32_t),
789 i386_cpu_info, "I", "Denominator of TSC/CCC ratio");
790
791 static const uint32_t apic_timer_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_TIMER_INTERRUPT);
792 static const uint32_t apic_IPI_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_INTERPROCESSOR_INTERRUPT);
793
794 SYSCTL_NODE(_machdep, OID_AUTO, vectors, CTLFLAG_RD | CTLFLAG_LOCKED, 0,
795 "Interrupt vector assignments");
796
797 SYSCTL_UINT(_machdep_vectors, OID_AUTO, timer, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, __DECONST(uint32_t *, &apic_timer_vector), 0, "");
798 SYSCTL_UINT(_machdep_vectors, OID_AUTO, IPI, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, __DECONST(uint32_t *, &apic_IPI_vector), 0, "");
799
800 uint64_t pmap_pv_hashlist_walks;
801 uint64_t pmap_pv_hashlist_cnts;
802 uint32_t pmap_pv_hashlist_max;
803 uint32_t pmap_kernel_text_ps = PAGE_SIZE;
804 extern uint32_t pv_hashed_kern_low_water_mark;
805
806 /*extern struct sysctl_oid_list sysctl__machdep_pmap_children;*/
807
808 SYSCTL_NODE(_machdep, OID_AUTO, pmap, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
809 "PMAP info");
810
811 SYSCTL_QUAD(_machdep_pmap, OID_AUTO, hashwalks, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &pmap_pv_hashlist_walks, "");
812 SYSCTL_QUAD(_machdep_pmap, OID_AUTO, hashcnts, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &pmap_pv_hashlist_cnts, "");
813 SYSCTL_INT(_machdep_pmap, OID_AUTO, hashmax, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &pmap_pv_hashlist_max, 0, "");
814 SYSCTL_INT(_machdep_pmap, OID_AUTO, kernel_text_ps, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &pmap_kernel_text_ps, 0, "");
815 SYSCTL_INT(_machdep_pmap, OID_AUTO, kern_pv_reserve, CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED, &pv_hashed_kern_low_water_mark, 0, "");
816
817 SYSCTL_NODE(_machdep, OID_AUTO, memmap, CTLFLAG_RD | CTLFLAG_LOCKED, NULL, "physical memory map");
818
819 uint64_t firmware_Conventional_bytes = 0;
820 uint64_t firmware_RuntimeServices_bytes = 0;
821 uint64_t firmware_ACPIReclaim_bytes = 0;
822 uint64_t firmware_ACPINVS_bytes = 0;
823 uint64_t firmware_PalCode_bytes = 0;
824 uint64_t firmware_Reserved_bytes = 0;
825 uint64_t firmware_Unusable_bytes = 0;
826 uint64_t firmware_other_bytes = 0;
827
828 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Conventional, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_Conventional_bytes, "");
829 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, RuntimeServices, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_RuntimeServices_bytes, "");
830 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, ACPIReclaim, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_ACPIReclaim_bytes, "");
831 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, ACPINVS, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_ACPINVS_bytes, "");
832 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, PalCode, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_PalCode_bytes, "");
833 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Reserved, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_Reserved_bytes, "");
834 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Unusable, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_Unusable_bytes, "");
835 SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Other, CTLFLAG_RD | CTLFLAG_LOCKED, &firmware_other_bytes, "");
836
837 SYSCTL_NODE(_machdep, OID_AUTO, tsc, CTLFLAG_RD | CTLFLAG_LOCKED, NULL, "Timestamp counter parameters");
838
839 SYSCTL_QUAD(_machdep_tsc, OID_AUTO, frequency,
840 CTLFLAG_RD | CTLFLAG_LOCKED, &tscFreq, "");
841
842 extern uint32_t deep_idle_rebase;
843 SYSCTL_UINT(_machdep_tsc, OID_AUTO, deep_idle_rebase,
844 CTLFLAG_RD | CTLFLAG_LOCKED, &deep_idle_rebase, 0, "");
845 SYSCTL_QUAD(_machdep_tsc, OID_AUTO, at_boot,
846 CTLFLAG_RD | CTLFLAG_LOCKED, &tsc_at_boot, "");
847 SYSCTL_QUAD(_machdep_tsc, OID_AUTO, rebase_abs_time,
848 CTLFLAG_RD | CTLFLAG_LOCKED, &tsc_rebase_abs_time, "");
849 #if DEVELOPMENT || DEBUG
850 SYSCTL_PROC(_machdep_tsc, OID_AUTO, synch_deltas,
851 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
852 0, 0, x86_cpu_tsc_deltas, "A", "TSC synch deltas");
853 #endif
854
855 SYSCTL_NODE(_machdep_tsc, OID_AUTO, nanotime,
856 CTLFLAG_RD | CTLFLAG_LOCKED, NULL, "TSC to ns conversion");
857 SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, tsc_base,
858 CTLFLAG_RD | CTLFLAG_LOCKED,
859 __DECONST(uint64_t *, &pal_rtc_nanotime_info.tsc_base), "");
860 SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, ns_base,
861 CTLFLAG_RD | CTLFLAG_LOCKED,
862 __DECONST(uint64_t *, &pal_rtc_nanotime_info.ns_base), "");
863 SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, scale,
864 CTLFLAG_RD | CTLFLAG_LOCKED,
865 __DECONST(uint32_t *, &pal_rtc_nanotime_info.scale), 0, "");
866 SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, shift,
867 CTLFLAG_RD | CTLFLAG_LOCKED,
868 __DECONST(uint32_t *, &pal_rtc_nanotime_info.shift), 0, "");
869 SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, generation,
870 CTLFLAG_RD | CTLFLAG_LOCKED,
871 __DECONST(uint32_t *, &pal_rtc_nanotime_info.generation), 0, "");
872
873 SYSCTL_NODE(_machdep, OID_AUTO, misc, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
874 "Miscellaneous x86 kernel parameters");
875
876 #if (DEVELOPMENT || DEBUG)
877 extern uint32_t mp_interrupt_watchdog_events;
878 SYSCTL_UINT(_machdep_misc, OID_AUTO, interrupt_watchdog_events,
879 CTLFLAG_RW | CTLFLAG_LOCKED, &mp_interrupt_watchdog_events, 0, "");
880
881 extern int insnstream_force_cacheline_mismatch;
882 SYSCTL_INT(_machdep_misc, OID_AUTO, insnstream_force_clmismatch,
883 CTLFLAG_RW | CTLFLAG_LOCKED, &insnstream_force_cacheline_mismatch, 0, "");
884 #endif
885
886
887 SYSCTL_PROC(_machdep_misc, OID_AUTO, panic_restart_timeout,
888 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
889 0, 0,
890 panic_set_restart_timeout, "I", "Panic restart timeout in seconds");
891
892 SYSCTL_PROC(_machdep_misc, OID_AUTO, interrupt_latency_max,
893 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
894 0, 0,
895 misc_interrupt_latency_max, "A", "Maximum Interrupt latency");
896
897 extern boolean_t is_x2apic;
898 SYSCTL_INT(_machdep, OID_AUTO, x2apic_enabled,
899 CTLFLAG_KERN | CTLFLAG_RD | CTLFLAG_LOCKED,
900 &is_x2apic, 0, "");
901
902 #if DEVELOPMENT || DEBUG
903 SYSCTL_PROC(_machdep_misc, OID_AUTO, machine_check_panic,
904 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
905 0, 0,
906 misc_machine_check_panic, "A", "Machine-check exception test");
907
908 SYSCTL_PROC(_machdep_misc, OID_AUTO, kernel_timeout_spin,
909 CTLTYPE_QUAD | CTLFLAG_RW | CTLFLAG_LOCKED,
910 0, sizeof(kernel_timeout_spin),
911 misc_kernel_timeout_spin, "Q", "Kernel timeout panic test");
912
913 SYSCTL_QUAD(_machdep, OID_AUTO, reportphyreadabs,
914 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
915 &report_phy_read_delay, "");
916 SYSCTL_QUAD(_machdep, OID_AUTO, reportphywriteabs,
917 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
918 &report_phy_write_delay, "");
919 SYSCTL_QUAD(_machdep, OID_AUTO, tracephyreadabs,
920 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
921 &trace_phy_read_delay, "");
922 SYSCTL_QUAD(_machdep, OID_AUTO, tracephywriteabs,
923 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
924 &trace_phy_write_delay, "");
925 SYSCTL_INT(_machdep, OID_AUTO, phyreaddelaypanic,
926 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
927 &phy_read_panic, 0, "");
928 SYSCTL_INT(_machdep, OID_AUTO, phywritedelaypanic,
929 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
930 &phy_write_panic, 0, "");
931 #if DEVELOPMENT || DEBUG
932 extern uint64_t simulate_stretched_io;
933 SYSCTL_QUAD(_machdep, OID_AUTO, sim_stretched_io_ns,
934 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
935 &simulate_stretched_io, "");
936 #endif
937
938 extern int pmap_pagezero_mitigation;
939 extern int pmap_asserts_enabled, pmap_asserts_traced;
940 /* On DEV/DEBUG kernels, clear this to disable the SMAP emulation
941 * (address space disconnect) for pagezero-less processes.
942 */
943 SYSCTL_INT(_machdep, OID_AUTO, pmap_pagezero_mitigation,
944 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
945 &pmap_pagezero_mitigation, 0, "");
946 /* Toggle pmap assertions */
947 SYSCTL_INT(_machdep, OID_AUTO, pmap_asserts,
948 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
949 &pmap_asserts_enabled, 0, "");
950 /* Transform pmap assertions into kernel trace terminations */
951 SYSCTL_INT(_machdep, OID_AUTO, pmap_asserts_traced,
952 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
953 &pmap_asserts_traced, 0, "");
954
955 static int
misc_svisor_read(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)956 misc_svisor_read(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
957 {
958 uint64_t new_value = 0, old_value = 0;
959 int changed = 0, error;
960
961 error = sysctl_io_number(req, old_value, sizeof(uint64_t), &new_value, &changed);
962 if ((error == 0) && changed) {
963 volatile uint32_t *raddr = (uint32_t *) new_value;
964 printf("Supervisor: value at 0x%llx is 0x%x\n", new_value, *raddr);
965 }
966 return error;
967 }
968
969 SYSCTL_PROC(_machdep_misc, OID_AUTO, misc_svisor_read,
970 CTLTYPE_QUAD | CTLFLAG_RW | CTLFLAG_LOCKED,
971 0, 0,
972 misc_svisor_read, "I", "supervisor mode read");
973
974 #endif /* DEVELOPMENT || DEBUG */
975
976 extern void timer_queue_trace_cpu(int);
977 static int
misc_timer_queue_trace(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)978 misc_timer_queue_trace(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
979 {
980 int changed = 0, error;
981 char buf[128];
982 buf[0] = '\0';
983
984 error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed);
985
986 if (error == 0 && changed) {
987 timer_queue_trace_cpu(0);
988 }
989 return error;
990 }
991
992 SYSCTL_PROC(_machdep_misc, OID_AUTO, timer_queue_trace,
993 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,
994 0, 0,
995 misc_timer_queue_trace, "A", "Cut timer queue tracepoint");
996
997 extern long NMI_count;
998 extern void NMI_cpus(void);
999 static int
misc_nmis(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)1000 misc_nmis(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
1001 {
1002 int new = 0, old = 0, changed = 0, error;
1003
1004 old = (int)MIN(NMI_count, INT_MAX);
1005
1006 error = sysctl_io_number(req, old, sizeof(int), &new, &changed);
1007 if (error == 0 && changed) {
1008 NMI_cpus();
1009 }
1010
1011 return error;
1012 }
1013
1014 SYSCTL_PROC(_machdep_misc, OID_AUTO, nmis,
1015 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
1016 0, 0,
1017 misc_nmis, "I", "Report/increment NMI count");
1018
1019 /* Parameters related to timer coalescing tuning, to be replaced
1020 * with a dedicated systemcall in the future.
1021 */
1022 /* Enable processing pending timers in the context of any other interrupt */
1023 SYSCTL_INT(_kern, OID_AUTO, interrupt_timer_coalescing_enabled,
1024 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1025 &interrupt_timer_coalescing_enabled, 0, "");
1026 /* Upon entering idle, process pending timers with HW deadlines
1027 * this far in the future.
1028 */
1029 SYSCTL_INT(_kern, OID_AUTO, timer_coalesce_idle_entry_hard_deadline_max,
1030 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1031 &idle_entry_timer_processing_hdeadline_threshold, 0, "");
1032
1033 /* Track potentially expensive eager timer evaluations on QoS tier
1034 * switches.
1035 */
1036 extern uint32_t ml_timer_eager_evaluations;
1037
1038 SYSCTL_INT(_machdep, OID_AUTO, eager_timer_evaluations,
1039 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1040 &ml_timer_eager_evaluations, 0, "");
1041
1042 extern uint64_t ml_timer_eager_evaluation_max;
1043
1044 SYSCTL_QUAD(_machdep, OID_AUTO, eager_timer_evaluation_max,
1045 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1046 &ml_timer_eager_evaluation_max, "");
1047 extern uint64_t x86_isr_fp_simd_use;
1048 SYSCTL_QUAD(_machdep, OID_AUTO, x86_fp_simd_isr_uses,
1049 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1050 &x86_isr_fp_simd_use, "");
1051
1052 static int
1053 sysctl_kern_insn_copy_optout_task SYSCTL_HANDLER_ARGS
1054 {
1055 #pragma unused(oidp, arg1, arg2)
1056 uint32_t soflags = 0;
1057 uint32_t old_value = curtask_get_insn_copy_optout() ? 1 : 0;
1058
1059 int error = SYSCTL_IN(req, &soflags, sizeof(soflags));
1060 if (error) {
1061 return error;
1062 }
1063
1064 if (soflags) {
1065 curtask_set_insn_copy_optout();
1066 }
1067
1068 return SYSCTL_OUT(req, &old_value, sizeof(old_value));
1069 }
1070 SYSCTL_PROC(_machdep, OID_AUTO, insn_copy_optout_task,
1071 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_MASKED | CTLFLAG_ANYBODY,
1072 0, 0, sysctl_kern_insn_copy_optout_task, "I", "");
1073
1074
1075 #if DEVELOPMENT || DEBUG
1076
1077 extern int plctrace_enabled;
1078
1079 SYSCTL_INT(_machdep, OID_AUTO, pltrace,
1080 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1081 &plctrace_enabled, 0, "");
1082
1083 extern int fpsimd_fault_popc;
1084 SYSCTL_INT(_machdep, OID_AUTO, fpsimd_fault_popc,
1085 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1086 &fpsimd_fault_popc, 0, "");
1087
1088 volatile int stop_spinning;
1089 static int
spin_in_the_kernel(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)1090 spin_in_the_kernel(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
1091 {
1092 int new = 0, old = 0, changed = 0, error;
1093
1094 error = sysctl_io_number(req, old, sizeof(int), &new, &changed);
1095 if (error == 0 && changed) {
1096 stop_spinning = FALSE;
1097 while (stop_spinning == FALSE) {
1098 __builtin_ia32_pause();
1099 }
1100 } else if (error == 0) {
1101 stop_spinning = TRUE;
1102 }
1103
1104 return error;
1105 }
1106
1107 SYSCTL_PROC(_machdep_misc, OID_AUTO, spin_forever,
1108 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_MASKED,
1109 0, 0,
1110 spin_in_the_kernel, "I", "Spin forever");
1111
1112 SYSCTL_INT(_machdep_misc, OID_AUTO, fake_pte_corruption,
1113 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1114 &pmap_inject_pte_corruption, 0,
1115 "Fake a PTE corruption event (induces NMI IPIs and panics the system)");
1116
1117 extern int traptrace_enabled;
1118 SYSCTL_INT(_machdep_misc, OID_AUTO, traptrace_enabled,
1119 CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
1120 &traptrace_enabled, 0, "Enabled/disable trap trace");
1121
1122 #endif /* DEVELOPMENT || DEBUG */
1123