r4m0n / ZenStates-Linux

Dynamically edit AMD Ryzen processor P-States
MIT License
523 stars 64 forks source link

Error enabling states #1

Open CRCinAU opened 7 years ago

CRCinAU commented 7 years ago

When I try to enable a state, I get the following output:

# ./zenstates.py --enable --pstate 7
Current P7: Disabled
Enabling state
Traceback (most recent call last):
  File "./zenstates.py", line 103, in <module>
    print('New P' + str(args.pstate) + ': ' + pstate2str(new))
  File "./zenstates.py", line 40, in pstate2str
    ratio = 25*fid/(12.5 * did)
ZeroDivisionError: float division by zero

I notice in the listings:

# ./zenstates.py -l
P0 - Enabled - FID = 88 - DID = 8 - VID = 20 - Ratio = 34.00 - vCore = 1.35000
P1 - Enabled - FID = 78 - DID = 8 - VID = 2C - Ratio = 30.00 - vCore = 1.27500
P2 - Enabled - FID = 84 - DID = C - VID = 68 - Ratio = 22.00 - vCore = 0.90000
P3 - Disabled
P4 - Disabled
P5 - Disabled
P6 - Disabled
P7 - Disabled
C6 State - Package - Enabled
C6 State - Core - Enabled

Am I missing something?

CRCinAU commented 7 years ago

After a little toying, I set up the following for my 1700x:

# ./zenstates.py -l
P0 - Enabled - FID = 94 - DID = 8 - VID = 20 - Ratio = 37.00 - vCore = 1.35000
P1 - Enabled - FID = 88 - DID = 8 - VID = 2C - Ratio = 34.00 - vCore = 1.27500
P2 - Enabled - FID = 78 - DID = 8 - VID = 38 - Ratio = 30.00 - vCore = 1.20000
P3 - Enabled - FID = 70 - DID = 8 - VID = 3A - Ratio = 28.00 - vCore = 1.18750
P4 - Enabled - FID = 68 - DID = 8 - VID = 40 - Ratio = 26.00 - vCore = 1.15000
P5 - Enabled - FID = 60 - DID = 8 - VID = 48 - Ratio = 24.00 - vCore = 1.10000
P6 - Enabled - FID = 58 - DID = 8 - VID = 68 - Ratio = 22.00 - vCore = 0.90000
P7 - Enabled - FID = 48 - DID = 8 - VID = 78 - Ratio = 18.00 - vCore = 0.80000
C6 State - Package - Enabled
C6 State - Core - Enabled

How do I know if this actually takes effect? I notice that the output of /proc/cpuinfo doesn't seem to shift from 2.2GHz...

EUA commented 7 years ago

You can benchmark you CPU with 7zip, like 7za b

Or you can use I-Nex tool, It is like CPU-z for Linux. https://github.com/i-nex/I-Nex

Let me know if this tool helps you activate p-states functionality at Gigabyte board that doesn't have support for p-states ;)

seansweda commented 7 years ago

you can also use the cpupower tool, e.g.

# cpupower monitor -i 5

will calculate CPU frequencies after a 5 second sample

CRCinAU commented 7 years ago

Ok, so I've been tinkering more - and it seems on the 1700x in a Gigabyte AB350 Gaming 3 we get the following:

scaling_available_frequencies: 3400000 3000000 2200000

This explains why I see what I see when running zenstates.py without any further modification.

Right now, I'm setting:

### The 1700x only seems to support P0/1/2
## P0 = 3.900GHz, 1.3500v
./zenstates.py -p 0 -f 9C -d 8 -v 20

## P1 = 3.700GHz, 1.3000v
./zenstates.py -p 1 -f 94 -d 8 -v 28

## P2 = 1.800GHz, 0.8000v
./zenstates.py -p 2 -f 48 -d 8 -v 78

This gives me:

# 7za b

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_AU.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs AMD Ryzen 7 1700X Eight-Core Processor          (800F11),ASM,AES-NI)

AMD Ryzen 7 1700X Eight-Core Processor          (800F11)
CPU Freq:  2978  3883  3883  3881  3887  3884  3885  3880  3885

RAM size:   16058 MB,  # CPU hardware threads:  16
RAM usage:   3530 MB,  # Benchmark threads:     16

                       Compressing  |                  Decompressing
Dict     Speed Usage    R/U Rating  |      Speed Usage    R/U Rating
         KiB/s     %   MIPS   MIPS  |      KiB/s     %   MIPS   MIPS

22:      40061  1366   2853  38972  |     563145  1531   3137  48031
23:      37400  1371   2780  38107  |     560896  1555   3122  48529
24:      35574  1391   2751  38249  |     545391  1537   3114  47872
25:      34130  1445   2697  38969  |     535094  1545   3083  47622
----------------------------------  | ------------------------------
Avr:            1393   2770  38574  |             1542   3114  48013
Tot:            1467   2942  43294

If I set the CPU back to defaults:

# 7za b

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_AU.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs AMD Ryzen 7 1700X Eight-Core Processor          (800F11),ASM,AES-NI)

AMD Ryzen 7 1700X Eight-Core Processor          (800F11)
CPU Freq:  2867  3379  3379  3388  3388  3387  3386  3386  3387

RAM size:   16058 MB,  # CPU hardware threads:  16
RAM usage:   3530 MB,  # Benchmark threads:     16

                       Compressing  |                  Decompressing
Dict     Speed Usage    R/U Rating  |      Speed Usage    R/U Rating
         KiB/s     %   MIPS   MIPS  |      KiB/s     %   MIPS   MIPS

22:      36118  1333   2636  35136  |     488122  1516   2746  41632
23:      35279  1384   2598  35945  |     481296  1522   2736  41642
24:      32930  1373   2579  35407  |     460925  1483   2728  40458
25:      31540  1402   2569  36012  |     472302  1553   2707  42033
----------------------------------  | ------------------------------
Avr:            1373   2595  35625  |             1518   2729  41441
Tot:            1446   2662  38533
CRCinAU commented 7 years ago

Ok, from playing more - it seems the best I can get out of it is:

## P0 = 3.900GHz, 1.3500v
./zenstates.py -p 0 -f 9C -d 8 -v 20

## P1 = 3.700GHz, 1.3000v
./zenstates.py -p 1 -f 94 -d 8 -v 28

## P2 = 1.800GHz, 0.8000v
./zenstates.py -p 2 -f 48 -d 8 -v 68

That seems to output:

# 7za b

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_AU.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs AMD Ryzen 7 1700X Eight-Core Processor          (800F11),ASM,AES-NI)

AMD Ryzen 7 1700X Eight-Core Processor          (800F11)
CPU Freq:  3155  3885  3887  3886  3887  3886  3886  3886  3886

RAM size:   16058 MB,  # CPU hardware threads:  16
RAM usage:   3530 MB,  # Benchmark threads:     16

                       Compressing  |                  Decompressing
Dict     Speed Usage    R/U Rating  |      Speed Usage    R/U Rating
         KiB/s     %   MIPS   MIPS  |      KiB/s     %   MIPS   MIPS

22:      40506  1385   2844  39405  |     575141  1561   3143  49054
23:      38120  1427   2723  38840  |     563731  1558   3131  48775
24:      36009  1407   2751  38718  |     549774  1555   3103  48256
25:      34011  1426   2723  38833  |     533815  1543   3079  47508
----------------------------------  | ------------------------------
Avr:            1411   2760  38949  |             1554   3114  48398
Tot:            1483   2937  43674

If I try to go any higher than 3.900 (ie 3.95Ghz), then I get a system crash and have to hit the reset button. I tried at 3.95Ghz @ 1.36v with no better luck.

CRCinAU commented 7 years ago

Now, as far as P-States 3-7. I can enable these via software - but I'm not sure how to check if they are working or not. Interestingly enough, when I reboot after enabling 3-7, I get a prompt from the BIOS saying that things "aren't compatible" with expected values. This seems to cause the values in the BIOS to reset.

The other fun part - I flashed a mod'ed BIOS for the mainboard from here: http://www.win-raid.com/t2739f44-OFFER-Gigabyte-GA-AX-Aorus-Gaming-BIOS-mod.html

When I try to select any P-State customisation in the BIOS menus, it refused to let me select anything but P-State 0. I wasn't able to set any P1/P2/P3 etc to any slot.

So I'm gathering at the moment that either: 1) The p-states are enabled properly; or 2) The p-states are set up, but not working for P3-P7; or 3) Nothing is happening at all

The question is, how to tell? :)

EUA commented 7 years ago

Wow, scripts looks working! At least for P-0. So I can buy Gigabyte Mini ITX AM board for my purposes.

Indeed "7za b" tells what your CPU freq, which is With mod: 3886, Without 3387, calculated. You can assume that, It's 3.9Ghz and 3.4Ghz.

For 4Ghz, probably you need to push ~1.425v or similar. For me It's O.K. for experiment but will produce too much heat, stress your VRMs. Not worth for extra 100Mhz in terms of efficiency.

Why do you need every P-States? Most important state is P-0 because it's for overclocking and it's already working. If you are on High CPU load, than CPU is overclocked with that P-0 setting.

For other power states, it's not easy to tell if it's working with 7za but if P-0 works proper, you can assume other power states working well too.

CRCinAU commented 7 years ago

Yeah - I figure the P0 change is working - but not sure about the P2 state. I hear a lot that the 1700x can't get below 2.2GHz - so it may well not be capable of going below that physically. Not that it really matters I guess.

I settled on the following script settings:

### The 1700x only seems to support P0/1/2
## Defaults are:
#       P0 - Enabled - FID = 88 - DID = 8 - VID = 20 - Ratio = 34.00 - vCore = 1.35000
#       P1 - Enabled - FID = 78 - DID = 8 - VID = 2C - Ratio = 30.00 - vCore = 1.27500
#       P2 - Enabled - FID = 84 - DID = C - VID = 68 - Ratio = 22.00 - vCore = 0.90000

## P0 = 3.900GHz, 1.3500v
./zenstates.py -p 0 -f 9C -d 8 -v 20

## P1 = 3.700GHz, 1.3000v
./zenstates.py -p 1 -f 94 -d 8 -v 28

## P2 = 1.700GHz, 0.8000v
./zenstates.py -p 2 -f 66 -d C -v 78

As I said, I'm not sure P2 is actually working...

As for speeds, the biggest issue I have (even at stock speeds) is that the VRM temps will often get over 100c - I've seen it hit 105c on stock speeds using prime95 in Windows 10. It doesn't seem to get anywhere near that during normal usage - but I'm a bit concerned about that for long runs of very high CPU usage.

I'm using a H110i AIO cooler - so CPU temps never seem to get above around 50c - and the water never gets above about 37c - so there's heaps of capacity there.... Just a dodgy VRM :P

EUA commented 7 years ago

You better to put some slow rotating fan on VRM. Also such units might help you much: http://www.enzotechnology.com/mst_81.htm

CRCinAU commented 7 years ago

The "Gigabyte AB350 Gaming 3" already has a heatsink on the VRM... I'm not quite sure how effective it is though...

I'm looking to get one of these printed up at work: http://www.overclock.net/t/1626601/post-your-ryzen-vrm-temperatures

EUA commented 7 years ago

in linux, you can check your current P-State with cpupower frequency-info

CRCinAU commented 7 years ago

Ah - I was looking for this... For anyone else that stumbles across this later, Fedora 22 onwards has the 'cpupower' program in the 'kernel-tools' package... Output shows:

# cpupower frequency-info
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 2.20 GHz - 3.40 GHz
  available frequency steps:  3.40 GHz, 3.00 GHz, 2.20 GHz
  available cpufreq governors: conservative userspace powersave ondemand performance schedutil
  current policy: frequency should be within 2.20 GHz and 3.40 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency: 2.20 GHz (asserted by call to hardware)
  boost state support:
    Supported: no
    Active: no
    Boost States: 0
    Total States: 3
    Pstate-P0:  1100MHz
    Pstate-P1:  900MHz
    Pstate-P2:  2700MHz

Not even sure what to make of that ;)

Also:

# cpupower monitor
    |Mperf               || Idle_Stats
CPU | C0   | Cx   | Freq || POLL | C1   | C2
   0|  0.14| 99.86|  2805||  0.00|  0.00| 99.87
   1|  1.12| 98.88|  1921||  0.00|  0.00| 98.88
   2|  0.16| 99.84|  1487||  0.00|  0.37| 99.47
   3|  0.00|100.00|  1398||  0.00|  0.00|100.00
   4|  0.10| 99.90|  1476||  0.00|  0.00| 99.91
   5|  0.00|100.00|  1421||  0.00|  0.00|100.00
   6|  0.04| 99.96|  1482||  0.00|  0.00| 99.96
   7|  0.08| 99.92|  1476||  0.00|  0.00| 99.91
   8|  1.71| 98.29|  2657||  0.00|  0.70| 97.59
   9|  1.64| 98.36|  1942||  0.00|  0.00| 98.39
  10|  0.56| 99.44|  1510||  0.00|  0.27| 99.20
  11|  0.55| 99.45|  1511||  0.00|  0.00| 99.45
  12|  0.99| 99.01|  1506||  0.00|  0.00| 99.03
  13|  2.31| 97.69|  1517||  0.00|  0.24| 97.48
  14|  0.33| 99.67|  1512||  0.00|  0.19| 99.50
  15|  0.06| 99.94|  1523||  0.00|  0.00| 99.94
EUA commented 7 years ago

Do you run commands with "original" CPU P-States? If you are, than this "cpupower frequency-info" result is perfectly normal.

I believe freqency-info has some problem with detecting real P-States table clocks due Ryzen is new processor?? Who knows.

CRCinAU commented 7 years ago

Ok - so the final piece of the puzzle here is to get this stuff to apply on startup. I created this script called enable-pstates after copying zenstates.py to /usr/local/bin/

#!/bin/sh
### The 1700x only seems to support P0/1/2
## Defaults are:
#       P0 - Enabled - FID = 88 - DID = 8 - VID = 20 - Ratio = 34.00 - vCore = 1.35000
#       P1 - Enabled - FID = 78 - DID = 8 - VID = 2C - Ratio = 30.00 - vCore = 1.27500
#       P2 - Enabled - FID = 84 - DID = C - VID = 68 - Ratio = 22.00 - vCore = 0.90000

## P0 = 3.900GHz, 1.3500v
zenstates.py -p 0 -f 9C -d 8 -v 20

## P1 = 3.700GHz, 1.3000v
zenstates.py -p 1 -f 94 -d 8 -v 28

## P2 = 1.700GHz, 0.8000v
zenstates.py -p 2 -f 66 -d C -v 78

## List the result.
zenstates.py -l

I also have the following systemd service file in /etc/systemd/system/ryzen-overclock.service

[Unit]
Description=Ryzen Overclocker
DefaultDependencies=no
After=sysinit.target local-fs.target
Before=basic.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/enable-pstates

[Install]
WantedBy=basic.target

This causes the script to be called fairly early on in the boot - meaning you get the most benefit out of it.

Happy if you want to change that - and/or add it to the repo...

EDIT: As a thought, it may be worthwhile adding the full path to the enable-pstates script - or renaming it etc - as some distros may not have /usr/local/bin/ in $PATH...

LeJimster commented 6 years ago

@CRCinAU Nice startup script, I'm using a modified version of it. Unless you are loading the msr driver earlier by default, the script will fail. I added these lines into my script before the the 3 power states are set.

## Load the model-specific registers (MSR) driver
modprobe msr

Also as a note for the not so advanced linux users wanting to use this script. You need to set the script as executable and enable the service:

# chmod +x /usr/local/bin/enable-pstates
# systemctl enable ryzen-overclock.service

Thanks to @r4m0n for tool and @CRCinAU for the script =)

Shished commented 5 years ago

It seems that states p3-7 does not work at all. I have Ryzen 5 2600 and ASRock b450 pro4, it allows to set p-states in bios in the similar way to ZenStates. When p3 or later state is set to custom, Linux does not boots.