iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

Why `bpf_core_type_exists` is evaluated on every call? #4814

Closed flplv closed 10 months ago

flplv commented 10 months ago

https://github.com/iovisor/bcc/blob/bc9b43a00b83bcea600b3540c5a6124ebd78a7ff/libbpf-tools/core_fixes.bpf.h#L223-L228

I wonder why we evaluate the kernel configuration via bpf_core_type_exists on every time the probe function is called? Couldn't we have cached that value with an static? ie:

static __always_inline bool has_kmem_cache_free()
{
        static bool r = bpf_core_type_exists(struct trace_event_raw_kmem_cache_free___x);
    return r;
}
flplv commented 10 months ago

Answering my own question: Apparently the branches are resolved by the verifier on load time and dead code is removed. So not needed to worry about performance in those cases.