问题:
在 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
或/etc/pm/sleep.d/93cpufreq
,以更改它和之间的顺序/usr/lib/pm-utils/sleep.d/94cpufreq
,则两者在从暂停状态恢复时仍不会将 CPU 频率降低到 1600000。)
在,如果我在案例中添加后/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 连接 。
答案1
我刚刚找到了原因(见为什么 DE 和 pm-utils 的暂停之间存在这些差异?| Unix 和 Linux Stack Exchange),这也引出了一些新的问题:
我发现
pm-suspend
在 Ubuntu 16.04 上的 LXDE 中运行和单击“暂停”菜单项之间存在一些差异
在这两种情况下,我都可以通过按下笔记本电脑上的电源按钮来唤醒 Ubuntu,但是在通过 LXDE 中的“暂停”菜单项的方式中,我必须提供密码来解锁屏幕,而在通过
pm-suspend
(和通过pm-hibernate
或pm-suspend-hybrid
)的方式中,我不需要。根据这个问题:如何在挂起/从挂起返回时运行命令?| 超级用户
/usr/lib/pm-utils/sleep.d/
,和下的脚本/etc/pm/sleep.d/
应该在暂停/休眠和恢复/解冻时执行。但只有当我运行pm-suspend
(或pm-hibernate
或pm-suspend-hybrid
)时,它才为真,而当我单击 LXDE 中的“暂停”菜单项时,它为假。我曾经使用过 Gnome,我记得它与 LXDE 相同,只是 Gnome 除了挂起之外可能还有休眠选项。
我想知道为什么 DE 的暂停和 pm-utils 的暂停有区别?
是否可以
pm-suspend
以某种方式使用,使得恢复时需要密码来解锁屏幕?LXDE 中的“暂停”菜单项是否可以以某种方式使用,以便
/usr/lib/pm-utils/sleep.d/
在/etc/pm/sleep.d/
暂停/休眠和恢复/解冻时执行脚本?谢谢。