tools/testing/selftests/bpf/progs/xdp_lb_bench.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/xdp_lb_bench.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/xdp_lb_bench.c
Extension
.c
Size
15437 bytes
Lines
648
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct lru_inner_map {
	__uint(type, BPF_MAP_TYPE_LRU_HASH);
	__type(key, struct flow_key);
	__type(value, struct real_pos_lru);
	__uint(max_entries, DEFAULT_LRU_SIZE);
} lru_inner SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
	__type(key, __u32);
	__type(value, __u32);
	__uint(max_entries, BENCH_NR_CPUS);
	__array(values, struct lru_inner_map);
} lru_mapping SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, CH_RINGS_SIZE);
	__type(key, __u32);
	__type(value, __u32);
} ch_rings SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, MAX_REALS);
	__type(key, __u32);
	__type(value, struct real_definition);
} reals SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, STATS_SIZE);
	__type(key, __u32);
	__type(value, struct lb_stats);
} stats SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, MAX_REALS);
	__type(key, __u32);
	__type(value, struct lb_stats);
} reals_stats SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, struct ctl_value);
} ctl_array SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 1);
	__type(key, __u32);
	__type(value, struct vip_definition);
} vip_miss_stats SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, MAX_REALS);
	__type(key, __u32);
	__type(value, __u32);
} lru_miss_stats SEC(".maps");

volatile __u32 flow_mask;
volatile __u32 cold_lru;
__u32 batch_gen;

/*
 * old_eth MUST be read BEFORE writing the outer header because
 * bpf_xdp_adjust_head makes them overlap.
 */
static __always_inline int encap_v4(struct xdp_md *xdp, __be32 saddr, __be32 daddr,
				    __u16 payload_len, const __u8 *dst_mac)
{
	struct ethhdr *new_eth, *old_eth;
	void *data, *data_end;
	struct iphdr *iph;

	if (bpf_xdp_adjust_head(xdp, -(int)sizeof(struct iphdr)))
		return -1;

	data     = (void *)(long)xdp->data;
	data_end = (void *)(long)xdp->data_end;

	new_eth = data;
	iph     = data + sizeof(struct ethhdr);
	old_eth = data + sizeof(struct iphdr);

	if (new_eth + 1 > data_end || old_eth + 1 > data_end || iph + 1 > data_end)

Annotation

Implementation Notes