In Ubuntu 16.04, I run my shell script to scale down my cpu frequency to be 1600000, and its governor to be "userspace":

sudo /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000

which writes 1600000 and "userspace" to /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed and /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor respectively.

However, after suspension and then waking up of my Ubuntu, the cpu frequency is back up to 2667000, because /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed is rewritten by some unknown program to 2667000. I would like cpu frequency to be kept at 1600000 after resuming from suspension.

Tentative Solution:

I tried one solution from https://superuser.com/a/733336/9265 (see below), and added a file /etc/pm/sleep.d/20_cpu_freq , whose content is:

# upon resume from suspension, scale down the cpu freq
case "$1" in
     /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000

and make it executable by chmod a+x * so that its permission is -rwxrwxr-x. But it doesn't scale down the cpu frequency to 1600000 after resuming from suspension.

Is /etc/pm/sleep.d/20_cpu_freq actually run when resuming from suspension? How can I verify that?

Is /etc/pm/sleep.d/20_cpu_freq overridden by some other configuration file?

There is no other script under /etc/pm/sleep.d/ which deals with cpu frequency.

There is a system-default script /usr/lib/pm-utils/sleep.d/94cpufreq, which deals with cpu frequency (see below for its content). Does someone know what the script does? Does it override or is it overridden by /etc/pm/sleep.d/20_cpu_freq? (Note that if I rename /etc/pm/sleep.d/20_cpu_freq to /etc/pm/sleep.d/95cpufreq or /etc/pm/sleep.d/93cpufreq, in order to change the order between it and /usr/lib/pm-utils/sleep.d/94cpufreq, `both still don't scale down the cpu frequency to 1600000 upon resuming from suspension.)

In /usr/lib/pm-utils/sleep.d/94cpufreq, it doesn't work either If I add /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000 after thaw_cpufreq in the case resume|thaw) .

Where shall I run /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000, if not in /etc/pm/sleep.d/20_cpu_freq?

Content of /usr/lib/pm-utils/sleep.d/94cpufreq

# Ensure cpu governor is set to something sane.                                                                                                                                    
# TODO: Which of the cpu governors is still insane?  File bugs against                                                                                                             
#       those that are.                                                                                                                                                            


[ -d /sys/devices/system/cpu/ ] || exit $NA

  ( cd /sys/devices/system/cpu/
  for x in cpu[0-9]*; do
    # if cpufreq is a symlink, it is handled by another cpu. Skip.                                                                                                                 
    [ -L "$x/cpufreq" ] && continue
    # if we do not have a scaling_governor file, skip.                                                                                                                             
    [ -f "$gov" ] || continue
    # if our temporary governor is not available, skip.                                                                                                                            
            "$x/cpufreq/scaling_available_governors" || continue
    savestate "${x}_governor" < "$gov"
  done )

  ( cd /sys/devices/system/cpu/
  for x in cpu[0-9]*/cpufreq/scaling_governor ; do
    [ -f "$x" ] || continue
    state_exists "${x%%/*}_governor" || continue
    restorestate "${x%%/*}_governor" > "$x"
  done )

case "$1" in
  *) exit $NA

Copied from https://superuser.com/a/733336/9265

From manpage pm-action(8):

/etc/pm/sleep.d, /usr/lib/pm-utils/sleep.d
     Programs in these directories (called hooks) are combined
     and executed in C sort order before suspend and hibernate
     with as argument ´suspend´ or ´hibernate´. Afterwards they
     are called in reverse order with argument ´resume´ and
     ´thaw´ respectively. **If both directories contain a similar
     named file, the one in /etc/pm/sleep.d will get preference.**
     It is possible to disable a hook in the distribution
     directory by putting a non-executable file in
     /etc/pm/sleep.d, or by adding it to the HOOK_BLACKLIST
     configuration variable.

Thus you could simply put a shell-script like this:


case "$1" in
    actions to
    on suspend
    or hibernate
    other actions
    to trigger
    on resume

into e.g. 99-myhooks.sh and make it executable.

BTW, you can kill stale SSH-connections by entering Enter~.Enter in the SSH session.


I just found the reason (see Why are there these differences between suspension by the DEs and by pm-utils? | Unix & Linux Stack Exchange) which also leads to some new questions:

I found some differences between running pm-suspend and clicking "Suspend" menu item in LXDE on Ubuntu 16.04

  1. In both cases I can wake up Ubuntu by pushing the power button on my laptop, but in the way by "Suspend" menu item in LXDE, I have to provide my password to unlock the screen, while in the way by pm-suspend (and bypm-hibernate or pm-suspend-hybrid), I don't need to.

  2. According to this question: How do I run commands on suspend/return from suspend? | Super User, scripts under /usr/lib/pm-utils/sleep.d/ and /etc/pm/sleep.d/ are supposed to be executed upon suspension/hibernation and resuming/thawing. But it is true only when I run pm-suspend (orpm-hibernate or pm-suspend-hybrid), and false when I click "Suspend" menu item in LXDE.

I used to use Gnome, and I remember it was the same as in LXDE, except Gnome might have hibernate option besides suspend.

I wonder why there are the differences between suspension by the DEs and by pm-utils?

Can pm-suspend be used in a way so that resume requires password to unlock the screen?

Can "suspend" menu item in LXDE be used in a way so that the scripts in /usr/lib/pm-utils/sleep.d/ and /etc/pm/sleep.d/ are executed upon suspension/hibernation and resuming/thawing?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.