170 points · by todsacerdoti · 2y ago · 60 comments
# in milli-watt (1000 = 1W) because shell arithmetic doesn't do floating point
while true; do
LAST_MJ=$MJ
MJ=$(cat /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/energy_uj)
echo $(((MJ - LAST_MJ) / 1000))
sleep 1
done
Despite the powercap name being intel-rapl, the powercap interface is also available on AMD machines.For a more detailed reading on several more metrics about the CPU, I think pcm[1] may be a better tool (it's a successor to the Intel Power Gadget the project was forked from). Though, it only works on Intel CPU.
perf stat -e 'power/energy-pkg/' -I 1000 --interval-count 3
# time counts unit events
1.001064377 11.00 Joules power/energy-pkg/
2.002605466 10.98 Joules power/energy-pkg/
3.003726824 11.01 Joules power/energy-pkg/Power profiling is listed as supported on all CPUs though a bunch of features (including memory bandwidth, one that I had wanted) are limited to EPYC CPUs and don't exist in Ryzen or Threadripper.
https://www.kernel.org/doc/html/v5.8/hwmon/amd_energy.html
https://www.kernel.org/doc/html/v5.12/hwmon/amd_energy.html
https://www.kernel.org/doc/html/v5.13/hwmon/amd_energy.html (404)
>Long story short, since last year the AMD Energy sensor information has been limited to root due to the PLATYPUS security vulnerability. HWMON maintainer Guenter Roeck proposed slightly limiting and randomizing the sensor data so it couldn't be used for nefarious purposes but still accurate enough for genuine use-cases and no longer needing to be root-only access. However, AMD engineers didn't like that approach.
>With the hardware monitoring subsystem maintainer not wanting the information to be restricted to root-only and AMD not wanting the limiting/randomization approach, Guenter went ahead and removed the driver.
So... we're better off without having this system at all than we would be if it were limited to root OR if it were randomized? Sounds like silly kernel politicking to me. "You don't like my plan? Oh well, I guess I'll take the ball and go home, have fun losers!"
"Identifying Compiler Options to Minimise Energy Consumption for Embedded platforms"
There is also a paper about PMT: https://arxiv.org/pdf/2210.03724
For whole-node power on typical racked systems, I'd expect to interrogate the power strips or similar supplies with SNMP or otherwise.
If you are into overspending on PSUs you can get similar features in consumer PSUs, for example [1]. But at that point we have completely left the realm of "simple interface".
If you want to get a whole-system overview the PSU values are obviously better. But one of the biggest power consumer in many servers are the fans, and because they react to temperature sensors they always lag behind what's actually happening. That makes attributing a rise or fall in power tricky at sub-minute timescales. That's where CPU energy use is much more useful, even if it's a less complete picture.
1: https://www.thermaltake.com/toughpower-irgb-plus-850w-gold-t...
Why don't systems drive the fans based on the VR state instead of lagging temperature readings?
https://www.corsair.com/us/en/explorer/diy-builder/power-sup...
This was yesterday. Wild.