问题:
在 Ubuntu 16.04 中,我运行我的 shell 脚本来将我的 cpu 频率缩减为 1600000,并且它的调控器是“用户空间”:
sudo /home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000
分别写入 1600000 和“用户空间/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
” /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
。
但是,在我的Ubuntu挂起然后唤醒后,cpu频率又回到了2667000,因为/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
被一些未知的程序重写为2667000。我希望从挂起恢复后cpu频率保持在1600000。
暂定解决方案:
我尝试了https://superuser.com/a/733336/9265(见下文)的一种解决方案,并添加了一个文件/etc/pm/sleep.d/20_cpu_freq
,其内容为:
#!/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
并使其可执行chmod a+x *
,使其权限为-rwxrwxr-x
. 但它不会在从暂停中恢复后将 cpu 频率降低到 1600000。
是/etc/pm/sleep.d/20_cpu_freq
从暂停中恢复时实际运行的吗?我该如何验证呢?
是否/etc/pm/sleep.d/20_cpu_freq
被其他配置文件覆盖?
没有其他脚本/etc/pm/sleep.d/
可以处理 CPU 频率。
有一个系统默认脚本/usr/lib/pm-utils/sleep.d/94cpufreq
,它处理 CPU 频率(其内容见下文)。有人知道脚本的作用吗?它是覆盖还是被覆盖/etc/pm/sleep.d/20_cpu_freq
?(请注意,如果我重命名/etc/pm/sleep.d/20_cpu_freq
为 /etc/pm/sleep.d/95cpufreq
or /etc/pm/sleep.d/93cpufreq
,为了更改它和 之间的顺序/usr/lib/pm-utils/sleep.d/94cpufreq
,`两者仍然不会在暂停恢复后将 cpu 频率缩减到 1600000。)
在中,如果我在 case之后/usr/lib/pm-utils/sleep.d/94cpufreq
添加,它也不起作用。/home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000
thaw_cpufreq
resume|thaw)
/home/t/program_files/hardware/cpu/cpuFreq/changeCpuFreq.sh 1600000
如果不在,我应该跑到哪里去/etc/pm/sleep.d/20_cpu_freq
?
内容/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
复制自https://superuser.com/a/733336/9265
从手册页
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.
因此,您可以简单地放置一个这样的 shell 脚本:
#!/bin/bash case "$1" in suspend|hibernate) actions to take on suspend or hibernate ;; resume|thaw) other actions to trigger on resume ;; esac
进入例如
99-myhooks.sh
并使其可执行。Enter~.Enter顺便说一句,您可以通过进入SSH 会话来终止陈旧的 SSH 连接 。
我刚刚找到了原因(请参阅为什么 DEs 和 pm-utils 暂停之间存在这些差异?| Unix & Linux Stack Exchange),这也导致了一些新问题: