0

Problem:

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:

#!/bin/sh
# upon resume from suspension, scale down the cpu freq
case "$1" in
   thaw|resume)
     /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000
     ;;
esac

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

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

. "${PM_FUNCTIONS}"

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

hibernate_cpufreq()
{
  ( 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
    gov="$x/cpufreq/scaling_governor"
    # if we do not have a scaling_governor file, skip.                                                                                                                             
    [ -f "$gov" ] || continue
    # if our temporary governor is not available, skip.                                                                                                                            
    grep -q "$TEMPORARY_CPUFREQ_GOVERNOR" \
            "$x/cpufreq/scaling_available_governors" || continue
    savestate "${x}_governor" < "$gov"
    echo "$TEMPORARY_CPUFREQ_GOVERNOR" > "$gov"
  done )
}

thaw_cpufreq()
{
  ( 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
  suspend|hibernate)
    hibernate_cpufreq
    ;;
  resume|thaw)
    thaw_cpufreq
    ;;
  *) exit $NA
    ;;
esac

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:

#!/bin/bash

case "$1" in
suspend|hibernate)
    actions to
    take
    on suspend
    or hibernate
    ;;
resume|thaw)
    other actions
    to trigger
    on resume
    ;;
esac

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.

0

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?

Thanks.

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.