hattedsquirrel / ryzen_monitor

Monitor power information of Ryzen processors via the PM table of the SMU
GNU Affero General Public License v3.0
93 stars 16 forks source link

Support for Ryzen 2000 series #5

Open kostadinsh opened 3 years ago

kostadinsh commented 3 years ago

Hi, can you add support for Ryzen 2000 series?

hattedsquirrel commented 3 years ago

Hi, please use the following commands to create pm table dumps:

cat /sys/kernel/ryzen_smu_drv/pm_table_version | xxd -p > dump_pm_version
sleep 5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_idle.bin

yes > /dev/null &
sleep 0.5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_1Ta.bin
sleep 5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_1Tb.bin

yes > /dev/null &
sleep 0.5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_2Ta.bin
sleep 5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_2Tb.bin

for i in {1..14}; do (yes > /dev/null &); done
sleep 0.5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_16Ta.bin
sleep 5
cat /sys/kernel/ryzen_smu_drv/pm_table > dump_16Tb.bin

killall yes

Then create a .tar.gz from all dump_* files and attach the tar.gz to this thread. With those files I'll be able to figure out how the fields are organized in the 2000 series an can create the required translation tables.

kostadinsh commented 3 years ago

It seems like it is not possible to access the power tables in the ryzen_smu driver for my Ryzen 5 2600x (Pinnacle Ridge). Sorry for wasting your time.

irusanov commented 3 years ago

Zen and Zen+ have no table versions or at least I don't know how to read it, because the command returns 0. They have power tables though, which can be read. I don't know if the structure changes between AGESA versions. RSMU addresses are as follows:

Rsmu.SMU_ADDR_MSG = 0x03B1051C;
Rsmu.SMU_ADDR_RSP = 0x03B10568;
Rsmu.SMU_ADDR_ARG = 0x03B10590;

And corresponding commands:

Rsmu.SMU_MSG_TransferTableToDram = 0xA;
Rsmu.SMU_MSG_GetDramBaseAddress = 0xC;

There's a full table available and offsets differ between Zen and Zen+. I'm only using a handful of offsets for the purposes of ZenTimings.

// version, size, FCLK, UCLK, MCLK, VDDCR_SOC, CLDO_VDDP, CLDO_VDDG_IOD, CLDO_VDDG_CCD, Cores Power Offset
// Zen CPU
{ 0x000100, 0x7E4, 0x84, 0x84, 0x84, 0x68, 0x44, -1, -1, -1 },

// Zen+ CPU
{ 0x000101, 0x7E4, 0x84, 0x84, 0x84, 0x60, 0x3C, -1, -1, -1 },

where first value is a faux version for these in order to get the definition from the lookup table Table size is not the actual length, it's probably much shorter One offset is used for fclk/uclk/mclk, because there are no separate values on ZP VDDGs are also not available

linnaea commented 2 years ago

I modified ryzen_smu to dump PM table on my Ryzen 2700 and it seems to be 652 bytes long.

Reverse engineering Ryzen Master didn't yield much as it only report PPT/TDC/EDC/THM and index 5(haven't figured out what it is) for Zen+ and reports nothing from Zen's PMTable.

What I have guessed so far:

 0 PPT Limit
 1 PPT
 2 TDC Limit
 3 TDC
 4 EDC Limit
 5 Fast EDC?
 6 EDC
 7 Thermal Limit
 8 Tctl or Tdie
 9 FIT Limit?
10 FIT?
11 TDP?
12 Vcore VID?
13 Vsoc  VID?
15 CLDO VDDP?
16 Pcore
17 Psoc
20 Package Power
21 Vcore
22 Icore
23 Pcore
24 Vsoc
25 Isoc
26 Psoc
33 FCLK/MCLK/UCLK
40-47 Core0-7 Power?
56-63 Vcore0-7?
64-71 Core0-7 Temp?
72-79 Core0-7 FIT?
80-87 Core0-7 Peak Current? Power?
88-95 Core0-7 Freq
96-103 Core0-7 Effective Freq
104-111 Core0-7 C0
112-119 Core0-7 C1
120-127 Core0-7 C6
128-135 Core0-7 PState
140-141 L3 Temp
142-143 L3 FIT
146-147 L3 Freq?
148 something Temp
155 Package Power

dump.zip

PMTable dumped with hexdump -e '1/4 "%4_ad %08x "' -e '1/4 "%9.4f\n"' /sys/kernel/ryzen_smu_drv/pm_table

hattedsquirrel commented 2 years ago

@linnaea In your modifications to ryzen_smu I saw your comment "Not all platforms with PM Table has a version". Does this mean your system does not report any version at all? What could be a good way to identify what system / table it is from ryzen_monitor?

irusanov commented 2 years ago

@hattedsquirrel, original Zen and Zen+ don't have versions, at least I haven't found any. This doesn't mean there aren't different table versions, but they are not reported. 0xA is the command to transfer the table to RAM and 0xC is the command to get DRAM Base address. They have fully functional PM tables, at least in later bioses.

@linnaea, 15 (offset 0x3C) is CLDO_VDDP for Zen+ based on my code for ZenTimings, so your assumption is correct. I haven't bothered to decode other values since I don't need them, but have Zen and Zen+ test CPUs, so I can eventually dump PM tables.