[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180604115715.17895-6-bjorn.topel@gmail.com>
Date: Mon, 4 Jun 2018 13:57:15 +0200
From: Björn Töpel <bjorn.topel@...il.com>
To: bjorn.topel@...il.com, magnus.karlsson@...el.com,
magnus.karlsson@...il.com, alexander.h.duyck@...el.com,
alexander.duyck@...il.com, ast@...com, brouer@...hat.com,
daniel@...earbox.net, netdev@...r.kernel.org,
mykyta.iziumtsev@...aro.org
Cc: john.fastabend@...il.com, willemdebruijn.kernel@...il.com,
mst@...hat.com, michael.lundkvist@...csson.com,
jesse.brandeburg@...el.com, anjali.singhai@...el.com,
qi.z.zhang@...el.com, francois.ozog@...aro.org,
ilias.apalodimas@...aro.org, brian.brooks@...aro.org,
andy@...yhouse.net, michael.chan@...adcom.com
Subject: [PATCH bpf-next 5/5] samples/bpf: minor *_nb_free performance fix
From: Magnus Karlsson <magnus.karlsson@...el.com>
Signed-off-by: Magnus Karlsson <magnus.karlsson@...el.com>
---
samples/bpf/xdpsock_user.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index b71a342b9082..7494f60fbff8 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -157,15 +157,15 @@ static const char pkt_data[] =
static inline u32 umem_nb_free(struct xdp_umem_uqueue *q, u32 nb)
{
- u32 free_entries = q->size - (q->cached_prod - q->cached_cons);
+ u32 free_entries = q->cached_cons - q->cached_prod;
if (free_entries >= nb)
return free_entries;
/* Refresh the local tail pointer */
- q->cached_cons = *q->consumer;
+ q->cached_cons = *q->consumer + q->size;
- return q->size - (q->cached_prod - q->cached_cons);
+ return q->cached_cons - q->cached_prod;
}
static inline u32 xq_nb_free(struct xdp_uqueue *q, u32 ndescs)
@@ -439,6 +439,7 @@ static struct xdp_umem *xdp_umem_configure(int sfd)
umem->fq.producer = umem->fq.map + off.fr.producer;
umem->fq.consumer = umem->fq.map + off.fr.consumer;
umem->fq.ring = umem->fq.map + off.fr.desc;
+ umem->fq.cached_cons = FQ_NUM_DESCS;
umem->cq.map = mmap(0, off.cr.desc +
CQ_NUM_DESCS * sizeof(u64),
@@ -535,6 +536,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem)
xsk->tx.producer = xsk->tx.map + off.tx.producer;
xsk->tx.consumer = xsk->tx.map + off.tx.consumer;
xsk->tx.ring = xsk->tx.map + off.tx.desc;
+ xsk->tx.cached_cons = NUM_DESCS;
sxdp.sxdp_family = PF_XDP;
sxdp.sxdp_ifindex = opt_ifindex;
--
2.14.1
Powered by blists - more mailing lists