public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: xiyou.wangcong@gmail.com, jhs@mojatatu.com,
	alexei.starovoitov@gmail.com, eric.dumazet@gmail.com,
	brouer@redhat.com
Cc: john.r.fastabend@intel.com, netdev@vger.kernel.org,
	john.fastabend@gmail.com, davem@davemloft.net
Subject: [RFC PATCH 04/13] net: sched: provide atomic qlen helpers for bypass case
Date: Wed, 17 Aug 2016 12:35:03 -0700	[thread overview]
Message-ID: <20160817193503.27032.61305.stgit@john-Precision-Tower-5810> (raw)
In-Reply-To: <20160817193120.27032.20918.stgit@john-Precision-Tower-5810>

The qlen is used by the core/dev.c to determine if a packet
can skip the qdisc on qdiscs with bypass enabled. In these
cases a per cpu qlen value can cause one cpu to bypass a
qdisc that has packets in it.

To avoid this case use the simplest solution I could come
up with for now and add an atomic qlen value to the qdisc
to use in these cases.

Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
---
 include/net/sch_generic.h |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index f69da4b..193cf8c 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -78,6 +78,7 @@ struct Qdisc {
 	 */
 	struct sk_buff		*gso_skb ____cacheline_aligned_in_smp;
 	struct sk_buff_head	q;
+	atomic_t		qlen_atomic;
 	struct gnet_stats_basic_packed bstats;
 	seqcount_t		running;
 	struct gnet_stats_queue	qstats;
@@ -247,6 +248,11 @@ static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
 	BUILD_BUG_ON(sizeof(qcb->data) < sz);
 }
 
+static inline int qdisc_qlen_atomic(const struct Qdisc *q)
+{
+	return atomic_read(&q->qlen_atomic);
+}
+
 static inline int qdisc_qlen_cpu(const struct Qdisc *q)
 {
 	return this_cpu_ptr(q->cpu_qstats)->qlen;
@@ -254,8 +260,11 @@ static inline int qdisc_qlen_cpu(const struct Qdisc *q)
 
 static inline int qdisc_qlen(const struct Qdisc *q)
 {
+	/* current default is to use atomic ops for qdisc qlen when
+	 * running with TCQ_F_NOLOCK.
+	 */
 	if (q->flags & TCQ_F_NOLOCK)
-		return qdisc_qlen_cpu(q);
+		return qdisc_qlen_atomic(q);
 
 	return q->q.qlen;
 }
@@ -595,6 +604,16 @@ static inline void qdisc_qstats_cpu_backlog_inc(struct Qdisc *sch,
 	q->backlog += qdisc_pkt_len(skb);
 }
 
+static inline void qdisc_qstats_atomic_qlen_inc(struct Qdisc *sch)
+{
+	atomic_inc(&sch->qlen_atomic);
+}
+
+static inline void qdisc_qstats_atomic_qlen_dec(struct Qdisc *sch)
+{
+	atomic_dec(&sch->qlen_atomic);
+}
+
 static inline void qdisc_qstats_cpu_qlen_inc(struct Qdisc *sch)
 {
 	this_cpu_ptr(sch->cpu_qstats)->qlen++;

  parent reply	other threads:[~2016-08-17 19:35 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 19:33 [RFC PATCH 00/13] Series short description John Fastabend
2016-08-17 19:33 ` [RFC PATCH 01/13] net: sched: allow qdiscs to handle locking John Fastabend
2016-08-17 22:33   ` Eric Dumazet
2016-08-17 22:49     ` John Fastabend
2016-08-17 22:34   ` Eric Dumazet
2016-08-17 22:48     ` John Fastabend
2016-08-17 19:34 ` [RFC PATCH 02/13] net: sched: qdisc_qlen for per cpu logic John Fastabend
2016-08-17 19:34 ` [RFC PATCH 03/13] net: sched: provide per cpu qstat helpers John Fastabend
2016-08-17 19:35 ` John Fastabend [this message]
2016-08-17 19:35 ` [RFC PATCH 05/13] net: sched: a dflt qdisc may be used with per cpu stats John Fastabend
2016-08-17 19:35 ` [RFC PATCH 06/13] net: sched: per cpu gso handlers John Fastabend
2016-08-17 19:36 ` [RFC PATCH 07/13] net: sched: support qdisc_reset on NOLOCK qdisc John Fastabend
2016-08-17 22:53   ` Eric Dumazet
2016-08-17 22:59     ` John Fastabend
2016-08-17 19:36 ` [RFC PATCH 08/13] net: sched: support skb_bad_tx with lockless qdisc John Fastabend
2016-08-17 22:58   ` Eric Dumazet
2016-08-17 23:00     ` John Fastabend
2016-08-23 20:11       ` John Fastabend
2016-08-17 19:37 ` [RFC PATCH 09/13] net: sched: helper to sum qlen John Fastabend
2016-08-17 19:37 ` [RFC PATCH 10/13] net: sched: lockless support for netif_schedule John Fastabend
2016-08-17 19:46   ` John Fastabend
2016-08-17 23:01   ` Eric Dumazet
2016-08-17 23:17     ` John Fastabend
2016-08-17 23:33       ` Eric Dumazet
2016-08-17 19:38 ` [RFC PATCH 11/13] net: sched: pfifo_fast use alf_queue John Fastabend
2016-08-19 10:13   ` Jesper Dangaard Brouer
2016-08-19 15:44     ` John Fastabend
2016-08-17 19:38 ` [RFC PATCH 12/13] net: sched: add support for TCQ_F_NOLOCK subqueues to sch_mq John Fastabend
2016-08-17 19:49   ` John Fastabend
2016-08-17 23:04   ` Eric Dumazet
2016-08-17 23:18     ` John Fastabend
2016-08-17 19:39 ` [RFC PATCH 13/13] net: sched: add support for TCQ_F_NOLOCK subqueues to sch_mqprio John Fastabend

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160817193503.27032.61305.stgit@john-Precision-Tower-5810 \
    --to=john.fastabend@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=john.r.fastabend@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox