X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/7ddcb079202367355dddccdfa4318e57d50318be..7e41aa883dd258f888d0470250eead40a53ef1f5:/bsd/dev/i386/sysctl.c?ds=inline diff --git a/bsd/dev/i386/sysctl.c b/bsd/dev/i386/sysctl.c index cb15eb632..2e4672f23 100644 --- a/bsd/dev/i386/sysctl.c +++ b/bsd/dev/i386/sysctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2011 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -32,10 +32,14 @@ #include #include #include +#include #include +#include #include #include #include +#include + static int _i386_cpu_info SYSCTL_HANDLER_ARGS @@ -119,6 +123,7 @@ cpu_xsave SYSCTL_HANDLER_ARGS return _i386_cpu_info(oidp, ptr, arg2, req); } + static int cpu_features SYSCTL_HANDLER_ARGS { @@ -147,6 +152,24 @@ cpu_extfeatures SYSCTL_HANDLER_ARGS return SYSCTL_OUT(req, buf, strlen(buf) + 1); } +static int +cpu_leaf7_features SYSCTL_HANDLER_ARGS +{ + __unused struct sysctl_oid *unused_oidp = oidp; + __unused void *unused_arg1 = arg1; + __unused int unused_arg2 = arg2; + char buf[512]; + + uint32_t leaf7_features = cpuid_info()->cpuid_leaf7_features; + if (leaf7_features == 0) + return ENOENT; + + buf[0] = '\0'; + cpuid_get_leaf7_feature_names(leaf7_features, buf, sizeof(buf)); + + return SYSCTL_OUT(req, buf, strlen(buf) + 1); +} + static int cpu_logical_per_package SYSCTL_HANDLER_ARGS { @@ -262,6 +285,26 @@ misc_interrupt_latency_max(__unused struct sysctl_oid *oidp, __unused void *arg1 return error; } +/* + * Triggers a machine-check exception - for a suitably configured kernel only. + */ +extern void mca_exception_panic(void); +static int +misc_machine_check_panic(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) +{ + int changed = 0, error; + char buf[128]; + buf[0] = '\0'; + + error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed); + + if (error == 0 && changed) { + mca_exception_panic(); + } + return error; +} + + SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0, "CPU info"); @@ -305,6 +348,12 @@ SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CT (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t), i386_cpu_info, "IU", "CPU features"); +SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_feature_bits, + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, + (void *)offsetof(i386_cpu_info_t, cpuid_leaf7_features), + sizeof(uint32_t), + i386_cpu_info_nonzero, "IU", "CPU Leaf7 features"); + SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t), i386_cpu_info, "IU", "CPU extended features"); @@ -321,6 +370,11 @@ SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD | CTLF 0, 0, cpu_features, "A", "CPU feature names"); +SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_features, + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, + 0, 0, + cpu_leaf7_features, "A", "CPU Leaf7 feature names"); + SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, cpu_extfeatures, "A", "CPU extended feature names"); @@ -426,7 +480,7 @@ SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, package_thermal_intr, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(cpuid_thermal_leaf_t, package_thermal_intr), sizeof(boolean_t), - cpu_thermal, "I", "Packge Thermal interrupt and Status"); + cpu_thermal, "I", "Package Thermal interrupt and Status"); SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, hardware_feedback, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, @@ -445,9 +499,15 @@ SYSCTL_NODE(_machdep_cpu, OID_AUTO, xsave, CTLFLAG_RW|CTLFLAG_LOCKED, 0, SYSCTL_PROC(_machdep_cpu_xsave, OID_AUTO, extended_state, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, - (void *)offsetof(cpuid_xsave_leaf_t, extended_state), + (void *) 0, sizeof(cpuid_xsave_leaf_t), - cpu_xsave, "IU", "XSAVE Extended State"); + cpu_xsave, "IU", "XSAVE Extended State Main Leaf"); + +SYSCTL_PROC(_machdep_cpu_xsave, OID_AUTO, extended_state1, + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, + (void *) sizeof(cpuid_xsave_leaf_t), + sizeof(cpuid_xsave_leaf_t), + cpu_xsave, "IU", "XSAVE Extended State Sub-leaf 1"); SYSCTL_NODE(_machdep_cpu, OID_AUTO, arch_perf, CTLFLAG_RW|CTLFLAG_LOCKED, 0, @@ -628,9 +688,33 @@ SYSCTL_PROC(_machdep_cpu_flex_ratio, OID_AUTO, max, cpu_flex_ratio_max, "I", "Flex ratio max (non-turbo)"); SYSCTL_PROC(_machdep_cpu, OID_AUTO, ucupdate, - CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_LOCKED, 0, 0, + CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_LOCKED, 0, 0, cpu_ucode_update, "S", "Microcode update interface"); +SYSCTL_NODE(_machdep_cpu, OID_AUTO, tsc_ccc, CTLFLAG_RW|CTLFLAG_LOCKED, 0, + "TSC/CCC frequency information"); + +SYSCTL_PROC(_machdep_cpu_tsc_ccc, OID_AUTO, numerator, + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, + (void *)offsetof(i386_cpu_info_t, cpuid_tsc_leaf.numerator), + sizeof(uint32_t), + i386_cpu_info, "I", "Numerator of TSC/CCC ratio"); + +SYSCTL_PROC(_machdep_cpu_tsc_ccc, OID_AUTO, denominator, + CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, + (void *)offsetof(i386_cpu_info_t, cpuid_tsc_leaf.denominator), + sizeof(uint32_t), + i386_cpu_info, "I", "Denominator of TSC/CCC ratio"); + +static const uint32_t apic_timer_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_TIMER_INTERRUPT); +static const uint32_t apic_IPI_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_INTERPROCESSOR_INTERRUPT); + +SYSCTL_NODE(_machdep, OID_AUTO, vectors, CTLFLAG_RD | CTLFLAG_LOCKED, 0, + "Interrupt vector assignments"); + +SYSCTL_UINT (_machdep_vectors, OID_AUTO, timer, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, __DECONST(uint32_t *,&apic_timer_vector), 0, ""); +SYSCTL_UINT (_machdep_vectors, OID_AUTO, IPI, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, __DECONST(uint32_t *,&apic_IPI_vector), 0, ""); + uint64_t pmap_pv_hashlist_walks; uint64_t pmap_pv_hashlist_cnts; uint32_t pmap_pv_hashlist_max; @@ -670,7 +754,34 @@ SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Other, CTLFLAG_RD|CTLFLAG_LOCKED, &firmwa SYSCTL_NODE(_machdep, OID_AUTO, tsc, CTLFLAG_RD|CTLFLAG_LOCKED, NULL, "Timestamp counter parameters"); -SYSCTL_QUAD(_machdep_tsc, OID_AUTO, frequency, CTLFLAG_RD|CTLFLAG_LOCKED, &tscFreq, ""); +SYSCTL_QUAD(_machdep_tsc, OID_AUTO, frequency, + CTLFLAG_RD|CTLFLAG_LOCKED, &tscFreq, ""); + +extern uint32_t deep_idle_rebase; +SYSCTL_UINT(_machdep_tsc, OID_AUTO, deep_idle_rebase, + CTLFLAG_RD|CTLFLAG_LOCKED, &deep_idle_rebase, 0, ""); +SYSCTL_QUAD(_machdep_tsc, OID_AUTO, at_boot, + CTLFLAG_RD|CTLFLAG_LOCKED, &tsc_at_boot, ""); +SYSCTL_QUAD(_machdep_tsc, OID_AUTO, rebase_abs_time, + CTLFLAG_RD|CTLFLAG_LOCKED, &tsc_rebase_abs_time, ""); + +SYSCTL_NODE(_machdep_tsc, OID_AUTO, nanotime, + CTLFLAG_RD|CTLFLAG_LOCKED, NULL, "TSC to ns conversion"); +SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, tsc_base, + CTLFLAG_RD | CTLFLAG_LOCKED, + __DECONST(uint64_t *, &pal_rtc_nanotime_info.tsc_base), ""); +SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, ns_base, + CTLFLAG_RD | CTLFLAG_LOCKED, + __DECONST(uint64_t *, &pal_rtc_nanotime_info.ns_base), ""); +SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, scale, + CTLFLAG_RD | CTLFLAG_LOCKED, + __DECONST(uint32_t *, &pal_rtc_nanotime_info.scale), 0, ""); +SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, shift, + CTLFLAG_RD | CTLFLAG_LOCKED, + __DECONST(uint32_t *, &pal_rtc_nanotime_info.shift), 0, ""); +SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, generation, + CTLFLAG_RD | CTLFLAG_LOCKED, + __DECONST(uint32_t *, &pal_rtc_nanotime_info.generation), 0, ""); SYSCTL_NODE(_machdep, OID_AUTO, misc, CTLFLAG_RW|CTLFLAG_LOCKED, 0, "Miscellaneous x86 kernel parameters"); @@ -680,6 +791,97 @@ SYSCTL_PROC(_machdep_misc, OID_AUTO, panic_restart_timeout, 0, 0, panic_set_restart_timeout, "I", "Panic restart timeout in seconds"); -SYSCTL_PROC(_machdep_misc, OID_AUTO, interrupt_latency_max, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, +SYSCTL_PROC(_machdep_misc, OID_AUTO, interrupt_latency_max, + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, 0, 0, misc_interrupt_latency_max, "A", "Maximum Interrupt latency"); + +SYSCTL_PROC(_machdep_misc, OID_AUTO, machine_check_panic, + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, + 0, 0, + misc_machine_check_panic, "A", "Machine-check exception test"); + +#if DEVELOPMENT || DEBUG +SYSCTL_QUAD(_machdep, OID_AUTO, reportphyreadabs, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &reportphyreaddelayabs, ""); +SYSCTL_INT(_machdep, OID_AUTO, reportphyreadosbt, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &reportphyreadosbt, 0, ""); +#endif + +extern void timer_queue_trace_cpu(int); +static int +misc_timer_queue_trace(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) +{ + int changed = 0, error; + char buf[128]; + buf[0] = '\0'; + + error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed); + + if (error == 0 && changed) { + timer_queue_trace_cpu(0); + } + return error; +} + +SYSCTL_PROC(_machdep_misc, OID_AUTO, timer_queue_trace, + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, + 0, 0, + misc_timer_queue_trace, "A", "Cut timer queue tracepoint"); + +extern long NMI_count; +extern void NMI_cpus(void); +static int +misc_nmis(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) +{ + int new = 0, old = 0, changed = 0, error; + + old = NMI_count; + + error = sysctl_io_number(req, old, sizeof(int), &new, &changed); + if (error == 0 && changed) { + NMI_cpus(); + } + + return error; +} + +SYSCTL_PROC(_machdep_misc, OID_AUTO, nmis, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, + 0, 0, + misc_nmis, "I", "Report/increment NMI count"); + +/* Parameters related to timer coalescing tuning, to be replaced + * with a dedicated systemcall in the future. + */ +/* Enable processing pending timers in the context of any other interrupt */ +SYSCTL_INT(_kern, OID_AUTO, interrupt_timer_coalescing_enabled, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &interrupt_timer_coalescing_enabled, 0, ""); +/* Upon entering idle, process pending timers with HW deadlines + * this far in the future. + */ +SYSCTL_INT(_kern, OID_AUTO, timer_coalesce_idle_entry_hard_deadline_max, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &idle_entry_timer_processing_hdeadline_threshold, 0, ""); + +/* Track potentially expensive eager timer evaluations on QoS tier + * switches. + */ +extern uint32_t ml_timer_eager_evaluations; + +SYSCTL_INT(_machdep, OID_AUTO, eager_timer_evaluations, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &ml_timer_eager_evaluations, 0, ""); + +extern uint64_t ml_timer_eager_evaluation_max; + +SYSCTL_QUAD(_machdep, OID_AUTO, eager_timer_evaluation_max, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &ml_timer_eager_evaluation_max, ""); +extern uint64_t x86_isr_fp_simd_use; +SYSCTL_QUAD(_machdep, OID_AUTO, x86_fp_simd_isr_uses, + CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, + &x86_isr_fp_simd_use, "");