MQ_INIT(9)
πΈ NAME πΈ
okay so this is mq_init(9) from the Kernel Developer's Manual, and it's literally the whole mbuf queue API, bestie. It covers mq_init, mq_enqueue, mq_push, mq_dequeue, mq_enlist, mq_delist, mq_dechain, mq_len, mq_empty, mq_full, mq_hdatalen, mq_purge, mq_drops, mq_set_maxlen, and MBUF_QUEUE_INITIALIZER β¨
β¨ SYNOPSIS β¨
#include <sys/mbuf.h>
void
mq_init(struct mbuf_queue *mq, unsigned int maxlen, int ipl);
int
mq_enqueue(struct mbuf_queue *mq, struct mbuf *m);
int
mq_push(struct mbuf_queue *mq, struct mbuf *m);
struct mbuf *
mq_dequeue(struct mbuf_queue *mq);
int
mq_enlist(struct mbuf_queue *mq, struct mbuf_list *ml);
void
mq_delist(struct mbuf_queue *mq, struct mbuf_list *ml);
struct mbuf *
mq_dechain(struct mbuf_queue *mq);
unsigned int
mq_len(struct mbuf_queue *mq);
int
mq_empty(struct mbuf_queue *mq);
int
mq_full(struct mbuf_queue *mq);
unsigned int
mq_hdatalen(struct mbuf_queue *mq);
unsigned int
mq_purge(struct mbuf_queue *mq);
unsigned int
mq_drops(struct mbuf_queue *mq);
void
mq_set_maxlen(struct mbuf_queue *mq, unsigned int);
struct mbuf_queue
MBUF_QUEUE_INITIALIZER(unsigned int maxlen, int ipl);
π DESCRIPTION π
The mbuf queue API gives you implementations of data structures and operations for queueing mbufs and lists of mbufs between contexts. It's giving "organized chaos, but make it kernel-safe" π«Ά
mbuf_queue data structures provide a superset of the functionality available in mbuf_lists, and they protect themselves internally with a mutex(9), making them useful for moving mbufs between contexts or subsystems. Additionally, mbuf_queues provide a limit on the number of mbufs that may be queued. No cap, that's just the vibe check π
π§Έ what mbuf_queue structures can do π§Έ
These mbuf_queue structures support the following functionality:
- Insertion of a new mbuf at the end of the queue.
- Removal of an mbuf from the head of the queue.
- Reinsertion of an mbuf at the head of the queue.
- Removal of the entire chain of mbufs on the queue.
- Insertion of the mbufs in an
mbuf_listat the end of the queue. - Removal of all the mbufs on the queue as an
mbuf_list.
π« the functions, one by one π«
mq_init(struct mbuf_queue *mq, unsigned int maxlen, int ipl)β Initialises the mbuf queue structuremq. The maximum number of mbufs that should be queued is specified withmaxlen. The highest interrupt priority level the queue will be operated at is specified viaipl. It's the setup era, main character energy β¨MBUF_QUEUE_INITIALIZER(unsigned int maxlen, int ipl)β Initialises an mbuf queue structure declaration. The maximum number of mbufs that should be queued is specified withmaxlen. The highest interrupt priority level the queue will be operated at is specified viaipl. Declare it, bestie πmq_enqueue(struct mbuf_queue *mq, struct mbuf *m)β Enqueue mbufmon the end of themqmbuf queue. If the queue is full thenmwill be dropped. Sad but true πmq_push(struct mbuf_queue *mq, struct mbuf *m)β Enqueue mbufmon the end of themqmbuf queue. If the queue is full then the mbuf at the head of the queue will be dropped. Out with the old, in with the new πmq_dequeue(struct mbuf_queue *mq)β Dequeue an mbuf from the front of themqmbuf queue. Front of the line, no cuts π¦mq_enlist(struct mbuf_queue *mq, struct mbuf_list *ml)β Enqueue all the mbufs on themlmbuf list on to the end of themqmbuf queue. Heads up: the number of mbufs placed on the queue may exceed its maximum length πmq_delist(struct mbuf_queue *mq, struct mbuf_list *ml)β Dequeue all the mbufs on themqmbuf queue on to themlmbuf list. Whole queue? Moved. Periodt β¨mq_dechain(struct mbuf_queue *mq)β Dequeue all mbufs from themqmbuf queue. Chain reaction, but make it orderly π₯mq_len(struct mbuf_queue *mq)β Return the number of mbufs on themqmbuf queue. Length check, but for mbufs πmq_empty(struct mbuf_queue *mq)β Return if themqmbuf queue is empty. Is it giving empty? Let's find out π«Άmq_full(struct mbuf_queue *mq)β Return if themqmbuf queue is full. Full house, no vacancies πmq_hdatalen(struct mbuf_queue *mq)β Return the number of bytes in the packet at the head of themqmbuf queue. Head packet size reveal πmq_purge(struct mbuf_queue *mq)β Free all the mbufs on themqmbuf queue. Clean slate, iconic behavior π§mq_drops(struct mbuf_queue *mq)β Return how many mbufs were dropped and freed bym_freem(9)if themqmbuf queue was too full. The drop counter, no cap πmq_set_maxlen(struct mbuf_queue *mq, unsigned int)β Alter the maximum number of mbufs that should be queued on themqmbuf queue. Note,mq_set_maxlen()will only set a new limit, it will not free any excess mbufs that may already exist on the queue. It changes the rule, not the population, bestie π
π CONTEXT π
mq_init(), mq_enqueue(), mq_push(), mq_dequeue(), mq_enlist(), mq_delist(), mq_dechain(), mq_len(), mq_empty(), mq_full(), mq_purge(), mq_drops(), mq_set_maxlen(), and MBUF_QUEUE_INITIALIZER() can be called during autoconf, from process context, or from interrupt context. Flexible? Obsessed π
π RETURN VALUES π
mq_dequeue()returns the mbuf that was at the head of its queue. If the queue was empty,NULLis returned. Empty queue said "no thoughts, head empty" πmq_dechain()returns all the mbufs that were on its queues via a pointer to an mbuf with the chain accessible viam_nextpktmembers. If the queue was empty,NULLis returned. Whole chain, returned with receipts π¦mq_len()returns the number of mbufs on the queue. Counted, periodt πmq_empty()returns a non-zero value if the queue is empty, otherwise 0. Empty vibe check βmq_full()returns a non-zero value if the queue is full, otherwise 0. Full vibe check βmq_enqueue()returns 0 if the mbuf was successfully queued, or non-zero if the mbuf was freed because it would cause the queue to exceed its maximum length. Success slay, or drop situation πmq_push()returns 0 if there was space on the queue for the mbuf, or non-zero if the head of the queue was freed to make space for it. Space found, or head said bye πmq_enlist()returns the number of mbufs that were dropped from the list if the length of the queue exceeded its maximum length. The list got humbled, ngl πmq_hdatalen()returns the size of a packet on the queue, or 0 if the queue is empty. Size check, bestie πmq_purge()returns the number of mbufs that were freed. Freed count, iconic cleanup π§mq_drops()returns the number of mbufs that were freed duringmq_enqueue()operations that would have caused the queue to exceed its maximum length. Drop receipts, fr fr π
π SEE ALSO π
cute lil sign-off: this page is Debian-flavoured, dated August 28, 2020, and its footer says MQ_INIT(9) β that's the whole vibe, bestie π
β¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2015 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