cpufreqd

最後更新: 2020-12-12

目錄

 


cpufreqd

 

BIOS Setting

make sure Cool'n'Quiet (AMD) or SpeedStep (Intel) is enabled for you CPU

否則用唔到 cpufrequtils

apt-get install cpufrequtils

  • /etc/init.d/loadcpufreq
  • /etc/init.d/cpufrequtils
  • cpufreq-info
  • cpufreq-set
  • cpufreq-aperf

/etc/init.d/loadcpufreq

* Loading cpufreq kernel modules...

/etc/init.d/cpufrequtils

 * CPUFreq Utilities: Setting ondemand CPUFreq governor...                                          
 * CPU0...                                                                                          
 * CPU1...                                                                                  [ OK ]

 


查看 CPU frequency 的資訊

 

cpufreq-info

analyzing CPU 0:
  driver: powernow-k8
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 8.0 us.
  hardware limits: 1.40 GHz - 3.60 GHz
  available frequency steps: 3.60 GHz, 3.20 GHz, 2.80 GHz, 2.40 GHz, 1.90 GHz, 1.40 GHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 3.60 GHz and 3.60 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 3.60 GHz (asserted by call to hardware).
  cpufreq stats: 3.60 GHz:5.19%, 3.20 GHz:0.29%, 2.80 GHz:0.25%, 2.40 GHz:0.56%, 1.90 GHz:0.30%, 1.40 GHz:93.41%  (8187765)

analyzing CPU 1:
...

# 現在 core 0 的 frequency (-m: human-readable output)

cpufreq-info -c 0 -fm

# 查看統計資料 (-s: statistics)

cpufreq-info -sm

File

/sys/devices/system/cpu/cpu*/cpufreq/

/sys/devices/system/cpu/cpu0/cpufreq/:
affected_cpus     cpuinfo_max_freq            related_cpus                   scaling_driver    scaling_setspeed
bios_limit        cpuinfo_min_freq            scaling_available_frequencies  scaling_governor  stats
cpb               cpuinfo_transition_latency  scaling_available_governors    scaling_max_freq
cpuinfo_cur_freq  freqdomain_cpus             scaling_cur_freq               scaling_min_freq

...

 


cpufreq-aperf

 

行 cpufreq-aperf 出 Err

CPU     Average freq(KHz)       Time in C0      Time in Cx      C0 percentage
Could not read cpuid, is the cpuid driver loaded or compiled into the kernel?

解決:

modprobe cpuid msr

cpufreq-aperf Usage:

cpufreq-aperf

output:

CPU     Average freq(KHz)       Time in C0      Time in Cx      C0 percentage

000     3600000                 00 sec 096 ms   00 sec 903 ms   09
001     3636000                 00 sec 129 ms   00 sec 870 ms   12

000     3600000                 00 sec 098 ms   00 sec 901 ms   09
001     3672000                 00 sec 137 ms   00 sec 862 ms   13

000     3600000                 00 sec 130 ms   00 sec 869 ms   13
001     3672000                 00 sec 106 ms   00 sec 893 ms   10

 


cpufreq-set

 

  • -g --governor <GOV>
  • -c --cpu <CPU>                    # 在那 core 上套用設定, default: 0

# the governor may select

  • -d --min <FREQ>
  • -u --max <FREQ>

# Requires userspace  governor

  • -f --freq <FREQ>

 


Kernel Modules

 

ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/

p4-clockmod.ko                # Intel Pentium 4 / Xeon / Celeron processors

pcc-cpufreq.ko                 #

speedstep-lib.ko               # for Intel speedstep

在 ubuntu 12.04 是見不到以下 module 的, 因為它們 compile 到了 kernel

powernow-k8                   # AMD CPU

acpi-cpufreq

CPUFreq driver which utilizes the ACPI Processor Performance States.

This driver also supports Intel Enhanced SpeedStep

 

/boot/config-3.2.0-54-generic:

CONFIG_X86_ACPI_CPUFREQ=y
CONFIG_X86_POWERNOW_K8=y

 

/etc/default/cpufrequtils (you might need to create it if it doesn't exist)

# valid values: userspace conservative powersave ondemand performance
# get them from cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 
GOVERNOR="conservative"

/etc/init.d/cpufrequtils 負責 load 此設定

 

支援與否

root@home:~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

3600000 3200000 2800000 2400000 1900000 1400000

root@home:~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

conservative ondemand userspace powersave performance

查看 CPU 現在的  freq

root@home:~# cat /sys/devices/system/cpu/*/cpufreq/cpuinfo_cur_freq

3600000
3600000

scaling_driver:

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

 


在使用中的 CPU

 

AMD A6-5400K APU with Radeon(tm) HD Graphics

power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

 


Tuning the ondemand governor

 

  • performance     Run the cpu at max frequency
  • ondemand         Does a periodic polling and changes frequency based on the CPU utilization.
  • conservative     Similar to ondemand. The frequency is gracefully increased and decreased
  • powersave        Run the cpu at the minimum frequency

 

# stepping up
# echo -n percent > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

To set the threshold for stepping down to another frequency:

# echo -n percent > /sys/devices/system/cpu/cpufreq/ondemand/down_threshold

Sampling rate

/sys/devices/system/cpu/cpufreq/ondemand/

sampling_rate
10000

sampling_down_factor
1

 


 

userland-based governors

apt-get install cpufreqd

cpufreqd      
    cpufreqd-get       透過 cpufreqd 獲得資料
    cpufreqd-set

/etc/init.d/cpufreqd

/etc/default/cpufreqd
    負責設定載入的 module
    # CPU kernel module
    # Governor modules

/etc/cpufreqd.conf

cpufreqd-get 與 cpufreqd-set

修改 /etc/cpufreqd.conf 後才用到

enable_remote=1
remote_group=root

cpufreqd-get

        NULL        查看在 /etc/cpufreqd.conf 預先設定好的 profile
        -l                list applied Profiles for all cpus.

root@home:~# cpufreqd-get -l

    CPU#0: "Performance High" performance 3600000-3600000
    CPU#1: "Performance High" performance 3600000-3600000

root@home:~# cpufreqd-get

Name (#1):      Performance High
Active on CPU#: 0, 1
Governor:       performance
Min freq:       3600000
Max freq:       3600000

Name (#2):      Performance Low
Governor:       performance
Min freq:       2800000
Max freq:       2800000

Name (#3):      Powersave High
Governor:       powersave
Min freq:       2400000
Max freq:       2400000

Name (#4):      Powersave Low
Governor:       powersave
Min freq:       1400000
Max freq:       1400000

 

cpufreqd-set <command>

  • manual
  • dynamic     <-- cpufreqd will poll system parameters
  • number      <-- 用 cpufreqd-get 拿到的 Profile number
     

 


P-state 與 C-states

 

Processor performance states (P-states)

processor operating states (C-states)

* A P-state is a voltage and frequency operating point

* Higher P-state numbers represent slower processor speeds

* To operate at any P-state, the processor must be in the C0 operational state

* Higher C-state numbers represent deeper CPU sleep states

Intel: Enhanced Intel SpeedStep Technology

Software: CPUFreq

 


Dell Active Power controller (DAPC)

 

power profile:

OS Control
    Enabled and all supported processor P-states are provided to the OS in the ACPI table
Active Power Controller
    Enable DellSystem DBPM (BIOS will not make all P states available to OS)
Max Performance
    The processor P-state is statically set to the highest supported P-state DBPM is disabled
Custom

詞語:

DBPM: demand‐based power management

 


C-States

 

There are only a few reasons to Disable any C-States:

1. Overclocking

2. The CPU needs to be in a full power mode 24/7

C0 ~ C10

C0 - CPU fully turned on

C1 - Halt

當有程式執行了 "HLT"(Halt) 指令後, CPU會進入傳統 halt 模式

halt: the processor is not executing instructions,

        but can return to an executing state essentially instantaneously.

bus interface unit and APIC are kept running at full speed.

C1E (Enhanced C1 state)

Intel)

Stops CPU main internal clocks via software and reduces CPU voltage;

bus interface unit and APIC are kept running at full speed.

AMD)

Stops all CPU internal clocks.

C2 - Stop Grant

Stops CPU main internal clocks via hardware("STPCLK" 引腳);

bus interface unit and APIC are kept running at full speed.

AMD)

Stops CPU internal and external clocks via hardware

C3 - Deep Sleep

Stops all CPU internal and external clocks & bus interface

C4 - Deeper Sleep

降低 Core 的電壓

C4E/C5 - Enhanced Deeper Sleep (Intel)

Reduces CPU voltage even more and turns off the memory cache

C6 - Deep Power Down

CPU 的完整狀態儲存到一個特定的SRAM中, 之後關閉 CPU

AMD: 每個 CPU Core 均擁有自己的 VDD 線路

C7

C8

C9

C10

 

 

 

 

Creative Commons license icon Creative Commons license icon