Module ring

Module ring 

Source
Expand description

§AF_XDP Ring Buffer Management

§Purpose

This file defines the core data structures and logic for managing the various ring buffers used in AF_XDP sockets. These rings are the primary mechanism for communication between the userspace application and the kernel.

§How it works

It provides a generic Ring<T> struct that encapsulates a memory-mapped ring buffer. This struct provides methods for atomically accessing and updating the producer and consumer indices, accessing descriptors, and checking ring flags. It also defines the XdpDesc struct for packet descriptors. The RingType enum helps manage the specifics of the four different rings (TX, RX, Fill, Completion), such as their memory map offsets and socket option names.

§Main components

  • Ring<T>: A generic struct representing a shared memory ring buffer.
  • RingMmap<T>: A struct holding the raw memory-mapped components of a ring.
  • XdpDesc: The descriptor structure for packets in the TX and RX rings, containing address, length, and options.
  • RingType: An enum to differentiate between ring types and handle their specific setup requirements.

Structs§

Ring
A generic, safe wrapper for an AF_XDP ring buffer.
RingMmap
Holds the raw memory-mapped components of a ring buffer.
XdpDesc
An XDP descriptor, used in the TX and RX rings.

Enums§

RingType
An enum representing the four types of AF_XDP rings.

Constants§

FRAME_COUNT
The default number of frames to allocate for the UMEM.
FRAME_SIZE
The size of a single frame in the UMEM, typically 2KB or 4KB.

Functions§

mmap_ring
A low-level function to memory-map a single AF_XDP ring.