added option where only lapotps with intel_pstate enabled are supported

This commit is contained in:
Adnan Hodzic 2019-12-29 22:56:16 +01:00
parent 2e4ec58536
commit 8d501d80ad
1 changed files with 28 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import os
import sys import sys
import time import time
import psutil import psutil
import platform
# ToDo: # ToDo:
# - only run if driver is Intel pstate # - only run if driver is Intel pstate
@ -15,10 +16,21 @@ import psutil
# - add option to enable turbo in powersave # - add option to enable turbo in powersave
# - go thru all other ToDo's # - go thru all other ToDo's
# global var
p = psutil p = psutil
s = subprocess s = subprocess
tool_run = "python3 auto-cpufreq.py" tool_run = "python3 auto-cpufreq.py"
def driver_check():
driver = s.getoutput("cpufreqctl --driver")
if driver != "intel_pstate":
sys.exit(f"\nError:\nOnly laptops with enabled \"intel_pstate\" (CPU Performance Scaling Driver) are supported.\n")
# print distro
# print chipset
# print laptop
def avail_gov(): def avail_gov():
# available governors # available governors
get_avail_gov = s.getoutput("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") get_avail_gov = s.getoutput("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors")
@ -40,7 +52,7 @@ def root_check():
# set powersave # set powersave
def set_powersave(): def set_powersave():
print("\nSetting: powersave") print("\nSetting: powersave")
s.run("sudo cpufreqctl --governor --set=powersave", shell=True) s.run("cpufreqctl --governor --set=powersave", shell=True)
print("Setting turbo: off") print("Setting 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)
@ -48,9 +60,9 @@ def set_powersave():
# set performance # set performance
def set_performance(): def set_performance():
print("\nSetting: performance") print("\nSetting: performance")
s.run("sudo cpufreqctl --governor --set=performance", shell=True) s.run("cpufreqctl --governor --set=performance", shell=True)
# alternative # alternative
# sudo echo performance /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # echo performance /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# enable turbo boost # enable turbo boost
set_turbo() set_turbo()
@ -81,9 +93,19 @@ def set_turbo():
# - display cpu/load/sensors(?) info # - display cpu/load/sensors(?) info
#def sysload_info(): #def sysload_info():
# .... # distro
# kernel
# number of cores
# driver?
# chipset
# laptop maker/model?
# sensors?
def autofreq(): def autofreq():
driver_check()
# ToDo: make a function?
# 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")
bat_state = get_bat_state.split()[0] bat_state = get_bat_state.split()[0]
@ -97,7 +119,9 @@ def autofreq():
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
root_check() root_check()
#load() #load()
#set_powersave() #set_powersave()
autofreq() autofreq()
time.sleep(10) time.sleep(10)