Bug 2217179

Summary: bpf-cpufreq looks for the wrong cpu number
Product: [Fedora] Fedora Reporter: Carlos Rodriguez-Fernandez <carlosrodrifernandez>
Component: bccAssignee: Jerome Marchand <jmarchan>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 38CC: acaringi, jmarchan, olsajiri, rdossant, skozina
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: bcc-0.28.0-1.fc40 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-08-16 08:42:23 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Carlos Rodriguez-Fernandez 2023-06-24 21:55:03 UTC
This is the error:

```
# bpf-cpufreq 
failed to open '/sys/devices/system/cpu/cpu12/cpufreq/scaling_cur_freq': No such file or directory
failed to init freqs
```

```
bpf-opensnoop --name=bpf-cpufreq
PID    COMM              FD ERR PATH
49029  bpf-cpufreq        3   0 /etc/ld.so.cache
49029  bpf-cpufreq        3   0 /lib64/libelf.so.1
49029  bpf-cpufreq        3   0 /lib64/libz.so.1
49029  bpf-cpufreq        3   0 /lib64/libc.so.6
49029  bpf-cpufreq        3   0 /lib64/libzstd.so.1
49029  bpf-cpufreq        3   0 /sys/devices/system/cpu/possible
49029  bpf-cpufreq        3   0 /sys/kernel/btf/vmlinux
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu8/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu9/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu10/cpufreq/scaling_cur_freq
49029  bpf-cpufreq        9   0 /sys/devices/system/cpu/cpu11/cpufreq/scaling_cur_freq
49029  bpf-cpufreq       -1   2 /sys/devices/system/cpu/cpu12/cpufreq/scaling_cur_freq
```

```
# cat /sys/devices/system/cpu/possible
0-31
```

```
inxi --cpu --system -z
System:
  Kernel: 6.3.8-200.fc38.x86_64 arch: x86_64 bits: 64 Console: pty pts/1
    Distro: Fedora release 38 (Thirty Eight)
CPU:
  Info: 6-core model: AMD Ryzen 5 5600G with Radeon Graphics bits: 64
    type: MT MCP cache: L2: 3 MiB
  Speed (MHz): avg: 1608 min/max: 1400/4464 cores: 1: 1400 2: 3900 3: 1400
    4: 1400 5: 1400 6: 1400 7: 1400 8: 1400 9: 1400 10: 1400 11: 1400 12: 1400
```

It looks to me that the tool should be using /sys/devices/system/cpu/present

https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/cputopology.rst
> present: CPUs that have been identified as being present in the system [cpu_present_mask]

Reproducible: Always

Steps to Reproduce:
1.sudo bpf-cpufreq
2.
3.
Actual Results:  
failed to open '/sys/devices/system/cpu/cpu12/cpufreq/scaling_cur_freq': No such file or directory

Expected Results:  
CPU frequencies

Comment 1 Carlos Rodriguez-Fernandez 2023-06-24 22:24:10 UTC
I submitted it as well on the bcc project itself: https://github.com/iovisor/bcc/issues/4651

Comment 2 Jerome Marchand 2023-08-09 15:16:33 UTC
This should get fixed by the rebase to bcc-0.28.0