IF_RXR_INIT(9)
๐ฆ 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 therxrstructure. Thelwmargument defines the minimum number of descriptors the chip needs to operate the ring correctly.hwmis used to describe the maximum number of descriptors the ring can contain. ๐if_rxr_get()โ allocates and accounts for up tomaxdescriptors in the ring as being used. ๐ซถif_rxr_put()โ returnsnreceive 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 withif_rxr_put()before callingif_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 themaxrequested. ๐if_rxr_needrefill()โ returns1if the number of receive descriptor slots currently in use on the ring is below the value oflwm. 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
- Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms