AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1021448
Accepted
Tim
Tim
Asked: 2018-04-03 14:21:13 +0800 CST2018-04-03 14:21:13 +0800 CST 2018-04-03 14:21:13 +0800 CST

从 Ubuntu 暂停恢复后如何配置 cpu 频率?

  • 772

问题:

在 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/95cpufreqor /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 1600000thaw_cpufreqresume|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 连接 。

power-management suspend hibernate cpufreq
  • 1 1 个回答
  • 176 Views

1 个回答

  • Voted
  1. Best Answer
    Tim
    2018-04-03T21:20:50+08:002018-04-03T21:20:50+08:00

    我刚刚找到了原因(请参阅为什么 DEs 和 pm-utils 暂停之间存在这些差异?| Unix & Linux Stack Exchange),这也导致了一些新问题:

    pm-suspend我发现在 Ubuntu 16.04 上的 LXDE 中运行和单击“暂停”菜单项之间存在一些差异

    1. 在这两种情况下,我都可以通过按下笔记本电脑上的电源按钮来唤醒 Ubuntu,但顺便说一下,通过 LXDE 中的“暂停”菜单项,我必须提供我的密码才能解锁屏幕,而顺便说一下 pm-suspend(and by pm-hibernateor pm-suspend-hybrid),我不需要。

    2. 根据这个问题:如何在挂起/从挂起返回时运行命令?| Super User/usr/lib/pm-utils/sleep.d/ ,和下的脚本/etc/pm/sleep.d/应该在暂停/休眠和恢复/解冻时执行。但只有在我运行pm-suspend(或pm-hibernate或 pm-suspend-hybrid)时才为真,当我单击 LXDE 中的“暂停”菜单项时为假。

    我曾经使用 Gnome,我记得它和 LXDE 中的一样,除了 Gnome 除了挂起之外可能还有休眠选项。

    我想知道为什么 DEs 和 pm-utils 暂停之间存在差异?

    可以pm-suspend以某种方式使用,以便恢复需要密码才能解锁屏幕?

    LXDE 中的“暂停”菜单项可以以某种方式使用,以便在暂停/休眠和恢复/解冻时执行脚本 /usr/lib/pm-utils/sleep.d/吗/etc/pm/sleep.d/?

    谢谢。

    • 0

相关问题

  • 如何让我的电脑中的风扇在暂停时关闭?[关闭]

  • 延长笔记本电脑和笔记本电脑电池寿命的技巧

  • 为什么我的 Kubuntu 会话在恢复后需要相当长的时间才能响应?

  • 如何让“您的电池坏了”消息消失?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve