Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.kernel > #59286 > unrolled thread

Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored

Started byLeon Meier <Leon.Meier@yandex.ru>
First post2017-10-30 16:00 +0100
Last post2017-11-01 14:40 +0100
Articles 11 — 3 participants

Back to article view | Back to linux.debian.kernel


Contents

  Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored Leon Meier <Leon.Meier@yandex.ru> - 2017-10-30 16:00 +0100
    Processed: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq  is ignored owner@bugs.debian.org (Debian Bug Tracking System) - 2017-10-31 01:30 +0100
    Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored Ben Hutchings <ben@decadent.org.uk> - 2017-10-31 01:30 +0100
      Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored Leon Meier <Leon.Meier@yandex.ru> - 2017-10-31 11:20 +0100
    Bug#880203: marked as done (After suspend&resume, cpufreq/scaling_max_freq  is ignored) owner@bugs.debian.org (Debian Bug Tracking System) - 2017-10-31 11:40 +0100
    Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored) Leon Meier <Leon.Meier@yandex.ru> - 2017-10-31 13:40 +0100
      Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script Leon Meier <Leon.Meier@yandex.ru> - 2017-11-01 13:20 +0100
        Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script Ben Hutchings <ben@decadent.org.uk> - 2017-11-01 13:50 +0100
      Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored) Ben Hutchings <ben@decadent.org.uk> - 2017-11-01 13:50 +0100
        Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored) Leon Meier <Leon.Meier@yandex.ru> - 2017-11-01 14:00 +0100
    Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - alternative shell script Leon Meier <Leon.Meier@yandex.ru> - 2017-11-01 14:40 +0100

#59286 — Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-10-30 16:00 +0100
SubjectBug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
Message-ID<uGjHJ-6Nr-33@gated-at.bofh.it>
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 1200000 > 
/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
1200000
1200000
1200000
1200000
1200000
1200000
1200000
1200000
$ 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

[toc] | [next] | [standalone]


#59292 — Processed: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored

Fromowner@bugs.debian.org (Debian Bug Tracking System)
Date2017-10-31 01:30 +0100
SubjectProcessed: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
Message-ID<uGsBk-3WH-15@gated-at.bofh.it>
In reply to#59286
Processing control commands:

> tag -1 moreinfo
Bug #880203 [linux-image-4.9.0-4-amd64] After suspend&resume, cpufreq/scaling_max_freq is ignored
Added tag(s) moreinfo.

-- 
880203: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=880203
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems

[toc] | [prev] | [next] | [standalone]


#59293

FromBen Hutchings <ben@decadent.org.uk>
Date2017-10-31 01:30 +0100
Message-ID<uGsBj-3WH-5@gated-at.bofh.it>
In reply to#59286

[Multipart message — attachments visible in raw view] — view raw

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.

[toc] | [prev] | [next] | [standalone]


#59295

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-10-31 11:20 +0100
Message-ID<uGBEB-Xq-11@gated-at.bofh.it>
In reply to#59293
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 1200000 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

[toc] | [prev] | [next] | [standalone]


#59296 — Bug#880203: marked as done (After suspend&resume, cpufreq/scaling_max_freq is ignored)

Fromowner@bugs.debian.org (Debian Bug Tracking System)
Date2017-10-31 11:40 +0100
SubjectBug#880203: marked as done (After suspend&resume, cpufreq/scaling_max_freq is ignored)
Message-ID<uGC7E-174-15@gated-at.bofh.it>
In reply to#59286

[Multipart message — attachments visible in raw view] — view raw

Your message dated Tue, 31 Oct 2017 10:36:59 +0000
with message-id <1509446219.2748.35.camel@decadent.org.uk>
and subject line Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored
has caused the Debian Bug report #880203,
regarding After suspend&resume, cpufreq/scaling_max_freq is ignored
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
880203: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=880203
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems

[toc] | [prev] | [next] | [standalone]


#59299 — Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-10-31 13:40 +0100
SubjectBug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
Message-ID<uGDZL-2db-7@gated-at.bofh.it>
In reply to#59286
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?

[toc] | [prev] | [next] | [standalone]


#59312 — Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-11-01 13:20 +0100
SubjectBug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script
Message-ID<uH09Y-cD-1@gated-at.bofh.it>
In reply to#59299
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 999999999999999 > 
/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.

[toc] | [prev] | [next] | [standalone]


#59313 — Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script

FromBen Hutchings <ben@decadent.org.uk>
Date2017-11-01 13:50 +0100
SubjectBug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - (wild hack) shell script
Message-ID<uH0CZ-nP-3@gated-at.bofh.it>
In reply to#59312

[Multipart message — attachments visible in raw view] — view raw

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.

[toc] | [prev] | [next] | [standalone]


#59314 — Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)

FromBen Hutchings <ben@decadent.org.uk>
Date2017-11-01 13:50 +0100
SubjectBug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
Message-ID<uH0CZ-nP-5@gated-at.bofh.it>
In reply to#59299

[Multipart message — attachments visible in raw view] — view raw

On Tue, 31 Oct 2017 13:25:11 +0100 Leon Meier <Leon.Meier@yandex.ru> 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.

[toc] | [prev] | [next] | [standalone]


#59315 — Bug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-11-01 14:00 +0100
SubjectBug#880203: closed by Ben Hutchings <ben@decadent.org.uk> (Re: Fwd: Re: Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored)
Message-ID<uH0MG-sS-7@gated-at.bofh.it>
In reply to#59314
On 01.11.2017 13:38, Ben Hutchings wrote:
> On Tue, 31 Oct 2017 13:25:11 +0100 Leon Meier <Leon.Meier@yandex.ru> 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.

[toc] | [prev] | [next] | [standalone]


#59316 — Bug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - alternative shell script

FromLeon Meier <Leon.Meier@yandex.ru>
Date2017-11-01 14:40 +0100
SubjectBug#880203: After suspend&resume, cpufreq/scaling_max_freq is ignored - alternative shell script
Message-ID<uH1pn-XL-5@gated-at.bofh.it>
In reply to#59286
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.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.kernel


csiph-web