tools/testing/selftests/bpf/xskxceiver.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/xskxceiver.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/xskxceiver.c- Extension
.c- Size
- 13704 bytes
- Lines
- 480
- 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
assert.hfcntl.hgetopt.hlinux/if_link.hlinux/if_ether.hlinux/mman.hlinux/netdev.hlinux/ethtool.hlinux/align.harpa/inet.hnet/if.hlocale.hstdio.hstdlib.hlibgen.hstddef.hsys/mman.hsys/types.hprog_tests/test_xsk.hxsk_xdp_progs.skel.hxsk.hxskxceiver.hbpf/bpf.hlinux/filter.hkselftest.hxsk_xdp_common.hnetwork_helpers.h
Detected Declarations
function test__failfunction ifobj_zc_availfunction print_usagefunction validate_interfacefunction parse_command_linefunction xsk_unload_xdp_programsfunction run_pkt_testfunction is_xdp_supportedfunction print_testsfunction main
Annotated Snippet
void test__fail(void) { /* for network_helpers.c */ }
static void __exit_with_error(int error, const char *file, const char *func, int line)
{
ksft_test_result_fail("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line,
error, strerror(error));
ksft_exit_xfail();
}
#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
static bool ifobj_zc_avail(struct ifobject *ifobject)
{
size_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;
int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
struct xsk_socket_info *xsk;
struct xsk_umem_info *umem;
bool zc_avail = false;
void *bufs;
int ret;
bufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
if (bufs == MAP_FAILED)
exit_with_error(errno);
umem = calloc(1, sizeof(struct xsk_umem_info));
if (!umem) {
munmap(bufs, umem_sz);
exit_with_error(ENOMEM);
}
umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
ret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);
if (ret)
exit_with_error(-ret);
xsk = calloc(1, sizeof(struct xsk_socket_info));
if (!xsk)
goto out;
ifobject->bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;
ifobject->rx_on = true;
xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
ret = xsk_configure_socket(xsk, umem, ifobject, false);
if (!ret)
zc_avail = true;
xsk_socket__delete(xsk->xsk);
free(xsk);
out:
munmap(umem->buffer, umem_sz);
xsk_umem__delete(umem->umem);
free(umem);
return zc_avail;
}
static struct option long_options[] = {
{"interface", required_argument, 0, 'i'},
{"busy-poll", no_argument, 0, 'b'},
{"verbose", no_argument, 0, 'v'},
{"mode", required_argument, 0, 'm'},
{"list", no_argument, 0, 'l'},
{"test", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
static void print_usage(char **argv)
{
const char *str =
" Usage: xskxceiver [OPTIONS]\n"
" Options:\n"
" -i, --interface Use interface\n"
" -v, --verbose Verbose output\n"
" -b, --busy-poll Enable busy poll\n"
" -m, --mode Run only mode skb, drv, or zc\n"
" -l, --list List all available tests\n"
" -t, --test Run a specific test. Enter number from -l option.\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
ksft_exit_xfail();
}
static bool validate_interface(struct ifobject *ifobj)
{
if (!strcmp(ifobj->ifname, ""))
return false;
return true;
}
static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
Annotation
- Immediate include surface: `assert.h`, `fcntl.h`, `getopt.h`, `linux/if_link.h`, `linux/if_ether.h`, `linux/mman.h`, `linux/netdev.h`, `linux/ethtool.h`.
- Detected declarations: `function test__fail`, `function ifobj_zc_avail`, `function print_usage`, `function validate_interface`, `function parse_command_line`, `function xsk_unload_xdp_programs`, `function run_pkt_test`, `function is_xdp_supported`, `function print_tests`, `function main`.
- 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.