On my Ubuntu 16.04, I am trying to understand a system default file /usr/lib/pm-utils/sleep.d/94cpufreq (see the end of this post for its content.)

Is "${PM_FUNCTIONS}" a script, given that it is sourced by .?

When I echo "${PM_FUNCTIONS}" in bash, it outputs nothing. Is PM_FUNCTIONS defined in another script which calls the script?

Are savestate, state_exists, and restorestate functions defined in "${PM_FUNCTIONS}"?


What does the script try to do upon suspend|hibernate and upon thaw|resume?


# 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

The functions state_exists, etc are defined in /usr/lib/pm-utils/functions and PM_FUNCTIONS refers to the script /usr/lib/pm-utils/pm-functions. And yes, TEMPORARY_CPUFREQ_GOVERNOR is defined in PM_FUNCTIONS.

  • Thanks. How did you find them out by just looking at the file system? Where is PM_FUNCTIONS defined? How shall I find out where /usr/lib/pm-utils/sleep.d/94cpufreq and /etc/pm/sleep.d/20_cpu_freq are called? – Tim Apr 2 '18 at 23:30
  • You can find filenames using find or locate and then search the files using grep. For instance, to search for the variable TEMPORARY_CPUFREQ_GOVERNOR you can use the command grep -ri "TEMPORARY_CPUFREQ_GOVERNOR" /usr/lib/pm-utils – J. Taylor Apr 2 '18 at 23:36
  • Thanks. I was wondering how to find out where /usr/lib/pm-utils/sleep.d/94cpufreq and /etc/pm/sleep.d/20_cpu_freq are called? Under /usr/lib/pm-utils/, I run grep -R freq ., and it only return the file /usr/lib/pm-utils/sleep.d/94cpufreq, which is meaningless. I run grep -R sleep.d ., and it returns nothing useful either. – Tim Apr 2 '18 at 23:39
  • They are hooks that are run in the function _run_hooks() from the file pm-functions. Note the part that looks like this: for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~]; do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ; ... See How do I run commands on suspend/return from suspend? – J. Taylor Apr 3 '18 at 0:14
  • By the way, to find that, I used grep as follows: grep -ri '\.d' /usr/lib/pm-utils/, which returned a couple of lines that looked like this: usr/lib/pm-utils/pm-functions: local syshooks="${PM_UTILS_ETCDIR}/$1.d" I searched for ".d" in because since sleep.d wasn't showing up explicitly, I figured there was some kind of loop that went through all of the ".d" directories. – J. Taylor Apr 3 '18 at 0:22

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.