From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, brouer@redhat.com
Subject: Re: [PATCH net-next 1/3] veth: Account for packet drops in ndo_xdp_xmit
Date: Sat, 13 Oct 2018 09:48:28 +0200 [thread overview]
Message-ID: <20181013094828.00979d39@redhat.com> (raw)
In-Reply-To: <1539250610-2557-2-git-send-email-makita.toshiaki@lab.ntt.co.jp>
On Thu, 11 Oct 2018 18:36:48 +0900
Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp> wrote:
> Use existing atomic drop counter. Since drop path is really an
> exceptional case here, I'm thinking atomic ops would not hurt the
> performance.
Hmm... we try very hard not to add atomic ops to XDP code path. The
XDP_DROP case is also considered hot-path. In below code, the
atomic64_add happens for a bulk of dropped packets (currently up-to
16), so it might be okay.
> XDP packets and bytes are not counted in ndo_xdp_xmit, but will be
> accounted on rx side by the following commit.
>
> Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
> ---
> drivers/net/veth.c | 30 ++++++++++++++++++++++--------
> 1 file changed, 22 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 224c56a..452193f2 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -308,16 +308,20 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
> {
> struct veth_priv *rcv_priv, *priv = netdev_priv(dev);
> struct net_device *rcv;
> + int i, ret, drops = n;
> unsigned int max_len;
> struct veth_rq *rq;
> - int i, drops = 0;
>
> - if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
> - return -EINVAL;
> + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) {
> + ret = -EINVAL;
> + goto drop;
> + }
>
> rcv = rcu_dereference(priv->peer);
> - if (unlikely(!rcv))
> - return -ENXIO;
> + if (unlikely(!rcv)) {
> + ret = -ENXIO;
> + goto drop;
> + }
>
> rcv_priv = netdev_priv(rcv);
> rq = &rcv_priv->rq[veth_select_rxq(rcv)];
> @@ -325,9 +329,12 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
> * side. This means an XDP program is loaded on the peer and the peer
> * device is up.
> */
> - if (!rcu_access_pointer(rq->xdp_prog))
> - return -ENXIO;
> + if (!rcu_access_pointer(rq->xdp_prog)) {
> + ret = -ENXIO;
> + goto drop;
> + }
>
> + drops = 0;
> max_len = rcv->mtu + rcv->hard_header_len + VLAN_HLEN;
>
> spin_lock(&rq->xdp_ring.producer_lock);
> @@ -346,7 +353,14 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
> if (flags & XDP_XMIT_FLUSH)
> __veth_xdp_flush(rq);
>
> - return n - drops;
> + if (likely(!drops))
> + return n;
> +
> + ret = n - drops;
> +drop:
> + atomic64_add(drops, &priv->dropped);
> +
> + return ret;
> }
>
> static void veth_xdp_flush(struct net_device *dev)
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
next prev parent reply other threads:[~2018-10-13 15:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-11 9:36 [PATCH net-next 0/3] veth: XDP stats improvement Toshiaki Makita
2018-10-11 9:36 ` [PATCH net-next 1/3] veth: Account for packet drops in ndo_xdp_xmit Toshiaki Makita
2018-10-13 7:48 ` Jesper Dangaard Brouer [this message]
2018-10-13 8:57 ` Toshiaki Makita
2018-10-11 9:36 ` [PATCH net-next 2/3] veth: Account for XDP packet statistics on rx side Toshiaki Makita
2018-10-11 9:36 ` [PATCH net-next 3/3] veth: Add ethtool statistics support for XDP Toshiaki Makita
2018-10-16 4:58 ` [PATCH net-next 0/3] veth: XDP stats improvement David Miller
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=20181013094828.00979d39@redhat.com \
--to=brouer@redhat.com \
--cc=davem@davemloft.net \
--cc=makita.toshiaki@lab.ntt.co.jp \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.