sys/info: retrieve better CPU description on Darwin

Previously either `ARM` or `ARM64`, now you get something like `Apple
M1`
This commit is contained in:
Laytan Laats
2024-04-30 00:24:09 +02:00
parent 8660718ebe
commit d40c207fde
2 changed files with 41 additions and 13 deletions
+15
View File
@@ -1,6 +1,10 @@
//+build arm32, arm64 //+build arm32, arm64
package sysinfo package sysinfo
import "core:sys/unix"
_ :: unix
CPU_Feature :: enum u64 { CPU_Feature :: enum u64 {
// Advanced SIMD & floating-point capabilities: // Advanced SIMD & floating-point capabilities:
asimd, // General support for Advanced SIMD instructions/neon. asimd, // General support for Advanced SIMD instructions/neon.
@@ -45,6 +49,16 @@ cpu_name_buf: [128]byte
@(init, private) @(init, private)
init_cpu_name :: proc "contextless" () { init_cpu_name :: proc "contextless" () {
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 { when ODIN_ARCH == .arm64 {
copy(cpu_name_buf[:], "ARM64") copy(cpu_name_buf[:], "ARM64")
cpu_name = string(cpu_name_buf[:len("ARM64")]) cpu_name = string(cpu_name_buf[:len("ARM64")])
@@ -52,4 +66,5 @@ init_cpu_name :: proc "contextless" () {
copy(cpu_name_buf[:], "ARM") copy(cpu_name_buf[:], "ARM")
cpu_name = string(cpu_name_buf[:len("ARM")]) cpu_name = string(cpu_name_buf[:len("ARM")])
} }
}
} }
+13
View File
@@ -204,6 +204,18 @@ gb_internal void report_cpu_info() {
} }
#elif defined(GB_CPU_ARM) #elif defined(GB_CPU_ARM)
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`. TODO(Jeroen): On *nix, perhaps query `/proc/cpuinfo`.
*/ */
@@ -212,6 +224,7 @@ gb_internal void report_cpu_info() {
#else #else
gb_printf("ARM\n"); gb_printf("ARM\n");
#endif #endif
}
#else #else
gb_printf("Unknown\n"); gb_printf("Unknown\n");
#endif #endif