2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
5 #include <sys/kernel.h>
6 #include <sys/sysctl.h>
8 #include <machine/machine_routines.h>
10 #include <mach/host_info.h>
11 #include <mach/mach_host.h>
12 #include <arm/cpuid.h>
13 #include <libkern/libkern.h>
15 extern uint64_t wake_abstime
;
16 extern int lck_mtx_adaptive_spin_mode
;
19 SYSCTL_QUAD(_machdep
, OID_AUTO
, wake_abstime
,
20 CTLFLAG_RD
, &wake_abstime
,
21 "Absolute Time at the last wakeup");
24 sysctl_time_since_reset SYSCTL_HANDLER_ARGS
26 #pragma unused(arg1, arg2, oidp)
28 uint64_t return_value
= 0;
30 return_value
= ml_get_time_since_reset();
32 SYSCTL_OUT(req
, &return_value
, sizeof(return_value
));
37 SYSCTL_PROC(_machdep
, OID_AUTO
, time_since_reset
,
38 CTLFLAG_RD
| CTLTYPE_QUAD
| CTLFLAG_LOCKED
,
39 0, 0, sysctl_time_since_reset
, "I",
40 "Continuous time since last SOC boot/wake started");
43 sysctl_wake_conttime SYSCTL_HANDLER_ARGS
45 #pragma unused(arg1, arg2, oidp)
47 uint64_t return_value
= 0;
49 return_value
= ml_get_conttime_wake_time();
51 SYSCTL_OUT(req
, &return_value
, sizeof(return_value
));
56 SYSCTL_PROC(_machdep
, OID_AUTO
, wake_conttime
,
57 CTLFLAG_RD
| CTLTYPE_QUAD
| CTLFLAG_LOCKED
,
58 0, 0, sysctl_wake_conttime
, "I",
59 "Continuous Time at the last wakeup");
63 * For source compatibility, here's some machdep.cpu mibs that
64 * use host_info() to simulate reasonable answers.
67 SYSCTL_NODE(_machdep
, OID_AUTO
, cpu
, CTLFLAG_RW
| CTLFLAG_LOCKED
, 0,
71 arm_host_info SYSCTL_HANDLER_ARGS
73 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
75 host_basic_info_data_t hinfo
;
76 mach_msg_type_number_t count
= HOST_BASIC_INFO_COUNT
;
78 kern_return_t kret
= host_info((host_t
)BSD_HOST
,
79 HOST_BASIC_INFO
, (host_info_t
)&hinfo
, &count
);
80 if (KERN_SUCCESS
!= kret
) {
84 if (sizeof(uint32_t) != arg2
) {
85 panic("size mismatch");
88 uintptr_t woffset
= (uintptr_t)arg1
/ sizeof(uint32_t);
89 uint32_t datum
= *(uint32_t *)(((uint32_t *)&hinfo
) + woffset
);
90 return SYSCTL_OUT(req
, &datum
, sizeof(datum
));
94 * machdep.cpu.cores_per_package
96 * x86: derived from CPUID data.
97 * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max
100 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, cores_per_package
,
101 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
102 (void *)offsetof(host_basic_info_data_t
, physical_cpu_max
),
104 arm_host_info
, "I", "CPU cores per package");
107 * machdep.cpu.core_count
109 * x86: derived from CPUID data.
110 * ARM: # active physical cores in the AP; aka hw.physicalcpu
113 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, core_count
,
114 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
115 (void *)offsetof(host_basic_info_data_t
, physical_cpu
),
117 arm_host_info
, "I", "Number of enabled cores per package");
120 * machdep.cpu.logical_per_package
122 * x86: derived from CPUID data. Returns ENOENT if HTT bit not set, but
123 * most x64 CPUs have that, so assume it's available.
124 * ARM: total # logical cores in the AP; aka hw.logicalcpu_max
127 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, logical_per_package
,
128 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
129 (void *)offsetof(host_basic_info_data_t
, logical_cpu_max
),
131 arm_host_info
, "I", "CPU logical cpus per package");
134 * machdep.cpu.thread_count
136 * x86: derived from CPUID data.
137 * ARM: # active logical cores in the AP; aka hw.logicalcpu
140 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, thread_count
,
141 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
142 (void *)offsetof(host_basic_info_data_t
, logical_cpu
),
144 arm_host_info
, "I", "Number of enabled threads per package");
147 * machdep.cpu.brand_string
149 * x86: derived from CPUID data.
150 * ARM: cons something up from the CPUID register. Could include cpufamily
151 * here and map it to a "marketing" name, but there's no obvious need;
152 * the value is already exported via the commpage. So keep it simple.
155 make_brand_string SYSCTL_HANDLER_ARGS
157 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
158 __unused
void *unused_arg1
= arg1
;
159 __unused
int unused_arg2
= arg2
;
163 switch (cpuid_info()->arm_info
.arm_implementor
) {
171 impl
= "ARM architecture";
175 snprintf(buf
, sizeof(buf
), "%s processor", impl
);
176 return SYSCTL_OUT(req
, buf
, strlen(buf
) + 1);
179 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, brand_string
,
180 CTLTYPE_STRING
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
181 0, 0, make_brand_string
, "A", "CPU brand string");
184 SYSCTL_INT(_machdep
, OID_AUTO
, lck_mtx_adaptive_spin_mode
,
185 CTLFLAG_RW
, &lck_mtx_adaptive_spin_mode
, 0,
186 "Enable adaptive spin behavior for kernel mutexes");
188 #if DEVELOPMENT || DEBUG
189 extern uint64_t TLockTimeOut
;
190 SYSCTL_QUAD(_machdep
, OID_AUTO
, tlto
,
191 CTLFLAG_RW
| CTLFLAG_LOCKED
, &TLockTimeOut
,
192 "Ticket spinlock timeout (MATUs): use with care");