added function to check for availability of necessary governors

This commit is contained in:
Adnan Hodzic 2019-12-30 20:02:30 +01:00
parent 30b72f7400
commit c3aab9fc03
1 changed files with 18 additions and 14 deletions

View File

@ -13,33 +13,38 @@ import re
# ToDo: # ToDo:
# - check if debian based + first time setup (install necessary packages) # - check if debian based + first time setup (install necessary packages)
# - add option to run as daemon on boot # - add option to run as daemon on boot
# - add revert options
# - sort out imports # - sort out imports
# - 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
# - copy cpufreqctl script if it doesn't exist # - copy cpufreqctl script if it doesn't exist
# - clean/refresh screen instead of constant publish
# global var # global var
p = psutil p = psutil
s = subprocess s = subprocess
tool_run = "python3 auto-cpufreq.py" tool_run = "python3 auto-cpufreq.py"
# check for necessary driver
def driver_check(): def driver_check():
driver = s.getoutput("cpufreqctl --driver") driver = s.getoutput("cpufreqctl --driver")
if driver != "intel_pstate": if driver != "intel_pstate":
sys.exit(f"\nError:\nOnly laptops with enabled \"intel_pstate\" (CPU Performance Scaling Driver) are supported.\n") print("\n" + "-" * 23 + " Driver check " + "-" * 23 + "\n")
sys.exit("ERROR:\n\n\"intel_pstate\" CPU Performance Scaling Driver is not enabled.\n")
def avail_gov(): # check for necessary scaling governors
# available governors def gov_check():
get_avail_gov = s.getoutput("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") avail_gov = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
# ToDo: make check to fail if powersave and performance are not available
# check current scaling governor governors=['performance','powersave']
#get_gov_state = subprocess.getoutput("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor")
#get_gov_state = s.getoutput("cpufreqctl --governor")
#gov_state = get_gov_state.split()[0] for line in open(avail_gov):
#print("\nCurrent scaling_governor: " + gov_state) for keyword in governors:
if keyword in line:
pass
else:
print("\n" + "-" * 9 + " Checking for necessary scaling governors " + "-" * 9 + "\n")
sys.exit("ERROR:\n\nCouldn't find any of the necessary scaling governors.\n")
# root check func # root check func
def root_check(): def root_check():
@ -89,8 +94,6 @@ def autofreq():
print("\n" + "-" * 18 + " CPU frequency scaling " + "-" * 19 + "\n") print("\n" + "-" * 18 + " CPU frequency scaling " + "-" * 19 + "\n")
driver_check()
# ToDo: make a function and more generic (move to psutil) # ToDo: make a function and more generic (move to psutil)
# 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")
@ -142,7 +145,8 @@ def sysinfo():
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
root_check() root_check()
#avail_gov() driver_check()
gov_check()
sysinfo() sysinfo()
autofreq() autofreq()
time.sleep(10) time.sleep(10)