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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stddef.hstdbool.hlinux/bpf.hlinux/if_ether.hlinux/ip.hlinux/ipv6.hlinux/in.hlinux/tcp.hlinux/udp.hbpf/bpf_helpers.hbpf/bpf_endian.hbpf_compiler.hxdp_lb_bench_common.hbench_bpf_timing.bpf.h
Detected Declarations
struct lru_inner_mapfunction rol32function __jhash_nwordsfunction jhash_2wordsfunction jhash2_4wordsfunction ipv4_csumfunction encap_v4function encap_v6function update_statsfunction count_actionfunction is_under_floodfunction get_packet_dstfunction update_vip_lru_miss_statsfunction process_packetfunction strip_encapfunction randomize_srcfunction xdp_lb_benchfunction BENCH_BPF_LOOP
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
- Immediate include surface: `stddef.h`, `stdbool.h`, `linux/bpf.h`, `linux/if_ether.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/in.h`, `linux/tcp.h`.
- Detected declarations: `struct lru_inner_map`, `function rol32`, `function __jhash_nwords`, `function jhash_2words`, `function jhash2_4words`, `function ipv4_csum`, `function encap_v4`, `function encap_v6`, `function update_stats`, `function count_action`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.