android进入深睡log,在18.04中将CPU调速器设置为性能

默认的Ubuntu内核配置是在引导过程中使用性能CPU频率缩放调节器。内核配置文件(/boot/config-4.15.0-36-generic在此示例中)的相关部分是:

#

# CPU Frequency scaling

#

CONFIG_CPU_FREQ=y

CONFIG_CPU_FREQ_GOV_ATTR_SET=y

CONFIG_CPU_FREQ_GOV_COMMON=y

CONFIG_CPU_FREQ_STAT=y

CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y

# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set

# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set

# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set

# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set

# CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL is not set

CONFIG_CPU_FREQ_GOV_PERFORMANCE=y

CONFIG_CPU_FREQ_GOV_POWERSAVE=y

CONFIG_CPU_FREQ_GOV_USERSPACE=y

CONFIG_CPU_FREQ_GOV_ONDEMAND=y

CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y

CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y

#

# CPU frequency scaling drivers

#

CONFIG_X86_INTEL_PSTATE=y

CONFIG_X86_PCC_CPUFREQ=y

CONFIG_X86_ACPI_CPUFREQ=y

CONFIG_X86_ACPI_CPUFREQ_CPB=y

CONFIG_X86_POWERNOW_K8=y

CONFIG_X86_AMD_FREQ_SENSITIVITY=m

CONFIG_X86_SPEEDSTEP_CENTRINO=y

CONFIG_X86_P4_CLOCKMOD=m

但默认情况下,在启动过程中ondemand也会执行该服务。它睡觉包1分钟,然后或者改变缩放调速器interactive,ondemand或powersave,视情况而定。反过来,可用性取决于您使用的CPU频率缩放驱动程序。代码是(在多个位置搜索ondemand):

#! /bin/sh

### BEGIN INIT INFO

# Provides: ondemand

# Required-Start: $remote_fs $all

# Required-Stop:

# Default-Start: 2 3 4 5

# Default-Stop:

# Short-Description: Set the CPU Frequency Scaling governor to "ondemand"

### END INIT INFO

# Don't run if we're going to start an Android LXC container:

[ ! -f /etc/init/lxc-android-config.conf ] || exit 0

PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh

. /lib/lsb/init-functions

AVAILABLE="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"

DOWN_FACTOR="/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"

case "$1" in

start)

start-stop-daemon --start --background --exec /etc/init.d/ondemand -- background

;;

background)

sleep 60 # probably enough time for desktop login

[ -f $AVAILABLE ] || exit 0

read governors < $AVAILABLE

case $governors in

*interactive*)

GOVERNOR="interactive"

break

;;

*ondemand*)

GOVERNOR="ondemand"

case $(uname -m) in

ppc64*)

SAMPLING=100

;;

esac

break

;;

*powersave*)

GOVERNOR="powersave"

break

;;

*)

exit 0

;;

esac

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

do

[ -f $CPUFREQ ] || continue

echo -n $GOVERNOR > $CPUFREQ

done

if [ -n "$SAMPLING" ] && [ -f $DOWN_FACTOR ]; then

echo -n $SAMPLING > $DOWN_FACTOR

fi

;;

restart|reload|force-reload)

echo "Error: argument '$1' not supported" >&2

exit 3

;;

stop)

;;

*)

echo "Usage: $0 start|stop" >&2

exit 3

;;

esac

为什么将其称为“ ondemand”,但却设置了其他控制器(例如,使用intel_pstate驱动程序将设置省电控制器)?因为此工具的日期早于intel_pstate驱动程序,所以可以追溯到到目前为止主要的频率缩放驱动程序是acpi-cpufreq驱动程序,而“ ondemand”是首选的Ubuntu默认调控器。

因此,一种引导并保持使用性能CPU频率缩放调节器的方法是禁用与其发生变化的服务(在另一个答案中也提到):

之前:

~$ systemctl list-units --all --type=service | grep ondemand

ondemand.service loaded inactive dead Set the CPU Frequency Scaling governor

~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

ondemand

ondemand

禁用服务:

~$ sudo systemctl disable ondemand

Removed /etc/systemd/system/multi-user.target.wants/ondemand.service.

重新启动,然后再次检查(请务必在重新启动后等待一分钟):

doug@s17:~$ systemctl list-units --all --type=service | grep ondemand

doug@s17:~$

doug@s17:~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

performance

performance

注意:此答案中的示例来自使用acpi-cpufreq CPU频率缩放驱动程序的计算机。如果您使用的intel_pstate驱动程序没有按需调控器,则默认情况下将使用节电调控器。

预期的问题:即使使用性能调节器,为什么我的CPU频率也会缩放?

答:现代处理器可以扩展CPU频率,即使在性能模式下,也取决于它们进入空闲状态的深度。如果您确实想锁定CPU频率,则禁用比0更深的所有空闲状态。但是,请注意,这将消耗大量的电源。

就个人而言,如另一个答复中所述,我将性能调节器或节电调节器用作我所做工作的函数。我的脚本有些不同:

$ cat set_cpu_performance

#! /bin/bash

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > $file; done

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

和:

$ cat set_cpu_powersave

#! /bin/bash

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "powersave" > $file; done

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

用法示例(在使用intel_pstate驱动程序的计算机上):

$ sudo ./set_cpu_performance

powersave

powersave

powersave

powersave

powersave

powersave

powersave

powersave

performance

performance

performance

performance

performance

performance

performance

performance

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值