erpalma / throttled

Workaround for Intel throttling issues in Linux.
MIT License
2.68k stars 166 forks source link

Error if Power Limit Isn't Set #350

Open notstarboard opened 6 months ago

notstarboard commented 6 months ago

I've been having no success using georgewhewell/undervolt to undervolt my laptop and I stumbled upon this project as a possible alternative. I have no interest in anything other than undervolting, so I put together a relatively sparse config file aimed at doing just that:

[GENERAL]
# Enable or disable the script execution
Enabled: True
# SYSFS path for checking if the system is running on AC power
Sysfs_Power_Path: /sys/class/power_supply/ADP1/online
# Auto reload config on changes
Autoreload: True

[BATTERY]
# Update the registers every this many seconds
Update_Rate_s: 30

[AC]
# Update the registers every this many seconds
Update_Rate_s: 30

[UNDERVOLT]
# CPU core voltage offset (mV)
CORE: -100
# Integrated GPU voltage offset (mV)
GPU: -100
# CPU cache voltage offset (mV)
CACHE: -100
# System Agent voltage offset (mV)
UNCORE: 0
# Analog I/O voltage offset (mV)
ANALOGIO: 0

This configuration causes an exception to be thrown by the service:

Apr 29 20:07:17 josh-MacBookPro systemd[1]: Started Stop Intel throttling.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Detected CPU architecture: Intel Crystal Well-DT
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Trying to unlock MSR allow_writes.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Testing if undervolt is supported...
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Testing if HWP is supported...
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [E] Unable to read to MSR IA32_HWP_REQUEST (774). Unknown error.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [W] HWP seems not to be supported by your system, disabling.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Loading config file.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] AC trip temperature is disabled in config.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] AC package power limits are disabled in config.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] BATTERY trip temperature is disabled in config.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] BATTERY package power limits are disabled in config.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: [I] Starting main loop.
Apr 29 20:07:17 josh-MacBookPro python3[22531]: Exception in thread Thread-1 (power_thread):
Apr 29 20:07:17 josh-MacBookPro python3[22531]: Traceback (most recent call last):
Apr 29 20:07:17 josh-MacBookPro python3[22531]:   File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
Apr 29 20:07:17 josh-MacBookPro python3[22531]:     self.run()
Apr 29 20:07:17 josh-MacBookPro python3[22531]:   File "/usr/lib/python3.10/threading.py", line 953, in run
Apr 29 20:07:17 josh-MacBookPro python3[22531]:     self._target(*self._args, **self._kwargs)
Apr 29 20:07:17 josh-MacBookPro python3[22531]:   File "/opt/throttled/throttled.py", line 755, in power_thread
Apr 29 20:07:17 josh-MacBookPro python3[22531]:     write_value = regs[power['source']]['MSR_PKG_POWER_LIMIT']
Apr 29 20:07:17 josh-MacBookPro python3[22531]: KeyError: 'MSR_PKG_POWER_LIMIT'

The issue seems to be that regs[power_source]['MSR_PKG_POWER_LIMIT'] is never set on line 625 because none of PL1_Tdp_W, PL1_Duration_s, PL2_Tdp_W, and PL2_Duration_s are set in my config file. power_thread is always called in main(), and then within power_thread it tries to use regs[power_source]['MSR_PKG_POWER_LIMIT'], which has not been set.

A conditional should probably be added to avoid this. I don't think power_thread needs to be called at all unless the user attempts to change related settings in the config file.

Klusio19 commented 6 months ago

I have exact same error, and similar usecase. In my case undervolting was working (I was using intel-undervolt), but I need program to undervolt based on power source, intel-undervolt has no feature like that. For some reason, the same undervolt values are stable on AC but on battery with the same undervolt values my laptop freezes. Now throttled looks perfect for me, and it works (the undervolting part, which I'm only intrested in), but it throws ugly errors on logs. So it's the case of executing this in a clean way.

@notstarboard like I said, I have exact same usecase, I just want to undervolt, and I can confirm, the undervolting part works despite of the errors (I am sure it works, because when I set some absurdly high values like -200mV and I apply it, my laptop instantly freezes). So if you still can't undervolt with that tool, the problem should be somewhere else.