Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
Package: linux-image-4.9.0-4-amd64 Version: 4.9.51-1 To avoid fan noise, I set up my laptop such that it sets a low CPU frequency upon boot via for i in `seq 0 7`; do echo 120 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done in a startup script. This all goes well until I make a break in my work by closing the laptop lid (which then suspends the laptop) and resuming later. After resume, we still have low frequency in scaling_max_freq, but this setting is ignored: $ for i in `seq 0 7`; do cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done 120 120 120 120 120 120 120 120 $ cat /proc/cpuinfo | grep MHz cpu MHz : 1899.853 cpu MHz : 1900.964 cpu MHz : 1899.853 cpu MHz : 1899.853 cpu MHz : 1899.853 cpu MHz : 1899.853 cpu MHz : 1899.853 cpu MHz : 947.546 $ for i in `seq 0 7`; do cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor; done powersave powersave powersave powersave powersave powersave powersave powersave Moreover, the fan kicks in, and the laptop feels to run without speed restrictions (noisy fan, etc.) Any bugfix? Thanks in advance, Leon
Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
Control: tag -1 moreinfo If this system has an Intel CPU, I'm afraid this is expected behaviour. They no longer allow the OS to set an exact frequency, only a 'P- state' (performance level). The Linux cpufreq driver for these processors (intel_pstate) translates the requested frequency into a P- state, but the actual frequency is controlled by an embedded controller that may choose a higher or lower value. Unless you can show that a different kernel version reproducibly shows different results, or you're not using an Intel CPU, I don't think there's anything to be done here. Ben. -- Ben Hutchings friends: People who know you well, but like you anyway. signature.asc Description: This is a digitally signed message part
Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
tags 880203 - moreinfo thanks Ben, thank you for the clarification. On 31.10.2017 00:35, Ben Hutchings wrote: Control: tag -1 moreinfo If this system has an Intel CPU, I'm afraid this is expected behaviour. They no longer allow the OS to set an exact frequency, only a 'P- state' (performance level). The Linux cpufreq driver for these processors (intel_pstate) translates the requested frequency into a P- state, but the actual frequency is controlled by an embedded controller that may choose a higher or lower value. However, the cpufreq driver is not loaded in my case: # lsmod | grep cpufreq # lsmod | grep intel_pstate # Would loading some driver help? Your text explains _what_ is happening, but not why the embedded controller chooses a higher frequency only upon suspend&resume and not earlier, when the root actually sets scaling_max_freq or when the machine is loaded with heavy applications (firefox + thunderbird + video player + some mathematical computation in the background + word processor + ...) The way I understand it is that when the root writes to the file scaling_max_freq, a performance-level--setting request, let's call it R, goes to the embedded controller, which then chooses some frequency. Probably, upon suspend/resume, the controller thinks that there is more job to do (and, in general, there are some running applications before suspend which do incur work), and raises the actual frequency. Now, after suspend&resume, the kernel _could_, in addition to what it usually does, re-issue the request R to "undo" the too eager action of the embedded controller. If a user herself writes the same value 120 to scaling_max_freq again, nothing happens. The current behavior might be expected from the viewpoint of the processor and of the embedded controller; I don't wish to question that. But, from the viewpoint of the user, this is extremely, overly _counterintuitive_. The user simply expects that the machine behaves the same after closing&opening the laptop lid. E.g., that if the user enjoyed noise-free Skype calls or noise-free music before, she expects noise-free Skype calls and noise-free music afterwards. The noise, in turn, depends on the fan, which depends on the produced heat, which depends on the frequency... Unless you can show that a different kernel version reproducibly shows different results, or you're not using an Intel CPU, I don't think there's anything to be done here. It's Intel. Unfortunately, I don't have another Linux kernel to test on the same machine right now. Ben. Here is the processor data (before suspend&resume): $ cat /proc/cpuinfo | head -27 processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz stepping: 9 microcode : 0x1c cpu MHz : 1200.024 cache size : 6144 KB physical id : 0 siblings: 8 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts bugs: bogomips: 5183.16 clflush size: 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: After s&r, the MHz value goes up to some value, up to 2600. Best regards, Leon
Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - alternative shell script
One can also sidestep writing to /tmp in the script in /lib/systemd/system-sleep/: #!/bin/bash ### Ensure that the frequency is restored upon resuming from suspend # The array to store frequencies: declare -a frequencies # Number of processors minus 1: N=$((`nproc --all`-1)) case "${1}" in post) # Read the old values: for i in `seq 0 $N`; do frequencies[$i]=`cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq`; done # Write a junk value first: for i in `seq 0 $N`; do echo 1${frequencies[$i]} > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done # Let the file kernel digest the previous requests a bit: sleep 1 # Write the old values: for i in `seq 0 $N`; do echo ${frequencies[$i]} > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done ;; esac Though this script now avoids writing into /tmp, it's a terribly wild hack again invoking bash and other utilities. I'm feeling that it is too much an overkill as opposed to doing the right thing in the kernel.
Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script
On 31.10.2017 13:25, Leon Meier wrote: On 31.10.2017 11:39, Debian Bug Tracking System wrote: Yes, but that doesn't mean we can do anything about it. Why not simply re-issue the request setting the performance-level after resume? You could at least suggest a script similar to the following one to be added to /lib/systemd/system-sleep. #!/bin/sh ### Ensure that the frequency is stored/restored upon resume case "${1}" in pre) # Store the old frequency for i in `seq 0 7`; do cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq > /tmp/scaling_max_freq$i; done ;; post) # Wild hack: insert a junk value first for i in `seq 0 7`; do echo 999 > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done # Set the old frequency for i in `seq 0 7`; do cat /tmp/scaling_max_freq$i > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq rm -f /tmp/scaling_max_freq$i; done ;; esac Exercise for the reader: automatically determine the number of CPUs, ensure that created files have fresh names, that there is sufficient unused space in /tmp, and that proper error handling is done if it is not the case. However, really, this is much better done in the kernel manipulating p-states directly rather than through the overkill of wild hacks and invoking a shell script modifying various places in the file system.
Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script
On Wed, 2017-11-01 at 13:02 +0100, Leon Meier wrote: > On 31.10.2017 13:25, Leon Meier wrote: > > On 31.10.2017 11:39, Debian Bug Tracking System wrote: > > > Yes, but that doesn't mean we can do anything about it. > > > > Why not simply re-issue the request setting the performance-level after > > resume? > > You could at least suggest a script similar to the following one to be > added to /lib/systemd/system-sleep. [...] Didn't you already say that scaling_max_freq is unchanged after resume? Ben. -- Ben Hutchings Make three consecutive correct guesses and you will be considered an expert. signature.asc Description: This is a digitally signed message part
Bug#880203: closed by Ben Hutchings (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
On 31.10.2017 11:39, Debian Bug Tracking System wrote: Yes, but that doesn't mean we can do anything about it. Why not simply re-issue the request setting the performance-level after resume?
Bug#880203: closed by Ben Hutchings (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
On Tue, 31 Oct 2017 13:25:11 +0100 Leon Meier wrote: > On 31.10.2017 11:39, Debian Bug Tracking System wrote: > > Yes, but that doesn't mean we can do anything about it. > > Why not simply re-issue the request setting the performance-level after > resume? The driver does that. Ben. -- Ben Hutchings Make three consecutive correct guesses and you will be considered an expert. signature.asc Description: This is a digitally signed message part
Bug#880203: closed by Ben Hutchings (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
On 01.11.2017 13:38, Ben Hutchings wrote: On Tue, 31 Oct 2017 13:25:11 +0100 Leon Meier wrote: On 31.10.2017 11:39, Debian Bug Tracking System wrote: Yes, but that doesn't mean we can do anything about it. Why not simply re-issue the request setting the performance-level after resume? The driver does that. Oh. But in this case the effect of this action is not visible on my machine.