Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | /* * Copyright (c) 2003-2007 Apple Inc. All rights reserved. */ #include <sys/param.h> #include <sys/kernel.h> #include <sys/sysctl.h> #include <machine/machine_routines.h> #include <mach/host_info.h> #include <mach/mach_host.h> #include <arm/cpuid.h> #include <libkern/libkern.h> extern uint64_t wake_abstime; extern int lck_mtx_adaptive_spin_mode; static SYSCTL_QUAD(_machdep, OID_AUTO, wake_abstime, CTLFLAG_RD, &wake_abstime, "Absolute Time at the last wakeup"); static int sysctl_time_since_reset SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = ml_get_time_since_reset(); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } SYSCTL_PROC(_machdep, OID_AUTO, time_since_reset, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_time_since_reset, "I", "Continuous time since last SOC boot/wake started"); static int sysctl_wake_conttime SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = ml_get_conttime_wake_time(); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } SYSCTL_PROC(_machdep, OID_AUTO, wake_conttime, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_wake_conttime, "I", "Continuous Time at the last wakeup"); #if defined(HAS_IPI) static int cpu_signal_deferred_timer(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) { int new_value = 0; int changed = 0; int old_value = (int)ml_cpu_signal_deferred_get_timer(); int error = sysctl_io_number(req, old_value, sizeof(int), &new_value, &changed); if (error == 0 && changed) { ml_cpu_signal_deferred_adjust_timer((uint64_t)new_value); } return error; } SYSCTL_PROC(_machdep, OID_AUTO, deferred_ipi_timeout, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, 0, 0, cpu_signal_deferred_timer, "I", "Deferred IPI timeout (nanoseconds)"); #endif /* defined(HAS_IPI) */ /* * For source compatibility, here's some machdep.cpu mibs that * use host_info() to simulate reasonable answers. */ SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW | CTLFLAG_LOCKED, 0, "CPU info"); static int arm_host_info SYSCTL_HANDLER_ARGS { __unused struct sysctl_oid *unused_oidp = oidp; host_basic_info_data_t hinfo; mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; #define BSD_HOST 1 kern_return_t kret = host_info((host_t)BSD_HOST, HOST_BASIC_INFO, (host_info_t)&hinfo, &count); if (KERN_SUCCESS != kret) { return EINVAL; } if (sizeof(uint32_t) != arg2) { panic("size mismatch"); } uintptr_t woffset = (uintptr_t)arg1 / sizeof(uint32_t); uint32_t datum = *(uint32_t *)(((uint32_t *)&hinfo) + woffset); return SYSCTL_OUT(req, &datum, sizeof(datum)); } /* * machdep.cpu.cores_per_package * * x86: derived from CPUID data. * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max */ static SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(host_basic_info_data_t, physical_cpu_max), sizeof(integer_t), arm_host_info, "I", "CPU cores per package"); /* * machdep.cpu.core_count * * x86: derived from CPUID data. * ARM: # active physical cores in the AP; aka hw.physicalcpu */ static SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(host_basic_info_data_t, physical_cpu), sizeof(integer_t), arm_host_info, "I", "Number of enabled cores per package"); /* * machdep.cpu.logical_per_package * * x86: derived from CPUID data. Returns ENOENT if HTT bit not set, but * most x64 CPUs have that, so assume it's available. * ARM: total # logical cores in the AP; aka hw.logicalcpu_max */ static SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(host_basic_info_data_t, logical_cpu_max), sizeof(integer_t), arm_host_info, "I", "CPU logical cpus per package"); /* * machdep.cpu.thread_count * * x86: derived from CPUID data. * ARM: # active logical cores in the AP; aka hw.logicalcpu */ static SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, (void *)offsetof(host_basic_info_data_t, logical_cpu), sizeof(integer_t), arm_host_info, "I", "Number of enabled threads per package"); /* * machdep.cpu.brand_string * * x86: derived from CPUID data. * ARM: cons something up from the CPUID register. Could include cpufamily * here and map it to a "marketing" name, but there's no obvious need; * the value is already exported via the commpage. So keep it simple. */ static int make_brand_string SYSCTL_HANDLER_ARGS { __unused struct sysctl_oid *unused_oidp = oidp; __unused void *unused_arg1 = arg1; __unused int unused_arg2 = arg2; const char *impl; switch (cpuid_info()->arm_info.arm_implementor) { case CPU_VID_APPLE: impl = "Apple"; break; case CPU_VID_ARM: impl = "ARM"; break; default: impl = "ARM architecture"; break; } char buf[80]; snprintf(buf, sizeof(buf), "%s processor", impl); return SYSCTL_OUT(req, buf, strlen(buf) + 1); } SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0, make_brand_string, "A", "CPU brand string"); static SYSCTL_INT(_machdep, OID_AUTO, lck_mtx_adaptive_spin_mode, CTLFLAG_RW, &lck_mtx_adaptive_spin_mode, 0, "Enable adaptive spin behavior for kernel mutexes"); #if DEVELOPMENT || DEBUG extern uint64_t TLockTimeOut; SYSCTL_QUAD(_machdep, OID_AUTO, tlto, CTLFLAG_RW | CTLFLAG_LOCKED, &TLockTimeOut, "Ticket spinlock timeout (MATUs): use with care"); static int sysctl_sysreg_vbar_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("VBAR_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_vbar_el1 * * ARM64: Vector Base Address Register. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_vbar_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_vbar_el1, "Q", "VBAR_EL1 register on the current CPU"); static int sysctl_sysreg_mair_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("MAIR_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_mair_el1 * * ARM64: Memory Attribute Indirection Register. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_mair_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_mair_el1, "Q", "MAIR_EL1 register on the current CPU"); static int sysctl_sysreg_ttbr1_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("TTBR1_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_ttbr1_el1 * * ARM64: Translation table base register 1. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_ttbr1_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_ttbr1_el1, "Q", "TTBR1_EL1 register on the current CPU"); static int sysctl_sysreg_sctlr_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("SCTLR_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_sctlr_el1 * * ARM64: System Control Register. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_sctlr_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_sctlr_el1, "Q", "SCTLR_EL1 register on the current CPU"); static int sysctl_sysreg_tcr_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("TCR_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_tcr_el1 * * ARM64: Translation Control Register. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_tcr_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_tcr_el1, "Q", "TCR_EL1 register on the current CPU"); static int sysctl_sysreg_id_aa64mmfr0_el1 SYSCTL_HANDLER_ARGS { #pragma unused(arg1, arg2, oidp) uint64_t return_value = __builtin_arm_rsr64("ID_AA64MMFR0_EL1"); return SYSCTL_OUT(req, &return_value, sizeof(return_value)); } /* * machdep.cpu.sysreg_id_aa64mmfr0_el1 * * ARM64: AArch64 Memory Model Feature Register 0. * Read from the current CPU's system registers. */ SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_id_aa64mmfr0_el1, CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, 0, 0, sysctl_sysreg_id_aa64mmfr0_el1, "Q", "ID_AA64MMFR0_EL1 register on the current CPU"); #endif |