From: Jesper Dangaard Brouer <brouer@redhat.com>
To: netdev@vger.kernel.org, Daniel Borkmann <borkmann@iogearbox.net>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
"David S. Miller" <davem@davemloft.net>
Cc: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
bpf@vger.kernel.org, "Toke Høiland-Jørgensen" <toke@toke.dk>,
"Jesper Dangaard Brouer" <brouer@redhat.com>
Subject: [PATCH bpf-next 1/5] bpf: cpumap use ptr_ring_consume_batched
Date: Wed, 10 Apr 2019 13:43:37 +0200 [thread overview]
Message-ID: <155489661778.20826.7424374812567038804.stgit@firesoul> (raw)
In-Reply-To: <155489659290.20826.1108770347511292618.stgit@firesoul>
Move ptr_ring dequeue outside loop, that allocate SKBs and calls network
stack, as these operations that can take some time. The ptr_ring is a
communication channel between CPUs, where we want to reduce/limit any
cacheline bouncing.
Do a concentrated bulk dequeue via ptr_ring_consume_batched, to shorten the
period and times the remote cacheline in ptr_ring is read
Batch size 8 is both to (1) limit BH-disable period, and (2) consume one
cacheline on 64-bit archs. After reducing the BH-disable section further
then we can consider changing this, while still thinking about L1 cacheline
size being active.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
kernel/bpf/cpumap.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 3c18260403dd..430103e182a0 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -240,6 +240,8 @@ static void put_cpu_map_entry(struct bpf_cpu_map_entry *rcpu)
}
}
+#define CPUMAP_BATCH 8
+
static int cpu_map_kthread_run(void *data)
{
struct bpf_cpu_map_entry *rcpu = data;
@@ -252,8 +254,9 @@ static int cpu_map_kthread_run(void *data)
* kthread_stop signal until queue is empty.
*/
while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) {
- unsigned int processed = 0, drops = 0, sched = 0;
- struct xdp_frame *xdpf;
+ unsigned int drops = 0, sched = 0;
+ void *frames[CPUMAP_BATCH];
+ int i, n;
/* Release CPU reschedule checks */
if (__ptr_ring_empty(rcpu->queue)) {
@@ -269,14 +272,16 @@ static int cpu_map_kthread_run(void *data)
sched = cond_resched();
}
- /* Process packets in rcpu->queue */
- local_bh_disable();
/*
* The bpf_cpu_map_entry is single consumer, with this
* kthread CPU pinned. Lockless access to ptr_ring
* consume side valid as no-resize allowed of queue.
*/
- while ((xdpf = __ptr_ring_consume(rcpu->queue))) {
+ n = ptr_ring_consume_batched(rcpu->queue, frames, CPUMAP_BATCH);
+
+ local_bh_disable();
+ for (i = 0; i < n; i++) {
+ struct xdp_frame *xdpf = frames[i];
struct sk_buff *skb;
int ret;
@@ -290,13 +295,9 @@ static int cpu_map_kthread_run(void *data)
ret = netif_receive_skb_core(skb);
if (ret == NET_RX_DROP)
drops++;
-
- /* Limit BH-disable period */
- if (++processed == 8)
- break;
}
/* Feedback loop via tracepoint */
- trace_xdp_cpumap_kthread(rcpu->map_id, processed, drops, sched);
+ trace_xdp_cpumap_kthread(rcpu->map_id, n, drops, sched);
local_bh_enable(); /* resched point, may call do_softirq() */
}
next prev parent reply other threads:[~2019-04-10 11:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 11:43 [PATCH bpf-next 0/5] Bulk optimization for XDP cpumap redirect Jesper Dangaard Brouer
2019-04-10 11:43 ` Jesper Dangaard Brouer [this message]
2019-04-10 23:24 ` [PATCH bpf-next 1/5] bpf: cpumap use ptr_ring_consume_batched Song Liu
2019-04-11 11:23 ` Jesper Dangaard Brouer
2019-04-11 17:38 ` Song Liu
2019-04-10 11:43 ` [PATCH bpf-next 2/5] bpf: cpumap use netif_receive_skb_list Jesper Dangaard Brouer
2019-04-10 18:56 ` Edward Cree
2019-04-10 11:43 ` [PATCH bpf-next 3/5] net: core: introduce build_skb_around Jesper Dangaard Brouer
2019-04-10 23:34 ` Song Liu
2019-04-11 15:39 ` Jesper Dangaard Brouer
2019-04-11 17:43 ` Song Liu
2019-04-11 5:33 ` Ilias Apalodimas
2019-04-11 11:17 ` Jesper Dangaard Brouer
2019-04-10 11:43 ` [PATCH bpf-next 4/5] bpf: cpumap do bulk allocation of SKBs Jesper Dangaard Brouer
2019-04-10 23:30 ` Song Liu
2019-04-10 11:43 ` [PATCH bpf-next 5/5] bpf: cpumap memory prefetchw optimizations for struct page Jesper Dangaard Brouer
2019-04-10 23:35 ` Song Liu
2019-04-11 5:47 ` Ilias Apalodimas
2019-04-10 23:36 ` [PATCH bpf-next 0/5] Bulk optimization for XDP cpumap redirect Song Liu
2019-04-11 13:18 ` Jesper Dangaard Brouer
2019-04-11 17:45 ` Song Liu
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=155489661778.20826.7424374812567038804.stgit@firesoul \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=borkmann@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=ilias.apalodimas@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=toke@toke.dk \
/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