linrunner / TLP

TLP - Optimize Linux Laptop Battery Life
https://linrunner.de/tlp
GNU General Public License v2.0
2.51k stars 129 forks source link

fix support for raptor lake dynamic frequency #693

Closed 70p4z closed 1 year ago

70p4z commented 1 year ago

After switching from my lenovo x1 yoga gen 6 (tiger lake 1135) to lenovo x1 yoga gen 8 (raptor lake) I had the bad surprise of a laptop draining battery faster! After some digging I found out the frequency management was off. I also discovered that we need to toggle active/passive intel pstate status for the dynamic frequency to be reenabled. Although it's probably not the root cause, I was not ready for a Linux kernel side digging.

My tlp.conf for fan less experience contains:

CPU_SCALING_GOVERNOR_ON_AC=powersave
CPU_SCALING_GOVERNOR_ON_BAT=powersave
CPU_SCALING_MAX_FREQ_ON_AC=2000000
CPU_SCALING_MAX_FREQ_ON_BAT=400000
CPU_ENERGY_PERF_POLICY_ON_AC=power
CPU_ENERGY_PERF_POLICY_ON_BAT=power
CPU_HWP_DYN_BOOST_ON_AC=0
CPU_HWP_DYN_BOOST_ON_BAT=0
CPU_MIN_PERF_ON_AC=0
CPU_MAX_PERF_ON_AC=80
CPU_MIN_PERF_ON_BAT=0
CPU_MAX_PERF_ON_BAT=40
SCHED_POWERSAVE_ON_AC=1
SCHED_POWERSAVE_ON_BAT=1
CPU_BOOST_ON_AC=1
CPU_BOOST_ON_BAT=1
INTEL_GPU_MIN_FREQ_ON_AC=300
INTEL_GPU_MIN_FREQ_ON_BAT=300
INTEL_GPU_MAX_FREQ_ON_AC=500
INTEL_GPU_MAX_FREQ_ON_BAT=300
INTEL_GPU_BOOST_FREQ_ON_AC=500
INTEL_GPU_BOOST_FREQ_ON_BAT=300

And with the pull request patch, the dynamic frequency is working like a charm. Hope it could help others.

linrunner commented 1 year ago

Hi,

the workaround may work in your case, but it has an undesired side effect: it changes the intel_pstate operating mode from active to passive in all cases. There's no way I'll merge that.

Comprehension questions:

Also show the output of

tlp-stat -p -v
70p4z commented 1 year ago

Hey, Nice review, clearly you've hit the point, it's definitely using the passive mode. I'm running devuan, and it sounds like cpufreq is not installed by default. Also, the hardware old tech is fine for saving some watts. On my laptop I'm running at 1.7W with passive mode instead of 3.0W with active mode. So I bet it's not that obsolete :) However I'm still far from the 0.9W of passive mode of the tiger lake :cry:!

Here is the output you've asked:

--- TLP 1.6.0-alpha.0 --------------------------------------------

+++ Processor
CPU model      = 13th Gen Intel(R) Core(TM) i5-1345U

/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu1/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu1/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu1/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu2/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu2/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu2/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu2/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu3/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu3/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu3/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu3/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu4/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu4/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu4/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu4/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu4/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu5/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu5/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu5/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu5/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu5/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu5/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu6/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu6/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu6/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu6/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu6/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu7/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu7/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu7/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu7/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu7/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu7/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu7/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu8/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu8/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu8/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu8/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu8/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu8/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu8/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu8/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu8/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu9/cpufreq/scaling_driver    = intel_cpufreq
/sys/devices/system/cpu/cpu9/cpufreq/scaling_governor  = schedutil
/sys/devices/system/cpu/cpu9/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu9/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu9/cpufreq/scaling_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu9/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu9/cpufreq/cpuinfo_max_freq  =  3500000 [kHz]
/sys/devices/system/cpu/cpu9/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu9/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu10/cpufreq/scaling_driver   = intel_cpufreq
/sys/devices/system/cpu/cpu10/cpufreq/scaling_governor = schedutil
/sys/devices/system/cpu/cpu10/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu10/cpufreq/scaling_min_freq =   400000 [kHz]
/sys/devices/system/cpu/cpu10/cpufreq/scaling_max_freq =  3500000 [kHz]
/sys/devices/system/cpu/cpu10/cpufreq/cpuinfo_min_freq =   400000 [kHz]
/sys/devices/system/cpu/cpu10/cpufreq/cpuinfo_max_freq =  3500000 [kHz]
/sys/devices/system/cpu/cpu10/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu10/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/cpu11/cpufreq/scaling_driver   = intel_cpufreq
/sys/devices/system/cpu/cpu11/cpufreq/scaling_governor = schedutil
/sys/devices/system/cpu/cpu11/cpufreq/scaling_available_governors = powersave performance schedutil 
/sys/devices/system/cpu/cpu11/cpufreq/scaling_min_freq =   400000 [kHz]
/sys/devices/system/cpu/cpu11/cpufreq/scaling_max_freq =  3500000 [kHz]
/sys/devices/system/cpu/cpu11/cpufreq/cpuinfo_min_freq =   400000 [kHz]
/sys/devices/system/cpu/cpu11/cpufreq/cpuinfo_max_freq =  3500000 [kHz]
/sys/devices/system/cpu/cpu11/cpufreq/energy_performance_preference = power [EPP]
/sys/devices/system/cpu/cpu11/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

/sys/devices/system/cpu/intel_pstate/status            = passive
/sys/devices/system/cpu/intel_pstate/min_perf_pct      =  10 [%]
/sys/devices/system/cpu/intel_pstate/max_perf_pct      = 100 [%]
/sys/devices/system/cpu/intel_pstate/no_turbo          =   0
/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost = (not available)
/sys/devices/system/cpu/intel_pstate/turbo_pct         = (not available) 
/sys/devices/system/cpu/intel_pstate/num_pstates       = (not available)
/sys/module/workqueue/parameters/power_efficient       = N
/proc/sys/kernel/nmi_watchdog                          = 0

+++ Platform Profile
/sys/firmware/acpi/platform_profile                    = balanced
/sys/firmware/acpi/platform_profile_choices            = low-power balanced performance
/sys/devices/platform/thinkpad_acpi/dytc_lapmode       = 0

I'll give cpufreq a go before concluding, and maybe the loosy specific patch I proposed won't even be necessary.

Anyway, thanks for the head up.

linrunner commented 1 year ago

Your output shows the difference between performance (0-3) and efficiency cores (4-11) based on the frequencies.

Why do you use CPU_MAX_PERF_ON_AC/BAT plus CPU_SCALING_MAX_FREQ_ON_AC/BAT together to limit power dissipation? In my experience, the former alone is sufficient.

I can't tell from your answer if you have tried this and if it works.

70p4z commented 1 year ago

Actually this is a remnant of my past experiment. I just ditched it. I also reverted my proposed patch and try to play with the active mode more accurately. But there is something I just don't get :

CPU_SCALING_MAX_FREQ_ON_AC=2000000
CPU_SCALING_MAX_FREQ_ON_BAT=1200000

And tlp-stat -p in AC mode:

/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver    = intel_pstate
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor  = powersave
/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors = performance powersave
/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq  =  1600000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq  =  4700000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference = balance_power [EPP]
/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power 

Where is the 1600000 coming from? Is there some quantized values?

linrunner commented 1 year ago

Afaik Intel processors since Skylake work with "hardware managed P-states (HWP)". The active mode displays how many of these are available - example:

+++ Processor CPU model = Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver = intel_pstate /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor = powersave /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors = performance powersave /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq = 400000 [kHz] /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq = 1800000 [kHz] /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq = 400000 [kHz] /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq = 4000000 [kHz] /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference = balance_performance [EPP] /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power /sys/devices/system/cpu/intel_pstate/status = active /sys/devices/system/cpu/intel_pstate/min_perf_pct = 10 [%] /sys/devices/system/cpu/intel_pstate/max_perf_pct = 100 [%] /sys/devices/system/cpu/intel_pstate/no_turbo = 1 /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost = 1 /sys/devices/system/cpu/intel_pstate/turbo_pct = 60 [%] /sys/devices/system/cpu/intel_pstate/num_pstates = 37

The documentation does not say how to map them to frequencies, it just states:

At the same time, it would not be practical for intel_pstate to supply the CPUFreq core with a table of available frequencies due to the possible size of it, so the driver does not do that. Some functionality of the core is limited by that.

Above I had already given the recommendation to limit the power consumption per

 CPU_MAX_PERF_ON_AC=80
 CPU_MAX_PERF_ON_BAT=40

only and to not use the frequency settings at all.

My reading of the documentation is that frequencies have become irrelevant due to P-states. On my hardware CPU_MAX_PERF_ON_AC/BAT limits power consumption properly.

Why so many users still want to use frequencies is beyond me.

EDIT:

Where is the 1600000 coming from?

Look at the turbo_pct value in my example above: 4000 MHz - 60% = 1800 MHz

EDIT2: ok, my calculation does not fit exactly, but I hope you get the point. The docs say 60% (turbo_pct) of available P-states.

EDIT3: 400 + ( (4000 - 400) * (1 - 0.6) ) = 1.840 MHz fits better.

70p4z commented 1 year ago

I totally get your point on meddling with frequency instead of percent. I'm not narrow minded on that. My only goal are the watts consumed at the end of the day! Anyway, thanks for the detailed information. However, I've not bothered with mapping the values as on my system, some information is lacking:

/sys/devices/system/cpu/intel_pstate/turbo_pct         = (not available) 
/sys/devices/system/cpu/intel_pstate/num_pstates       = (not available)

And more importantly, whatever values I choose for CPU_MAX_PERF_ON_AC or CPU_MIN_PERF_ON_BAT, values in

/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq  =   400000 [kHz]
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq  =  1600000 [kHz]

are not changed! But I think some configuration glitch is to be expected, (like enabling turbo or a thing like that, I'll dig a bit).

EDIT: as expected from my past playing with skylake and tiger lake, when CPU_BOOST_ON_AC and CPU_BOOST_ON_BAT is 0, then percentage is just ignored blatantly...

70p4z commented 1 year ago

The conclusion is that I'll discard my PR :) and work onto a more generalistic approach on how to set raptor lake power cap.

linrunner commented 1 year ago

Thinking about it, I wonder if capping is purposeful in your case.

The power consumptions between 0.9 and 3W that you mention must be at idle. So you say that at idle the governor selects too high P-states or frequencies. If you limit the maximum P-state via capping, the governor selects lower, but still too high P-states. In idle mode, the lowest P-state should be used for the most part.

If the problem is the governor, capping will not solve the problem of high consumption.

Maybe some process produces too much load in idle or a kernel bug generates too many wakeups, so that the deep C-states are not reached.

I suppose you are familiar with the relevant tools for analysis such as htop and powertop. Don't be fooled by powertop's nonsensical statements about the consumption of individual components. Apart from that, it is a valuable tool.

It is best to search for relevant kernel bugs as well.

Since this is all seems only marginally related to TLP, I'll close here and end my advice on the subject. Of course, I'm still interested in your findings, so feel free to post them here.

linrunner commented 1 year ago

some information is lacking: /sys/devices/system/cpu/intel_pstate/turbo_pct = (not available) /sys/devices/system/cpu/intel_pstate/num_pstates = (not available)

Only active mode shows them.

And more importantly, whatever values I choose for CPU_MAX_PERF_ON_AC or CPU_MIN_PERF_ON_BAT, values in /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq = 400000 [kHz] /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq = 1600000 [kHz] are not changed!

Same for my machines but the capping works nevertheless (in active mode however). I say it again, forget about the stupid frequeny approach.

70p4z commented 1 year ago

Thanks for the head up.

I'm familiar with powertop, and clearly it's fooling a lot of people with its wrongly reported consumption by lines. Actually, I'm only monitoring the battery current indicator only. On the contrary, the activity per second information is really useful.

To reach 0.9w, I had to mainly kill pulseaudio, and ensure web browser and mailer are kill -TSTOP, and wifi+ble are rfkilled. This is my default mode when in train, and is mainly meant to edit code and compile a few times. I'm still 1.2w away from that with raptor lake compared to tiger lake. And it really is iching a lot to reach the same level :)

Yeah I won't stick to frequencies, only the watt consumption, I promess :)

Also, adb and openocd, are killing consumption when left enabled, they do tick a lot (yeah the usecase is not that common).