aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-04-29 23:44:48 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-04-30 00:24:09 +0200
commitd40c207fdee3d975f708a146d9b06d3715445c67 (patch)
treedd7c1bd430890d0a3205f0f9f740d0d7a93a0bf1
parent8660718ebe1b53af6c6ef13f1dae5689234454ed (diff)
sys/info: retrieve better CPU description on Darwin
Previously either `ARM` or `ARM64`, now you get something like `Apple M1`
-rw-r--r--core/sys/info/cpu_arm.odin27
-rw-r--r--src/bug_report.cpp27
2 files changed, 41 insertions, 13 deletions
diff --git a/core/sys/info/cpu_arm.odin b/core/sys/info/cpu_arm.odin
index 10c37ceef..aa4bb368a 100644
--- a/core/sys/info/cpu_arm.odin
+++ b/core/sys/info/cpu_arm.odin
@@ -1,6 +1,10 @@
//+build arm32, arm64
package sysinfo
+import "core:sys/unix"
+
+_ :: unix
+
CPU_Feature :: enum u64 {
// Advanced SIMD & floating-point capabilities:
asimd, // General support for Advanced SIMD instructions/neon.
@@ -45,11 +49,22 @@ cpu_name_buf: [128]byte
@(init, private)
init_cpu_name :: proc "contextless" () {
- when ODIN_ARCH == .arm64 {
- copy(cpu_name_buf[:], "ARM64")
- cpu_name = string(cpu_name_buf[:len("ARM64")])
- } else {
- copy(cpu_name_buf[:], "ARM")
- cpu_name = string(cpu_name_buf[:len("ARM")])
+ generic := true
+
+ when ODIN_OS == .Darwin {
+ if unix.sysctlbyname("machdep.cpu.brand_string", &cpu_name_buf) {
+ cpu_name = string(cstring(rawptr(&cpu_name_buf)))
+ generic = false
+ }
+ }
+
+ if generic {
+ when ODIN_ARCH == .arm64 {
+ copy(cpu_name_buf[:], "ARM64")
+ cpu_name = string(cpu_name_buf[:len("ARM64")])
+ } else {
+ copy(cpu_name_buf[:], "ARM")
+ cpu_name = string(cpu_name_buf[:len("ARM")])
+ }
}
}
diff --git a/src/bug_report.cpp b/src/bug_report.cpp
index e919ba67b..88ab9492c 100644
--- a/src/bug_report.cpp
+++ b/src/bug_report.cpp
@@ -204,14 +204,27 @@ gb_internal void report_cpu_info() {
}
#elif defined(GB_CPU_ARM)
- /*
- TODO(Jeroen): On *nix, perhaps query `/proc/cpuinfo`.
- */
- #if defined(GB_ARCH_64_BIT)
- gb_printf("ARM64\n");
- #else
- gb_printf("ARM\n");
+ bool generic = true;
+
+ #if defined(GB_SYSTEM_OSX)
+ char cpu_name[128] = {};
+ size_t cpu_name_size = 128;
+ if (sysctlbyname("machdep.cpu.brand_string", &cpu_name, &cpu_name_size, nullptr, 0) == 0) {
+ generic = false;
+ gb_printf("%s\n", (char *)&cpu_name[0]);
+ }
#endif
+
+ if (generic) {
+ /*
+ TODO(Jeroen): On *nix, perhaps query `/proc/cpuinfo`.
+ */
+ #if defined(GB_ARCH_64_BIT)
+ gb_printf("ARM64\n");
+ #else
+ gb_printf("ARM\n");
+ #endif
+ }
#else
gb_printf("Unknown\n");
#endif