amanusk / s-tui

Terminal-based CPU stress and monitoring utility
https://amanusk.github.io/s-tui/
GNU General Public License v2.0
4k stars 139 forks source link

Support for Power read on AMD systems #32

Open amanusk opened 6 years ago

amanusk commented 6 years ago

Power measurement is available on modern AMD systems via the fam15h_power sensor in 'lm_sensors'.
Documentation is available here: fam15h_power
An AMD system is needed to implement and test the feature.

jangrewe commented 5 years ago

Hi, i came across this: https://github.com/djselbeck/rapl-read-ryzen I had to load the msr kernel module, then it gave me pretty plausible wattage numbers for my TR 2950X. Would be great if you could somehow integrate it. :-)

Example output on an idle box:

$ sudo ./ryzen
        0 (0), 1 (0), 2 (0), 3 (0), 4 (0), 5 (0), 6 (0), 7 (0)
        8 (0), 9 (0), 10 (0), 11 (0), 12 (0), 13 (0), 14 (0), 15 (0)
        16 (0), 17 (0), 18 (0), 19 (0), 20 (0), 21 (0), 22 (0), 23 (0)
        24 (0), 25 (0), 26 (0), 27 (0), 28 (0), 29 (0), 30 (0), 31 (0)

        Detected 32 cores in 1 packages

Core energy units: a1003
Time_unit:10, Energy_unit: 16, Power_unit: 3
Time_unit:0.000976562, Energy_unit: 1.52588e-05, Power_unit: 0.125
Core 0, energy used: 0.594635W, Package: 56.2228W
Core 1, energy used: 0.779114W, Package: 56.7767W
Core 2, energy used: 0.770111W, Package: 56.7767W
Core 3, energy used: 0.77713W, Package: 56.7767W
Core 4, energy used: 0.765839W, Package: 57.3302W
Core 5, energy used: 0.730286W, Package: 56.7677W
Core 6, energy used: 0.77774W, Package: 56.7677W
Core 7, energy used: 0.778656W, Package: 56.7677W
Core 8, energy used: 0.696411W, Package: 56.7677W
Core 9, energy used: 0.76828W, Package: 57.3244W
Core 10, energy used: 0.760651W, Package: 57.3244W
Core 11, energy used: 0.766754W, Package: 57.3244W
Core 12, energy used: 0.810089W, Package: 57.8799W
Core 13, energy used: 0.8078W, Package: 57.3352W
Core 14, energy used: 0.747375W, Package: 57.3352W
Core 15, energy used: 0.692444W, Package: 57.3352W
Core sum: 12.0233W
amanusk commented 5 years ago

@jangrewe thanks for the reference! This looks promising. I'll look into getting more information by reading MSRs. This will require root but would be a good option to have.

I hope I'll get a chance to implement this on Intel first (as I don't have AMD system), and it would be great if you could help test this on AMD (eventually)

schaerfo commented 3 years ago

I would look into this based on the amd_energy driver (https://www.kernel.org/doc/html/v5.8-rc1/hwmon/amd_energy.html). This works at least for Ryzen 3000 series CPUs (I have one of those) but documentation suggests that Ryzen 1000 and 2000 series are also supported.

amanusk commented 3 years ago

@schaerfo I don't have a system to test AMD(yet), if you have a working implementation, could you make a pull request?

zocker-160 commented 3 years ago

I am coming from the reddit post asking for help.

So here are my results using Kernel 5.8.1 on Ubuntu 20.04 and s-tui master:

Bildschirmfoto von 2020-08-16 00-19-57

amanusk commented 3 years ago

@schaerfo I have asked some users on /r/thinkpad to check if AMD power measurements works on their system. Looks like something is missing as @zocker-160 shows.

Are there additional steps requires to enable this feature on the OS side, and make the relevant paths available? Thanks

schaerfo commented 3 years ago

Thanks for the interest in this patch! Unfortunately, since kernel 5.8.0-rc6, the amd_energy driver performs a more restrictive match for supported CPUs. Therefore, it is necessary to either download the kernel source tree and revert commit f28e360f29031fdef8df3a1bcad666243bd6872d or use kernel 5.8.0-rc5 until this resolved in the kernel.

zocker-160 commented 3 years ago

it is necessary to either download the kernel source tree and revert commit f28e360f29031fdef8df3a1bcad666243bd6872d

@schaerfo @amanusk I can confirm that, I have tested again with Kernel 5.8 with the reverted commit, which does indeed fix the problem:

Bildschirmfoto von 2020-08-16 11-44-20

amanusk commented 3 years ago

@zocker-160 This is fantastic! Thanks! @schaerfo do you have any idea if/when will this make it to the official kernel release?

schaerfo commented 3 years ago

@amanusk Unfortunately not, the author of the amd_energy driver deliberately introduced this restriction in the mentioned patch citing "inconsistant values" being reported. For kernel 5.9 I have not found any changed in the driver. I will perhaps reach out to the developer to see if the restriction can be lifted somewhat. For that it would be useful to gather some data on which CPUs the reported numbers are reasonable.