ice: optimize for XDP_REDIRECT in xsk path
authorMagnus Karlsson <magnus.karlsson@intel.com>
Wed, 2 Dec 2020 15:07:24 +0000 (16:07 +0100)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 15 Mar 2021 19:04:51 +0000 (12:04 -0700)
Optimize ice_run_xdp_zc() for the XDP program verdict being
XDP_REDIRECT in the xsk zero-copy path. This path is only used when
having AF_XDP zero-copy on and in that case most packets will be
directed to user space. This provides a little over 100k extra packets
in throughput on my server when running l2fwd in xdpsock.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Tested-by: George Kuruvinakunnel <george.kuruvinakunnel@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_xsk.c

index 83f3c95..727f277 100644 (file)
@@ -473,6 +473,14 @@ ice_run_xdp_zc(struct ice_ring *rx_ring, struct xdp_buff *xdp)
        xdp_prog = READ_ONCE(rx_ring->xdp_prog);
 
        act = bpf_prog_run_xdp(xdp_prog, xdp);
+
+       if (likely(act == XDP_REDIRECT)) {
+               err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog);
+               result = !err ? ICE_XDP_REDIR : ICE_XDP_CONSUMED;
+               rcu_read_unlock();
+               return result;
+       }
+
        switch (act) {
        case XDP_PASS:
                break;
@@ -480,10 +488,6 @@ ice_run_xdp_zc(struct ice_ring *rx_ring, struct xdp_buff *xdp)
                xdp_ring = rx_ring->vsi->xdp_rings[rx_ring->q_index];
                result = ice_xmit_xdp_buff(xdp, xdp_ring);
                break;
-       case XDP_REDIRECT:
-               err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog);
-               result = !err ? ICE_XDP_REDIR : ICE_XDP_CONSUMED;
-               break;
        default:
                bpf_warn_invalid_xdp_action(act);
                fallthrough;