Re: priq: introduce ifq_drop

2017-03-01 Thread David Gwynne
On Wed, Mar 01, 2017 at 10:06:30PM +0100, Mike Belopuhov wrote:
> I've realised that something like this would be nice for convenience,
> but not crucial.  I'd prefer not to pass the mbuf pointer, but there's
> no decent way around it.

the api published in ifq.h should list what can safely be called
from outside ifq.c. i dont think ifq_drop qualifies for this.

it is unsafe because updates to ifq_len and ifq_drops are supposed
to done while holding the ifq mutex, and as i said previously, id
prefer not to hold that while calling m_freem.

i cant think of anything outside ifq.c that would need to call this
either.

> 
> ---
>  sys/net/ifq.c | 12 +---
>  sys/net/ifq.h |  1 +
>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git sys/net/ifq.c sys/net/ifq.c
> index f678c2b01fd..ee302e99c3b 100644
> --- sys/net/ifq.c
> +++ sys/net/ifq.c
> @@ -330,10 +330,18 @@ ifq_dequeue(struct ifqueue *ifq)
>   ifq_deq_commit(ifq, m);
>  
>   return (m);
>  }
>  
> +void
> +ifq_drop(struct ifqueue *ifq, struct mbuf *m)
> +{
> + m_freem(m);
> + ifq->ifq_len--;
> + ifq->ifq_qdrops++;
> +}
> +
>  unsigned int
>  ifq_purge(struct ifqueue *ifq)
>  {
>   struct mbuf_list ml = MBUF_LIST_INITIALIZER();
>   unsigned int rv;
> @@ -418,13 +426,11 @@ priq_enq(struct ifqueue *ifq, struct mbuf *m)
>   /* Find a lower priority queue to drop from */
>   if (ifq_len(ifq) >= ifq->ifq_maxlen) {
>   for (prio = 0; prio < m->m_pkthdr.pf.prio; prio++) {
>   pl = &pq->pq_lists[prio];
>   if (ml_len(pl) > 0) {
> - m_freem(ml_dequeue(pl));
> - ifq->ifq_len--;
> - ifq->ifq_qdrops++;
> + ifq_drop(ifq, ml_dequeue(pl));
>   break;
>   }
>   }
>   /*
>* There's no lower priority queue that we can
> diff --git sys/net/ifq.h sys/net/ifq.h
> index 3a6891da6f6..df0193214c5 100644
> --- sys/net/ifq.h
> +++ sys/net/ifq.h
> @@ -345,10 +345,11 @@ int  ifq_enqueue_try(struct ifqueue *, 
> struct mbuf *);
>  int   ifq_enqueue(struct ifqueue *, struct mbuf *);
>  struct mbuf  *ifq_deq_begin(struct ifqueue *);
>  void  ifq_deq_commit(struct ifqueue *, struct mbuf *);
>  void  ifq_deq_rollback(struct ifqueue *, struct mbuf *);
>  struct mbuf  *ifq_dequeue(struct ifqueue *);
> +void  ifq_drop(struct ifqueue *, struct mbuf *);
>  unsigned int  ifq_purge(struct ifqueue *);
>  void *ifq_q_enter(struct ifqueue *, const struct ifq_ops *);
>  void  ifq_q_leave(struct ifqueue *, void *);
>  void  ifq_serialize(struct ifqueue *, struct task *);
>  int   ifq_is_serialized(struct ifqueue *);
> -- 
> 2.12.0
> 



Re: priq: introduce ifq_drop

2017-03-01 Thread Alexander Bluhm
On Wed, Mar 01, 2017 at 10:06:30PM +0100, Mike Belopuhov wrote:
> I've realised that something like this would be nice for convenience,
> but not crucial.  I'd prefer not to pass the mbuf pointer, but there's
> no decent way around it.

A new function that combines only three commands and that is only
used once?  That looks like too much abstraction.  Wait until you
have more uses cases.

bluhm

> 
> ---
>  sys/net/ifq.c | 12 +---
>  sys/net/ifq.h |  1 +
>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git sys/net/ifq.c sys/net/ifq.c
> index f678c2b01fd..ee302e99c3b 100644
> --- sys/net/ifq.c
> +++ sys/net/ifq.c
> @@ -330,10 +330,18 @@ ifq_dequeue(struct ifqueue *ifq)
>   ifq_deq_commit(ifq, m);
>  
>   return (m);
>  }
>  
> +void
> +ifq_drop(struct ifqueue *ifq, struct mbuf *m)
> +{
> + m_freem(m);
> + ifq->ifq_len--;
> + ifq->ifq_qdrops++;
> +}
> +
>  unsigned int
>  ifq_purge(struct ifqueue *ifq)
>  {
>   struct mbuf_list ml = MBUF_LIST_INITIALIZER();
>   unsigned int rv;
> @@ -418,13 +426,11 @@ priq_enq(struct ifqueue *ifq, struct mbuf *m)
>   /* Find a lower priority queue to drop from */
>   if (ifq_len(ifq) >= ifq->ifq_maxlen) {
>   for (prio = 0; prio < m->m_pkthdr.pf.prio; prio++) {
>   pl = &pq->pq_lists[prio];
>   if (ml_len(pl) > 0) {
> - m_freem(ml_dequeue(pl));
> - ifq->ifq_len--;
> - ifq->ifq_qdrops++;
> + ifq_drop(ifq, ml_dequeue(pl));
>   break;
>   }
>   }
>   /*
>* There's no lower priority queue that we can
> diff --git sys/net/ifq.h sys/net/ifq.h
> index 3a6891da6f6..df0193214c5 100644
> --- sys/net/ifq.h
> +++ sys/net/ifq.h
> @@ -345,10 +345,11 @@ int  ifq_enqueue_try(struct ifqueue *, 
> struct mbuf *);
>  int   ifq_enqueue(struct ifqueue *, struct mbuf *);
>  struct mbuf  *ifq_deq_begin(struct ifqueue *);
>  void  ifq_deq_commit(struct ifqueue *, struct mbuf *);
>  void  ifq_deq_rollback(struct ifqueue *, struct mbuf *);
>  struct mbuf  *ifq_dequeue(struct ifqueue *);
> +void  ifq_drop(struct ifqueue *, struct mbuf *);
>  unsigned int  ifq_purge(struct ifqueue *);
>  void *ifq_q_enter(struct ifqueue *, const struct ifq_ops *);
>  void  ifq_q_leave(struct ifqueue *, void *);
>  void  ifq_serialize(struct ifqueue *, struct task *);
>  int   ifq_is_serialized(struct ifqueue *);
> -- 
> 2.12.0



priq: introduce ifq_drop

2017-03-01 Thread Mike Belopuhov
I've realised that something like this would be nice for convenience,
but not crucial.  I'd prefer not to pass the mbuf pointer, but there's
no decent way around it.

---
 sys/net/ifq.c | 12 +---
 sys/net/ifq.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git sys/net/ifq.c sys/net/ifq.c
index f678c2b01fd..ee302e99c3b 100644
--- sys/net/ifq.c
+++ sys/net/ifq.c
@@ -330,10 +330,18 @@ ifq_dequeue(struct ifqueue *ifq)
ifq_deq_commit(ifq, m);
 
return (m);
 }
 
+void
+ifq_drop(struct ifqueue *ifq, struct mbuf *m)
+{
+   m_freem(m);
+   ifq->ifq_len--;
+   ifq->ifq_qdrops++;
+}
+
 unsigned int
 ifq_purge(struct ifqueue *ifq)
 {
struct mbuf_list ml = MBUF_LIST_INITIALIZER();
unsigned int rv;
@@ -418,13 +426,11 @@ priq_enq(struct ifqueue *ifq, struct mbuf *m)
/* Find a lower priority queue to drop from */
if (ifq_len(ifq) >= ifq->ifq_maxlen) {
for (prio = 0; prio < m->m_pkthdr.pf.prio; prio++) {
pl = &pq->pq_lists[prio];
if (ml_len(pl) > 0) {
-   m_freem(ml_dequeue(pl));
-   ifq->ifq_len--;
-   ifq->ifq_qdrops++;
+   ifq_drop(ifq, ml_dequeue(pl));
break;
}
}
/*
 * There's no lower priority queue that we can
diff --git sys/net/ifq.h sys/net/ifq.h
index 3a6891da6f6..df0193214c5 100644
--- sys/net/ifq.h
+++ sys/net/ifq.h
@@ -345,10 +345,11 @@ intifq_enqueue_try(struct ifqueue *, 
struct mbuf *);
 int ifq_enqueue(struct ifqueue *, struct mbuf *);
 struct mbuf*ifq_deq_begin(struct ifqueue *);
 voidifq_deq_commit(struct ifqueue *, struct mbuf *);
 voidifq_deq_rollback(struct ifqueue *, struct mbuf *);
 struct mbuf*ifq_dequeue(struct ifqueue *);
+voidifq_drop(struct ifqueue *, struct mbuf *);
 unsigned intifq_purge(struct ifqueue *);
 void   *ifq_q_enter(struct ifqueue *, const struct ifq_ops *);
 voidifq_q_leave(struct ifqueue *, void *);
 voidifq_serialize(struct ifqueue *, struct task *);
 int ifq_is_serialized(struct ifqueue *);
-- 
2.12.0