Packed ring vectorized datapath can be selected when requirements are
fulfilled.

1. AVX512 is allowed by config file and compiler
2. VERSION_1 and in_order features are negotiated
3. ring size is power of two
4. LRO and mergeable feature disabled in Rx datapath

Signed-off-by: Marvin Liu <yong....@intel.com>

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index f9d0ea70d..d27306d50 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1518,9 +1518,12 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
        if (vtpci_packed_queue(hw)) {
                PMD_INIT_LOG(INFO,
                        "virtio: using packed ring %s Tx path on port %u",
-                       hw->use_inorder_tx ? "inorder" : "standard",
+                       hw->packed_vec_tx ? "vectorized" : "standard",
                        eth_dev->data->port_id);
-               eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed;
+               if (hw->packed_vec_tx)
+                       eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed_vec;
+               else
+                       eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed;
        } else {
                if (hw->use_inorder_tx) {
                        PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on 
port %u",
@@ -1534,7 +1537,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
        }
 
        if (vtpci_packed_queue(hw)) {
-               if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+               if (hw->packed_vec_rx) {
+                       PMD_INIT_LOG(INFO,
+                               "virtio: using packed ring vectorized Rx path 
on port %u",
+                               eth_dev->data->port_id);
+                       eth_dev->rx_pkt_burst =
+                               &virtio_recv_pkts_packed_vec;
+               } else if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
                        PMD_INIT_LOG(INFO,
                                "virtio: using packed ring mergeable buffer Rx 
path on port %u",
                                eth_dev->data->port_id);
@@ -2159,6 +2168,26 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 
        hw->use_simple_rx = 1;
 
+       if (vtpci_packed_queue(hw)) {
+#if defined(RTE_ARCH_X86) && defined(CC_AVX512_SUPPORT)
+               unsigned int vq_size;
+               vq_size = VTPCI_OPS(hw)->get_queue_num(hw, 0);
+               if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) &&
+                   rte_is_power_of_2(vq_size) &&
+                   vtpci_with_feature(hw, VIRTIO_F_IN_ORDER) &&
+                   vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
+                       hw->packed_vec_rx = 1;
+                       hw->packed_vec_tx = 1;
+               }
+
+               if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF))
+                       hw->packed_vec_rx = 0;
+
+               if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
+                       hw->packed_vec_rx = 0;
+#endif
+       }
+
        if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
                hw->use_inorder_tx = 1;
                hw->use_inorder_rx = 1;
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index 7433d2f08..8103b7a18 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -251,6 +251,8 @@ struct virtio_hw {
        uint8_t     use_msix;
        uint8_t     modern;
        uint8_t     use_simple_rx;
+       uint8_t     packed_vec_rx;
+       uint8_t     packed_vec_tx;
        uint8_t     use_inorder_rx;
        uint8_t     use_inorder_tx;
        uint8_t     weak_barriers;
-- 
2.17.1

Reply via email to