wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
xskring.h File Reference

SPSC ring operations shared by the four AF_XDP rings (fill/comp/rx/tx). More...

Go to the source code of this file.

Data Structures

struct  xdp_desc
 AF_XDP descriptor (binary-compatible with linux/if_xdp.h struct xdp_desc). More...
struct  xskring_view
 Raw mmap'd ring pointers as handed in by the caller (or, in tests, plain local variables). More...
struct  xskring
 One SPSC ring side, caching the peer's last-known index so the hot path avoids re-reading the shared cell on every call. More...

Functions

void xskring_init (xskring *r, const xskring_view *v)
 Initialize r from a view.
u32 xskring_prod_reserve (xskring *r, u32 n, u32 *idx)
 Producer side (feeding the fill ring, submitting to the tx ring).
void xskring_prod_submit (xskring *r, u32 n)
 Publish n previously reserved slots: advances cached_prod by n and RELEASE-stores it to *producer.
u32 xskring_cons_peek (xskring *r, u32 n, u32 *idx)
 Consumer side (draining the rx ring, reaping the comp ring).
void xskring_cons_release (xskring *r, u32 n)
 Release n previously peeked slots back to the producer.
u64 * xskring_addr_at (xskring *r, u32 idx)
 Address slot accessor (fill/comp rings); idx is a raw (unmasked) index, masked here.
xdp_desc * xskring_desc_at (xskring *r, u32 idx)
 Descriptor slot accessor (rx/tx rings); idx is a raw (unmasked) index, masked here.

Detailed Description

SPSC ring operations shared by the four AF_XDP rings (fill/comp/rx/tx).

Producer and consumer indices are free-running u32 counters (never masked in place); every accessor masks a raw index at the point of use, matching the kernel's own ring protocol (linux/if_xdp.h descriptions of XDP_UMEM_PGOFF_FILL_RING etc). This file operates purely on caller-owned pointers: no mmap, no syscalls, so it is unit-testable against plain local variables.

Function Documentation

◆ xskring_cons_peek()

u32 xskring_cons_peek ( xskring * r,
u32 n,
u32 * idx )

Consumer side (draining the rx ring, reaping the comp ring).

Returns the number of slots actually available (<= n): if the cached available count is short, the producer index is re-read with ACQUIRE and the available count recomputed once before giving up. *idx receives the first available slot's raw (unmasked) index.

◆ xskring_init()

void xskring_init ( xskring * r,
const xskring_view * v )

Initialize r from a view.

size must be a power of two.

◆ xskring_prod_reserve()

u32 xskring_prod_reserve ( xskring * r,
u32 n,
u32 * idx )

Producer side (feeding the fill ring, submitting to the tx ring).

Returns the number of slots actually granted (<= n): if the cached free count is short, the consumer index is re-read with ACQUIRE and the free count recomputed once before giving up. *idx receives the first granted slot's raw (unmasked) index.