Browse Source

Added the togglecode.py utility;

zenstates.py now updates the P-State settings in all cores, and locks
the TSC to the P0 boot frequency (so it doesn't get out of sync with the
HPET);
master
r4m0n 5 years ago
parent
commit
1a4bae5039
  1. 8
      README.md
  2. 16
      togglecode.py
  3. 26
      zenstates.py

8
README.md

@ -1,4 +1,7 @@
# ZenStates-Linux
Collection of utilities for Ryzen processors and motherboards
## zenstates.py
Dynamically edit AMD Ryzen processor P-States
Requires root access and the msr kernel module loaded (just run "modprobe msr" as root).
@ -18,3 +21,8 @@ Requires root access and the msr kernel module loaded (just run "modprobe msr" a
-d DID, --did DID DID to set (in hex)
-v VID, --vid VID VID to set (in hex)
## togglecode.py
Turns on/off the Q-Code display on ASUS Crosshair VI Hero motherboards (and other boards with a compatible Super I/O chip)
Requires root access and the portio python module (to install run "pip install portio")

16
togglecode.py

@ -0,0 +1,16 @@
#!/usr/bin/python
import portio
portio.iopl(3)
portio.ioperm(0x2E, 2, 1)
portio.outb_p(0x87, 0x2E)
portio.outb_p(0x01, 0x2E)
portio.outb_p(0x55, 0x2E)
portio.outb_p(0x55, 0x2E)
portio.outb_p(0x07, 0x2E)
portio.outb_p(0x03, 0x2F)
portio.outb_p(0xF0, 0x2E)
f = portio.inb_p(0x2F)
f ^= 0x08
portio.outb_p(f, 0x2F)

26
zenstates.py

@ -1,22 +1,30 @@
#!/usr/bin/python
import struct
import os
import glob
import argparse
pstates = range(0xC0010064, 0xC001006C)
def writemsr(msr, val):
def writemsr(msr, val, cpu = -1):
try:
f = os.open('/dev/cpu/0/msr', os.O_WRONLY)
os.lseek(f, msr, os.SEEK_SET)
os.write(f, struct.pack('Q', val))
os.close(f)
if cpu == -1:
for c in glob.glob('/dev/cpu/[0-9]*/msr'):
f = os.open(c, os.O_WRONLY)
os.lseek(f, msr, os.SEEK_SET)
os.write(f, struct.pack('Q', val))
os.close(f)
else:
f = os.open('/dev/cpu/%d/msr' % (cpu), os.O_WRONLY)
os.lseek(f, msr, os.SEEK_SET)
os.write(f, struct.pack('Q', val))
os.close(f)
except:
raise OSError("msr module not loaded (run modprobe msr)")
def readmsr(msr):
def readmsr(msr, cpu = 0):
try:
f = os.open('/dev/cpu/0/msr', os.O_RDONLY)
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)
@ -84,6 +92,10 @@ if args.pstate >= 0:
new = setvid(new, args.fid)
print('Setting VID to %X' % args.fid)
if new != old:
if not (readmsr(0xC0010015) & (1 << 21)):
print('Locking TSC frequency')
for c in range(len(glob.glob('/dev/cpu/[0-9]*/msr'))):
writemsr(0xC0010015, readmsr(0xC0010015, c) | (1 << 21), c)
print('New P' + str(args.pstate) + ': ' + pstate2str(new))
writemsr(pstates[args.pstate], new)

Loading…
Cancel
Save