在我的 Ubuntu 16.04 上,我试图理解系统默认文件/usr/lib/pm-utils/sleep.d/94cpufreq
(有关其内容,请参阅本文末尾。)
是"${PM_FUNCTIONS}"
一个脚本,因为它的来源是.
?
当我echo "${PM_FUNCTIONS}"
在 bash 中时,它什么也不输出。是PM_FUNCTIONS
在调用该脚本的另一个脚本中定义的吗?
savestate
、state_exists
和restorestate
函数是在 中定义的"${PM_FUNCTIONS}"
吗?
变量TEMPORARY_CPUFREQ_GOVERNOR"
定义在"${PM_FUNCTIONS}"
?
该脚本试图在suspend|hibernate
之上做什么thaw|resume
?
谢谢。
#!/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
答案1
函数state_exists
等定义在/usr/lib/pm-utils/函数并PM_FUNCTIONS
引用脚本/usr/lib/pm-utils/pm-functions。是的,TEMPORARY_CPUFREQ_GOVERNOR
是在 中定义的PM_FUNCTIONS
。