Which file should I include for KERNEL_VERSION macro ?


chenhengqi@...
 

I'v read this blog post

https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html

And want to apply this technique to my program:

extern u32 LINUX_KERNEL_VERSION __kconfig; extern u32 CONFIG_HZ __kconfig; u64 utime_ns; if (LINUX_KERNEL_VERSION >= KERNEL_VERSION(4, 11, 0)) utime_ns = BPF_CORE_READ(task, utime); else /* convert jiffies to nanoseconds */ utime_ns = BPF_CORE_READ(task, utime) * (1000000000UL / CONFIG_HZ);


Andrii Nakryiko
 

On Wed, Mar 17, 2021 at 5:10 AM <chenhengqi@outlook.com> wrote:

I'v read this blog post

https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html

And want to apply this technique to my program:

extern u32 LINUX_KERNEL_VERSION __kconfig; extern u32 CONFIG_HZ __kconfig; u64 utime_ns; if (LINUX_KERNEL_VERSION >= KERNEL_VERSION(4, 11, 0)) utime_ns = BPF_CORE_READ(task, utime); else /* convert jiffies to nanoseconds */ utime_ns = BPF_CORE_READ(task, utime) * (1000000000UL / CONFIG_HZ);
It will soon be part of bpf_helpers.h, but meanwhile just copy/paste
it into your code. See
https://patchwork.kernel.org/project/netdevbpf/patch/20210317200510.1354627-2-andrii@kernel.org/