useful_scripts/speedstep.py

29 lines
1.6 KiB
Python

import os
import subprocess
import time
# available frequency steps: 2.53 GHz, 2.39 GHz, 2.26 GHz, 2.13 GHz, 2.00 GHz, 1.86 GHz, 1.73 GHz, 1.60 GHz, 1.46 GHz, 931 MHz
actual_values=["2.53GHz", "2.40GHz", "2.27GHz", "2.13GHz", "2.00GHz", "1.87GHz", "1.73GHz", "1.60GHz", "1.47GHz", "931MHz"]
steps=["2.53GHz", "2,39GHz", "2.26GHz", "2.13GHz", "2.00GHz", "1.86GHz", "1.73GHz", "1.60GHz", "1.46GHz", "931MHz"]
curstep=0
# the command to change max frequency is cpupower frequency-set -u states.get(key)
# the command to get current freq is sudo cpupower frequency-info -wm | awk '{print $4}' | grep "\S"
while True:
# step down as long as temp is above 82ºC
if int(subprocess.getoutput('cat /sys/class/thermal/thermal_zone0/temp'))>=82000 and subprocess.getoutput('sudo cpupower frequency-info -wm | awk \'{print $4 $5}\' | grep "\S"')!=steps[9]:
curstep=curstep+1
print("changing frequency to %s" % steps[curstep])
os.system('sudo cpupower frequency-set -u %s' % actual_values[curstep])
#subprocess.run('sudo cpupower frequency-set -u %s' % actual_values[curstep])
time.sleep(1)
# step up as long as temp is below 70ºC
if int(subprocess.getoutput('cat /sys/class/thermal/thermal_zone0/temp'))<=70000 and subprocess.getoutput('sudo cpupower frequency-info -wm | awk \'{print $4 $5}\' | grep "\S"')!=steps[0]:
curstep=curstep-1
print("changing frequency to %s" % steps[curstep])
os.system('sudo cpupower frequency-set -u %s' % actual_values[curstep])
#subprocess.run('sudo cpupower frequency-set -u %s' % actual_values[curstep])
time.sleep(1)
# wait a second before completing loop
time.sleep(1)