enabled turbo based on cpu load

This commit is contained in:
Adnan Hodzic 2019-12-29 22:02:27 +01:00
parent a462f495db
commit d079b179fe
1 changed files with 14 additions and 6 deletions

View File

@ -8,12 +8,12 @@ import psutil
# ToDo: # ToDo:
# - only run if driver is Intel pstate # - only run if driver is Intel pstate
# - display cpu/load/sensors(?) info
# - check if debian based # - check if debian based
# - set to install necesasry packages? # - set to install necesasry packages?
# - even when plugged in go back to powersave depending on load # - even when plugged in go back to powersave depending on load
# - sort out imports # - sort out imports
# go thru all other ToDo's # - add option to enable turbo in powersave
# - go thru all other ToDo's
p = psutil p = psutil
s = subprocess s = subprocess
@ -57,17 +57,21 @@ def set_performance():
def set_turbo(): def set_turbo():
load1m, _, _ = os.getloadavg() load1m, _, _ = os.getloadavg()
cpuload = p.cpu_percent(interval=1)
print("-" * 20) print("CPU usage:", cpuload, "%")
print("CPU usage:", p.cpu_percent(interval=1), "%")
print("Current load:", load1m) print("Current load:", load1m)
print("-" * 25)
if load1m > 2: if load1m > 2:
print("Load too high, turbo: ON") print("High load, turbo: ON")
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
print("High CPU:", p.cpu_percent(interval=1), "%")
print("High load:", load1m) print("High load:", load1m)
print("CPU load:", cpuload, "%")
elif cpuload > 25:
print("High CPU load, turbo: ON")
s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
else: else:
print("Load optimal, turbo: OFF") print("Load optimal, turbo: OFF")
s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True)
@ -75,6 +79,10 @@ def set_turbo():
#print(psutil.cpu_freq()) #print(psutil.cpu_freq())
#print(psutil.cpu_count()) #print(psutil.cpu_count())
# - display cpu/load/sensors(?) info
#def sysload_info():
# ....
def autofreq(): def autofreq():
# check battery status # check battery status
get_bat_state = s.getoutput("cat /sys/class/power_supply/BAT0/status") get_bat_state = s.getoutput("cat /sys/class/power_supply/BAT0/status")