From: Puranjay Mohan <puranjay@kernel.org>
To: bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>,
Puranjay Mohan <puranjay12@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
Fei Chen <feichen@meta.com>, Taruna Agrawal <taragrawal@meta.com>,
Nikhil Dixit Limaye <ndixit@meta.com>,
"Nikita V. Shirokov" <tehnerd@tehnerd.com>,
kernel-team@meta.com
Subject: [RFC PATCH bpf-next 3/6] selftests/bpf: Add XDP load-balancer common definitions
Date: Mon, 20 Apr 2026 04:17:03 -0700 [thread overview]
Message-ID: <20260420111726.2118636-4-puranjay@kernel.org> (raw)
In-Reply-To: <20260420111726.2118636-1-puranjay@kernel.org>
Add the shared header for the XDP load-balancer benchmark. This
defines the data structures used by both the BPF program and
userspace: flow_key, vip_definition, real_definition, and the
stats/control structures.
Also provides the encapsulation source-address helpers shared
between the BPF datapath (for encap) and userspace (for building
expected output packets used in validation).
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
---
.../selftests/bpf/xdp_lb_bench_common.h | 112 ++++++++++++++++++
1 file changed, 112 insertions(+)
create mode 100644 tools/testing/selftests/bpf/xdp_lb_bench_common.h
diff --git a/tools/testing/selftests/bpf/xdp_lb_bench_common.h b/tools/testing/selftests/bpf/xdp_lb_bench_common.h
new file mode 100644
index 000000000000..aed20a963701
--- /dev/null
+++ b/tools/testing/selftests/bpf/xdp_lb_bench_common.h
@@ -0,0 +1,112 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#ifndef XDP_LB_BENCH_COMMON_H
+#define XDP_LB_BENCH_COMMON_H
+
+#define F_IPV6 (1 << 0)
+#define F_LRU_BYPASS (1 << 1)
+
+#define CH_RING_SIZE 65537 /* per-VIP consistent hash ring slots */
+#define MAX_VIPS 16
+#define CH_RINGS_SIZE (MAX_VIPS * CH_RING_SIZE)
+#define MAX_REALS 512
+#define DEFAULT_LRU_SIZE 100000 /* connection tracking cache size */
+#define ONE_SEC 1000000000U /* 1 sec in nanosec */
+#define MAX_CONN_RATE 100000000 /* high enough to never trigger in bench */
+#define LRU_UDP_TIMEOUT 30000000000ULL /* 30 sec in nanosec */
+#define PCKT_FRAGMENTED 0x3FFF
+#define KNUTH_HASH_MULT 2654435761U
+#define IPIP_V4_PREFIX 4268 /* 172.16/12 in network order */
+#define IPIP_V6_PREFIX1 1 /* 0100::/64 (RFC 6666 discard) */
+#define IPIP_V6_PREFIX2 0
+#define IPIP_V6_PREFIX3 0
+
+/* Stats indices (0..MAX_VIPS-1 are per-VIP packet/byte counters) */
+#define STATS_LRU (MAX_VIPS + 0) /* v1: total VIP packets, v2: LRU misses */
+#define STATS_XDP_TX (MAX_VIPS + 1)
+#define STATS_XDP_PASS (MAX_VIPS + 2)
+#define STATS_XDP_DROP (MAX_VIPS + 3)
+#define STATS_NEW_CONN (MAX_VIPS + 4) /* v1: conn count, v2: last reset ts */
+#define STATS_LRU_MISS (MAX_VIPS + 5) /* v1: TCP LRU misses */
+#define STATS_SIZE (MAX_VIPS + 6)
+
+#ifdef __BPF__
+#define lb_htons(x) bpf_htons(x)
+#define LB_INLINE static __always_inline
+#else
+#define lb_htons(x) htons(x)
+#define LB_INLINE static inline
+#endif
+
+LB_INLINE __be32 create_encap_ipv4_src(__u16 port, __be32 src)
+{
+ __u32 ip_suffix = lb_htons(port);
+
+ ip_suffix <<= 16;
+ ip_suffix ^= src;
+ return (0xFFFF0000 & ip_suffix) | IPIP_V4_PREFIX;
+}
+
+LB_INLINE void create_encap_ipv6_src(__u16 port, __be32 src, __be32 *saddr)
+{
+ saddr[0] = IPIP_V6_PREFIX1;
+ saddr[1] = IPIP_V6_PREFIX2;
+ saddr[2] = IPIP_V6_PREFIX3;
+ saddr[3] = src ^ port;
+}
+
+struct flow_key {
+ union {
+ __be32 src;
+ __be32 srcv6[4];
+ };
+ union {
+ __be32 dst;
+ __be32 dstv6[4];
+ };
+ union {
+ __u32 ports;
+ __u16 port16[2];
+ };
+ __u8 proto;
+ __u8 pad[3];
+};
+
+struct vip_definition {
+ union {
+ __be32 vip;
+ __be32 vipv6[4];
+ };
+ __u16 port;
+ __u8 proto;
+ __u8 pad;
+};
+
+struct vip_meta {
+ __u32 flags;
+ __u32 vip_num;
+};
+
+struct real_pos_lru {
+ __u32 pos;
+ __u64 atime;
+};
+
+struct real_definition {
+ __be32 dst;
+ __be32 dstv6[4];
+ __u8 flags;
+};
+
+struct lb_stats {
+ __u64 v1;
+ __u64 v2;
+};
+
+struct ctl_value {
+ __u8 mac[6];
+ __u8 pad[2];
+};
+
+#endif /* XDP_LB_BENCH_COMMON_H */
--
2.52.0
next prev parent reply other threads:[~2026-04-20 11:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 11:17 [RFC PATCH bpf-next 0/6] selftests/bpf: Add XDP load-balancer benchmark Puranjay Mohan
2026-04-20 11:17 ` [RFC PATCH bpf-next 1/6] selftests/bpf: Add bench_force_done() for early benchmark completion Puranjay Mohan
2026-04-20 12:41 ` sashiko-bot
2026-04-20 15:32 ` Mykyta Yatsenko
2026-04-20 11:17 ` [RFC PATCH bpf-next 2/6] selftests/bpf: Add BPF batch-timing library Puranjay Mohan
2026-04-20 13:18 ` sashiko-bot
2026-04-22 1:10 ` Alexei Starovoitov
2026-04-20 11:17 ` Puranjay Mohan [this message]
2026-04-20 13:26 ` [RFC PATCH bpf-next 3/6] selftests/bpf: Add XDP load-balancer common definitions sashiko-bot
2026-04-20 11:17 ` [RFC PATCH bpf-next 4/6] selftests/bpf: Add XDP load-balancer BPF program Puranjay Mohan
2026-04-20 13:57 ` sashiko-bot
2026-04-20 11:17 ` [RFC PATCH bpf-next 5/6] selftests/bpf: Add XDP load-balancer benchmark driver Puranjay Mohan
2026-04-20 17:11 ` sashiko-bot
2026-04-20 11:17 ` [RFC PATCH bpf-next 6/6] selftests/bpf: Add XDP load-balancer benchmark run script Puranjay Mohan
2026-04-20 17:36 ` sashiko-bot
2026-04-22 1:16 ` [RFC PATCH bpf-next 0/6] selftests/bpf: Add XDP load-balancer benchmark Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420111726.2118636-4-puranjay@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=feichen@meta.com \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=ndixit@meta.com \
--cc=puranjay12@gmail.com \
--cc=taragrawal@meta.com \
--cc=tehnerd@tehnerd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox