Description:
Background
Currently, GetCPUInfos() in pkg/cpuinfo/cpuinfo.go parses /proc/cpuinfo to extract three fields: processor (CpuID), physical id (SocketID),
and core id (CoreID). After that, it immediately turns to sysfs to populate the remaining topology data (NUMA node, L3 cache, siblings, etc.)
— and even overwrites SocketID with the sysfs value in populateTopologyInfo().
This means /proc/cpuinfo parsing is effectively redundant. All three fields are available directly from sysfs:
Proposal
Replace the /proc/cpuinfo text parsing with sysfs-only enumeration
- Enumerate online CPUs from /sys/devices/system/cpu/online (or by listing cpu directories).
- For each CPU, read topology/physical_package_id and topology/core_id directly from sysfs.
- Remove parseCPUInfo() and the /proc/cpuinfo reading logic entirely.
This also eliminates the trailing-block edge case in the current line-by-line parser (the duplicated parseCPUInfo call after the loop to handle the last CPU block).
Alternative: use an existing Go library
Instead of hand-rolling sysfs reads, we could consider using an existing library such as ghw , which provides a clean topology API (ghw.Topology()) backed by sysfs. This would reduce the amount of low-level file reading code we maintain. However, introducing an external dependency needs to be weighed against the simplicity of a few direct sysfs reads.Benefits
- Single, consistent data source (sysfs) — no more reading /proc/cpuinfo then overwriting values from sysfs
- Simpler, more maintainable code
- Removes fragile text parsing logic
- No change in plugin behavior (same CPUInfo struct, same data)
Verification
- Unit tests with mock sysfs trees (existing test pattern in the repo)
Description:
Background
Currently, GetCPUInfos() in pkg/cpuinfo/cpuinfo.go parses /proc/cpuinfo to extract three fields: processor (CpuID), physical id (SocketID),
and core id (CoreID). After that, it immediately turns to sysfs to populate the remaining topology data (NUMA node, L3 cache, siblings, etc.)
— and even overwrites SocketID with the sysfs value in populateTopologyInfo().
This means /proc/cpuinfo parsing is effectively redundant. All three fields are available directly from sysfs:
Proposal
Replace the /proc/cpuinfo text parsing with sysfs-only enumeration
This also eliminates the trailing-block edge case in the current line-by-line parser (the duplicated parseCPUInfo call after the loop to handle the last CPU block).
Alternative: use an existing Go library
Instead of hand-rolling sysfs reads, we could consider using an existing library such as ghw , which provides a clean topology API (ghw.Topology()) backed by sysfs. This would reduce the amount of low-level file reading code we maintain. However, introducing an external dependency needs to be weighed against the simplicity of a few direct sysfs reads.Benefits
Verification