Skip to content

Commit

Permalink
samples/bpf: minor *_nb_free performance fix
Browse files Browse the repository at this point in the history
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Magnus Karlsson authored and Daniel Borkmann committed Jun 4, 2018
1 parent a412ef5 commit a65ea68
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions samples/bpf/xdpsock_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a65ea68

Please sign in to comment.