tools/testing/selftests/bpf/prog_tests/test_xsk.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_xsk.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_xsk.c- Extension
.c- Size
- 67880 bytes
- Lines
- 2637
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
bpf/bpf.herrno.hlinux/bitmap.hlinux/if_link.hlinux/mman.hlinux/netdev.hpoll.hpthread.hsignal.hstring.hsys/mman.hsys/socket.hsys/time.hunistd.hnetwork_helpers.htest_xsk.hxsk_xdp_common.hxsk_xdp_progs.skel.h
Detected Declarations
function numberfunction gen_eth_hdrfunction is_umem_validfunction mode_to_xdp_flagsfunction umem_sizefunction xsk_configure_umemfunction umem_alloc_bufferfunction umem_reset_allocfunction enable_busy_pollfunction xsk_configure_socketfunction set_ring_sizefunction hw_ring_size_resetfunction __test_spec_initfunction test_initfunction test_spec_resetfunction test_spec_set_unalignedfunction test_spec_set_frame_sizefunction test_spec_set_xdp_progfunction test_spec_set_mtufunction pkt_stream_resetfunction pkt_stream_deletefunction pkt_stream_restore_defaultfunction pkt_nb_fragsfunction set_pkt_validfunction pkt_setfunction pkt_stream_pkt_setfunction pkt_get_buffer_lenfunction pkt_stream_replace_ifobjectfunction pkt_stream_replacefunction __pkt_stream_replace_halffunction pkt_stream_replace_halffunction pkt_stream_receive_halffunction pkt_stream_even_odd_sequencefunction release_even_odd_sequencefunction pkt_get_addrfunction pkt_stream_cancelfunction pkt_generatefunction pkt_stream_generate_customfunction pkt_print_datafunction pkt_dumpfunction is_offset_correctfunction is_metadata_correctfunction is_adjust_tail_supportedfunction is_frag_validfunction is_pkt_validfunction load_valuefunction kick_tx_with_checkfunction kick_tx
Annotated Snippet
if (i == 0) {
ifobj->rx_on = false;
ifobj->tx_on = true;
} else {
ifobj->rx_on = true;
ifobj->tx_on = false;
}
umem_real = ifobj->xsk_arr[0].umem_real;
memset(umem_real, 0, sizeof(*umem_real));
for (j = 0; j < MAX_SOCKETS; j++) {
struct xsk_socket_info *xsk = &ifobj->xsk_arr[j];
memset(xsk, 0, sizeof(*xsk));
xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
if (j == 0)
xsk->umem_real = umem_real;
xsk->umem = umem_real;
xsk->batch_size = DEFAULT_BATCH_SIZE;
if (i == 0)
xsk->pkt_stream = test->tx_pkt_stream_default;
else
xsk->pkt_stream = test->rx_pkt_stream_default;
memcpy(xsk->src_mac, g_mac, ETH_ALEN);
memcpy(xsk->dst_mac, g_mac, ETH_ALEN);
xsk->src_mac[5] += ((j * 2) + 0);
xsk->dst_mac[5] += ((j * 2) + 1);
}
ifobj->xsk->umem->num_frames = DEFAULT_UMEM_BUFFERS;
ifobj->xsk->umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
}
if (ifobj_tx->hw_ring_size_supp)
hw_ring_size_reset(ifobj_tx);
test->ifobj_tx = ifobj_tx;
test->ifobj_rx = ifobj_rx;
test->current_step = 0;
test->total_steps = 1;
test->nb_sockets = 1;
test->fail = false;
test->set_ring = false;
test->adjust_tail = false;
test->adjust_tail_support = false;
test->mtu = MAX_ETH_PKT_SIZE;
test->xdp_prog_rx = ifobj_rx->xdp_progs->progs.xsk_def_prog;
test->xskmap_rx = ifobj_rx->xdp_progs->maps.xsk;
test->xdp_prog_tx = ifobj_tx->xdp_progs->progs.xsk_def_prog;
test->xskmap_tx = ifobj_tx->xdp_progs->maps.xsk;
}
void test_init(struct test_spec *test, struct ifobject *ifobj_tx,
struct ifobject *ifobj_rx, enum test_mode mode,
const struct test_spec *test_to_run)
{
struct pkt_stream *tx_pkt_stream;
struct pkt_stream *rx_pkt_stream;
u32 i;
tx_pkt_stream = test->tx_pkt_stream_default;
rx_pkt_stream = test->rx_pkt_stream_default;
memset(test, 0, sizeof(*test));
test->tx_pkt_stream_default = tx_pkt_stream;
test->rx_pkt_stream_default = rx_pkt_stream;
for (i = 0; i < MAX_INTERFACES; i++) {
struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;
ifobj->bind_flags = XDP_USE_NEED_WAKEUP;
if (mode == TEST_MODE_ZC)
ifobj->bind_flags |= XDP_ZEROCOPY;
else
ifobj->bind_flags |= XDP_COPY;
}
memcpy(test->name, test_to_run->name, MAX_TEST_NAME_SIZE);
test->test_func = test_to_run->test_func;
test->mode = mode;
__test_spec_init(test, ifobj_tx, ifobj_rx);
}
static void test_spec_reset(struct test_spec *test)
{
__test_spec_init(test, test->ifobj_tx, test->ifobj_rx);
}
static void test_spec_set_unaligned(struct test_spec *test)
{
Annotation
- Immediate include surface: `bpf/bpf.h`, `errno.h`, `linux/bitmap.h`, `linux/if_link.h`, `linux/mman.h`, `linux/netdev.h`, `poll.h`, `pthread.h`.
- Detected declarations: `function number`, `function gen_eth_hdr`, `function is_umem_valid`, `function mode_to_xdp_flags`, `function umem_size`, `function xsk_configure_umem`, `function umem_alloc_buffer`, `function umem_reset_alloc`, `function enable_busy_poll`, `function xsk_configure_socket`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.