如何更改 intel_pspace 性能调节器的频率范围

如何更改 intel_pspace 性能调节器的频率范围

我想在基于 Ubuntu 20.04 的系统(KDE neon)上设置更高的 CPU 频率,内核为 5.4.0-58-generic。CPU 是 Intel(R) Core(TM) i7-8700,硬件限制为 800 MHz - 4.60 GHz。

环境

sudo cpupower frequency-set --min 4500Hz 

按照建议这里不起作用。频率仍然在 800 MHz 和 4.60 GHz 范围内。

cpufreq-info 的示例输出为:

analyzing CPU 11:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 11
  CPUs which need to have their frequency coordinated by software: 11
  maximum transition latency: 4294.55 ms.
  hardware limits: 800 MHz - 4.60 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 4.60 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 4.21 GHz.

对于所有核心。

改变scaling_min_freq也无济于事:

MAX_CPU=$((`nproc --all` - 1))
for i in $(seq 0 $MAX_CPU); do
    echo 4500000 | sudo tee /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
done

示例输出cpufreq-info

analyzing CPU 11:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 11
  CPUs which need to have their frequency coordinated by software: 11
  maximum transition latency: 4294.55 ms.
  hardware limits: 800 MHz - 4.60 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 4.50 GHz and 4.60 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 4.23 GHz.

虽然频率应该在 4.50 GHz 和 4.60 GHz 之间,但当前 CPU 频率仍为 4.23 GHz。看来这 scaling_min_freq 仅用于打印信息,并没有真正改变性能调节器。

我也试过pstate-frequency

sudo pstate-frequency -S -p max 
pstate-frequency version 3.11.0
    pstate::CPU_DRIVER   -> intel_pstate
    pstate::CPU_GOVERNOR -> performance
    pstate::TURBO        -> 0 [ON]
    pstate::CPU_MIN      -> 99% [4554000KHz]
    pstate::CPU_MAX      -> 100% [4600000KHz]

但这再次只是改变scaling_min_freq,而 cpufreq-info 的输出仍然不明确

analyzing CPU 11:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 11
  CPUs which need to have their frequency coordinated by software: 11
  maximum transition latency: 4294.55 ms.
  hardware limits: 800 MHz - 4.60 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 4.55 GHz and 4.60 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 4.24 GHz.

除了使用遗留cpufreq_userspace驱动程序相反intel_pstate,有没有办法设置更高的最小(或更好的恒定)CPU频率?

答案1

处理器可以自行降低 CPU 频率,即使在性能模式下也是如此。在性能模式下,启用 HWP 后,您应该无法检测到任何性能下降。另请注意,调整各种最小值不会对性能模式产生任何影响。

现在,如果确实希望始终获得准确的 CPU 报告频率,那么可以使用以下方法:

首先,您必须处理最大 CPU 频率作为活动核心的函数。如果您不要求 Turbostat 保持安静,它将为您列出此信息。示例 1 (i7-2600K):

$ sudo turbostat
...
cpu5: MSR_TURBO_RATIO_LIMIT: 0x23242526
35 * 100.0 = 3500.0 MHz max turbo 4 active cores
36 * 100.0 = 3600.0 MHz max turbo 3 active cores
37 * 100.0 = 3700.0 MHz max turbo 2 active cores
38 * 100.0 = 3800.0 MHz max turbo 1 active cores

因此,即使我将最低 CPU 频率设置为 3.8 GHz,处理器本身也会根据活动核心的功能覆盖该频率。因此,我必须将最高 CPU 频率设置为 3.5 GHz 以避免此问题。

示例 2(i5-9600K):

cpu5: MSR_TURBO_RATIO_LIMIT: 0x2b2b2e2e2e2e2e2e
43 * 100.0 = 4300.0 MHz max turbo 8 active cores << I only have 6 cores
43 * 100.0 = 4300.0 MHz max turbo 7 active cores << I only have 6 cores
46 * 100.0 = 4600.0 MHz max turbo 6 active cores
46 * 100.0 = 4600.0 MHz max turbo 5 active cores
46 * 100.0 = 4600.0 MHz max turbo 4 active cores
46 * 100.0 = 4600.0 MHz max turbo 3 active cores
46 * 100.0 = 4600.0 MHz max turbo 2 active cores
46 * 100.0 = 4600.0 MHz max turbo 1 active cores

请注意,我已将其设置为不根据活动核心来降低 CPU 频率。

免责声明:除非您确定您的系统能够处理热量和电流要求,否则请勿执行此操作。还需要解锁的处理器。

现在,即使如此,性能模式下 CPU 频率也可能不会保持在 4.6 GHz:

$ sudo turbostat --Summary --quiet --show Busy%,Bzy_MHz,IRQ,PkgWatt,PkgTmp --interval 10
Busy%   Bzy_MHz IRQ     PkgTmp  PkgWatt
0.14    4579    650     32      2.10  <<<
0.40    4600    507     32      2.27
0.09    4600    270     31      2.01
0.13    4600    322     32      2.10
0.02    4600    205     31      1.99
0.11    4600    229     32      2.04
0.10    4600    269     32      2.02
0.08    4600    300     32      2.00
0.04    4598    443     32      2.01
0.05    4600    215     32      1.98
0.02    4586    210     32      1.95 <<
0.05    4594    233     32      1.97 <<
0.01    4600    246     32      1.95

可以通过完全禁用空闲状态来消除此问题,但会消耗大量电量:

$ echo 1 | sudo tee /sys/devices/system/cpu/cpu*/cpuidle/state*/disable

$ sudo turbostat --Summary --quiet --show Busy%,Bzy_MHz,IRQ,PkgWatt,PkgTmp --interval 10
Busy%   Bzy_MHz IRQ     PkgTmp  PkgWatt
100.26  4600    60109   47      52.88  <<< not 100% busy, but 100% idle state 0
100.26  4600    60113   48      53.01  <<< if no idle states enabled the kernel will use 0.
100.26  4600    60107   48      53.01
100.26  4600    60183   48      53.01

好的,但是还有另一种方法。事实证明空闲状态 2 是 HWP 的问题,所以只需禁用它即可:

doug@s18:~/idle$ echo 1 | sudo tee /sys/devices/system/cpu/cpu*/cpuidle/state*/disable
1
doug@s18:~/idle$ sudo ~/c/msr-decoder^C
doug@s18:~/idle$ echo 0 | sudo tee /sys/devices/system/cpu/cpu*/cpuidle/state*/disable
0
doug@s18:~/idle$ echo 1 | sudo tee /sys/devices/system/cpu/cpu*/cpuidle/state2/disable
1
doug@s18:~/idle$ grep . /sys/devices/system/cpu/cpu3/cpuidle/state*/disable
/sys/devices/system/cpu/cpu3/cpuidle/state0/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state1/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state2/disable:1
/sys/devices/system/cpu/cpu3/cpuidle/state3/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state4/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state5/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state6/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state7/disable:0
/sys/devices/system/cpu/cpu3/cpuidle/state8/disable:0

$ sudo turbostat --Summary --quiet --show Busy%,Bzy_MHz,IRQ,PkgWatt,PkgTmp --interval 10
Busy%   Bzy_MHz IRQ     PkgTmp  PkgWatt
0.02    4600    332     35      1.96
0.03    4600    209     35      1.94
0.09    4600    290     35      2.00
0.17    4600    377     35      2.07
0.03    4600    205     34      1.94
0.05    4600    192     35      1.95
0.15    4600    274     35      2.04
0.04    4600    208     35      1.96
0.11    4600    279     35      2.02
0.06    4600    219     34      1.97
0.13    4600    251     34      2.03
0.03    4600    173     34      1.94
0.11    4600    343     34      2.02
0.02    4600    205     33      1.94
0.03    4600    180     34      1.94
0.04    4600    183     34      1.95
0.12    4600    250     34      2.03
0.08    4600    236     33      1.99
0.02    4600    225     34      1.94
0.02    4600    165     34      1.93
0.01    4600    173     33      1.93
0.01    4600    170     33      1.93
0.02    4600    200     33      1.95
0.02    4600    199     33      1.94
0.02    4600    218     33      1.94
0.01    4600    161     33      1.93
0.01    4600    170     33      1.94
0.01    4600    187     33      1.94
0.02    4600    218     33      1.95
0.02    4600    176     33      1.94
0.01    4600    212     32      1.94

为了完整性,请使用没有 HWP 的 i7-2600K。

$ grep . /sys/devices/system/cpu/cpu3/cpufreq/*
/sys/devices/system/cpu/cpu3/cpufreq/affected_cpus:3
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq:3800000
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_min_freq:1600000
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_transition_latency:20000
/sys/devices/system/cpu/cpu3/cpufreq/related_cpus:3
/sys/devices/system/cpu/cpu3/cpufreq/scaling_available_governors:ondemand performance schedutil
/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq:1605486
/sys/devices/system/cpu/cpu3/cpufreq/scaling_driver:intel_cpufreq
/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor:ondemand
/sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq:3800000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq:1600000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_setspeed:<unsupported>
doug@s15:~/diag$ grep . /sys/devices/system/cpu/cpu3/cpufreq/*^C
doug@s15:~/diag$ echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
doug@s15:~/diag$ echo 3500000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
3500000
doug@s15:~/diag$ sudo turbostat --Summary --quiet --show Busy%,Bzy_MHz,IRQ,PkgWatt,PkgTmp --interval 10
Busy%   Bzy_MHz IRQ     PkgTmp  PkgWatt
0.02    1806    453     28      3.75
0.02    1889    340     28      3.73
0.01    1896    268     31      3.72
0.02    1771    437     28      3.73

嘿,为什么 CPU 频率不稳定?嗯,对于非 HWP 处理器,只有禁用所有空闲状态的方法才有效。通过设置能效偏差(仅在非 HWP 模式下使用)可以获得一点响应提升:

$ cat /sys/devices/system/cpu/cpu3/power/energy_perf_bias
6
doug@s15:~/diag$ echo 0 | sudo tee /sys/devices/system/cpu/cpu3/power/energy_perf_bias
0
$ echo 1 | sudo tee /sys/devices/system/cpu/cpu*/cpuidle/state*/disable

$ sudo turbostat --Summary --quiet --show Busy%,Bzy_MHz,IRQ,PkgWatt,PkgTmp --interval 10
Busy%   Bzy_MHz IRQ     PkgTmp  PkgWatt
100.00  3500    20114   52      49.06
100.00  3500    20146   54      49.49
100.00  3500    20096   58      49.87
100.00  3500    20086   59      50.17
100.00  3500    22609   61      50.50
100.00  3500    20110   62      51.02
100.00  3500    20105   63      51.53
100.00  3500    20081   65      51.78
100.00  3500    20059   66      52.02
100.00  3500    20090   67      52.23
100.00  3500    20717   68      52.37
100.00  3500    20066   68      52.48
100.00  3500    20074   68      52.58
100.00  3500    20222   71      52.78
100.00  3500    20109   70      52.83
100.00  3500    20075   70      52.81
100.00  3500    21040   70      52.92
100.00  3500    20066   70      52.95

相关内容