diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-05-25 19:43:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-25 19:43:10 +0200 |
| commit | 655fab7227fbd92837c82fdbeea65c9121b0f70b (patch) | |
| tree | c7c4b24837d94e140cdef5f5f0458cdf04b0c69a /core/sys/info/cpu_linux_intel.odin | |
| parent | 0a6dced9daf6baa1b2e81b7d5542899ca6022c7e (diff) | |
Add core/hyperthread count for Windows and Linux (#5216)
Add core/hyperthread count to `core:sys/info` for Windows and Linux.
TODO: Linux RISCV, Linux ARM, Darwin, and the BSDs.
Diffstat (limited to 'core/sys/info/cpu_linux_intel.odin')
| -rw-r--r-- | core/sys/info/cpu_linux_intel.odin | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/core/sys/info/cpu_linux_intel.odin b/core/sys/info/cpu_linux_intel.odin new file mode 100644 index 000000000..e43737475 --- /dev/null +++ b/core/sys/info/cpu_linux_intel.odin @@ -0,0 +1,38 @@ +#+build i386, amd64 +#+build linux +package sysinfo + +import "core:sys/linux" +import "core:strings" +import "core:strconv" + +@(init, private) +init_cpu_core_count :: proc() { + fd, err := linux.open("/proc/cpuinfo", {}) + if err != .NONE { return } + defer linux.close(fd) + + // This is probably enough right? + buf: [4096]byte + n, rerr := linux.read(fd, buf[:]) + if rerr != .NONE || n == 0 { return } + + str := string(buf[:n]) + for line in strings.split_lines_iterator(&str) { + key, _, value := strings.partition(line, ":") + key = strings.trim_space(key) + value = strings.trim_space(value) + + if key == "cpu cores" { + if num_physical_cores, ok := strconv.parse_int(value); ok { + cpu.physical_cores = num_physical_cores + } + } + + if key == "siblings" { + if num_logical_cores, ok := strconv.parse_int(value); ok { + cpu.logical_cores = num_logical_cores + } + } + } +}
\ No newline at end of file |