]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/arm64/sysctl.c
e2715281d2132e024a88d102452db9b8792ff11b
[apple/xnu.git] / bsd / dev / arm64 / sysctl.c
1 /*
2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
3 */
4 #include <sys/param.h>
5 #include <sys/kernel.h>
6 #include <sys/sysctl.h>
7
8 #include <machine/machine_routines.h>
9
10 #include <mach/host_info.h>
11 #include <mach/mach_host.h>
12 #include <arm/cpuid.h>
13 #include <libkern/libkern.h>
14
15 extern uint64_t wake_abstime;
16 extern int lck_mtx_adaptive_spin_mode;
17
18 static
19 SYSCTL_QUAD(_machdep, OID_AUTO, wake_abstime,
20 CTLFLAG_RD, &wake_abstime,
21 "Absolute Time at the last wakeup");
22
23 static int
24 sysctl_time_since_reset SYSCTL_HANDLER_ARGS
25 {
26 #pragma unused(arg1, arg2, oidp)
27 int error = 0;
28 uint64_t return_value = 0;
29
30 return_value = ml_get_time_since_reset();
31
32 SYSCTL_OUT(req, &return_value, sizeof(return_value));
33
34 return error;
35 }
36
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");
41
42 static int
43 sysctl_wake_conttime SYSCTL_HANDLER_ARGS
44 {
45 #pragma unused(arg1, arg2, oidp)
46 int error = 0;
47 uint64_t return_value = 0;
48
49 return_value = ml_get_conttime_wake_time();
50
51 SYSCTL_OUT(req, &return_value, sizeof(return_value));
52
53 return error;
54 }
55
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");
60
61
62 /*
63 * For source compatibility, here's some machdep.cpu mibs that
64 * use host_info() to simulate reasonable answers.
65 */
66
67 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
68 "CPU info");
69
70 static int
71 arm_host_info SYSCTL_HANDLER_ARGS
72 {
73 __unused struct sysctl_oid *unused_oidp = oidp;
74
75 host_basic_info_data_t hinfo;
76 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
77 #define BSD_HOST 1
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) {
81 return EINVAL;
82 }
83
84 if (sizeof(uint32_t) != arg2) {
85 panic("size mismatch");
86 }
87
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));
91 }
92
93 /*
94 * machdep.cpu.cores_per_package
95 *
96 * x86: derived from CPUID data.
97 * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max
98 */
99 static
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),
103 sizeof(integer_t),
104 arm_host_info, "I", "CPU cores per package");
105
106 /*
107 * machdep.cpu.core_count
108 *
109 * x86: derived from CPUID data.
110 * ARM: # active physical cores in the AP; aka hw.physicalcpu
111 */
112 static
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),
116 sizeof(integer_t),
117 arm_host_info, "I", "Number of enabled cores per package");
118
119 /*
120 * machdep.cpu.logical_per_package
121 *
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
125 */
126 static
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),
130 sizeof(integer_t),
131 arm_host_info, "I", "CPU logical cpus per package");
132
133 /*
134 * machdep.cpu.thread_count
135 *
136 * x86: derived from CPUID data.
137 * ARM: # active logical cores in the AP; aka hw.logicalcpu
138 */
139 static
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),
143 sizeof(integer_t),
144 arm_host_info, "I", "Number of enabled threads per package");
145
146 /*
147 * machdep.cpu.brand_string
148 *
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.
153 */
154 static int
155 make_brand_string SYSCTL_HANDLER_ARGS
156 {
157 __unused struct sysctl_oid *unused_oidp = oidp;
158 __unused void *unused_arg1 = arg1;
159 __unused int unused_arg2 = arg2;
160
161 const char *impl;
162
163 switch (cpuid_info()->arm_info.arm_implementor) {
164 case CPU_VID_APPLE:
165 impl = "Apple";
166 break;
167 case CPU_VID_ARM:
168 impl = "ARM";
169 break;
170 default:
171 impl = "ARM architecture";
172 break;
173 }
174 char buf[80];
175 snprintf(buf, sizeof(buf), "%s processor", impl);
176 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
177 }
178
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");
182
183 static
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");
187
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");
193 #endif