From: John Fastabend <john.fastabend@gmail.com>
To: jasowang@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/2] ptr_ring_ll: pop/push multiple objects at once
Date: Thu, 10 Nov 2016 20:44:32 -0800 [thread overview]
Message-ID: <20161111044432.1547.65342.stgit@john-Precision-Tower-5810> (raw)
In-Reply-To: <20161111043857.1547.70337.stgit@john-Precision-Tower-5810>
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
---
include/linux/ptr_ring_ll.h | 22 ++++++++++++++++------
include/linux/skb_array.h | 11 +++++++++--
net/sched/sch_generic.c | 2 +-
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/include/linux/ptr_ring_ll.h b/include/linux/ptr_ring_ll.h
index bcb11f3..5dc25f7 100644
--- a/include/linux/ptr_ring_ll.h
+++ b/include/linux/ptr_ring_ll.h
@@ -45,9 +45,10 @@ struct ptr_ring_ll {
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax(). Callers must hold producer_lock.
*/
-static inline int __ptr_ring_ll_produce(struct ptr_ring_ll *r, void *ptr)
+static inline int __ptr_ring_ll_produce_many(struct ptr_ring_ll *r,
+ void **ptr, int num)
{
- u32 ret, head, tail, next, slots, mask;
+ u32 ret, head, tail, next, slots, mask, i;
do {
head = READ_ONCE(r->prod_head);
@@ -55,21 +56,30 @@ static inline int __ptr_ring_ll_produce(struct ptr_ring_ll *r, void *ptr)
tail = READ_ONCE(r->cons_tail);
slots = mask + tail - head;
- if (slots < 1)
+ if (slots < num)
+ num = slots;
+
+ if (unlikely(!num))
return -ENOMEM;
- next = head + 1;
+ next = head + num;
ret = cmpxchg(&r->prod_head, head, next);
} while (ret != head);
- r->queue[head & mask] = ptr;
+ for (i = 0; i < num; i++)
+ r->queue[(head + i) & mask] = ptr[i];
smp_wmb();
while (r->prod_tail != head)
cpu_relax();
r->prod_tail = next;
- return 0;
+ return num;
+}
+
+static inline int __ptr_ring_ll_produce(struct ptr_ring_ll *r, void **ptr)
+{
+ return __ptr_ring_ll_produce_many(r, ptr, 1);
}
static inline void *__ptr_ring_ll_consume(struct ptr_ring_ll *r)
diff --git a/include/linux/skb_array.h b/include/linux/skb_array.h
index 9b43dfd..de3c700 100644
--- a/include/linux/skb_array.h
+++ b/include/linux/skb_array.h
@@ -48,9 +48,16 @@ static inline bool skb_array_full(struct skb_array *a)
return ptr_ring_full(&a->ring);
}
-static inline int skb_array_ll_produce(struct skb_array_ll *a, struct sk_buff *skb)
+static inline int skb_array_ll_produce_many(struct skb_array_ll *a,
+ struct sk_buff **skb, int num)
{
- return __ptr_ring_ll_produce(&a->ring, skb);
+ return __ptr_ring_ll_produce_many(&a->ring, (void **)skb, num);
+}
+
+static inline int skb_array_ll_produce(struct skb_array_ll *a,
+ struct sk_buff **skb)
+{
+ return __ptr_ring_ll_produce(&a->ring, (void **)skb);
}
static inline int skb_array_produce(struct skb_array *a, struct sk_buff *skb)
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 4648ec8..58f2011 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -571,7 +571,7 @@ static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
struct skb_array_ll *q = band2list(priv, band);
int err;
- err = skb_array_ll_produce(q, skb);
+ err = skb_array_ll_produce(q, &skb);
if (unlikely(err)) {
net_warn_ratelimited("drop a packet from fast enqueue\n");
next prev parent reply other threads:[~2016-11-11 4:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 4:43 [RFC PATCH 0/2] illustrate cmpxchg ring for tap/tun and qdisc John Fastabend
2016-11-11 4:44 ` [RFC PATCH 1/2] net: use cmpxchg instead of spinlock in ptr rings John Fastabend
2016-11-14 11:09 ` Jesper Dangaard Brouer
2016-11-14 23:01 ` Michael S. Tsirkin
2016-11-16 4:30 ` John Fastabend
2016-11-11 4:44 ` John Fastabend [this message]
2016-11-14 23:06 ` [RFC PATCH 2/2] ptr_ring_ll: pop/push multiple objects at once Michael S. Tsirkin
2016-11-16 4:42 ` John Fastabend
2016-11-16 5:23 ` Michael S. Tsirkin
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=20161111044432.1547.65342.stgit@john-Precision-Tower-5810 \
--to=john.fastabend@gmail.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).