Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zenstates keeps saying MSR isn't loaded when it is #6

Open
smithaa02 opened this issue Jan 20, 2019 · 10 comments
Open

Zenstates keeps saying MSR isn't loaded when it is #6

smithaa02 opened this issue Jan 20, 2019 · 10 comments

Comments

@smithaa02
Copy link

smithaa02 commented Jan 20, 2019

I've enabled MSR. I've done this on boot up...

sudo nano -w /etc/modules-load.d/modules.conf
msr
ctrl-x (y)
sudo reboot now

I've also also added this manually:

sudo modprobe msr

When I check to see if my modules are listed with lsmod, I do indeed see MSR:

lsmod | grep msr

But...when I run zenstates...it always says MSR module not loaded.

/home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --c6-disable
Traceback (most recent call last):
File "/home/smithaa02/ryzen/ZenStates-Linux/zenstates.py", line 112, in <module> writemsr(0xC0010292, readmsr(0xC0010292) & ~(1 << 32))
File "/home/smithaa02/ryzen/ZenStates-Linux/zenstates.py", line 33, in readmsr raise OSError("msr module not loaded (run modprobe msr)")
OSError: msr module not loaded (run modprobe msr)

Even the list command shows no MSR:

smithaa02@smithaa02-MS-7B79:/dev/cpu/1$ /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py -l Traceback (most recent call last):
File "/home/smithaa02/ryzen/ZenStates-Linux/zenstates.py", line 76, in <module> print('P' + str(p) + " - " + pstate2str(readmsr(pstates[p])))
File "/home/smithaa02/ryzen/ZenStates-Linux/zenstates.py", line 33, in readmsr raise OSError("msr module not loaded (run modprobe msr)")
OSError: msr module not loaded (run modprobe msr)

The Pythod code this references is:

try:
f = os.open('/dev/cpu/%d/msr' % cpu, os.O_RDONLY)
os.lseek(f, msr, os.SEEK_SET)
val = struct.unpack('Q', os.read(f, 8))[0]
os.close(f)
return val
except:
raise OSError("msr module not loaded (run modprobe msr)")

But this makes no sense. How can the program complain about missing /dev/cpu/*/msr when I see them?

smithaa02@smithaa02-MS-7B79:/dev/cpu$ ls -al /dev/cpu/*/msr
crw------- 1 root root 202, 0 Jan 20 16:38 /dev/cpu/0/msr
crw------- 1 root root 202, 1 Jan 20 16:38 /dev/cpu/1/msr
crw------- 1 root root 202, 2 Jan 20 16:38 /dev/cpu/2/msr
crw------- 1 root root 202, 3 Jan 20 16:38 /dev/cpu/3/msr

Any help would be appreciated. My ryzen crashes have been hell...I really think it is the c6 issues and I'm desperate to fix this.

My system is:

  • CPU: Ryzen 2200G
  • MB: MSI X470 G (with 2019-01-04 bios version)
  • OS: Linux Mint Tessa 19.1 (fresh install...just a few days old)
@OdinVex
Copy link

OdinVex commented Jan 26, 2019

Due to changes in Linux regarding MSR-permissions (read/write can be used to subvert Kernel, code can be executed) you must (for python 3.6...) (disabling SecureBoot used to work before the changes were made):

sudo setcap cap_sys_rawio=ep /usr/bin/python3.6
sudo /usr/bin/python3.6 ./zenstates.py ...

However, I wouldn't recommend giving python such capabilities like that as a whole. Hopefully a SIGNED kernel module will be available in the future to allow mediating MSR reads/writes for sudoers.

Edit:
zenstates.py should be modified to check for a -13 error code. This will differentiate the situation so that you can tell if module msr is loaded or not, instead of reporting (erroneously) that msr is not loaded just because any error occurs.

Edit:
To undo any setcap:
sudo setcap -r /usr/bin/python3.6

Edit:
I would recommend: https://github.com/jfredrickson/disable-c6
Originally posted by @jfredrickson in #4 (comment)

@smithaa02
Copy link
Author

smithaa02 commented Feb 7, 2019

Thank you for your suggestion. I followed your instructions and now I don't get an error when I run this command:

sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --c6-disable

Furthermore I can confirm that C6 is indeed off with this command:

sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py -l

P0 - Enabled - FID = 73 - DID = A - VID = 35 - Ratio = 23.00 - vCore = 1.21875
P1 - Enabled - FID = 8A - DID = C - VID = 5C - Ratio = 23.00 - vCore = 0.97500
P2 - Enabled - FID = 80 - DID = 10 - VID = 6C - Ratio = 16.00 - vCore = 0.87500
P3 - Disabled
P4 - Disabled
P5 - Disabled
P6 - Disabled
P7 - Disabled
C6 State - Package - Disabled
C6 State - Core - Disabled

Question though...how can I automatically load this? "Disable-c6" uses a different permutation of my command, so I assume that wouldn't work?

This site (https://forum.manjaro.org/t/ryzen-freezes-possible-solution-related-to-c6-state/37870) suggests you just need to load the kill command in Systemd...but I'm not super familiar with SystemD...do you know how I would set this up and if it would work with sudo access?

Also, do you know if this kill command must be run continually in a loop on the background, or do you just need to load it once on bootup?

Thanks again for your help.

@OdinVex
Copy link

OdinVex commented Feb 7, 2019

In response, again, I would recommend: https://github.com/jfredrickson/disable-c6. You can use systemd to automatically do this on boot. I modified Zenstates to disable all but P0 and C6 with my own command-line parameter and incorporated that into the systemd stuff that the link mentions. I never had to do anything with kill commands or any such stuff. It seems to keep until shutdown. Not sure if the systemd task/job needs sudo, but I put it in anyway. I did not need to give python any special permission!

@smithaa02
Copy link
Author

smithaa02 commented Feb 13, 2019

If any Ryzen user finds this via Google...I continue to suffer system crashes. I'm going to try to disable P1 and P2 now to see if that helps. Cross my fingers...

sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --disable -p 1
sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --disable -p 2
sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --c6-disable

@OdinVex
Copy link

OdinVex commented Feb 13, 2019

If any Ryzen user finds this via Google...I continue to suffer system crashes. I'm going to try to disable P1 and P2 now to see if that helps. Cross my fingers...

sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --disable -p 1
sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --disable -p 2
sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --c6-disable

I hope that is through systemd. You don't need to give python those caps if you do it through systemd making it much safer...

My modified version of disable-c6 loops through all P-states except 0 and disables them but leaves C6 optionally enabled or disabled. Trivial to modify both projects to add this functionality. I did it to stop ASUS from modifying my rig to throttle with the power unplugged. Helps but not perfect.

@smithaa02
Copy link
Author

smithaa02 commented Mar 20, 2019

What's curious is it seems this script is less effective if executed later. For example if I boot up...load my browser, music program etc...then execute zenstates.py...then I have higher chances of a crash. This appears to be more effective if executed as soon as possible.

Ideally this is executed at bootup. The following are instruction on how to do this for Mint/Ubuntu and SystemD.

1) sudo nano /etc/systemd/system/killryzen.service

2) Wite your file. eg:

[Unit]
Description=Kill Ryzen

[Service]
ExecStart=/usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py --c6-disable

[Install]
WantedBy=multi-user.target

3) Save (with nano this is ctrl-x + y)

4) Make the file writeable

sudo chmod u+x /etc/systemd/system/killryzen.service

5) Test this to make sure it works

sudo systemctl start killryzen

6) Add to your startup

sudo systemctl enable killryzen

7) Reboot to verify that this worked

sudo reboot now
sudo /usr/bin/python3.6 /home/smithaa02/ryzen/ZenStates-Linux/zenstates.py -l

If C6 is off, then you know this worked. As Yuji mentioned, this is a nice way to do this as you don't need to run systemd commands with sudo.

@smithaa02
Copy link
Author

Another update for wayward googlers that find this. I've tried a LOT of things to fix this stupid Ryzen bug...nothing worked. Except...once I got an external video card ALL problems went away. The card I got was the R7240-2GD3-L which is about $75 on Amazon, and is comparable to the graphics on the 2200.

@OdinVex
Copy link

OdinVex commented Jun 7, 2019

bug

What bug, anyway? Behaves fine on all of my Ryzen systems.

@smithaa02
Copy link
Author

smithaa02 commented Jun 20, 2019

Never worked on my MSI X470 motherboard. Many other users have had similar problem. I suspect this issue might be motherboard specific. Doesn't matter now...an external graphics card fixed all my random lockups.

@All3xJ
Copy link

All3xJ commented Sep 27, 2021

For me the issue was that I wasn't running zenstates as root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants