-
Some users run into problems when trying to open a perf reader for a perf event array. Given a map definition like this: #define EVENT_MAX_ENTRIES 512
struct bpf_elf_map __section_maps event = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.size_key = sizeof(int),
.size_value = sizeof(__u32),
.max_elem = EVENT_MAX_ENTRIES,
.pinning = PIN_GLOBAL_NS,
}; Given code like this: m, err := ebpf.LoadPinnedMap("/path/to/map", nil)
if err != nil {
fmt.Printf("err: %v\n", err)
return
}
reader, err := perf.NewReader(m, 8192)
if err != nil {
fmt.Printf("err: %v\n", err)
return
} Will generate an error like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The problem is that the map size is larger than the total number of possible CPUs in the system. In the example the system probably has 16 cores / 32 hyperthreads numbered from 0-31, hence the error when trying to create a perf ring for CPU 32. The fix is to not specify |
Beta Was this translation helpful? Give feedback.
-
I am not specifying the max entries at all. My definition looks like
My machine has 80 CPUs, and when I run
The libbpf version is 1:0.5.0-1ubuntu22.04.1 . |
Beta Was this translation helpful? Give feedback.
-
I was able to fix it. The Maxentries were being set due to a variable assignment error. Please close this. |
Beta Was this translation helpful? Give feedback.
The problem is that the map size is larger than the total number of possible CPUs in the system. In the example the system probably has 16 cores / 32 hyperthreads numbered from 0-31, hence the error when trying to create a perf ring for CPU 32.
The fix is to not specify
max_elems
for perf event arrays, which makes the loader determine the correct size for the current system. This is supported both by cilium/ebpf and newer libbpf / iproute2 versions.