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}"
?
Is TEMPORARY_CPUFREQ_GOVERNOR"
a variable defined in "${PM_FUNCTIONS}"
?
What does the script try to do upon suspend|hibernate
and upon thaw|resume
?
Thanks.
#!/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
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 02 '18 at 23:30find
orlocate
and then search the files using grep. For instance, to search for the variableTEMPORARY_CPUFREQ_GOVERNOR
you can use the commandgrep -ri "TEMPORARY_CPUFREQ_GOVERNOR" /usr/lib/pm-utils
– J. Taylor Apr 02 '18 at 23:36/usr/lib/pm-utils/sleep.d/94cpufreq
and/etc/pm/sleep.d/20_cpu_freq
are called? Under/usr/lib/pm-utils/
, I rungrep -R freq .
, and it only return the file/usr/lib/pm-utils/sleep.d/94cpufreq
, which is meaningless. I rungrep -R sleep.d .
, and it returns nothing useful either. – Tim Apr 02 '18 at 23:39_run_hooks()
from the filepm-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 03 '18 at 00:14grep
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 sincesleep.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 03 '18 at 00:22/usr/lib/pm-utils/sleep.d/94cpufreq
doesn't seem to be executed upon resuming from suspension. – Tim Apr 03 '18 at 01:20