mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
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.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package sysinfo
|
||||
|
||||
import sys "core:sys/windows"
|
||||
import "base:intrinsics"
|
||||
|
||||
@(init, private)
|
||||
init_cpu_core_count :: proc() {
|
||||
infos: []sys.SYSTEM_LOGICAL_PROCESSOR_INFORMATION
|
||||
defer delete(infos)
|
||||
|
||||
returned_length: sys.DWORD
|
||||
// Query for the required buffer size.
|
||||
if ok := sys.GetLogicalProcessorInformation(raw_data(infos), &returned_length); !ok {
|
||||
infos = make([]sys.SYSTEM_LOGICAL_PROCESSOR_INFORMATION, returned_length / size_of(sys.SYSTEM_LOGICAL_PROCESSOR_INFORMATION))
|
||||
}
|
||||
|
||||
// If it still doesn't work, return
|
||||
if ok := sys.GetLogicalProcessorInformation(raw_data(infos), &returned_length); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
for info in infos {
|
||||
#partial switch info.Relationship {
|
||||
case .RelationProcessorCore: cpu.physical_cores += 1
|
||||
case .RelationNumaNode: cpu.logical_cores += int(intrinsics.count_ones(info.ProcessorMask))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user