zeus
zeus copied to clipboard
CPU socket detection for the current process
In a system, there can be multiple CPU sockets. Just like GPUs, after #36, Zeus will be able to measure the energy consumption of specific CPU packages. However, unlike GPUs, which socket the process ends up in is often not explicitly controlled by the user. So we want to have a utility function in Zeus that detects the CPU package the current process is running in, and allow the user to select the current CPU for measurement.
# Get CPU ID
cat /proc/self/stat | awk '{print $39}'
# Map CPU ID to physical socket
cat /sys/devices/system/cpu/cpu60/topology/physical_package_id
Haven't checked how generic this is. I think relying on procfs should be fine in general.
See procfs manpage -- /proc/pid/stat -- (39) processor.