[dpdk-dev,8/9] net/virtio: keep Rx handler whatever the Tx queue config

Message ID 20170831134015.1383-9-olivier.matz@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Olivier Matz Aug. 31, 2017, 1:40 p.m. UTC
  Split use_simple_rxtx into use_simple_rx and use_simple_tx,
and ensure that only use_simple_tx is updated when txq flags
forces to use the standard Tx handler.

This change is also useful for next commit (disable simple Rx
path when Rx checksum is requested).

Cc: stable@dpdk.org

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 drivers/net/virtio/virtio_ethdev.c      | 25 ++++++++++++++++---------
 drivers/net/virtio/virtio_pci.h         |  3 ++-
 drivers/net/virtio/virtio_rxtx.c        | 18 +++++++++---------
 drivers/net/virtio/virtio_user_ethdev.c |  3 ++-
 4 files changed, 29 insertions(+), 20 deletions(-)
  

Comments

Olivier Matz Aug. 31, 2017, 1:50 p.m. UTC | #1
Platform description
--------------------

guest (dpdk)
+----------------+
|                |
|                |
|    port0       |
+----------------+
       |
       | virtio
       |
+----------------+
|     tap0       |
|                |
|                |
+----------------+
host (linux, vhost-net)

Host configuration
------------------

Start qemu with:

- a ne2k management interface to avoi any conflict with dpdk
- a virtio net device, connected to a tap interface through vhost-net
- mergeable buffers disabled

  /usr/bin/qemu-system-x86_64 -k fr -daemonize --enable-kvm -m 2G -cpu host \
    -smp 3 -serial telnet::40564,server,nowait -serial null \
    -qmp tcp::44340,server,nowait -monitor telnet::49229,server,nowait \
    -device ne2k_pci,mac=de:ad:de:01:02:03,netdev=user.0,addr=03 \
    -netdev user,id=user.0,hostfwd=tcp::34965-:22 \
    -netdev type=tap,id=vhostnet0,script=no,vhost=on,queues=8 \
    -device virtio-net-pci,mrg_rxbuf=off,netdev=vhostnet0,mq=on,vectors=17 \
    -hda "${VM_PATH}/ubuntu-16.04-template.qcow2" \
    -snapshot -vga none -display none

Guest configuration
-------------------

Compile dpdk:

  cd dpdk.org
  make config T=x86_64-native-linuxapp-gcc
  sed -i 's,CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n,CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=y,' build/.config
  sed -i 's,CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=n,CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=y,' build/.config
  make -j4

Prepare environment:

  mkdir -p /mnt/huge
  mount -t hugetlbfs nodev /mnt/huge
  echo 256 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
  modprobe uio_pci_generic
  python usertools/dpdk-devbind.py -b uio_pci_generic 0000:00:02.0

  ./build/app/testpmd -l 0,1 --log-level 7 -- --total-num-mbufs=16384 \
    -i --port-topology=chained --disable-hw-vlan-filter \
    --disable-hw-vlan-strip --txqflags=0

Without the fix, standard path is used in rx and tx, but simple rx could
be used:

  ...
  PMD: set_rxtx_funcs(): virtio: using standard Rx path on port 0
  PMD: set_rxtx_funcs(): virtio: using standard Tx path on port 0
  ...

With the fix:

  ...
  PMD: set_rxtx_funcs(): virtio: using simple Rx path on port 0
  PMD: set_rxtx_funcs(): virtio: using standard Tx path on port 0
  ...
  
Yuanhan Liu Sept. 1, 2017, 9:25 a.m. UTC | #2
On Thu, Aug 31, 2017 at 03:40:14PM +0200, Olivier Matz wrote:
> Split use_simple_rxtx into use_simple_rx and use_simple_tx,
> and ensure that only use_simple_tx is updated when txq flags
> forces to use the standard Tx handler.

I think it's a good idea to split it.

> This change is also useful for next commit (disable simple Rx
> path when Rx checksum is requested).
> 
> Cc: stable@dpdk.org

But again, I don't think it's a good idea to put them (including the
next patch) to stable releases.

	--yliu
  
Olivier Matz Sept. 1, 2017, 9:58 a.m. UTC | #3
On Fri, Sep 01, 2017 at 05:25:38PM +0800, Yuanhan Liu wrote:
> On Thu, Aug 31, 2017 at 03:40:14PM +0200, Olivier Matz wrote:
> > Split use_simple_rxtx into use_simple_rx and use_simple_tx,
> > and ensure that only use_simple_tx is updated when txq flags
> > forces to use the standard Tx handler.
> 
> I think it's a good idea to split it.
> 
> > This change is also useful for next commit (disable simple Rx
> > path when Rx checksum is requested).
> > 
> > Cc: stable@dpdk.org
> 
> But again, I don't think it's a good idea to put them (including the
> next patch) to stable releases.

Yes, you're right this one is more an enhancement than a fix: it
just selects a faster handler if it's possible.

But next one is a fix: it must not select the simple handler if
offload is requested.

If these commits are not pushed in stable, it's not a problem for
me, so I let you decide. In that case, I will remove the Cc: stable
from the last 3 commits. Do you confirm?

Thanks for the review.
Olivier
  
Yuanhan Liu Sept. 1, 2017, 12:22 p.m. UTC | #4
On Fri, Sep 01, 2017 at 11:58:07AM +0200, Olivier MATZ wrote:
> On Fri, Sep 01, 2017 at 05:25:38PM +0800, Yuanhan Liu wrote:
> > On Thu, Aug 31, 2017 at 03:40:14PM +0200, Olivier Matz wrote:
> > > Split use_simple_rxtx into use_simple_rx and use_simple_tx,
> > > and ensure that only use_simple_tx is updated when txq flags
> > > forces to use the standard Tx handler.
> > 
> > I think it's a good idea to split it.
> > 
> > > This change is also useful for next commit (disable simple Rx
> > > path when Rx checksum is requested).
> > > 
> > > Cc: stable@dpdk.org
> > 
> > But again, I don't think it's a good idea to put them (including the
> > next patch) to stable releases.
> 
> Yes, you're right this one is more an enhancement than a fix: it
> just selects a faster handler if it's possible.

Exactly.

> But next one is a fix: it must not select the simple handler if
> offload is requested.
> 
> If these commits are not pushed in stable, it's not a problem for
> me, so I let you decide. In that case, I will remove the Cc: stable
> from the last 3 commits. Do you confirm?

Yes, I think it's better to drop the cc stable tag.

> Thanks for the review.

Thanks for the work!

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 8dad3095f..4845d44b0 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1241,7 +1241,7 @@  set_rxtx_funcs(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 
-	if (hw->use_simple_rxtx) {
+	if (hw->use_simple_rx) {
 		PMD_INIT_LOG(INFO, "virtio: using simple Rx path on port %u",
 			eth_dev->data->port_id);
 		eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
@@ -1256,7 +1256,7 @@  set_rxtx_funcs(struct rte_eth_dev *eth_dev)
 		eth_dev->rx_pkt_burst = &virtio_recv_pkts;
 	}
 
-	if (hw->use_simple_rxtx) {
+	if (hw->use_simple_tx) {
 		PMD_INIT_LOG(INFO, "virtio: using simple Tx path on port %u",
 			eth_dev->data->port_id);
 		eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;
@@ -1741,17 +1741,24 @@  virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	hw->use_simple_rxtx = 1;
+	hw->use_simple_rx = 1;
+	hw->use_simple_tx = 1;
 
 #if defined RTE_ARCH_X86
-	if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE3))
-		hw->use_simple_rxtx = 0;
+	if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE3)) {
+		hw->use_simple_rx = 0;
+		hw->use_simple_tx = 0;
+	}
 #elif defined RTE_ARCH_ARM64 || defined CONFIG_RTE_ARCH_ARM
-	if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON))
-		hw->use_simple_rxtx = 0;
+	if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON)) {
+		hw->use_simple_rx = 0;
+		hw->use_simple_tx = 0;
+	}
 #endif
-	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF))
-		hw->use_simple_rxtx = 0;
+	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+		hw->use_simple_rx = 0;
+		hw->use_simple_tx = 0;
+	}
 
 	return 0;
 }
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index 18caebdd7..2ff526c88 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -259,7 +259,8 @@  struct virtio_hw {
 	uint8_t	    vlan_strip;
 	uint8_t	    use_msix;
 	uint8_t     modern;
-	uint8_t     use_simple_rxtx;
+	uint8_t     use_simple_rx;
+	uint8_t     use_simple_tx;
 	uint8_t     port_id;
 	uint8_t     mac_addr[ETHER_ADDR_LEN];
 	uint32_t    notify_off_multiplier;
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index c9d97b643..b81ba0d4a 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -456,7 +456,7 @@  virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 	/* Allocate blank mbufs for the each rx descriptor */
 	nbufs = 0;
 
-	if (hw->use_simple_rxtx) {
+	if (hw->use_simple_rx) {
 		for (desc_idx = 0; desc_idx < vq->vq_nentries;
 		     desc_idx++) {
 			vq->vq_ring.avail->ring[desc_idx] = desc_idx;
@@ -478,7 +478,7 @@  virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 			break;
 
 		/* Enqueue allocated buffers */
-		if (hw->use_simple_rxtx)
+		if (hw->use_simple_rx)
 			error = virtqueue_enqueue_recv_refill_simple(vq, m);
 		else
 			error = virtqueue_enqueue_recv_refill(vq, m);
@@ -502,17 +502,17 @@  virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 }
 
 static void
-virtio_update_rxtx_handler(struct rte_eth_dev *dev,
+virtio_update_tx_handler(struct rte_eth_dev *dev,
 			   const struct rte_eth_txconf *tx_conf)
 {
 	struct virtio_hw *hw = dev->data->dev_private;
-	uint8_t use_simple_rxtx = hw->use_simple_rxtx;
+	uint8_t use_simple_tx = hw->use_simple_tx;
 
-	/* cannot use simple rxtx funcs with multisegs or offloads */
+	/* use simple tx func if single segment and no offloads */
 	if ((tx_conf->txq_flags & VIRTIO_SIMPLE_FLAGS) != VIRTIO_SIMPLE_FLAGS)
-		use_simple_rxtx = 0;
+		use_simple_tx = 0;
 
-	hw->use_simple_rxtx = use_simple_rxtx;
+	hw->use_simple_tx = use_simple_tx;
 }
 
 /*
@@ -537,7 +537,7 @@  virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	virtio_update_rxtx_handler(dev, tx_conf);
+	virtio_update_tx_handler(dev, tx_conf);
 
 	if (nb_desc == 0 || nb_desc > vq->vq_nentries)
 		nb_desc = vq->vq_nentries;
@@ -579,7 +579,7 @@  virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	if (hw->use_simple_rxtx) {
+	if (hw->use_simple_tx) {
 		for (desc_idx = 0; desc_idx < mid_idx; desc_idx++) {
 			vq->vq_ring.avail->ring[desc_idx] =
 				desc_idx + mid_idx;
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index c96144434..57c964d6d 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -369,7 +369,8 @@  virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	 */
 	hw->use_msix = 1;
 	hw->modern   = 0;
-	hw->use_simple_rxtx = 0;
+	hw->use_simple_rx = 0;
+	hw->use_simple_tx = 0;
 	hw->virtio_user_dev = dev;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
 	return eth_dev;