Fix BPF perf event array creation failure on glibc 2.36+ - #40
Fix BPF perf event array creation failure on glibc 2.36+#40malladisiddu wants to merge 1 commit into
Conversation
Hello @malladisiddu, thanks for looking into this issue! Could you take a look at PR #41 instead? It implements better CPU detection, since the CPU topology on the machine allows for holes in the CPU index list |
|
Hey @alessandrogario, your #41 is a much better approach, reading Thanks for the quick and thorough fix! |

Summary
Replace
get_nprocs_conf()withget_nprocs()inperfeventarray.cppto fix BPF initialization failures on systems running glibc 2.36+ where the reported "configured" CPU count exceeds the actual online CPU count.Problem Description
BPF-based applications (i.e., in my case it is osquery) using
ebpf-commonfail to initialize on Ubuntu 24.04 (glibc 2.39) with the following error:Root Cause
The
PerfEventArray::create()function usesget_nprocs_conf()to determine the number of CPUs for perf event array creation.glibc 2.36 changed the behavior of
get_nprocs_conf():get_nprocs_conf()reads from/sys/devices/system/cpu/cpu*)/sys/devices/system/cpu/possibleBoth approaches are valid interpretations of "configured processors." The issue is that the code using this function assumed the returned value would always represent CPUs usable with
perf_event_open().Per the man page,
get_nprocs_conf()returns "the number of processors configured by the operating system" whileget_nprocs()returns "the number of processors currently available in the system." On systems where configured CPUs exceed online CPUs, usingget_nprocs_conf()causes failures when attempting to create perf events for CPUs that are not currently available.strace Output (Failing System)
CPU Configuration (Affected System)
Testing
Before Fix
After Fix
Impact
Affected Systems
get_nprocs_conf()) exceeds available CPUs (get_nprocs())Downstream Projects Affected
References
Additional Notes
This issue was discovered while debugging osquery's BPFEventPublisher failures on Ubuntu 24.04. The fix has been validated in production environments.
If maintainers prefer an alternative approach, I'm happy to discuss and implement accordingly.