tools/testing/selftests/bpf/xdp_hw_metadata.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/xdp_hw_metadata.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/xdp_hw_metadata.c- Extension
.c- Size
- 22839 bytes
- Lines
- 895
- 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
test_progs.hnetwork_helpers.hxdp_hw_metadata.skel.hxsk.herror.hlinux/kernel.hlinux/bits.hlinux/bitfield.hlinux/errqueue.hlinux/if_link.hlinux/net_tstamp.hnetinet/udp.hlinux/sockios.hlinux/if_xdp.hsys/mman.hnet/if.hctype.hpoll.htime.hunistd.hlibgen.hstdio.hstdlib.hstring.hsys/ioctl.hlinux/pkt_sched.hlinux/pkt_cls.hlinux/ethtool.hsys/socket.harpa/inet.hxdp_metadata.h
Detected Declarations
struct xskfunction test__failfunction close_xskfunction refill_rxfunction kick_txfunction kick_rxfunction gettimefunction print_tstamp_deltafunction print_vlan_tcifunction verify_xdp_metadatafunction verify_skb_metadatafunction complete_txfunction ping_pongfunction verify_metadatafunction rxq_numfunction hwtstamp_ioctlfunction hwtstamp_restorefunction hwtstamp_enablefunction cleanupfunction handle_signalfunction print_usagefunction read_argsfunction clean_existing_configurationsfunction main
Annotated Snippet
struct xsk {
void *umem_area;
struct xsk_umem *umem;
struct xsk_ring_prod fill;
struct xsk_ring_cons comp;
struct xsk_ring_prod tx;
struct xsk_ring_cons rx;
struct xsk_socket *socket;
};
struct xdp_hw_metadata *bpf_obj;
__u16 bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;
struct xsk *rx_xsk;
const char *ifname;
int ifindex;
int rxq;
bool skip_tx;
__u64 last_hw_rx_timestamp;
__u64 last_xdp_rx_timestamp;
__u64 last_launch_time;
__u64 launch_time_delta_to_hw_rx_timestamp;
int launch_time_queue;
#define run_command(cmd, ...) \
({ \
char command[1024]; \
memset(command, 0, sizeof(command)); \
snprintf(command, sizeof(command), cmd, ##__VA_ARGS__); \
fprintf(stderr, "Running: %s\n", command); \
system(command); \
})
void test__fail(void) { /* for network_helpers.c */ }
static int open_xsk(int ifindex, struct xsk *xsk, __u32 queue_id)
{
int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
const struct xsk_socket_config socket_config = {
.rx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.bind_flags = bind_flags,
};
const struct xsk_umem_config umem_config = {
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
.flags = XDP_UMEM_TX_METADATA_LEN,
.tx_metadata_len = sizeof(struct xsk_tx_metadata),
};
__u32 idx = 0;
u64 addr;
int ret;
int i;
xsk->umem_area = mmap(NULL, UMEM_SIZE, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
if (xsk->umem_area == MAP_FAILED)
return -ENOMEM;
ret = xsk_umem__create(&xsk->umem,
xsk->umem_area, UMEM_SIZE,
&xsk->fill,
&xsk->comp,
&umem_config);
if (ret)
return ret;
ret = xsk_socket__create(&xsk->socket, ifindex, queue_id,
xsk->umem,
&xsk->rx,
&xsk->tx,
&socket_config);
if (ret)
return ret;
/* First half of umem is for TX. This way address matches 1-to-1
* to the completion queue index.
*/
for (i = 0; i < UMEM_NUM / 2; i++) {
addr = i * UMEM_FRAME_SIZE;
printf("%p: tx_desc[%d] -> %lx\n", xsk, i, addr);
}
/* Second half of umem is for RX. */
ret = xsk_ring_prod__reserve(&xsk->fill, UMEM_NUM / 2, &idx);
for (i = 0; i < UMEM_NUM / 2; i++) {
addr = (UMEM_NUM / 2 + i) * UMEM_FRAME_SIZE;
printf("%p: rx_desc[%d] -> %lx\n", xsk, i, addr);
*xsk_ring_prod__fill_addr(&xsk->fill, idx + i) = addr;
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `xdp_hw_metadata.skel.h`, `xsk.h`, `error.h`, `linux/kernel.h`, `linux/bits.h`, `linux/bitfield.h`.
- Detected declarations: `struct xsk`, `function test__fail`, `function close_xsk`, `function refill_rx`, `function kick_tx`, `function kick_rx`, `function gettime`, `function print_tstamp_delta`, `function print_vlan_tci`, `function verify_xdp_metadata`.
- 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.