IF_RXR_INIT(9)

๐Ÿ“ฆ in nixpkgs unstable

๐Ÿฆ‹ the Interface Receive Ring accounting API โ€” a IF_RXR_INIT(9) bestie explainer ๐Ÿฆ‹

okay so this is a section 9 kernel developer's manual page, and the manual name is literally IF_RXR_INIT(9) โ€” but don't let the all-caps intimidate you, bestie ๐Ÿ’–. This whole page is about the Interface Receive Ring accounting API, aka the little system that manages how many descriptors are available on a network card's receive ring. It's giving "descriptor bouncer at the club door", no cap ๐ŸŽ€.

โœจ NAME โœจ

if_rxr_init, if_rxr_get, if_rxr_put, if_rxr_livelocked, if_rxr_needrefill, if_rxr_inuse, if_rxr_cwm, if_rxr_ioctl, if_rxr_info_ioctl โ€” Interface Receive Ring accounting ๐ŸŒธ

๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

#include <net/if.h>

void
if_rxr_init(struct if_rxring *rxr, unsigned int lwm, unsigned int hwm);

unsigned int
if_rxr_get(struct if_rxring *rxr, unsigned int max);

void
if_rxr_put(struct if_rxring *rxr, unsigned int n);

void
if_rxr_livelocked(struct if_rxring *rxr);

int
if_rxr_needrefill(struct if_rxring *rxr);

unsigned int
if_rxr_inuse(struct if_rxring *rxr);

unsigned int
if_rxr_cwm(struct if_rxring *rxr);

int
if_rxr_ioctl(struct if_rxrinfo *ifri, const char *name,
    unsigned int size, struct if_rxring *rxr);

int
if_rxr_info_ioctl(struct if_rxrinfo *ifri, unsigned int n,
    struct if_rxring_info *rings);

๐Ÿ’… DESCRIPTION ๐Ÿ’…

The Interface Receive Ring accounting API provides a mechanism to manage the number of available descriptors on a network card's receive ring. The API restricts the allocation of receive descriptors using a heuristic that monitors the use of the ring. The number of descriptors granted on the ring may increase over time as the interface proves it uses them. Additionally, if the algorithm detects that the system is livelocked as a result of being overwhelmed with network traffic, it will restrict the number of available receive descriptors. ๐Ÿ’€

Now the function-by-function tea โ˜•:

  • if_rxr_init() โ€” initialises the rxr structure. The lwm argument defines the minimum number of descriptors the chip needs to operate the ring correctly. hwm is used to describe the maximum number of descriptors the ring can contain. ๐Ÿ‘‘
  • if_rxr_get() โ€” allocates and accounts for up to max descriptors in the ring as being used. ๐Ÿซถ
  • if_rxr_put() โ€” returns n receive descriptor slots to the ring. ๐Ÿ’ซ
  • if_rxr_livelocked() โ€” can signal that the receive ring is generating too much load. ๐Ÿ”ฅ
  • if_rxr_needrefill() โ€” signals that the receive ring runs below the low watermark of descriptors. ๐Ÿšจ
  • if_rxr_inuse() โ€” can be used to determine how many descriptor slots have been allocated on the ring. ๐Ÿงฎ
  • if_rxr_cwm() โ€” can be used to determine what the current watermark is for the ring. ๐ŸŒŠ

The if_rxr_ioctl() and if_rxr_info_ioctl() functions are provided to assist drivers in reporting their rings' state to userland via a SIOCGIFRXR ioctl request. The ioctl data payload will be an ifreq structure, with ifr_data pointing at a struct if_rxrinfo in userland memory. This if_rxrinfo pointer should be passed via ifri. ๐Ÿ“ฌ

If a driver only has a single receive ring, it may pass the ring state to if_rxr_ioctl() via the rxr argument. size is used to describe the size of the mbuf cluster the receive ring uses. If the driver wishes to name the ring it can pass it via name, otherwise NULL. ๐Ÿท๏ธ

If the driver has multiple receive rings, it can prepare an array of if_rxring_info structures and pass that to if_rxr_info_ioctl() via rings with the number of elements in the array passed via n. ๐Ÿงบ

okay but fr fr, important: for the heuristic to work correctly, a driver using this API should return all possible descriptor slots with if_rxr_put() before calling if_rxr_get() to fill them again. periodt ๐Ÿ’…

๐Ÿซถ CONTEXT ๐Ÿซถ

if_rxr_init(), if_rxr_get(), if_rxr_put(), if_rxr_livelocked(), if_rxr_needrefill(), if_rxr_inuse(), and if_rxr_cwm() can be called during autoconf, from process context, or from interrupt context. โœจ

if_rxr_ioctl() and if_rxr_info_ioctl() can be called from process context, and only from the context of the process generating an ioctl call. ๐Ÿงš

another lock-check, bestie: it is up to the caller to provide appropriate locking around calls to these functions to prevent inconsistencies in the relevant if_rxring data structure. no cap ๐Ÿ”’

โญ RETURN VALUES โญ

  • if_rxr_get() โ€” returns the number of receive descriptors available on the ring. The number of descriptors may be less than the max requested. ๐ŸŽ€
  • if_rxr_needrefill() โ€” returns 1 if the number of receive descriptor slots currently in use on the ring is below the value of lwm. Otherwise, zero is returned. 0๏ธโƒฃ
  • if_rxr_inuse() โ€” returns the number of receive descriptor slots currently in use on the ring. ๐Ÿ“Š
  • if_rxr_cwm() โ€” returns the currently allowed allocation watermark. ๐Ÿ’ง

๐Ÿ” SEE ALSO ๐Ÿ”

  • autoconf(9) โ€” go give her a read, iykyk ๐Ÿ’œ

๐Ÿ“œ HISTORY ๐Ÿ“œ

The Interface Receive Ring API was originally written by David Gwynne <dlg@openbsd.org>. The API first appeared in OpenBSD 5.6. ๐Ÿ‘‘


and that's the whole page, bestie โ€” Debian edition, September 10, 2022, signing off with a little kiss ๐Ÿ’‹๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • nixpkgs unstable: cvs-export
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms