Skip to contentSkip to conversation

implement packed virtqueues

PATCH Superseded Jens Freimann 2 participants 22 messages Dec 14, 2018 – Dec 17, 2018 Network drivers

v13 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v13 cover implement packed virtqueues

This is a basic implementation of packed virtqueues as specified in the Virtio 1.1 draft. A compiled version of the current draft is available at https://github.com/oasis-tcs/virtio-docs.git (or as .pdf at
https://github.com/oasis-tcs/virtio-docs/blob/master/virtio-v1.1-packed-wd10.pdf

A packed virtqueue is different from a split virtqueue in that it consists of only a single descriptor ring that replaces available and used ring, index and descriptor pointers.

Each descriptor is readable and writable and has a flags field. These flags will mark if a descriptor is available or used. To detect new available descriptors even after the ring has wrapped, device and driver each have a single-bit wrap counter that is flipped from 0 to 1 and vice versa every time the last descriptor in the ring is used/made available.

With this patch set I see performance equal or slightly better (+2-3%) in a PVP scenario compared to split virtqueues (v18.11 in host)

regards,
Jens

v12->v13:
* re-order patches 1-3 to address Maximes comment. Move all defines and data structures to patch one, all helpers to patch 2.
* build-tested and ran checkpatch on all patches again
* add split/packed versions for virtio_enable_intr()
* remove redundant changes from split vq code
* just return -1 when cq is enabled for packed vqs in virtio-user

v11->v12:
* add a patch to disable control vq when packed vq is enabled. I have a patch to support this but it needs a bit more work and I think it shouldn't stop this series from being applied
* rework mergeable receive buffer code to be more efficient, by batching descriptor refill, similar to what Maxime proposed for split virtqueues
* removed unnecessary checks in virtio_recv_mergeable_pkts_packed (Maxime)
* Did not merge receive functions as Maxime suggested because it seemed to cause a small performance regression
* Move event_flags_shadow from patch 3 to 1 (Maxime)
* Did not merge xmit functions and call _split/_packed functions from there because it seemed to cause small performance drop (-0.5%) (Maxime)

v10-v11:
* this version includes some fixes from Tiwei, so I added his Signed-off-by to some of the patches
* fix hang with mergable rx buffers (Tiwei)
* clean-up code and simplify buffer handling (Tiwei)
* rebase to current virtio-next master branch

v9-v10:
* don't mix index into buffer list and descriptors
* whitespace and formatting issues
* remove "VQ:" in dump virtqueue patch
* add extra packed vring struct to virtqueue and change function prototypes and code accordingly
* move wrap_counters to virtqueue
* make if-conditions for packed and !packed more clear in set_rxtx_funcs()
* initialize wrap counters in first patch, instead of rx and tx implementation patch
* make virtio-user not supported with packed virtqueues, to be fixed in other patch set?

v8-v9:
* fix virtio_ring_free_chain_packed() to handle descriptors correctly in case of out-of-order
* fix check in virtqueue_xmit_cleanup_packed() to improve performance

v7->v8:
* move desc_is_used change to correct patch
* remove trailing newline
* correct xmit code, flags update and memory barrier
* move packed desc init to dedicated function, split and packed variant

Jens Freimann (9):
net/virtio: add packed virtqueue defines net/virtio: add packed virtqueue helpers net/virtio: vring init for packed queues net/virtio: dump packed virtqueue data net/virtio: implement transmit path for packed queues net/virtio: implement receive path for packed queues net/virtio: add virtio send command packed queue support net/virtio-user: fail if q used with packed vq net/virtio: enable packed virtqueues by default

Yuanhan Liu (1):
net/virtio-user: add option to use packed queues

 drivers/net/virtio/virtio_ethdev.c            | 221 +++++--
 drivers/net/virtio/virtio_ethdev.h            |   8 +
 drivers/net/virtio/virtio_pci.h               |   7 +
 drivers/net/virtio/virtio_ring.h              |  64 +-
 drivers/net/virtio/virtio_rxtx.c              | 611 +++++++++++++++++-
 .../net/virtio/virtio_user/virtio_user_dev.c  |  27 +-
 .../net/virtio/virtio_user/virtio_user_dev.h  |   2 +-
 drivers/net/virtio/virtio_user_ethdev.c       |  14 +-
 drivers/net/virtio/virtqueue.c                |  43 +-
 drivers/net/virtio/virtqueue.h                | 128 +++-
 10 files changed, 1059 insertions(+), 66 deletions(-)
Signature · 1 line
2.17.2
#1 lore raw

PATCH v13 1/10 net/virtio: add packed virtqueue defines

---
 drivers/net/virtio/virtio_pci.h  |  1 +
 drivers/net/virtio/virtio_ring.h | 30 ++++++++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h   |  6 ++++++
 3 files changed, 37 insertions(+)
drivers/net/virtio/virtio_pci.h +1 -0
index e961a58ca..4c975a531 100644
@@ -113,6 +113,7 @@ struct virtnet_ctl;
 
 #define VIRTIO_F_VERSION_1		32
 #define VIRTIO_F_IOMMU_PLATFORM	33
+#define VIRTIO_F_RING_PACKED		34
 
 /*
  * Some VirtIO feature bits (currently bits 28 through 31) are
drivers/net/virtio/virtio_ring.h +30 -0
index 9e3c2a015..464449074 100644
@@ -15,6 +15,10 @@
 #define VRING_DESC_F_WRITE      2
 /* This means the buffer contains a list of buffer descriptors. */
 #define VRING_DESC_F_INDIRECT   4
+/* This flag means the descriptor was made available by the driver */
+#define VRING_DESC_F_AVAIL(b)   ((uint16_t)(b) << 7)
+/* This flag means the descriptor was used by the device */
+#define VRING_DESC_F_USED(b)    ((uint16_t)(b) << 15)
 
 /* The Host uses this in used->flags to advise the Guest: don't kick me
  * when you add a buffer.  It's unreliable, so it's simply an
@@ -54,6 +58,32 @@ struct vring_used {
 	struct vring_used_elem ring[0];
 };
 
+/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
+ * looks like this.
+ */
+struct vring_packed_desc {
+	uint64_t addr;
+	uint32_t len;
+	uint16_t id;
+	uint16_t flags;
+};
+
+#define RING_EVENT_FLAGS_ENABLE 0x0
+#define RING_EVENT_FLAGS_DISABLE 0x1
+#define RING_EVENT_FLAGS_DESC 0x2
+struct vring_packed_desc_event {
+	uint16_t desc_event_off_wrap;
+	uint16_t desc_event_flags;
+};
+
+struct vring_packed {
+	unsigned int num;
+	struct vring_packed_desc *desc_packed;
+	struct vring_packed_desc_event *driver_event;
+	struct vring_packed_desc_event *device_event;
+
+};
+
 struct vring {
 	unsigned int num;
 	struct vring_desc  *desc;
drivers/net/virtio/virtqueue.h +6 -0
index 26518ed98..d4e0858e4 100644
@@ -161,11 +161,17 @@ struct virtio_pmd_ctrl {
 struct vq_desc_extra {
 	void *cookie;
 	uint16_t ndescs;
+	uint16_t next;
 };
 
 struct virtqueue {
 	struct virtio_hw  *hw; /**< virtio_hw structure pointer. */
 	struct vring vq_ring;  /**< vring keeping desc, used and avail */
+	struct vring_packed ring_packed;  /**< vring keeping descs */
+	bool avail_wrap_counter;
+	bool used_wrap_counter;
+	uint16_t event_flags_shadow;
+	uint16_t avail_used_flags;
 	/**
 	 * Last consumed descriptor in the used table,
 	 * trails vq_ring.used->idx.
Signature · 1 line
2.17.2
#3 lore raw

PATCH v13 2/10 net/virtio: add packed virtqueue helpers

In reply to Jens Freimann

Add helper functions to set/clear and check descriptor flags.

---
 drivers/net/virtio/virtio_pci.h |  6 +++
 drivers/net/virtio/virtqueue.h  | 91 ++++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_pci.h +6 -0
index 4c975a531..b22b62dad 100644
@@ -315,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)
 	return (hw->guest_features & (1ULL << bit)) != 0;
 }
 
+static inline int
+vtpci_packed_queue(struct virtio_hw *hw)
+{
+	return vtpci_with_feature(hw, VIRTIO_F_RING_PACKED);
+}
+
 /*
  * Function declaration from virtio_pci.c
  */
drivers/net/virtio/virtqueue.h +89 -2

115 lines not on this page · raw message

Signature · 1 line
2.17.2
#4 lore raw

Re: [PATCH v13 02/10] net/virtio: add packed virtqueue helpers

Quoted 78 lines · Jens Freimann

Add helper functions to set/clear and check descriptor flags.

---
  drivers/net/virtio/virtio_pci.h |  6 +++
  drivers/net/virtio/virtqueue.h  | 91 ++++++++++++++++++++++++++++++++-
  2 files changed, 95 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_pci.h +6 -0
index 4c975a531..b22b62dad 100644
@@ -315,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)
  	return (hw->guest_features & (1ULL << bit)) != 0;
  }
 
+static inline int
+vtpci_packed_queue(struct virtio_hw *hw)
+{
+	return vtpci_with_feature(hw, VIRTIO_F_RING_PACKED);
+}
+
  /*
   * Function declaration from virtio_pci.c
   */
drivers/net/virtio/virtqueue.h +38 -0
index d4e0858e4..19fabae0b 100644
@@ -251,6 +251,44 @@ struct virtio_tx_region {
  			   __attribute__((__aligned__(16)));
  };
 
+static inline void
+_set_desc_avail(struct vring_packed_desc *desc, int wrap_counter)
+{
+	desc->flags |= VRING_DESC_F_AVAIL(wrap_counter) |
+		       VRING_DESC_F_USED(!wrap_counter);
+}
+
+static inline void
+set_desc_avail(struct virtqueue *vq, struct vring_packed_desc *desc)
+{
+	_set_desc_avail(desc, vq->avail_wrap_counter);
+}
+
+static inline int
+desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
+{
+	uint16_t used, avail, flags;
+
+	flags = desc->flags;
+	used = !!(flags & VRING_DESC_F_USED(1));
+	avail = !!(flags & VRING_DESC_F_AVAIL(1));
+
+	return avail == used && used == vq->used_wrap_counter;
+}
+
+
+static inline void
+vring_desc_init_packed(struct virtqueue *vq, int n)
+{
+	int i;
+	for (i = 0; i < n - 1; i++) {
+		vq->ring_packed.desc_packed[i].id = i;
+		vq->vq_descx[i].next = i + 1;
+	}
+	vq->ring_packed.desc_packed[i].id = i;
+	vq->vq_descx[i].next = VQ_RING_DESC_CHAIN_END;
+}
+
  /* Chain all the descriptors in the ring with an END */
  static inline void
  vring_desc_init(struct vring_desc *dp, uint16_t n)
@@ -262,13 +300,59 @@ vring_desc_init(struct vring_desc *dp, uint16_t n)
  	dp[i].next = VQ_RING_DESC_CHAIN_END;
  }
 

drivers/net/virtio/virtqueue.h vring_desc_init(struct vring_desc *dp, uint16_t n) · line 312

Quoted 10 lines
drivers/net/virtio/virtqueue.h +10 -0
+/**
+ * Tell the backend not to interrupt us.
+ */
+static inline void
+virtqueue_disable_intr_packed(struct virtqueue *vq)
+{
+	uint16_t *event_flags = &vq->ring_packed.driver_event->desc_event_flags;
+
+	if (*event_flags != RING_EVENT_FLAGS_DISABLE)
+		*event_flags = RING_EVENT_FLAGS_DISABLE;

Why not just setting the value unconditionally?
IIUC, it is not called in the hot path?

Quoted 17 lines
drivers/net/virtio/virtqueue.h +10 -1
+}
+
+
  /**
   * Tell the backend not to interrupt us.
   */
  static inline void
  virtqueue_disable_intr(struct virtqueue *vq)
  {
-	vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
+	if (vtpci_packed_queue(vq->hw))
+		virtqueue_disable_intr_packed(vq);
+	else
+		vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
+}
+
+/**

drivers/net/virtio/virtqueue.h vring_desc_init(struct vring_desc *dp, uint16_t n) · line 338

Quoted 10 lines
drivers/net/virtio/virtqueue.h +10 -0
+ * Tell the backend to interrupt. Implementation for packed virtqueues.
+ */
+static inline void
+virtqueue_enable_intr_packed(struct virtqueue *vq)
+{
+	uint16_t *off_wrap = &vq->ring_packed.driver_event->desc_event_off_wrap;
+	uint16_t *event_flags = &vq->ring_packed.driver_event->desc_event_flags;
+
+	*off_wrap = vq->vq_used_cons_idx |
+		((uint16_t)(vq->used_wrap_counter << 15));

Don't we want to set off_wrap only if VIRTIO_RING_F_EVENT_IDX negotiated?

Quoted 33 lines
drivers/net/virtio/virtqueue.h +21 -1
+
+	if (vq->event_flags_shadow == RING_EVENT_FLAGS_DISABLE) {
+		virtio_wmb();
+		vq->event_flags_shadow =
+			vtpci_with_feature(vq->hw, VIRTIO_RING_F_EVENT_IDX) ?
+				RING_EVENT_FLAGS_DESC : RING_EVENT_FLAGS_ENABLE;
+		*event_flags = vq->event_flags_shadow;
+	}
+}
+
+/**
+ * Tell the backend to interrupt. Implementation for split virtqueues.
+ */
+static inline void
+virtqueue_enable_intr_split(struct virtqueue *vq)
+{
+	vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT);
  }
 
  /**
@@ -277,7 +361,10 @@ virtqueue_disable_intr(struct virtqueue *vq)
  static inline void
  virtqueue_enable_intr(struct virtqueue *vq)
  {
-	vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT);
+	if (vtpci_packed_queue(vq->hw))
+		virtqueue_enable_intr_packed(vq);
+	else
+		virtqueue_enable_intr_split(vq);
  }
 
  /**
#5 lore raw

Re: [PATCH v13 02/10] net/virtio: add packed virtqueue helpers

In reply to Jens Freimann

drivers/net/virtio/virtqueue.h struct virtio_tx_region { · line 266

Quoted 13 lines · Jens Freimann
drivers/net/virtio/virtqueue.h +13 -0
+static inline void
+_set_desc_avail(struct vring_packed_desc *desc, int wrap_counter)
+{
+	desc->flags |= VRING_DESC_F_AVAIL(wrap_counter) |
+		       VRING_DESC_F_USED(!wrap_counter);
+}
+
+static inline void
+set_desc_avail(struct virtqueue *vq, struct vring_packed_desc *desc)
+{
+	_set_desc_avail(desc, vq->avail_wrap_counter);
+}
+

I wonder whether these helpers are really needed, as they are no more used in virtio_rxtx.c.

Only _set_desc_avail() is used for the ctrl vq.

#6 lore raw

PATCH v13 3/10 net/virtio: vring init for packed queues

In reply to Jens Freimann

Add and initialize descriptor data structures.

---
 drivers/net/virtio/virtio_ethdev.c | 32 ++++++++++++++++++----------
 drivers/net/virtio/virtio_ring.h   | 34 ++++++++++++++++++++++++------
 drivers/net/virtio/virtqueue.h     |  2 +-
 3 files changed, 49 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio_ethdev.c +21 -11
index cb2b2e0bf..e6ba1282b 100644
@@ -299,20 +299,22 @@ virtio_init_vring(struct virtqueue *vq)
 
 	PMD_INIT_FUNC_TRACE();
 
-	/*
-	 * Reinitialise since virtio port might have been stopped and restarted
-	 */
 	memset(ring_mem, 0, vq->vq_ring_size);
-	vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
+
 	vq->vq_used_cons_idx = 0;
 	vq->vq_desc_head_idx = 0;
 	vq->vq_avail_idx = 0;
 	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
 	vq->vq_free_cnt = vq->vq_nentries;
 	memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
-
-	vring_desc_init(vr->desc, size);
-
+	if (vtpci_packed_queue(vq->hw)) {
+		vring_init_packed(&vq->ring_packed, ring_mem,
+				  VIRTIO_PCI_VRING_ALIGN, size);
+		vring_desc_init_packed(vq, size);
+	} else {
+		vring_init_split(vr, ring_mem, VIRTIO_PCI_VRING_ALIGN, size);
+		vring_desc_init_split(vr->desc, size);
+	}
 	/*
 	 * Disable device(host) interrupting guest
 	 */
@@ -384,11 +386,16 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	vq->hw = hw;
 	vq->vq_queue_index = vtpci_queue_idx;
 	vq->vq_nentries = vq_size;
+	vq->event_flags_shadow = 0;
+	if (vtpci_packed_queue(hw)) {
+		vq->avail_wrap_counter = 1;
+		vq->used_wrap_counter = 1;
+	}
 
 	/*
 	 * Reserve a memzone for vring elements
 	 */
-	size = vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN);
+	size = vring_size(hw, vq_size, VIRTIO_PCI_VRING_ALIGN);
 	vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN);
 	PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d",
 		     size, vq->vq_ring_size);
@@ -491,7 +498,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		for (i = 0; i < vq_size; i++) {
 			struct vring_desc *start_dp = txr[i].tx_indir;
 
-			vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir));
+			vring_desc_init_split(start_dp,
+					      RTE_DIM(txr[i].tx_indir));
 
 			/* first indirect descriptor is always the tx header */
 			start_dp->addr = txvq->virtio_net_hdr_mem
@@ -1488,7 +1496,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
 	/* Setting up rx_header size for the device */
 	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
-	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1))
+	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
+	    vtpci_with_feature(hw, VIRTIO_F_RING_PACKED))
 		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
 	else
 		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
@@ -1908,7 +1917,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
 		hw->use_inorder_tx = 1;
-		if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+		if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) &&
+		    !vtpci_packed_queue(hw)) {
 			hw->use_inorder_rx = 1;
 			hw->use_simple_rx = 0;
 		} else {
drivers/net/virtio/virtio_ring.h +27 -7
index 464449074..9ab007c11 100644
@@ -86,7 +86,7 @@ struct vring_packed {
 
 struct vring {
 	unsigned int num;
-	struct vring_desc  *desc;
+	struct vring_desc *desc;
 	struct vring_avail *avail;
 	struct vring_used  *used;
 };
@@ -125,10 +125,18 @@ struct vring {
 #define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num])
 
 static inline size_t
-vring_size(unsigned int num, unsigned long align)
+vring_size(struct virtio_hw *hw, unsigned int num, unsigned long align)
 {
 	size_t size;
 
+	if (vtpci_packed_queue(hw)) {
+		size = num * sizeof(struct vring_packed_desc);
+		size += sizeof(struct vring_packed_desc_event);
+		size = RTE_ALIGN_CEIL(size, align);
+		size += sizeof(struct vring_packed_desc_event);
+		return size;
+	}
+
 	size = num * sizeof(struct vring_desc);
 	size += sizeof(struct vring_avail) + (num * sizeof(uint16_t));
 	size = RTE_ALIGN_CEIL(size, align);
@@ -136,17 +144,29 @@ vring_size(unsigned int num, unsigned long align)
 		(num * sizeof(struct vring_used_elem));
 	return size;
 }
-
 static inline void
-vring_init(struct vring *vr, unsigned int num, uint8_t *p,
-	unsigned long align)
+vring_init_split(struct vring *vr, uint8_t *p, unsigned long align,
+		 unsigned int num)
 {
 	vr->num = num;
 	vr->desc = (struct vring_desc *) p;
 	vr->avail = (struct vring_avail *) (p +
-		num * sizeof(struct vring_desc));
+			vr->num * sizeof(struct vring_desc));
 	vr->used = (void *)
-		RTE_ALIGN_CEIL((uintptr_t)(&vr->avail->ring[num]), align);
+		RTE_ALIGN_CEIL((uintptr_t)(&vr->avail->ring[vr->num]), align);
+}
+
+static inline void
+vring_init_packed(struct vring_packed *vr, uint8_t *p, unsigned long align,
+		 unsigned int num)
+{
+	vr->num = num;
+	vr->desc_packed = (struct vring_packed_desc *)p;
+	vr->driver_event = (struct vring_packed_desc_event *)(p +
+			vr->num * sizeof(struct vring_packed_desc));
+	vr->device_event = (struct vring_packed_desc_event *)
+		RTE_ALIGN_CEIL((uintptr_t)(vr->driver_event +
+				sizeof(struct vring_packed_desc_event)), align);
 }
 
 /*
drivers/net/virtio/virtqueue.h +1 -1
index 19fabae0b..809d15879 100644
@@ -291,7 +291,7 @@ vring_desc_init_packed(struct virtqueue *vq, int n)
 
 /* Chain all the descriptors in the ring with an END */
 static inline void
-vring_desc_init(struct vring_desc *dp, uint16_t n)
+vring_desc_init_split(struct vring_desc *dp, uint16_t n)
 {
 	uint16_t i;
 
Signature · 1 line
2.17.2
Reviewed-by on v13 3/10
#7 lore raw

Re: [PATCH v13 03/10] net/virtio: vring init for packed queues

Quoted 97 lines · Jens Freimann

Add and initialize descriptor data structures.

---
  drivers/net/virtio/virtio_ethdev.c | 32 ++++++++++++++++++----------
  drivers/net/virtio/virtio_ring.h   | 34 ++++++++++++++++++++++++------
  drivers/net/virtio/virtqueue.h     |  2 +-
  3 files changed, 49 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio_ethdev.c +21 -11
index cb2b2e0bf..e6ba1282b 100644
@@ -299,20 +299,22 @@ virtio_init_vring(struct virtqueue *vq)
 
  	PMD_INIT_FUNC_TRACE();
 
-	/*
-	 * Reinitialise since virtio port might have been stopped and restarted
-	 */
  	memset(ring_mem, 0, vq->vq_ring_size);
-	vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
+
  	vq->vq_used_cons_idx = 0;
  	vq->vq_desc_head_idx = 0;
  	vq->vq_avail_idx = 0;
  	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
  	vq->vq_free_cnt = vq->vq_nentries;
  	memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
-
-	vring_desc_init(vr->desc, size);
-
+	if (vtpci_packed_queue(vq->hw)) {
+		vring_init_packed(&vq->ring_packed, ring_mem,
+				  VIRTIO_PCI_VRING_ALIGN, size);
+		vring_desc_init_packed(vq, size);
+	} else {
+		vring_init_split(vr, ring_mem, VIRTIO_PCI_VRING_ALIGN, size);
+		vring_desc_init_split(vr->desc, size);
+	}
  	/*
  	 * Disable device(host) interrupting guest
  	 */
@@ -384,11 +386,16 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
  	vq->hw = hw;
  	vq->vq_queue_index = vtpci_queue_idx;
  	vq->vq_nentries = vq_size;
+	vq->event_flags_shadow = 0;
+	if (vtpci_packed_queue(hw)) {
+		vq->avail_wrap_counter = 1;
+		vq->used_wrap_counter = 1;
+	}
 
  	/*
  	 * Reserve a memzone for vring elements
  	 */
-	size = vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN);
+	size = vring_size(hw, vq_size, VIRTIO_PCI_VRING_ALIGN);
  	vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN);
  	PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d",
  		     size, vq->vq_ring_size);
@@ -491,7 +498,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
  		for (i = 0; i < vq_size; i++) {
  			struct vring_desc *start_dp = txr[i].tx_indir;
 
-			vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir));
+			vring_desc_init_split(start_dp,
+					      RTE_DIM(txr[i].tx_indir));
 
  			/* first indirect descriptor is always the tx header */
  			start_dp->addr = txvq->virtio_net_hdr_mem
@@ -1488,7 +1496,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
  	/* Setting up rx_header size for the device */
  	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
-	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1))
+	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
+	    vtpci_with_feature(hw, VIRTIO_F_RING_PACKED))
  		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
  	else
  		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
@@ -1908,7 +1917,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 
  	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
  		hw->use_inorder_tx = 1;
-		if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+		if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) &&
+		    !vtpci_packed_queue(hw)) {
  			hw->use_inorder_rx = 1;
  			hw->use_simple_rx = 0;
  		} else {
drivers/net/virtio/virtio_ring.h +0 -0
index 464449074..9ab007c11 100644

drivers/net/virtio/virtio_ring.h struct vring_packed { · line 89

Quoted 5 lines
drivers/net/virtio/virtio_ring.h +1 -1
@@ -86,7 +86,7 @@ struct vring_packed {
 
  struct vring {
  	unsigned int num;
-	struct vring_desc  *desc;
+	struct vring_desc *desc;

Unrelated change, please revert back.

Quoted 33 lines
drivers/net/virtio/virtio_ring.h +11 -4
  	struct vring_avail *avail;
  	struct vring_used  *used;
  };
@@ -125,10 +125,18 @@ struct vring {
  #define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num])
 
  static inline size_t
-vring_size(unsigned int num, unsigned long align)
+vring_size(struct virtio_hw *hw, unsigned int num, unsigned long align)
  {
  	size_t size;
 
+	if (vtpci_packed_queue(hw)) {
+		size = num * sizeof(struct vring_packed_desc);
+		size += sizeof(struct vring_packed_desc_event);
+		size = RTE_ALIGN_CEIL(size, align);
+		size += sizeof(struct vring_packed_desc_event);
+		return size;
+	}
+
  	size = num * sizeof(struct vring_desc);
  	size += sizeof(struct vring_avail) + (num * sizeof(uint16_t));
  	size = RTE_ALIGN_CEIL(size, align);
@@ -136,17 +144,29 @@ vring_size(unsigned int num, unsigned long align)
  		(num * sizeof(struct vring_used_elem));
  	return size;
  }
-
  static inline void
-vring_init(struct vring *vr, unsigned int num, uint8_t *p,
-	unsigned long align)
+vring_init_split(struct vring *vr, uint8_t *p, unsigned long align,
+		 unsigned int num)

drivers/net/virtio/virtio_ring.h vring_size(unsigned int num, unsigned long align) · line 157

Quoted 10 lines
drivers/net/virtio/virtio_ring.h +3 -2
  {
  	vr->num = num;
  	vr->desc = (struct vring_desc *) p;
  	vr->avail = (struct vring_avail *) (p +
-		num * sizeof(struct vring_desc));
+			vr->num * sizeof(struct vring_desc));
  	vr->used = (void *)
-		RTE_ALIGN_CEIL((uintptr_t)(&vr->avail->ring[num]), align);
+		RTE_ALIGN_CEIL((uintptr_t)(&vr->avail->ring[vr->num]), align);
+}

Not a big deal, but it is unrelated to patch purpose.

Quoted 21 lines
drivers/net/virtio/virtio_ring.h +12 -0
+
+static inline void
+vring_init_packed(struct vring_packed *vr, uint8_t *p, unsigned long align,
+		 unsigned int num)
+{
+	vr->num = num;
+	vr->desc_packed = (struct vring_packed_desc *)p;
+	vr->driver_event = (struct vring_packed_desc_event *)(p +
+			vr->num * sizeof(struct vring_packed_desc));
+	vr->device_event = (struct vring_packed_desc_event *)
+		RTE_ALIGN_CEIL((uintptr_t)(vr->driver_event +
+				sizeof(struct vring_packed_desc_event)), align);
  }
 
  /*
drivers/net/virtio/virtqueue.h +0 -0
index 19fabae0b..809d15879 100644

drivers/net/virtio/virtqueue.h vring_desc_init_packed(struct virtqueue *vq, int n) · line 297

Quoted 8 lines
drivers/net/virtio/virtqueue.h +1 -1
@@ -291,7 +291,7 @@ vring_desc_init_packed(struct virtqueue *vq, int n)
 
  /* Chain all the descriptors in the ring with an END */
  static inline void
-vring_desc_init(struct vring_desc *dp, uint16_t n)
+vring_desc_init_split(struct vring_desc *dp, uint16_t n)
  {
  	uint16_t i;
 

With above minor comments fixed:

Thanks,
Maxime

#8 lore raw

PATCH v13 4/10 net/virtio: dump packed virtqueue data

In reply to Jens Freimann

Add support to dump packed virtqueue data to the
VIRTQUEUE_DUMP() macro.

---
 drivers/net/virtio/virtqueue.h | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/virtio/virtqueue.h +9 -0
index 809d15879..9c65ad54f 100644
@@ -448,6 +448,15 @@ virtqueue_notify(struct virtqueue *vq)
 	uint16_t used_idx, nused; \
 	used_idx = (vq)->vq_ring.used->idx; \
 	nused = (uint16_t)(used_idx - (vq)->vq_used_cons_idx); \
+	if (vtpci_packed_queue((vq)->hw)) { \
+		PMD_INIT_LOG(DEBUG, \
+		"VQ: - size=%d; free=%d; used_cons_idx=%d; avail_idx=%d;" \
+		"VQ: - avail_wrap_counter=%d; used_wrap_counter=%d", \
+		(vq)->vq_nentries, (vq)->vq_free_cnt, (vq)->vq_used_cons_idx, \
+		(vq)->vq_avail_idx, (vq)->avail_wrap_counter, \
+		(vq)->used_wrap_counter); \
+		break; \
+	} \
 	PMD_INIT_LOG(DEBUG, \
 	  "VQ: - size=%d; free=%d; used=%d; desc_head_idx=%d;" \
 	  " avail.idx=%d; used_cons_idx=%d; used.idx=%d;" \
Signature · 1 line
2.17.2
#9 lore raw

PATCH v13 5/10 net/virtio: implement transmit path for packed queues

In reply to Jens Freimann

This implements the transmit path for devices with support for packed virtqueues.

---
 drivers/net/virtio/virtio_ethdev.c |  57 ++++---
 drivers/net/virtio/virtio_ethdev.h |   2 +
 drivers/net/virtio/virtio_rxtx.c   | 236 ++++++++++++++++++++++++++++-
 drivers/net/virtio/virtqueue.h     |  20 ++-
 4 files changed, 293 insertions(+), 22 deletions(-)
drivers/net/virtio/virtio_ethdev.c +39 -18
index e6ba1282b..9f1b72e56 100644
@@ -390,6 +390,9 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	if (vtpci_packed_queue(hw)) {
 		vq->avail_wrap_counter = 1;
 		vq->used_wrap_counter = 1;
+		vq->avail_used_flags =
+			VRING_DESC_F_AVAIL(vq->avail_wrap_counter) |
+			VRING_DESC_F_USED(!vq->avail_wrap_counter);
 	}
 
 	/*
@@ -497,17 +500,26 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		memset(txr, 0, vq_size * sizeof(*txr));
 		for (i = 0; i < vq_size; i++) {
 			struct vring_desc *start_dp = txr[i].tx_indir;
-
-			vring_desc_init_split(start_dp,
-					      RTE_DIM(txr[i].tx_indir));
+			struct vring_packed_desc *start_dp_packed =
+				txr[i].tx_indir_pq;
 
 			/* first indirect descriptor is always the tx header */
-			start_dp->addr = txvq->virtio_net_hdr_mem
-				+ i * sizeof(*txr)
-				+ offsetof(struct virtio_tx_region, tx_hdr);
-
-			start_dp->len = hw->vtnet_hdr_size;
-			start_dp->flags = VRING_DESC_F_NEXT;
+			if (vtpci_packed_queue(hw)) {
+				start_dp_packed->addr = txvq->virtio_net_hdr_mem
+					+ i * sizeof(*txr)
+					+ offsetof(struct virtio_tx_region,
+						   tx_hdr);
+				start_dp_packed->len = hw->vtnet_hdr_size;
+			} else {
+				vring_desc_init_split(start_dp,
+						      RTE_DIM(txr[i].tx_indir));
+				start_dp->addr = txvq->virtio_net_hdr_mem
+					+ i * sizeof(*txr)
+					+ offsetof(struct virtio_tx_region,
+						   tx_hdr);
+				start_dp->len = hw->vtnet_hdr_size;
+				start_dp->flags = VRING_DESC_F_NEXT;
+			}
 		}
 	}
 
@@ -1336,6 +1348,23 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 
+	if (vtpci_packed_queue(hw)) {
+		PMD_INIT_LOG(INFO,
+			"virtio: using packed ring standard Tx path on port %u",
+			eth_dev->data->port_id);
+		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",
+				eth_dev->data->port_id);
+			eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
+		} else {
+			PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->tx_pkt_burst = virtio_xmit_pkts;
+		}
+	}
+
 	if (hw->use_simple_rx) {
 		PMD_INIT_LOG(INFO, "virtio: using simple Rx path on port %u",
 			eth_dev->data->port_id);
@@ -1356,15 +1385,7 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
 		eth_dev->rx_pkt_burst = &virtio_recv_pkts;
 	}
 
-	if (hw->use_inorder_tx) {
-		PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
-	} else {
-		PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->tx_pkt_burst = virtio_xmit_pkts;
-	}
+
 }
 
 /* Only support 1:1 queue/interrupt mapping so far.
drivers/net/virtio/virtio_ethdev.h +2 -0
index e0f80e5a4..05d355180 100644
@@ -82,6 +82,8 @@ uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,
 
 uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 		uint16_t nb_pkts);
+uint16_t virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
+		uint16_t nb_pkts);
 
 uint16_t virtio_xmit_pkts_inorder(void *tx_queue, struct rte_mbuf **tx_pkts,
 		uint16_t nb_pkts);
drivers/net/virtio/virtio_rxtx.c +234 -2

266 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +18 -2
index 9c65ad54f..3cd7d6cf9 100644
@@ -247,8 +247,12 @@ struct virtio_net_hdr_mrg_rxbuf {
 #define VIRTIO_MAX_TX_INDIRECT 8
 struct virtio_tx_region {
 	struct virtio_net_hdr_mrg_rxbuf tx_hdr;
-	struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT]
-			   __attribute__((__aligned__(16)));
+	union {
+		struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT]
+			__attribute__((__aligned__(16)));
+		struct vring_packed_desc tx_indir_pq[VIRTIO_MAX_TX_INDIRECT]
+			__attribute__((__aligned__(16)));
+	};
 };
 
 static inline void
@@ -399,6 +403,7 @@ virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)
 #define VIRTQUEUE_NUSED(vq) ((uint16_t)((vq)->vq_ring.used->idx - (vq)->vq_used_cons_idx))
 
 void vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx);
+void vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t used_idx);
 void vq_ring_free_inorder(struct virtqueue *vq, uint16_t desc_idx,
 			  uint16_t num);
 
@@ -432,6 +437,17 @@ virtqueue_kick_prepare(struct virtqueue *vq)
 	return !(vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY);
 }
 
+static inline int
+virtqueue_kick_prepare_packed(struct virtqueue *vq)
+{
+	uint16_t flags;
+
+	virtio_mb();
+	flags = vq->ring_packed.device_event->desc_event_flags;
+
+	return flags != RING_EVENT_FLAGS_DISABLE;
+}
+
 static inline void
 virtqueue_notify(struct virtqueue *vq)
 {
Signature · 1 line
2.17.2
Reviewed-by on v13 5/10
#10 lore raw

Re: [PATCH v13 05/10] net/virtio: implement transmit path for packed queues

Quoted 90 lines · Jens Freimann

This implements the transmit path for devices with support for packed virtqueues.

---
  drivers/net/virtio/virtio_ethdev.c |  57 ++++---
  drivers/net/virtio/virtio_ethdev.h |   2 +
  drivers/net/virtio/virtio_rxtx.c   | 236 ++++++++++++++++++++++++++++-
  drivers/net/virtio/virtqueue.h     |  20 ++-
  4 files changed, 293 insertions(+), 22 deletions(-)
drivers/net/virtio/virtio_ethdev.c +38 -9
index e6ba1282b..9f1b72e56 100644
@@ -390,6 +390,9 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
  	if (vtpci_packed_queue(hw)) {
  		vq->avail_wrap_counter = 1;
  		vq->used_wrap_counter = 1;
+		vq->avail_used_flags =
+			VRING_DESC_F_AVAIL(vq->avail_wrap_counter) |
+			VRING_DESC_F_USED(!vq->avail_wrap_counter);
  	}
 
  	/*
@@ -497,17 +500,26 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
  		memset(txr, 0, vq_size * sizeof(*txr));
  		for (i = 0; i < vq_size; i++) {
  			struct vring_desc *start_dp = txr[i].tx_indir;
-
-			vring_desc_init_split(start_dp,
-					      RTE_DIM(txr[i].tx_indir));
+			struct vring_packed_desc *start_dp_packed =
+				txr[i].tx_indir_pq;
 
  			/* first indirect descriptor is always the tx header */
-			start_dp->addr = txvq->virtio_net_hdr_mem
-				+ i * sizeof(*txr)
-				+ offsetof(struct virtio_tx_region, tx_hdr);
-
-			start_dp->len = hw->vtnet_hdr_size;
-			start_dp->flags = VRING_DESC_F_NEXT;
+			if (vtpci_packed_queue(hw)) {
+				start_dp_packed->addr = txvq->virtio_net_hdr_mem
+					+ i * sizeof(*txr)
+					+ offsetof(struct virtio_tx_region,
+						   tx_hdr);
+				start_dp_packed->len = hw->vtnet_hdr_size;
+			} else {
+				vring_desc_init_split(start_dp,
+						      RTE_DIM(txr[i].tx_indir));
+				start_dp->addr = txvq->virtio_net_hdr_mem
+					+ i * sizeof(*txr)
+					+ offsetof(struct virtio_tx_region,
+						   tx_hdr);
+				start_dp->len = hw->vtnet_hdr_size;
+				start_dp->flags = VRING_DESC_F_NEXT;
+			}
  		}
  	}
 
@@ -1336,6 +1348,23 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
  {
  	struct virtio_hw *hw = eth_dev->data->dev_private;
 
+	if (vtpci_packed_queue(hw)) {
+		PMD_INIT_LOG(INFO,
+			"virtio: using packed ring standard Tx path on port %u",
+			eth_dev->data->port_id);
+		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",
+				eth_dev->data->port_id);
+			eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
+		} else {
+			PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->tx_pkt_burst = virtio_xmit_pkts;
+		}
+	}
+
  	if (hw->use_simple_rx) {
  		PMD_INIT_LOG(INFO, "virtio: using simple Rx path on port %u",
  			eth_dev->data->port_id);
@@ -1356,15 +1385,7 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
  		eth_dev->rx_pkt_burst = &virtio_recv_pkts;
  	}
 

drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1388

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +1 -9
-	if (hw->use_inorder_tx) {
-		PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
-	} else {
-		PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->tx_pkt_burst = virtio_xmit_pkts;
-	}
+

Trailing new line?

Apart from that, it looks good to me:

Thanks,
Maxime

#11 lore raw

PATCH v13 6/10 net/virtio: implement receive path for packed queues

In reply to Jens Freimann

Implement the receive part.

---
 drivers/net/virtio/virtio_ethdev.c |  58 +++--
 drivers/net/virtio/virtio_ethdev.h |   5 +
 drivers/net/virtio/virtio_rxtx.c   | 375 ++++++++++++++++++++++++++++-
 drivers/net/virtio/virtqueue.c     |  43 +++-
 4 files changed, 457 insertions(+), 24 deletions(-)
drivers/net/virtio/virtio_ethdev.c +39 -19
index 9f1b72e56..0394ac0af 100644
@@ -1365,27 +1365,41 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev)
 		}
 	}
 
-	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;
-	} else if (hw->use_inorder_rx) {
-		PMD_INIT_LOG(INFO,
-			"virtio: using inorder mergeable buffer Rx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts_inorder;
-	} else if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
-		PMD_INIT_LOG(INFO,
-			"virtio: using mergeable buffer Rx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts;
+	if (vtpci_packed_queue(hw)) {
+		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);
+			eth_dev->rx_pkt_burst =
+				&virtio_recv_mergeable_pkts_packed;
+		} else {
+			PMD_INIT_LOG(INFO,
+				"virtio: using packed ring standard Rx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed;
+		}
 	} else {
-		PMD_INIT_LOG(INFO, "virtio: using standard Rx path on port %u",
-			eth_dev->data->port_id);
-		eth_dev->rx_pkt_burst = &virtio_recv_pkts;
+		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;
+		} else if (hw->use_inorder_rx) {
+			PMD_INIT_LOG(INFO,
+				"virtio: using inorder mergeable buffer Rx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->rx_pkt_burst =
+				&virtio_recv_mergeable_pkts_inorder;
+		} else if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+			PMD_INIT_LOG(INFO,
+				"virtio: using mergeable buffer Rx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts;
+		} else {
+			PMD_INIT_LOG(INFO, "virtio: using standard Rx path on port %u",
+				eth_dev->data->port_id);
+			eth_dev->rx_pkt_burst = &virtio_recv_pkts;
+		}
 	}
-
-
 }
 
 /* Only support 1:1 queue/interrupt mapping so far.
@@ -1947,6 +1961,12 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 		}
 	}
 
+	if (vtpci_packed_queue(hw)) {
+		hw->use_simple_rx = 0;
+		hw->use_inorder_rx = 0;
+		hw->use_inorder_tx = 0;
+	}
+
 #if defined RTE_ARCH_ARM64 || defined RTE_ARCH_ARM
 	if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON)) {
 		hw->use_simple_rx = 0;
drivers/net/virtio/virtio_ethdev.h +5 -0
index 05d355180..88b8c42a3 100644
@@ -73,10 +73,15 @@ int virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
 
 uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 		uint16_t nb_pkts);
+uint16_t virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts,
+		uint16_t nb_pkts);
 
 uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 		uint16_t nb_pkts);
 
+uint16_t virtio_recv_mergeable_pkts_packed(void *rx_queue,
+		struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
+
 uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,
 		struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
 
drivers/net/virtio/virtio_rxtx.c +372 -3

423 lines not on this page · raw message

drivers/net/virtio/virtqueue.c +41 -2

53 lines not on this page · raw message

Signature · 1 line
2.17.2
Reviewed-by on v13 6/10
#12 lore raw

Re: [PATCH v13 06/10] net/virtio: implement receive path for packed queues

Quoted 11 lines · Jens Freimann

Implement the receive part.

---
  drivers/net/virtio/virtio_ethdev.c |  58 +++--
  drivers/net/virtio/virtio_ethdev.h |   5 +
  drivers/net/virtio/virtio_rxtx.c   | 375 ++++++++++++++++++++++++++++-
  drivers/net/virtio/virtqueue.c     |  43 +++-
  4 files changed, 457 insertions(+), 24 deletions(-)

Thanks,
Maxime

#13 lore raw

PATCH v13 7/10 net/virtio: add virtio send command packed queue support

In reply to Jens Freimann

Use packed virtqueue format when reading and writing descriptors to/from the ring.

---
 drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
drivers/net/virtio/virtio_ethdev.c +90 -0
index 0394ac0af..5e7af51c9 100644
@@ -141,6 +141,90 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
 
 struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
 
+static struct virtio_pmd_ctrl *
+virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
+		       int *dlen, int pkt_num)
+{
+	struct virtqueue *vq = cvq->vq;
+	int head;
+	struct vring_packed_desc *desc = vq->ring_packed.desc_packed;
+	struct virtio_pmd_ctrl *result;
+	int wrap_counter;
+	int sum = 0;
+	int k;
+
+	/*
+	 * Format is enforced in qemu code:
+	 * One TX packet for header;
+	 * At least one TX packet per argument;
+	 * One RX packet for ACK.
+	 */
+	head = vq->vq_avail_idx;
+	wrap_counter = vq->avail_wrap_counter;
+	desc[head].flags = VRING_DESC_F_NEXT;
+	desc[head].addr = cvq->virtio_net_hdr_mem;
+	desc[head].len = sizeof(struct virtio_net_ctrl_hdr);
+	vq->vq_free_cnt--;
+	if (++vq->vq_avail_idx >= vq->vq_nentries) {
+		vq->vq_avail_idx -= vq->vq_nentries;
+		vq->avail_wrap_counter ^= 1;
+	}
+
+	for (k = 0; k < pkt_num; k++) {
+		desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem
+			+ sizeof(struct virtio_net_ctrl_hdr)
+			+ sizeof(ctrl->status) + sizeof(uint8_t) * sum;
+		desc[vq->vq_avail_idx].len = dlen[k];
+		desc[vq->vq_avail_idx].flags = VRING_DESC_F_NEXT;
+		sum += dlen[k];
+		vq->vq_free_cnt--;
+		_set_desc_avail(&desc[vq->vq_avail_idx],
+				vq->avail_wrap_counter);
+		rte_smp_wmb();
+		vq->vq_free_cnt--;
+		if (++vq->vq_avail_idx >= vq->vq_nentries) {
+			vq->vq_avail_idx -= vq->vq_nentries;
+			vq->avail_wrap_counter ^= 1;
+		}
+	}
+
+
+	desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem
+		+ sizeof(struct virtio_net_ctrl_hdr);
+	desc[vq->vq_avail_idx].len = sizeof(ctrl->status);
+	desc[vq->vq_avail_idx].flags = VRING_DESC_F_WRITE;
+	_set_desc_avail(&desc[vq->vq_avail_idx],
+			vq->avail_wrap_counter);
+	_set_desc_avail(&desc[head], wrap_counter);
+	rte_smp_wmb();
+
+	vq->vq_free_cnt--;
+	if (++vq->vq_avail_idx >= vq->vq_nentries) {
+		vq->vq_avail_idx -= vq->vq_nentries;
+		vq->avail_wrap_counter ^= 1;
+	}
+
+	virtqueue_notify(vq);
+
+	/* wait for used descriptors in virtqueue */
+	do {
+		rte_rmb();
+		usleep(100);
+	} while (!desc_is_used(&desc[head], vq));
+
+	/* now get used descriptors */
+	while (desc_is_used(&desc[vq->vq_used_cons_idx], vq)) {
+		vq->vq_free_cnt++;
+		if (++vq->vq_used_cons_idx >= vq->vq_nentries) {
+			vq->vq_used_cons_idx -= vq->vq_nentries;
+			vq->used_wrap_counter ^= 1;
+		}
+	}
+
+	result = cvq->virtio_net_hdr_mz->addr;
+	return result;
+}
+
 static int
 virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 		int *dlen, int pkt_num)
@@ -174,6 +258,11 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 	memcpy(cvq->virtio_net_hdr_mz->addr, ctrl,
 		sizeof(struct virtio_pmd_ctrl));
 
+	if (vtpci_packed_queue(vq->hw)) {
+		result = virtio_pq_send_command(cvq, ctrl, dlen, pkt_num);
+		goto out_unlock;
+	}
+
 	/*
 	 * Format is enforced in qemu code:
 	 * One TX packet for header;
@@ -245,6 +334,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 
 	result = cvq->virtio_net_hdr_mz->addr;
 
+out_unlock:
 	rte_spinlock_unlock(&cvq->lock);
 	return result->status;
 }
Signature · 1 line
2.17.2
Reviewed-by on v13 7/10
#14 lore raw

Re: [PATCH v13 07/10] net/virtio: add virtio send command packed queue support

Quoted 7 lines · Jens Freimann

Use packed virtqueue format when reading and writing descriptors to/from the ring.

---
  drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++++++
  1 file changed, 90 insertions(+)

Thanks,
Maxime

#15 lore raw

PATCH v13 8/10 net/virtio-user: add option to use packed queues

In reply to Jens Freimann

From: Yuanhan Liu <[email protected]>

Add option to enable packed queue support for virtio-user devices.

---
 .../net/virtio/virtio_user/virtio_user_dev.c   | 18 ++++++++++++++----
 .../net/virtio/virtio_user/virtio_user_dev.h   |  2 +-
 drivers/net/virtio/virtio_user_ethdev.c        | 14 +++++++++++++-
 3 files changed, 28 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +14 -4
index 20816c936..697ba4ae8 100644
@@ -58,6 +58,8 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 
 	state.index = queue_sel;
 	state.num = 0; /* no reservation */
+	if (dev->features & (1ULL << VIRTIO_F_RING_PACKED))
+		state.num |= (1 << 15);
 	dev->ops->send_request(dev, VHOST_USER_SET_VRING_BASE, &state);
 
 	dev->ops->send_request(dev, VHOST_USER_SET_VRING_ADDR, &addr);
@@ -407,12 +409,13 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 	 1ULL << VIRTIO_NET_F_GUEST_TSO4	|	\
 	 1ULL << VIRTIO_NET_F_GUEST_TSO6	|	\
 	 1ULL << VIRTIO_F_IN_ORDER		|	\
-	 1ULL << VIRTIO_F_VERSION_1)
+	 1ULL << VIRTIO_F_VERSION_1		|	\
+	 1ULL << VIRTIO_F_RING_PACKED)
 
 int
 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 		     int cq, int queue_size, const char *mac, char **ifname,
-		     int mrg_rxbuf, int in_order)
+		     int mrg_rxbuf, int in_order, int packed_vq)
 {
 	pthread_mutex_init(&dev->mutex, NULL);
 	snprintf(dev->path, PATH_MAX, "%s", path);
@@ -464,10 +467,17 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	if (!in_order)
 		dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
 
-	if (dev->mac_specified)
-		dev->frontend_features |= (1ull << VIRTIO_NET_F_MAC);
+	if (packed_vq)
+		dev->device_features |= (1ull << VIRTIO_F_RING_PACKED);
 	else
+		dev->device_features &= ~(1ull << VIRTIO_F_RING_PACKED);
+
+	if (dev->mac_specified) {
+		dev->device_features |= (1ull << VIRTIO_NET_F_MAC);
+	} else {
+		dev->device_features &= ~(1ull << VIRTIO_NET_F_MAC);
 		dev->unsupported_features |= (1ull << VIRTIO_NET_F_MAC);
+	}
 
 	if (cq) {
 		/* device does not really need to know anything about CQ,
drivers/net/virtio/virtio_user/virtio_user_dev.h +1 -1
index c42ce5d4b..672a8161a 100644
@@ -50,7 +50,7 @@ int virtio_user_start_device(struct virtio_user_dev *dev);
 int virtio_user_stop_device(struct virtio_user_dev *dev);
 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 			 int cq, int queue_size, const char *mac, char **ifname,
-			 int mrg_rxbuf, int in_order);
+			 int mrg_rxbuf, int in_order, int packed_vq);
 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
drivers/net/virtio/virtio_user_ethdev.c +13 -1
index f8791391a..af2800605 100644
@@ -361,6 +361,8 @@ static const char *valid_args[] = {
 	VIRTIO_USER_ARG_MRG_RXBUF,
 #define VIRTIO_USER_ARG_IN_ORDER       "in_order"
 	VIRTIO_USER_ARG_IN_ORDER,
+#define VIRTIO_USER_ARG_PACKED_VQ "packed_vq"
+	VIRTIO_USER_ARG_PACKED_VQ,
 	NULL
 };
 
@@ -468,6 +470,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev)
 	char *ifname = NULL;
 	char *mac_addr = NULL;
 	int ret = -1;
+	uint64_t packed_vq = 0;
 
 	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
 	if (!kvlist) {
@@ -551,6 +554,15 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev)
 		cq = 1;
 	}
 
+	if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PACKED_VQ) == 1) {
+		if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PACKED_VQ,
+				       &get_integer_arg, &packed_vq) < 0) {
+			PMD_INIT_LOG(ERR, "error to parse %s",
+				     VIRTIO_USER_ARG_PACKED_VQ);
+			goto end;
+		}
+	}
+
 	if (queues > 1 && cq == 0) {
 		PMD_INIT_LOG(ERR, "multi-q requires ctrl-q");
 		goto end;
@@ -598,7 +610,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev)
 			vu_dev->is_server = false;
 		if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
 				 queue_size, mac_addr, &ifname, mrg_rxbuf,
-				 in_order) < 0) {
+				 in_order, packed_vq) < 0) {
 			PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
 			virtio_user_eth_dev_free(eth_dev);
 			goto end;
Signature · 1 line
2.17.2
Reviewed-by on v13 8/10
#16 lore raw

Re: [PATCH v13 08/10] net/virtio-user: add option to use packed queues

Quoted 5 lines · Jens Freimann

From: Yuanhan Liu <[email protected]>

Add option to enable packed queue support for virtio-user devices.

Quoted 7 lines
---
  .../net/virtio/virtio_user/virtio_user_dev.c   | 18 ++++++++++++++----
  .../net/virtio/virtio_user/virtio_user_dev.h   |  2 +-
  drivers/net/virtio/virtio_user_ethdev.c        | 14 +++++++++++++-
  3 files changed, 28 insertions(+), 6 deletions(-)

Thanks,
Maxime

#17 lore raw

PATCH v13 9/10 net/virtio-user: fail if q used with packed vq

In reply to Jens Freimann

Until we have support for ctrl virtqueues let's disable it and fail device initalization if specified as a parameter.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +8 -2
index 697ba4ae8..14597eb73 100644
@@ -467,10 +467,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	if (!in_order)
 		dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
 
-	if (packed_vq)
+	if (packed_vq) {
+		if (cq) {
+			PMD_INIT_LOG(ERR, "control vq not supported with "
+					  "packed virtqueues\n");
+			return -1;
+		}
 		dev->device_features |= (1ull << VIRTIO_F_RING_PACKED);
-	else
+	} else {
 		dev->device_features &= ~(1ull << VIRTIO_F_RING_PACKED);
+	}
 
 	if (dev->mac_specified) {
 		dev->device_features |= (1ull << VIRTIO_NET_F_MAC);
Signature · 1 line
2.17.2
#18 lore raw

Re: [PATCH v13 09/10] net/virtio-user: fail if q used with packed vq

I think you meant control queue in the title?

Quoted 13 lines · Jens Freimann

Until we have support for ctrl virtqueues let's disable it and fail device initalization if specified as a parameter.

---
  drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
index 697ba4ae8..14597eb73 100644

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, · line 472

Quoted 7 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -1
@@ -467,10 +467,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
  	if (!in_order)
  		dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
 
-	if (packed_vq)
+	if (packed_vq) {
+		if (cq) {
+			PMD_INIT_LOG(ERR, "control vq not supported with "

Maybe change to "not supported *yet*".

Quoted 12 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +5 -1
+					  "packed virtqueues\n");
+			return -1;
+		}
  		dev->device_features |= (1ull << VIRTIO_F_RING_PACKED);
-	else
+	} else {
  		dev->device_features &= ~(1ull << VIRTIO_F_RING_PACKED);
+	}
 
  	if (dev->mac_specified) {
  		dev->device_features |= (1ull << VIRTIO_NET_F_MAC);
#19 lore raw

Re: [PATCH v13 09/10] net/virtio-user: fail if q used with packed vq

Quoted 11 lines · Maxime Coquelin

I think you meant control queue in the title?

Quoted 8 lines · Jens Freimann

Until we have support for ctrl virtqueues let's disable it and fail device initalization if specified as a parameter.

---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, · line 471

Quoted 11 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -1
index 697ba4ae8..14597eb73 100644
@@ -467,10 +467,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	if (!in_order)
 		dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
-	if (packed_vq)
+	if (packed_vq) {
+		if (cq) {
+			PMD_INIT_LOG(ERR, "control vq not supported with "

Maybe change to "not supported *yet*".

sure, no problem.

regards,
Jens

#20 lore raw

PATCH v13 10/10 net/virtio: enable packed virtqueues by default

In reply to Jens Freimann
---
 drivers/net/virtio/virtio_ethdev.h               | 1 +
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_ethdev.h +1 -0
index 88b8c42a3..364ecbb50 100644
@@ -34,6 +34,7 @@
 	 1u << VIRTIO_RING_F_INDIRECT_DESC |    \
 	 1ULL << VIRTIO_F_VERSION_1       |	\
 	 1ULL << VIRTIO_F_IN_ORDER        |	\
+	 1ULL << VIRTIO_F_RING_PACKED	  |	\
 	 1ULL << VIRTIO_F_IOMMU_PLATFORM)
 
 #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES	\
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
index 14597eb73..376622a6c 100644
@@ -410,7 +410,8 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 	 1ULL << VIRTIO_NET_F_GUEST_TSO6	|	\
 	 1ULL << VIRTIO_F_IN_ORDER		|	\
 	 1ULL << VIRTIO_F_VERSION_1		|	\
-	 1ULL << VIRTIO_F_RING_PACKED)
+	 1ULL << VIRTIO_F_RING_PACKED		|	\
+	 1ULL << VIRTIO_RING_F_EVENT_IDX)
 
 int
 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
Signature · 1 line
2.17.2