tools/testing/selftests/bpf/prog_tests/xsk.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/xsk.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/xsk.c- Extension
.c- Size
- 4372 bytes
- Lines
- 171
- 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
net/if.hstdarg.hnetwork_helpers.htest_progs.htest_xsk.hxsk_xdp_progs.skel.h
Detected Declarations
function setup_vethfunction delete_vethfunction configure_ifobjfunction test_xskfunction test_ns_xsk_skbfunction test_ns_xsk_drv
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <net/if.h>
#include <stdarg.h>
#include "network_helpers.h"
#include "test_progs.h"
#include "test_xsk.h"
#include "xsk_xdp_progs.skel.h"
#define VETH_RX "veth0"
#define VETH_TX "veth1"
#define MTU 1500
int setup_veth(bool busy_poll)
{
SYS(fail,
"ip link add %s numtxqueues 4 numrxqueues 4 type veth peer name %s numtxqueues 4 numrxqueues 4",
VETH_RX, VETH_TX);
SYS(fail, "sysctl -wq net.ipv6.conf.%s.disable_ipv6=1", VETH_RX);
SYS(fail, "sysctl -wq net.ipv6.conf.%s.disable_ipv6=1", VETH_TX);
if (busy_poll) {
SYS(fail, "echo 2 > /sys/class/net/%s/napi_defer_hard_irqs", VETH_RX);
SYS(fail, "echo 200000 > /sys/class/net/%s/gro_flush_timeout", VETH_RX);
SYS(fail, "echo 2 > /sys/class/net/%s/napi_defer_hard_irqs", VETH_TX);
SYS(fail, "echo 200000 > /sys/class/net/%s/gro_flush_timeout", VETH_TX);
}
SYS(fail, "ip link set %s mtu %d", VETH_RX, MTU);
SYS(fail, "ip link set %s mtu %d", VETH_TX, MTU);
SYS(fail, "ip link set %s up", VETH_RX);
SYS(fail, "ip link set %s up", VETH_TX);
return 0;
fail:
return -1;
}
void delete_veth(void)
{
SYS_NOFAIL("ip link del %s", VETH_RX);
SYS_NOFAIL("ip link del %s", VETH_TX);
}
int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
{
rx->ifindex = if_nametoindex(VETH_RX);
if (!ASSERT_OK_FD(rx->ifindex, "get RX ifindex"))
return -1;
tx->ifindex = if_nametoindex(VETH_TX);
if (!ASSERT_OK_FD(tx->ifindex, "get TX ifindex"))
return -1;
tx->shared_umem = false;
rx->shared_umem = false;
return 0;
}
static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
{
u32 max_frags, umem_tailroom, cache_line_size;
struct ifobject *ifobj_tx, *ifobj_rx;
struct test_spec test;
int ret;
ifobj_tx = ifobject_create();
if (!ASSERT_OK_PTR(ifobj_tx, "create ifobj_tx"))
return;
ifobj_rx = ifobject_create();
if (!ASSERT_OK_PTR(ifobj_rx, "create ifobj_rx"))
goto delete_tx;
if (!ASSERT_OK(configure_ifobj(ifobj_tx, ifobj_rx), "conigure ifobj"))
goto delete_rx;
ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
if (!ret) {
ifobj_tx->hw_ring_size_supp = true;
ifobj_tx->set_ring.default_tx = ifobj_tx->ring.tx_pending;
ifobj_tx->set_ring.default_rx = ifobj_tx->ring.rx_pending;
}
cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
if (!cache_line_size)
cache_line_size = 64;
Annotation
- Immediate include surface: `net/if.h`, `stdarg.h`, `network_helpers.h`, `test_progs.h`, `test_xsk.h`, `xsk_xdp_progs.skel.h`.
- Detected declarations: `function setup_veth`, `function delete_veth`, `function configure_ifobj`, `function test_xsk`, `function test_ns_xsk_skb`, `function test_ns_xsk_drv`.
- 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.