Index: share/man/man9/Makefile =================================================================== RCS file: /cvs/src/share/man/man9/Makefile,v retrieving revision 1.236 diff -u -p -r1.236 Makefile --- share/man/man9/Makefile 2 Jul 2015 01:35:45 -0000 1.236 +++ share/man/man9/Makefile 3 Jul 2015 01:19:39 -0000 @@ -266,7 +266,8 @@ MLINKS+=microtime.9 getmicrotime.9 micro microtime.9 getnanotime.9 microtime.9 nanouptime.9 \ microtime.9 getnanouptime.9 microtime.9 bintime.9 \ microtime.9 binuptime.9 -MLINKS+=ml_init.9 ml_enqueue.9 ml_init.9 ml_dequeue.9 ml_init.9 ml_dechain.9 \ +MLINKS+=ml_init.9 ml_enqueue.9 ml_init.9 ml_dequeue.9 ml_init.9 ml_requeue.9 \ + ml_init.9 ml_dechain.9 \ ml_init.9 ml_filter.9 ml_init.9 ml_len.9 ml_init.9 ml_empty.9 \ ml_init.9 MBUF_LIST_INITIALIZER.9 ml_init.9 MBUF_LIST_FOREACH.9 MLINKS+=mountroothook_establish.9 mountroothook_disestablish.9 @@ -274,8 +275,9 @@ MLINKS+=mutex.9 mtx_init.9 mutex.9 mtx_e mutex.9 MUTEX_ASSERT_LOCKED.9 mutex.9 MUTEX_ASSERT_UNLOCKED.9 \ mutex.9 MUTEX_INITIALIZER.9 MLINKS+=mutex.9 mtx_enter_try.9 -MLINKS+=mq_init.9 mq_enqueue.9 mq_init.9 mq_dequeue.9 mq_init.9 mq_enlist.9 \ - mq_init.9 mq_delist.9 mq_init.9 mq_dechain.9 mq_init.9 mq_filter.9 \ +MLINKS+=mq_init.9 mq_enqueue.9 mq_init.9 mq_dequeue.9 mq_init.9 mq_requeue.9 \ + mq_init.9 mq_enlist.9 mq_init.9 mq_delist.9 mq_init.9 mq_relist.9 \ + mq_init.9 mq_dechain.9 mq_init.9 mq_filter.9 \ mq_init.9 mq_len.9 mq_init.9 mq_empty.9 mq_init.9 mq_drops.9 \ mq_init.9 mq_set_maxlen.9 mq_init.9 MBUF_QUEUE_INITIALIZER.9 MLINKS+=namei.9 vfs_lookup.9 namei.9 vfs_relookup.9 namei.9 NDINIT.9 Index: share/man/man9/ml_init.9 =================================================================== RCS file: /cvs/src/share/man/man9/ml_init.9,v retrieving revision 1.1 diff -u -p -r1.1 ml_init.9 --- share/man/man9/ml_init.9 17 Jun 2015 06:24:46 -0000 1.1 +++ share/man/man9/ml_init.9 3 Jul 2015 01:19:39 -0000 @@ -21,6 +21,7 @@ .Nm ml_init , .Nm ml_enqueue , .Nm ml_dequeue , +.Nm ml_requeue , .Nm ml_dechain , .Nm ml_len , .Nm ml_empty , @@ -34,6 +35,8 @@ .Fn "ml_enqueue" "struct mbuf_list *ml" "struct mbuf *m" .Ft struct mbuf * .Fn "ml_dequeue" "struct mbuf_list *ml" +.Ft void +.Fn "ml_requeue" "struct mbuf_list *ml" "struct mbuf *m" .Ft struct mbuf * .Fn "ml_dechain" "struct mbuf_list *ml" .Ft struct mbuf * @@ -61,6 +64,8 @@ Insertion of a new mbuf at the end of th .It Removal of an mbuf from the head of the list. .It +Reinsertion of an mbuf at the head of the list. +.It Removal of the entire chain of mbufs on the list. .El .Bl -tag -width Ds @@ -80,6 +85,12 @@ mbuf list. Dequeue an mbuf from the front of the .Fa ml mbuf list. +.It Fn "ml_requeue" "struct mbuf_list *ml" "struct mbuf *m" +Enqueue mbuf +.Fa m +at the head of the +.Fa ml +mbuf list. .It Fn "ml_dechain" "struct mbuf_list *ml" Dequeues all mbufs from the .Fa ml @@ -124,6 +135,7 @@ Note that it is unsafe to modify the lis .Fn ml_init , .Fn ml_enqueue , .Fn ml_dequeue , +.Fn ml_requeue , .Fn ml_dechain , .Fn ml_len , .Fn ml_empty , Index: share/man/man9/mq_init.9 =================================================================== RCS file: /cvs/src/share/man/man9/mq_init.9,v retrieving revision 1.1 diff -u -p -r1.1 mq_init.9 --- share/man/man9/mq_init.9 17 Jun 2015 06:24:46 -0000 1.1 +++ share/man/man9/mq_init.9 3 Jul 2015 01:19:39 -0000 @@ -21,8 +21,10 @@ .Nm mq_init , .Nm mq_enqueue , .Nm mq_dequeue , +.Nm mq_requeue , .Nm mq_enlist , .Nm mq_delist , +.Nm mq_relist , .Nm mq_dechain , .Nm mq_len , .Nm mq_empty , @@ -38,9 +40,13 @@ .Ft struct mbuf * .Fn "mq_dequeue" "struct mbuf_queue *mq" .Ft int +.Fn "mq_requeue" "struct mbuf_queue *mq" "struct mbuf *m" +.Ft int .Fn "mq_enlist" "struct mbuf_queue *mq" "struct mbuf_list *ml" .Ft void .Fn "mq_delist" "struct mbuf_queue *mq" "struct mbuf_list *ml" +.Ft int +.Fn "mq_relist" "struct mbuf_queue *mq" "struct mbuf_list *ml" .Ft struct mbuf * .Fn "mq_dechain" "struct mbuf_queue *mq" .Ft struct mbuf * @@ -78,24 +84,28 @@ Insertion of a new mbuf at the end of th .It Removal of an mbuf from the head of the queue. .It +Reinsertion of an mbuf at the head of the queue. +.It Removal of the entire chain of mbufs on the queue. .It Insertion of the mbufs in an mbuf_list at the end of the queue. .It Removal of all the mbufs on the queue as an mbuf_list. +.It +Reinsertion of the mbufs in an mbuf_list at the head of the queue. .El .Bl -tag -width Ds .It Fn "mq_init" "struct mbuf_queue *mq" "unsigned int maxlen" "int ipl" Initialises the mbuf queue structure .Fa mq . -The maximum number of mbufs that can be queued is specified with +The maximum number of mbufs that should be queued is specified with .Fa maxlen . The highest interrupt priority level the queue will be operated at is specified via .Fa ipl . .It Fn "MBUF_QUEUE_INITIALIZER" "unsigned int maxlen" "int ipl" Initialises an mbuf queue structure declaration. -The maximum number of mbufs that can be queued is specified with +The maximum number of mbufs that should be queued is specified with .Fa maxlen . The highest interrupt priority level the queue will be operated at is specified via @@ -110,6 +120,14 @@ mbuf queue. Dequeue an mbuf from the front of the .Fa mq mbuf queue. +.It Fn "mq_requeue" "struct mbuf_queue *mq" "struct mbuf *m" +Enqueue mbuf +.Fa m +at the head of the +.Fa mq +mbuf queue. +Note, this operation will succeed even if it will cause the queue to exceed its +maximum length. .It Fn "mq_enlist" "struct mbuf_queue *mq" "struct mbuf_list *ml" Enqueue all the mbufs on the .Fa ml @@ -123,6 +141,14 @@ Dequeue all the mbufs on the mbuf queue on to the .Fa ml mbuf list. +.It Fn "mq_relist" "struct mbuf_queue *mq" "struct mbuf_list *ml" +Enqueue all the mbufs on the +.Fa ml +mbuf list at the head of the +.Fa mq +mbuf queue. +Note, this operation will succeed even if it will cause the queue to exceed its +maximum length. .It Fn "mq_dechain" "struct mbuf_queue *mq" Dequeue all mbufs from the .Fa mq @@ -161,7 +187,7 @@ if the .Fa mq mbuf queue was too full. .It Fn "mq_set_maxlen" "struct mbuf_queue *mq" "unsigned int" -Alter the maximum number of mbufs that can be queued on the +Alter the maximum number of mbufs that should be queued on the .Fa mq mbuf queue. Note, @@ -173,8 +199,10 @@ already exist on the queue. .Fn mq_init , .Fn mq_enqueue , .Fn mq_dequeue , +.Fn mq_requeue , .Fn mq_enlist , .Fn mq_delist , +.Fn mq_relist , .Fn mq_dechain , .Fn mq_len , .Fn mq_empty , @@ -215,9 +243,16 @@ returns 0 if the mbuf was successfully q mbuf was freed because it would cause the queue to exceed its maximum length. .Pp +.Fn mq_requeue +returns non-zero if the mbuf queue is now full, otherwise 0. +length. +.Pp .Fn mq_enlist returns the number of mbufs that were dropped from the list if the length of the queue exceeded its maximum length. +.Pp +.Fn mq_relist +returns non-zero if the mbuf queue is now full, otherwise 0. .Pp .Fn mq_drops returns the number of mbufs that were freed during Index: share/man/man9/srp_enter.9 =================================================================== RCS file: /cvs/src/share/man/man9/srp_enter.9,v retrieving revision 1.2 diff -u -p -r1.2 srp_enter.9 --- share/man/man9/srp_enter.9 2 Jul 2015 01:38:35 -0000 1.2 +++ share/man/man9/srp_enter.9 3 Jul 2015 01:19:39 -0000 @@ -1,4 +1,4 @@ -.\" $OpenBSD: srp_enter.9,v 1.2 2015/07/02 01:38:35 dlg Exp $ +.\" $OpenBSD: srp_enter.9,v 1.1 2015/07/02 01:33:59 dlg Exp $ .\" .\" Copyright (c) 2015 David Gwynne .\" @@ -153,7 +153,7 @@ and can be called during autoconf, from process context, or from interrupt context. Calling .Fn srp_leave -from a different context to the preceding +from a different context or on a different CPU to the preceding .Fn srp_enter call will lead to undefined behaviour. .Sh RETURN VALUES Index: sys/kern/uipc_mbuf.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.205 diff -u -p -r1.205 uipc_mbuf.c --- sys/kern/uipc_mbuf.c 16 Jun 2015 11:09:39 -0000 1.205 +++ sys/kern/uipc_mbuf.c 3 Jul 2015 01:19:40 -0000 @@ -1296,6 +1296,19 @@ ml_dequeue(struct mbuf_list *ml) return (m); } +void +ml_requeue(struct mbuf_list *ml, struct mbuf *m) +{ + if (ml->ml_tail == NULL) + ml->ml_head = ml->ml_tail = m; + else { + m->m_nextpkt = ml->ml_head; + ml->ml_head = m; + } + + ml->ml_len++; +} + struct mbuf * ml_dechain(struct mbuf_list *ml) { @@ -1382,6 +1395,19 @@ mq_dequeue(struct mbuf_queue *mq) } int +mq_requeue(struct mbuf_queue *mq, struct mbuf *m) +{ + int full; + + mtx_enter(&mq->mq_mtx); + ml_requeue(&mq->mq_list, m); + full = mq_len(mq) > mq->mq_maxlen; + mtx_leave(&mq->mq_mtx); + + return (full); +} + +int mq_enlist(struct mbuf_queue *mq, struct mbuf_list *ml) { struct mbuf *m; @@ -1411,6 +1437,28 @@ mq_delist(struct mbuf_queue *mq, struct *ml = mq->mq_list; ml_init(&mq->mq_list); mtx_leave(&mq->mq_mtx); +} + +int +mq_relist(struct mbuf_queue *mq, struct mbuf_list *ml) +{ + int full; + + if (ml_empty(ml)) + return (mq_len(mq) > mq->mq_maxlen); + + mtx_enter(&mq->mq_mtx); + if (ml_empty(&mq->mq_list)) + mq->mq_list = *ml; + else { + ml->ml_tail->m_nextpkt = mq->mq_list.ml_head; + mq->mq_list.ml_head = ml->ml_head; + mq->mq_list.ml_len += ml->ml_len; + } + full = mq_len(mq) > mq->mq_maxlen; + mtx_leave(&mq->mq_mtx); + + return (full); } struct mbuf * Index: sys/sys/mbuf.h =================================================================== RCS file: /cvs/src/sys/sys/mbuf.h,v retrieving revision 1.194 diff -u -p -r1.194 mbuf.h --- sys/sys/mbuf.h 30 Jun 2015 15:30:17 -0000 1.194 +++ sys/sys/mbuf.h 3 Jul 2015 01:19:40 -0000 @@ -489,6 +489,7 @@ struct mbuf_list { void ml_init(struct mbuf_list *); void ml_enqueue(struct mbuf_list *, struct mbuf *); struct mbuf * ml_dequeue(struct mbuf_list *); +void ml_requeue(struct mbuf_list *, struct mbuf *); struct mbuf * ml_dechain(struct mbuf_list *); struct mbuf * ml_filter(struct mbuf_list *, int (*)(void *, const struct mbuf *), void *); @@ -516,8 +517,10 @@ struct mbuf_queue { void mq_init(struct mbuf_queue *, u_int, int); int mq_enqueue(struct mbuf_queue *, struct mbuf *); struct mbuf * mq_dequeue(struct mbuf_queue *); +int mq_requeue(struct mbuf_queue *, struct mbuf *); int mq_enlist(struct mbuf_queue *, struct mbuf_list *); void mq_delist(struct mbuf_queue *, struct mbuf_list *); +int mq_relist(struct mbuf_queue *, struct mbuf_list *); struct mbuf * mq_dechain(struct mbuf_queue *); struct mbuf * mq_filter(struct mbuf_queue *, int (*)(void *, const struct mbuf *), void *);