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 int trap_on_alignment_fault
;
16 extern uint64_t wake_abstime
;
19 SYSCTL_INT(_machdep
, OID_AUTO
, alignmenttrap
,
20 CTLFLAG_RW
, &trap_on_alignment_fault
, 0,
21 "trap on alignment faults (number of alignment faults per trap)");
24 SYSCTL_QUAD(_machdep
, OID_AUTO
, wake_abstime
,
25 CTLFLAG_RD
| CTLFLAG_KERN
, &wake_abstime
,
26 "Absolute Time at the last wakeup");
29 sysctl_time_since_reset SYSCTL_HANDLER_ARGS
31 #pragma unused(arg1, arg2, oidp)
33 uint64_t return_value
= 0;
35 return_value
= ml_get_time_since_reset();
37 SYSCTL_OUT(req
, &return_value
, sizeof(return_value
));
42 SYSCTL_PROC(_machdep
, OID_AUTO
, time_since_reset
,
43 CTLFLAG_RD
| CTLTYPE_QUAD
| CTLFLAG_LOCKED
,
44 0, 0, sysctl_time_since_reset
, "I",
45 "Continuous time since last SOC boot/wake started");
48 sysctl_wake_conttime SYSCTL_HANDLER_ARGS
50 #pragma unused(arg1, arg2, oidp)
52 uint64_t return_value
= 0;
54 return_value
= ml_get_conttime_wake_time();
56 SYSCTL_OUT(req
, &return_value
, sizeof(return_value
));
61 SYSCTL_PROC(_machdep
, OID_AUTO
, wake_conttime
,
62 CTLFLAG_RD
| CTLTYPE_QUAD
| CTLFLAG_LOCKED
,
63 0, 0, sysctl_wake_conttime
, "I",
64 "Continuous Time at the last wakeup");
67 * For source compatibility, here's some machdep.cpu mibs that
68 * use host_info() to simulate reasonable answers.
71 SYSCTL_NODE(_machdep
, OID_AUTO
, cpu
, CTLFLAG_RW
|CTLFLAG_LOCKED
, 0,
75 arm_host_info SYSCTL_HANDLER_ARGS
77 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
79 host_basic_info_data_t hinfo
;
80 mach_msg_type_number_t count
= HOST_BASIC_INFO_COUNT
;
82 kern_return_t kret
= host_info((host_t
)BSD_HOST
,
83 HOST_BASIC_INFO
, (host_info_t
)&hinfo
, &count
);
84 if (KERN_SUCCESS
!= kret
)
87 if (sizeof (uint32_t) != arg2
)
88 panic("size mismatch");
90 uintptr_t woffset
= (uintptr_t)arg1
/ sizeof (uint32_t);
91 uint32_t datum
= *(uint32_t *)(((uint32_t *)&hinfo
) + woffset
);
92 return (SYSCTL_OUT(req
, &datum
, sizeof (datum
)));
96 * machdep.cpu.cores_per_package
98 * x86: derived from CPUID data.
99 * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max
102 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, cores_per_package
,
103 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
104 (void *)offsetof(host_basic_info_data_t
, physical_cpu_max
),
106 arm_host_info
, "I", "CPU cores per package");
109 * machdep.cpu.core_count
111 * x86: derived from CPUID data.
112 * ARM: # active physical cores in the AP; aka hw.physicalcpu
115 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, core_count
,
116 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
117 (void *)offsetof(host_basic_info_data_t
, physical_cpu
),
119 arm_host_info
, "I", "Number of enabled cores per package");
122 * machdep.cpu.logical_per_package
124 * x86: derived from CPUID data. Returns ENOENT if HTT bit not set, but
125 * most x64 CPUs have that, so assume it's available.
126 * ARM: total # logical cores in the AP; aka hw.logicalcpu_max
129 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, logical_per_package
,
130 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
131 (void *)offsetof(host_basic_info_data_t
, logical_cpu_max
),
133 arm_host_info
, "I", "CPU logical cpus per package");
136 * machdep.cpu.thread_count
138 * x86: derived from CPUID data.
139 * ARM: # active logical cores in the AP; aka hw.logicalcpu
142 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, thread_count
,
143 CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
144 (void *)offsetof(host_basic_info_data_t
, logical_cpu
),
146 arm_host_info
, "I", "Number of enabled threads per package");
149 * machdep.cpu.brand_string
151 * x86: derived from CPUID data.
152 * ARM: cons something up from the CPUID register. Could include cpufamily
153 * here and map it to a "marketing" name, but there's no obvious need;
154 * the value is already exported via the commpage. So keep it simple.
157 make_brand_string SYSCTL_HANDLER_ARGS
159 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
160 __unused
void *unused_arg1
= arg1
;
161 __unused
int unused_arg2
= arg2
;
165 switch (cpuid_info()->arm_info
.arm_implementor
) {
173 impl
= "ARM architecture";
177 snprintf(buf
, sizeof (buf
), "%s processor", impl
);
178 return (SYSCTL_OUT(req
, buf
, strlen(buf
) + 1));
181 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, brand_string
,
182 CTLTYPE_STRING
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
183 0, 0, make_brand_string
, "A", "CPU brand string");