Extended mechanism to set turbo based temperature & CPU utilization/load

to mon_performance/powersave functions & other output improvements
This commit is contained in:
Adnan Hodzic 2020-12-05 21:15:15 +01:00
parent fa0979a755
commit ce4e119adb
2 changed files with 109 additions and 29 deletions

View File

@ -64,7 +64,6 @@ def main(monitor, live, daemon, install, log, debug):
gov_check() gov_check()
cpufreqctl() cpufreqctl()
distro_info() distro_info()
print("")
sysinfo() sysinfo()
mon_autofreq() mon_autofreq()
countdown(5) countdown(5)
@ -77,7 +76,6 @@ def main(monitor, live, daemon, install, log, debug):
gov_check() gov_check()
cpufreqctl() cpufreqctl()
distro_info() distro_info()
print("")
sysinfo() sysinfo()
set_autofreq() set_autofreq()
countdown(5) countdown(5)
@ -88,6 +86,7 @@ def main(monitor, live, daemon, install, log, debug):
root_check() root_check()
footer() footer()
distro_info() distro_info()
sysinfo()
print("") print("")
if os.getenv('PKG_MARKER') == "SNAP": if os.getenv('PKG_MARKER') == "SNAP":
print("Snap package: yes") print("Snap package: yes")
@ -103,8 +102,6 @@ def main(monitor, live, daemon, install, log, debug):
print("Battery is: discharging") print("Battery is: discharging")
print("") print("")
app_res_use() app_res_use()
print("")
sysinfo()
display_load() display_load()
get_current_gov() get_current_gov()
get_turbo() get_turbo()

View File

@ -206,7 +206,6 @@ def deploy_complete_msg():
def remove_complete_msg(): def remove_complete_msg():
print("\n" + "-" * 25 + " auto-cpufreq daemon removed " + "-" * 25 + "\n") print("\n" + "-" * 25 + " auto-cpufreq daemon removed " + "-" * 25 + "\n")
print("auto-cpufreq successfully removed.") print("auto-cpufreq successfully removed.")
footer()
def deploy_daemon(): def deploy_daemon():
@ -313,7 +312,8 @@ def display_load():
load1m, _, _ = os.getloadavg() load1m, _, _ = os.getloadavg()
print("\nTotal CPU usage:", cpuload, "%") print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n") print("Total system load:", load1m)
print("Average temp. of all cores:", avg_all_core_temp, "°C", "\n")
# set powersave and enable turbo # set powersave and enable turbo
def set_powersave(): def set_powersave():
@ -330,18 +330,60 @@ def set_powersave():
load1m, _, _ = os.getloadavg() load1m, _, _ = os.getloadavg()
print("\nTotal CPU usage:", cpuload, "%") print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n") print("Total system load:", load1m)
print("Average temp. of all cores:", avg_all_core_temp, "°C")
# conditions for setting turbo in powersave # conditions for setting turbo in powersave
if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100): if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100):
print("High CPU load, setting turbo boost: on") print("\nHigh CPU load")
turbo(True)
# high cpu usage trigger
if cpuload > 35:
print("setting turbo boost: on")
turbo(True)
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 70:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("setting turbo boost: off")
turbo(False)
else:
print("setting turbo boost: on")
turbo(True)
elif load1m > powersave_load_threshold: elif load1m > powersave_load_threshold:
print("High system load, setting turbo boost: on") print("\nHigh system load")
turbo(True)
# high cpu usage trigger
if cpuload > 35:
print("setting turbo boost: on")
turbo(True)
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 65:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("setting turbo boost: off")
turbo(False)
else:
print("setting turbo boost: on")
turbo(True)
else: else:
print("Load optimal, setting turbo boost: off") print("\nLoad optimal")
turbo(False)
# high cpu usage trigger
if cpuload > 35:
print("setting turbo boost: on")
turbo(True)
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 60:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("setting turbo boost: off")
turbo(False)
else:
print("setting turbo boost: on")
turbo(True)
footer() footer()
@ -356,20 +398,61 @@ def mon_powersave():
load1m, _, _ = os.getloadavg() load1m, _, _ = os.getloadavg()
print("\nTotal CPU usage:", cpuload, "%") print("\nTotal CPU usage:", cpuload, "%")
print("Total system load:", load1m, "\n") print("Total system load:", load1m)
print("Average temp. of all cores:", avg_all_core_temp, "°C")
if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100): if psutil.cpu_percent(percpu=False, interval=0.01) >= 30.0 or isclose(max(psutil.cpu_percent(percpu=True, interval=0.01)), 100):
print("High CPU load, suggesting to set turbo boost: on") print("\nHigh CPU load")
get_turbo()
footer() # high cpu usage trigger
if cpuload > 35:
print("suggesting to set turbo boost: on")
get_turbo()
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 70:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("suggesting to set turbo boost: off")
get_turbo()
else:
print("suggesting to set turbo boost: on")
get_turbo()
elif load1m > powersave_load_threshold: elif load1m > powersave_load_threshold:
print("High system load, suggesting to set turbo boost: on") print("\nHigh system load")
get_turbo()
footer() # high cpu usage trigger
if cpuload > 35:
print("suggesting to set turbo boost: on")
get_turbo()
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 65:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("suggesting to set turbo boost: off")
get_turbo()
else:
print("suggesting to set turbo boost: on")
get_turbo()
else: else:
print("Load optimal, suggesting to set turbo boost: off") print("\nLoad optimal")
get_turbo()
footer() # high cpu usage trigger
if cpuload > 35:
print("suggesting to set turbo boost: on")
get_turbo()
# set turbo state based on average of all core temperatures
elif cpuload < 35 and avg_all_core_temp >= 60:
print("Optimal total CPU usage:", cpuload, "%, high average core temp:", avg_all_core_temp, "°C")
print("suggesting to set turbo boost: off")
get_turbo()
else:
print("suggesting to set turbo boost: on")
get_turbo()
footer()
# set performance and enable turbo # set performance and enable turbo
def set_performance(): def set_performance():
@ -440,7 +523,7 @@ def set_performance():
else: else:
print("setting turbo boost: on") print("setting turbo boost: on")
turbo(True) turbo(True)
footer() footer()
@ -461,7 +544,7 @@ def mon_performance():
load1m, _, _ = os.getloadavg() load1m, _, _ = os.getloadavg()
if psutil.cpu_percent(percpu=False, interval=0.01) >= 20.0 or max(psutil.cpu_percent(percpu=True, interval=0.01)) >= 75: if psutil.cpu_percent(percpu=False, interval=0.01) >= 20.0 or max(psutil.cpu_percent(percpu=True, interval=0.01)) >= 75:
print("High CPU load") print("\nHigh CPU load")
# high cpu usage trigger # high cpu usage trigger
if cpuload > 25: if cpuload > 25:
@ -478,7 +561,7 @@ def mon_performance():
get_turbo() get_turbo()
elif load1m > performance_load_threshold: elif load1m > performance_load_threshold:
print("High system load") print("\nHigh system load")
# high cpu usage trigger # high cpu usage trigger
if cpuload > 25: if cpuload > 25:
@ -494,7 +577,6 @@ def mon_performance():
print("suggesting to set turbo boost: on") print("suggesting to set turbo boost: on")
get_turbo() get_turbo()
footer()
else: else:
print("\nLoad optimal") print("\nLoad optimal")
@ -511,7 +593,8 @@ def mon_performance():
else: else:
print("suggesting to set turbo boost: on") print("suggesting to set turbo boost: on")
get_turbo() get_turbo()
footer()
footer()
def set_autofreq(): def set_autofreq():
@ -592,7 +675,7 @@ def sysinfo():
# processor_info # processor_info
model_name = getoutput("egrep 'model name' /proc/cpuinfo -m 1").split(":")[-1] model_name = getoutput("egrep 'model name' /proc/cpuinfo -m 1").split(":")[-1]
print(f"Procesor:{model_name}") print(f"Processor:{model_name}")
# get core count # get core count
total_cpu_count = int(getoutput("nproc --all")) total_cpu_count = int(getoutput("nproc --all"))