add experimental HWP override on high load
This commit is contained in:
@@ -29,7 +29,9 @@ PL2_Tdp_W: 44
|
||||
# Time window #2 duration
|
||||
PL2_Duration_S: 0.002
|
||||
# Max allowed temperature before throttling
|
||||
Trip_Temp_C: 97
|
||||
Trip_Temp_C: 95
|
||||
# Set HWP energy performance hints to 'performance' on high load (EXPERIMENTAL)
|
||||
HWP_Mode: False
|
||||
|
||||
[UNDERVOLT]
|
||||
# CPU core voltage offset (mV)
|
||||
|
||||
@@ -4,11 +4,13 @@ import configparser
|
||||
import dbus
|
||||
import glob
|
||||
import os
|
||||
import psutil
|
||||
import struct
|
||||
import subprocess
|
||||
|
||||
from collections import defaultdict
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
from multiprocessing import cpu_count
|
||||
from periphery import MMIO
|
||||
from threading import Event, Thread
|
||||
|
||||
@@ -109,6 +111,15 @@ def calc_reg_values(config):
|
||||
return regs
|
||||
|
||||
|
||||
def set_hwp(pref):
|
||||
# set HWP energy performance hints
|
||||
assert pref in ('performance', 'balance_performance', 'default', 'balance_power', 'power')
|
||||
n = glob.glob('/sys/devices/system/cpu/cpu[0-9]*/cpufreq/energy_performance_preference')
|
||||
for c in n:
|
||||
with open(c, 'wb') as f:
|
||||
f.write(pref.encode())
|
||||
|
||||
|
||||
def power_thread(config, regs, exit_event):
|
||||
mchbar_mmio = MMIO(0xfed159a0, 8)
|
||||
|
||||
@@ -124,7 +135,15 @@ def power_thread(config, regs, exit_event):
|
||||
mchbar_mmio.write32(0, regs[power_source]['MSR_PKG_POWER_LIMIT'] & 0xffffffff)
|
||||
mchbar_mmio.write32(4, regs[power_source]['MSR_PKG_POWER_LIMIT'] >> 32)
|
||||
|
||||
exit_event.wait(config.getfloat(power_source, 'Update_Rate_s'))
|
||||
wait_t = config.getfloat(power_source, 'Update_Rate_s')
|
||||
enable_hwp_mode = config.getboolean('AC', 'HWP_Mode', fallback=False)
|
||||
if power_source == 'AC' and enable_hwp_mode:
|
||||
cpu_usage = float(psutil.cpu_percent(interval=wait_t))
|
||||
# set the full performance mode only when load is greater than this threshold (~ at least 1 core full speed)
|
||||
performance_mode = cpu_usage > 100. / (cpu_count() * 1.25)
|
||||
set_hwp('performance' if performance_mode else 'balance_performance')
|
||||
else:
|
||||
exit_event.wait(wait_t)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -136,6 +155,7 @@ def main():
|
||||
|
||||
exit_event = Event()
|
||||
t = Thread(target=power_thread, args=(config, regs, exit_event))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
undervolt(config)
|
||||
@@ -162,7 +182,7 @@ def main():
|
||||
|
||||
exit_event.set()
|
||||
loop.quit()
|
||||
t.join()
|
||||
t.join(timeout=1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
configparser==3.5.0
|
||||
dbus-python==1.2.4
|
||||
PyGObject==3.28.2
|
||||
dbus-python==1.2.8
|
||||
psutil==5.4.6
|
||||
PyGObject==3.28.3
|
||||
python-periphery==1.1.1
|
||||
|
||||
Reference in New Issue
Block a user