moved checks before the loop for efficiency

de-hardcode the CPU critical temperature by reading from the MSR
This commit is contained in:
erpalma
2018-08-13 14:40:18 -07:00
parent 1d521818e5
commit 015f3feedd

View File

@@ -32,7 +32,7 @@ VOLTAGE_PLANES = {
'ANALOGIO': 4, 'ANALOGIO': 4,
} }
TRIP_TEMP_RANGE = (40, 97) TRIP_TEMP_RANGE = [40, 97]
C_TDP_RANGE = (0, 2) C_TDP_RANGE = (0, 2)
power = {'source': None, 'method': 'polling'} power = {'source': None, 'method': 'polling'}
@@ -152,9 +152,17 @@ def load_config():
def calc_reg_values(config): def calc_reg_values(config):
regs = defaultdict(dict) regs = defaultdict(dict)
for power_source in ('AC', 'BATTERY'): for power_source in ('AC', 'BATTERY'):
# the critical temperature for this CPU is 100 C if readmsr(0xce, 30, 30) != 1:
trip_offset = int(round(100 - config.getfloat(power_source, 'Trip_Temp_C'))) print("[W] Setting temperature target is not supported by this CPU")
regs[power_source]['MSR_TEMPERATURE_TARGET'] = trip_offset << 24 else:
# the critical temperature for my CPU is 100 'C
critical_temp = readmsr(0x1a2, 16, 23)
# update the allowed temp range to keep at least 3 'C from the CPU critical temperature
global TRIP_TEMP_RANGE
TRIP_TEMP_RANGE[1] = min(TRIP_TEMP_RANGE[1], critical_temp - 3)
trip_offset = int(round(critical_temp - config.getfloat(power_source, 'Trip_Temp_C')))
regs[power_source]['MSR_TEMPERATURE_TARGET'] = trip_offset << 24
# 0.125 is the power unit of my CPU # 0.125 is the power unit of my CPU
power_unit = 1.0 / 2**readmsr(0x606, 0, 3) power_unit = 1.0 / 2**readmsr(0x606, 0, 3)
@@ -170,13 +178,13 @@ def calc_reg_values(config):
TW2 << 49) TW2 << 49)
# cTDP # cTDP
try: c_tdp_target_value = config.getint(power_source, 'cTDP', fallback=None)
c_tdp_target_value = int(config.getfloat(power_source, 'cTDP')) if c_tdp_target_value is not None:
valid_c_tdp_target_value = min(C_TDP_RANGE[1], max(C_TDP_RANGE[0], c_tdp_target_value)) if readmsr(0xce, 33, 34) < 2:
regs[power_source]['MSR_CONFIG_TDP_CONTROL'] = valid_c_tdp_target_value print("[W] cTDP setting not supported by this CPU")
except configparser.NoOptionError: else:
pass valid_c_tdp_target_value = min(C_TDP_RANGE[1], max(C_TDP_RANGE[0], c_tdp_target_value))
regs[power_source]['MSR_CONFIG_TDP_CONTROL'] = valid_c_tdp_target_value
return regs return regs
@@ -202,15 +210,11 @@ def power_thread(config, regs, exit_event):
power['source'] = 'BATTERY' if is_on_battery() else 'AC' power['source'] = 'BATTERY' if is_on_battery() else 'AC'
# set temperature trip point # set temperature trip point
if readmsr(0xce, 30, 30) != 1: if 'MSR_TEMPERATURE_TARGET' in regs[power['source']]:
print("setting temperature target is not supported by this CPU")
else:
writemsr(0x1a2, regs[power['source']]['MSR_TEMPERATURE_TARGET']) writemsr(0x1a2, regs[power['source']]['MSR_TEMPERATURE_TARGET'])
# set cTDP # set cTDP
if readmsr(0xce, 33, 34) < 2: if 'MSR_CONFIG_TDP_CONTROL' in regs[power['source']]:
print("cTDP setting not supported by this cpu")
else:
writemsr(0x64b, regs[power['source']]['MSR_CONFIG_TDP_CONTROL']) writemsr(0x64b, regs[power['source']]['MSR_CONFIG_TDP_CONTROL'])
# set PL1/2 on MSR # set PL1/2 on MSR