htop-dev / htop

htop - an interactive process viewer
https://htop.dev/
GNU General Public License v2.0
6.56k stars 440 forks source link

Incorrect CPU core frequency on intel_pstate #1070

Open martin-kokos opened 2 years ago

martin-kokos commented 2 years ago

Htop shows maximum base frequency of 2800MHz usually on 7 of 8 cores while system is idle and intel_pstate governor is being used with a performance hint (/sys/devices/system/cpu/intel_pstate/max_perf_pct ) of 20% which should force a lower frequency, as confirmed by cpufreq. The cores are sleeping a lot, C3 15%, C7 55%. I would speculate a cpu that happens to be sleeping shows the base frequency.

Similar issue: https://www.reddit.com/r/linuxquestions/comments/pw19c8/htop_is_not_showing_the_correct_cpu_frequency/

current frequencies:

cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq
553441
1064406
1044271
569879
792459
777940
967503
1043618

htop

  1[||||                                      6.1% 2800MHz]   5[||||                                      5.0% 2800MHz] Tasks: 190, 2061 thr, 156 kthr; 1 running
  2[||||                                      6.1%  876MHz]   6[||||||||                                 12.7% 2800MHz] Load average: 1.84 1.20 1.24
  3[|||||||||                                14.7% 2800MHz]   7[||||||||||||||                           24.1% 2800MHz] Uptime: 13 days, 03:10:36
  4[||||                                      6.0% 2800MHz]   8[||||                                      6.1% 2800MHz] Battery: 77.5% (Running on battery)
M

cpupower:

# cpupower -c 0 frequency-info
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 400 MHz - 4.70 GHz
  available cpufreq governors: performance powersave
  current policy: frequency should be within 400 MHz and 400 MHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 423 MHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes

lscpu

# lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  8
  On-line CPU(s) list:   0-7
Vendor ID:               GenuineIntel
  Model name:            11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    CPU family:          6
    Model:               140
    Thread(s) per core:  2
    Core(s) per socket:  4
    Socket(s):           1
    Stepping:            1
    CPU max MHz:         4700.0000
    CPU min MHz:         400.0000
    BogoMIPS:            5606.40
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology non
                         stop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm
                         3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq
                         rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512
                         vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
Virtualization features:
  Virtualization:        VT-x
Caches (sum of all):
  L1d:                   192 KiB (4 instances)
  L1i:                   128 KiB (4 instances)
  L2:                    5 MiB (4 instances)
  L3:                    12 MiB (1 instance)
Vulnerabilities:
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Vulnerable: eIBRS with unprivileged eBPF
  Srbds:                 Not affected
  Tsx async abort:       Not affected

htop version 3.2.1

maxpain commented 2 years ago

The same problem

1ridic commented 2 years ago

I think the problem stems from this comment. On my intel CPU, the read delay reaches 16000us, but the /proc/cpuinfo may have wrong CPU frequencies( #953 ). So I feel like we need to add an option to decide where to read the CPU frequency from.