* [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix
@ 2025-03-31 20:36 Anton Protopopov
2025-03-31 20:36 ` [PATCH bpf-next 1/2] bpf: fix a comment describing bpf_attr Anton Protopopov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Anton Protopopov @ 2025-03-31 20:36 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov
These two commits fix a comment describing bpf_attr in <linux/bpf.h>
and add likely/unlikely macros to <bph/bpf_helpers.h> to be consumed
by selftests and, later, by the static_branch_likely/unlikely macros.
v1 -> v2:
* squash libbpf and selftests fixes into one patch (Andrii)
Anton Protopopov (2):
bpf: fix a comment describing bpf_attr
libbpf: add likely/unlikely macros and use them in selftests
include/uapi/linux/bpf.h | 2 +-
tools/include/uapi/linux/bpf.h | 2 +-
tools/lib/bpf/bpf_helpers.h | 8 ++++++++
tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 3 ---
tools/testing/selftests/bpf/progs/iters.c | 2 --
5 files changed, 10 insertions(+), 7 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH bpf-next 1/2] bpf: fix a comment describing bpf_attr 2025-03-31 20:36 [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix Anton Protopopov @ 2025-03-31 20:36 ` Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 2/2] libbpf: add likely/unlikely macros and use them in selftests Anton Protopopov 2025-04-04 16:00 ` [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: Anton Protopopov @ 2025-03-31 20:36 UTC (permalink / raw) To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov The map_fd field of the bpf_attr union is used in the BPF_MAP_FREEZE syscall. Explicitly mention this in the comments. Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com> --- include/uapi/linux/bpf.h | 2 +- tools/include/uapi/linux/bpf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 661de2444965..1388db053d9e 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1506,7 +1506,7 @@ union bpf_attr { __s32 map_token_fd; }; - struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ + struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */ __u32 map_fd; __aligned_u64 key; union { diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 661de2444965..1388db053d9e 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1506,7 +1506,7 @@ union bpf_attr { __s32 map_token_fd; }; - struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ + struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */ __u32 map_fd; __aligned_u64 key; union { -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH bpf-next 2/2] libbpf: add likely/unlikely macros and use them in selftests 2025-03-31 20:36 [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 1/2] bpf: fix a comment describing bpf_attr Anton Protopopov @ 2025-03-31 20:36 ` Anton Protopopov 2025-04-04 16:00 ` [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: Anton Protopopov @ 2025-03-31 20:36 UTC (permalink / raw) To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov 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 <a.s.protopopov@gmail.com> --- tools/lib/bpf/bpf_helpers.h | 8 ++++++++ tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 3 --- tools/testing/selftests/bpf/progs/iters.c | 2 -- 3 files changed, 8 insertions(+), 5 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 diff --git a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h index fb8dc0768999..4e29c31c4ef8 100644 --- a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h +++ b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h @@ -95,9 +95,6 @@ struct arena_qnode { #define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET) #define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) - struct arena_qnode __arena qnodes[_Q_MAX_CPUS][_Q_MAX_NODES]; static inline u32 encode_tail(int cpu, int idx) diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c index 427b72954b87..76adf4a8f2da 100644 --- a/tools/testing/selftests/bpf/progs/iters.c +++ b/tools/testing/selftests/bpf/progs/iters.c @@ -7,8 +7,6 @@ #include "bpf_misc.h" #include "bpf_compiler.h" -#define unlikely(x) __builtin_expect(!!(x), 0) - static volatile int zero = 0; int my_pid; -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix 2025-03-31 20:36 [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 1/2] bpf: fix a comment describing bpf_attr Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 2/2] libbpf: add likely/unlikely macros and use them in selftests Anton Protopopov @ 2025-04-04 16:00 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 4+ messages in thread From: patchwork-bot+netdevbpf @ 2025-04-04 16:00 UTC (permalink / raw) To: Anton Protopopov; +Cc: bpf, andrii Hello: This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <andrii@kernel.org>: On Mon, 31 Mar 2025 20:36:16 +0000 you wrote: > These two commits fix a comment describing bpf_attr in <linux/bpf.h> > and add likely/unlikely macros to <bph/bpf_helpers.h> to be consumed > by selftests and, later, by the static_branch_likely/unlikely macros. > > v1 -> v2: > * squash libbpf and selftests fixes into one patch (Andrii) > > [...] Here is the summary with links: - [bpf-next,1/2] bpf: fix a comment describing bpf_attr https://git.kernel.org/bpf/bpf-next/c/62aa5790cec8 - [bpf-next,2/2] libbpf: add likely/unlikely macros and use them in selftests https://git.kernel.org/bpf/bpf-next/c/dafae1ae2ad3 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-04 15:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-03-31 20:36 [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 1/2] bpf: fix a comment describing bpf_attr Anton Protopopov 2025-03-31 20:36 ` [PATCH bpf-next 2/2] libbpf: add likely/unlikely macros and use them in selftests Anton Protopopov 2025-04-04 16:00 ` [PATCH v2 bpf-next 0/2] likely/unlikely for bpf_helpers and a small comment fix patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox