文章目录

  1. 安装依赖

    1. 安装内核通用包
    2. 安装具体工具包
  2. 设定cpu运行模式
  3. 查看cpu支持的频率设定
  4. 设置最大和最小频率
  5. 时时监控cpu频率

修改频率

安装依赖

安装内核通用包

    apt install linux-tools-common

安装具体工具包

这里一定要安装与当前内核匹配的 工具包

    apt install linux-tools-generic 
    //不管用的话用下面这个,记得指定内核版本
    apt install linux-tools-4.15.0-34-generic

设定cpu运行模式

我们把cpu设定成性能模式

    cpupower frequency-set -g performance

具体的性能模式列表

    performance   运行于最大频率
    powersave     运行于最小频率
    userspace     运行于用户指定的频率
    ondemand      按需快速动态调整CPU频率, 一有cpu计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率
    conservative  按需快速动态调整CPU频率, 比 ondemand 的调整更保守
    schedutil     基于调度程序调整 CPU 频率

查看cpu支持的频率设定

  1. 虽然我们可以随意指定cpu运行频率
  2. 但是cpu的频率设定不是非常精确的
  3. 一般只有几个挡位供我们选择
  4. 只有当我们设定的cpu运行频率是cpu支持的参数时,设置才生效

用以下命令查看cpu支持的频率设置

    cpupower frequency-info

我们一起来看一下返回结果

    analyzing CPU 0:
      driver: acpi-cpufreq
      CPUs which run at the same hardware frequency: 0
      CPUs which need to have their frequency coordinated by software: 0
      maximum transition latency: 10.0 us
      hardware limits: 798 MHz - 1.86 GHz
      available frequency steps:  1.86 GHz, 1.60 GHz, 1.33 GHz, 1.06 GHz, 798 MHz
      available cpufreq governors: conservative ondemand userspace powersave performance schedutil
      current policy: frequency should be within 798 MHz and 1.86 GHz.
                      The governor "userspace" may decide which speed to use
                      within this range.
      current CPU frequency: 1.86 GHz (asserted by call to hardware)
      boost state support:
        Supported: no
        Active: no

我们主要看一下这一行
available frequency steps: 1.86 GHz, 1.60 GHz, 1.33 GHz, 1.06 GHz, 798 MHz
这里几个参数就是cpu支持的频率模式

设置最大和最小频率

设置最大时钟频率

    cpupower frequency-set -u clock_freq

运设置最小时钟频率

    cpupower frequency-set -d clock_freq

设置运行于指定频率

    cpupower frequency-set -f clock_freq

频率单位

  1. clock_freq 为时钟频率,单位为:GHz, MHz
  2. 单位要紧跟在频率后面否则不起作用
    cpupower frequency-set -f 1.86GHz
    cpupower frequency-set -f 798MHz

时时监控cpu频率

    watch -n 0 "cat /proc/cpuinfo | grep -i mhz"

实际效果

阿童木锁核1.8其实还可以的

    ----------------------------------------------------------------------
    CPU model            : Intel(R) Atom(TM) CPU N2800   @ 1.86GHz
    Number of cores      : 4
    CPU frequency        : 1866.823 MHz
    Total size of Disk   : 1863.7 GB (726.3 GB Used)
    Total amount of Mem  : 3928 MB (176 MB Used)
    Total amount of Swap : 510 MB (0 MB Used)
    System uptime        : 0 days, 0 hour 18 min
    Load average         : 0.06, 0.04, 0.09
    OS                   : Ubuntu 18.04.1 LTS
    Arch                 : x86_64 (64 Bit)
    Kernel               : 4.15.0-36-generic
----------------------------------------------------------------------

四核全开

    processor       : 0
    cpu MHz         : 1866.808
    processor       : 1
    cpu MHz         : 1866.734
    processor       : 2
    cpu MHz         : 1866.795
    processor       : 3
    cpu MHz         : 1866.829
Last modification:November 19, 2020
如果觉得我的文章对你有用,请随意赞赏