samples/bpf/xdp_sample_user.c
Source file repositories/reference/linux-study-clean/samples/bpf/xdp_sample_user.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/xdp_sample_user.c- Extension
.c- Size
- 43387 bytes
- Lines
- 1674
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
arpa/inet.hbpf/bpf.hbpf/libbpf.herrno.hfcntl.hgetopt.hlinux/ethtool.hlinux/hashtable.hlinux/if_link.hlinux/jhash.hlinux/limits.hlinux/list.hlinux/sockios.hlocale.hmath.hnet/if.hpoll.hsignal.hstdbool.hstdio.hstdlib.hstring.hsys/ioctl.hsys/mman.hsys/signalfd.hsys/sysinfo.hsys/timerfd.hsys/utsname.htime.hunistd.hbpf_util.hxdp_sample_user.h
Detected Declarations
struct recordstruct map_entrystruct stats_recordstruct sample_outputstruct xdp_descenum map_typeenum log_levelfunction gettimefunction sample_print_helpfunction sample_usagefunction map_entry_initfunction map_collect_percpufunction map_collect_percpu_devmapfunction hash_for_each_possiblefunction free_stats_recordfunction calc_periodfunction sample_roundfunction calc_ppsfunction calc_drop_ppsfunction calc_errs_ppsfunction calc_info_ppsfunction calc_xdp_ppsfunction stats_get_rx_cntfunction stats_get_cpumap_enqueuefunction stats_get_cpumap_remotefunction stats_get_cpumap_kthreadfunction stats_get_redirect_cntfunction stats_get_redirect_err_cntfunction stats_get_exception_cntfunction stats_get_devmap_xmitfunction stats_get_devmap_xmit_multifunction hash_for_eachfunction hash_for_each_possiblefunction stats_printfunction sample_setup_mapsfunction sample_setup_maps_mappingsfunction __sample_initfunction __sample_remove_xdpfunction sample_install_xdpfunction sample_summary_printfunction sample_exitfunction sample_stats_collectfunction sample_summary_updatefunction sample_stats_printfunction sample_switch_modefunction sample_signal_cbfunction swapfunction sample_timer_cb
Annotated Snippet
struct record {
__u64 timestamp;
struct datarec total;
struct datarec *cpu;
};
struct map_entry {
struct hlist_node node;
__u64 pair;
struct record val;
};
struct stats_record {
struct record rx_cnt;
struct record redir_err[XDP_REDIRECT_ERR_MAX];
struct record kthread;
struct record exception[XDP_ACTION_MAX];
struct record devmap_xmit;
DECLARE_HASHTABLE(xmit_map, 5);
struct record enq[];
};
struct sample_output {
struct {
__u64 rx;
__u64 redir;
__u64 drop;
__u64 drop_xmit;
__u64 err;
__u64 xmit;
} totals;
struct {
union {
__u64 pps;
__u64 num;
};
__u64 drop;
__u64 err;
} rx_cnt;
struct {
__u64 suc;
__u64 err;
} redir_cnt;
struct {
__u64 hits;
} except_cnt;
struct {
__u64 pps;
__u64 drop;
__u64 err;
double bavg;
} xmit_cnt;
};
struct xdp_desc {
int ifindex;
__u32 prog_id;
int flags;
} sample_xdp_progs[32];
struct datarec *sample_mmap[NUM_MAP];
struct bpf_map *sample_map[NUM_MAP];
size_t sample_map_count[NUM_MAP];
enum log_level sample_log_level;
struct sample_output sample_out;
unsigned long sample_interval;
bool sample_err_exp;
int sample_xdp_cnt;
int sample_n_cpus;
int sample_sig_fd;
int sample_mask;
static const char *xdp_redirect_err_names[XDP_REDIRECT_ERR_MAX] = {
/* Key=1 keeps unknown errors */
"Success",
"Unknown",
"EINVAL",
"ENETDOWN",
"EMSGSIZE",
"EOPNOTSUPP",
"ENOSPC",
};
/* Keyed from Unknown */
static const char *xdp_redirect_err_help[XDP_REDIRECT_ERR_MAX - 1] = {
"Unknown error",
"Invalid redirection",
"Device being redirected to is down",
"Packet length too large for device",
"Operation not supported",
Annotation
- Immediate include surface: `arpa/inet.h`, `bpf/bpf.h`, `bpf/libbpf.h`, `errno.h`, `fcntl.h`, `getopt.h`, `linux/ethtool.h`, `linux/hashtable.h`.
- Detected declarations: `struct record`, `struct map_entry`, `struct stats_record`, `struct sample_output`, `struct xdp_desc`, `enum map_type`, `enum log_level`, `function gettime`, `function sample_print_help`, `function sample_usage`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.