tools/testing/selftests/bpf/xsk.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/xsk.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/xsk.h- Extension
.h- Size
- 6555 bytes
- Lines
- 250
- 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
stdio.hstdint.hstdbool.hlinux/if_xdp.hbpf/libbpf.h
Detected Declarations
struct namestruct xsk_umemstruct xsk_socketstruct xsk_umem_configstruct xsk_socket_configfunction xsk_ring_cons__comp_addrfunction xsk_ring_cons__rx_descfunction xsk_ring_prod__needs_wakeupfunction xsk_prod_nb_freefunction xsk_cons_nb_availfunction xsk_ring_prod__reservefunction xsk_ring_prod__submitfunction xsk_ring_prod__cancelfunction xsk_ring_cons__peekfunction xsk_ring_cons__cancelfunction xsk_ring_cons__releasefunction xsk_umem__extract_addrfunction xsk_umem__extract_offsetfunction xsk_umem__add_offset_to_addr
Annotated Snippet
struct name { \
__u32 cached_prod; \
__u32 cached_cons; \
__u32 mask; \
__u32 size; \
__u32 *producer; \
__u32 *consumer; \
void *ring; \
__u32 *flags; \
}
DEFINE_XSK_RING(xsk_ring_prod);
DEFINE_XSK_RING(xsk_ring_cons);
/* For a detailed explanation on the memory barriers associated with the
* ring, please take a look at net/xdp/xsk_queue.h.
*/
struct xsk_umem;
struct xsk_socket;
static inline __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill,
__u32 idx)
{
__u64 *addrs = (__u64 *)fill->ring;
return &addrs[idx & fill->mask];
}
static inline const __u64 *
xsk_ring_cons__comp_addr(const struct xsk_ring_cons *comp, __u32 idx)
{
const __u64 *addrs = (const __u64 *)comp->ring;
return &addrs[idx & comp->mask];
}
static inline struct xdp_desc *xsk_ring_prod__tx_desc(struct xsk_ring_prod *tx,
__u32 idx)
{
struct xdp_desc *descs = (struct xdp_desc *)tx->ring;
return &descs[idx & tx->mask];
}
static inline const struct xdp_desc *
xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx)
{
const struct xdp_desc *descs = (const struct xdp_desc *)rx->ring;
return &descs[idx & rx->mask];
}
static inline int xsk_ring_prod__needs_wakeup(const struct xsk_ring_prod *r)
{
return *r->flags & XDP_RING_NEED_WAKEUP;
}
static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb)
{
__u32 free_entries = r->cached_cons - r->cached_prod;
if (free_entries >= nb)
return free_entries;
/* Refresh the local tail pointer.
* cached_cons is r->size bigger than the real consumer pointer so
* that this addition can be avoided in the more frequently
* executed code that computes free_entries in the beginning of
* this function. Without this optimization it would have been
* free_entries = r->cached_prod - r->cached_cons + r->size.
*/
r->cached_cons = __atomic_load_n(r->consumer, __ATOMIC_ACQUIRE);
r->cached_cons += r->size;
return r->cached_cons - r->cached_prod;
}
static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb)
{
__u32 entries = r->cached_prod - r->cached_cons;
if (entries == 0) {
r->cached_prod = __atomic_load_n(r->producer, __ATOMIC_ACQUIRE);
entries = r->cached_prod - r->cached_cons;
}
return (entries > nb) ? nb : entries;
}
Annotation
- Immediate include surface: `stdio.h`, `stdint.h`, `stdbool.h`, `linux/if_xdp.h`, `bpf/libbpf.h`.
- Detected declarations: `struct name`, `struct xsk_umem`, `struct xsk_socket`, `struct xsk_umem_config`, `struct xsk_socket_config`, `function xsk_ring_cons__comp_addr`, `function xsk_ring_cons__rx_desc`, `function xsk_ring_prod__needs_wakeup`, `function xsk_prod_nb_free`, `function xsk_cons_nb_avail`.
- 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.