diff options
| author | Anton Protopopov <[email protected]> | 2025-03-31 20:36:18 +0000 |
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2025-04-04 15:53:24 +0000 |
| commit | dafae1ae2ad32d124ce4efb2105c00ccadc7bd32 (patch) | |
| tree | 2bc06ff098a7a77679dc0b6c85d9fc8794b059af /tools/lib/bpf/bpf_helpers.h | |
| parent | bpf: Fix a comment describing bpf_attr (diff) | |
| download | kernel-dafae1ae2ad32d124ce4efb2105c00ccadc7bd32.tar.gz kernel-dafae1ae2ad32d124ce4efb2105c00ccadc7bd32.zip | |
libbpf: Add likely/unlikely macros and use them in selftests
A few selftests and, more importantly, consequent changes to the
bpf_helpers.h file, use likely/unlikely macros, so define them here
and remove duplicate definitions from existing selftests.
Signed-off-by: Anton Protopopov <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/bpf_helpers.h')
| -rw-r--r-- | tools/lib/bpf/bpf_helpers.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 686824b8b413..a50773d4616e 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -15,6 +15,14 @@ #define __array(name, val) typeof(val) *name[] #define __ulong(name, val) enum { ___bpf_concat(__unique_value, __COUNTER__) = val } name +#ifndef likely +#define likely(x) (__builtin_expect(!!(x), 1)) +#endif + +#ifndef unlikely +#define unlikely(x) (__builtin_expect(!!(x), 0)) +#endif + /* * Helper macro to place programs, maps, license in * different sections in elf_bpf file. Section names |
