implement packed virtqueues
v6 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 buffer.
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.
The idea behind this is to 1. improve performance by avoiding cache misses and 2. be easier for devices to implement.
Regarding performance: with these patches I get 21.13 Mpps on my system as compared to 18.8 Mpps with the virtio 1.0 code. Packet size was 64 bytes, 0.05% acceptable loss. Test setup is described as in
http://dpdk.org/doc/guides/howto/pvp_reference_benchmark.html
Packet generator:
MoonGen
Intel(R) Xeon(R) CPU E5-2665 0 @ 2.40GHz
Intel X710 NIC
RHEL 7.4
Device under test:
Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
Intel X710 NIC
RHEL 7.4
VM on DuT: RHEL7.4
I plan to do more performance test with bigger frame sizes.
changes from v5->v6:
* fix VIRTQUEUE_DUMP macro
* rework mergeable rx buffer path, support out of order (not sure if I need a .next field to support chains)
* move wmb in virtio_receive_pkts_packed() (Gavin)
* rename to virtio_init_split/_packed (Maxime)
* add support for ctrl virtqueues (Tiwei, thx Max for fixing)
* rework tx path to support update_packet_stats and virtqueue_xmit_offload, TODO: merge with split-ring code to avoid a lot of duplicate code
* remove unnecessary check for avoiding to call VIRTQUEUE_DUMP (Maxime)
changes from v4->v5:
* fix VIRTQUEUE_DUMP macro
* fix wrap counter logic in transmit and receive functions
changes from v3->v4:
* added helpers to increment index and set available/used flags
* driver keeps track of number of descriptors used
* change logic in set_rxtx_funcs()
* add patch for ctrl virtqueue with support for packed virtqueues
* rename virtio-1.1.h to virtio-packed.h
* fix wrong sizeof() in "vhost: vring address setup for packed queues"
* fix coding style of function definition in "net/virtio: add packed virtqueue helpers"
* fix padding in vring_size()
* move patches to enable packed virtqueues end of series
* v4 has two open problems: I'm sending it out anyway for feedback/help:
* when VIRTIO_NET_F_MRG_RXBUF enabled only 128 packets are send in guest, i.e. when ring is full for the first time. I suspect a bug in setting the avail/used flags
changes from v2->v3:
* implement event suppression
* add code do dump packed virtqueues
* don't use assert in vhost code
* rename virtio-user parameter to packed-vq
* support rxvf flush
changes from v1->v2:
* don't use VIRTQ_DESC_F_NEXT in used descriptors (Jason)
* no rte_panice() in guest triggerable code (Maxime)
* use unlikely when checking for vq (Maxime)
* rename everything from _1_1 to _packed (Yuanhan)
* add two more patches to implement mergeable receive buffers
*** BLURB HERE ***
Jens Freimann (10):
net/virtio: vring init for packed queues
net/virtio: add packed virtqueue defines
net/virtio: add packed virtqueue helpers
net/virtio: flush packed receive virtqueues
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 support for mergeable buffers with packed virtqueues net/virtio: add virtio send command packed queue support 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 | 135 ++++- drivers/net/virtio/virtio_ethdev.h | 5 + drivers/net/virtio/virtio_pci.h | 8 + drivers/net/virtio/virtio_ring.h | 96 +++- drivers/net/virtio/virtio_rxtx.c | 490 +++++++++++++++++- .../net/virtio/virtio_user/virtio_user_dev.c | 10 +- .../net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/net/virtio/virtio_user_ethdev.c | 14 +- drivers/net/virtio/virtqueue.c | 21 + drivers/net/virtio/virtqueue.h | 50 +- 10 files changed, 796 insertions(+), 35 deletions(-)
Signature · 1 line
2.17.1
PATCH v6 1/11 net/virtio: vring init for packed queues
Add and initialize descriptor data structures.
--- drivers/net/virtio/virtio_ethdev.c | 24 +++++++------ drivers/net/virtio/virtio_pci.h | 8 +++++ drivers/net/virtio/virtio_ring.h | 55 +++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.h | 12 ++++++- 4 files changed, 82 insertions(+), 17 deletions(-)
drivers/net/virtio/virtio_ethdev.c +13 -11
@@ -299,19 +299,21 @@ 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 ); +vring_init (vq->hw, vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_free_cnt = vq->vq_nentries;memset (vq->vq_descx,0 ,sizeof (struct vq_desc_extra ) * vq->vq_nentries); + vq->vq_used_cons_idx =0 ; + vq->vq_avail_idx =0 ; +if (vtpci_packed_queue (vq->hw)) { +vring_desc_init_packed (vr, size); + }else { + vq->vq_desc_head_idx =0 ; + vq->vq_desc_tail_idx = (uint16_t )(vq->vq_nentries -1 ); -vring_desc_init (vr->desc, size); +vring_desc_init_split (vr->desc, size); + }/* * Disable device(host) interrupting guest
@@ -386,7 +388,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)/* * 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);
@@ -489,7 +491,7 @@ 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
drivers/net/virtio/virtio_pci.h +8 -0
@@ -113,6 +113,8 @@ struct virtnet_ctl;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 +#define VIRTIO_F_IN_ORDER 35/* * Some VirtIO feature bits (currently bits 28 through 31) are
@@ -314,6 +316,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/virtio_ring.h +50 -5
81 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +11 -1
@@ -245,9 +245,19 @@ struct virtio_tx_region { __attribute__((__aligned__(16))); }; +static inline void +vring_desc_init_packed (struct vring *vr,int n) +{ +int i; +for (i =0 ; i < n; i++) { +struct vring_desc_packed *desc = &vr->desc_packed[i]; + desc->index = i; + } +} +/* 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.1
PATCH v6 2/11 net/virtio: add packed virtqueue defines
In reply to Jens Freimann--- drivers/net/virtio/virtio_ring.h | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/virtio/virtio_ring.h +4 -0
@@ -15,7 +15,11 @@#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 * optimization. Guest will still kick if it's out of buffers. */
Signature · 1 line
2.17.1
PATCH v6 3/11 net/virtio: add packed virtqueue helpers
In reply to Jens FreimannAdd helper functions to set/clear and check descriptor flags.
--- drivers/net/virtio/virtio_ring.h | 26 ++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 11 +++++++++++ 2 files changed, 37 insertions(+)
drivers/net/virtio/virtio_ring.h +26 -0
@@ -78,6 +78,8 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter; +unsigned int used_wrap_counter;union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;
@@ -92,6 +94,30 @@ struct vring { }; }; +static inline void +_set_desc_avail (struct vring_desc_packed *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 vring *vr,struct vring_desc_packed *desc) +{ +_set_desc_avail (desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used, avail; + + used = !!(desc->flags &VRING_DESC_F_USED (1 )); + avail = !!(desc->flags &VRING_DESC_F_AVAIL (1 )); + +return used == avail && used == vr->used_wrap_counter; +} +/* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. *
drivers/net/virtio/virtqueue.h +11 -0
@@ -245,6 +245,17 @@ struct virtio_tx_region { __attribute__((__aligned__(16))); }; +static inline uint16_t +update_pq_avail_index (struct virtqueue *vq) +{ +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx =0 ; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + +return vq->vq_avail_idx; +} +static inline void vring_desc_init_packed (struct vring *vr,int n) {
Signature · 1 line
2.17.1
PATCH v6 4/11 net/virtio: flush packed receive virtqueues
In reply to Jens FreimannFlush used descriptors in packed receive virtqueue. As descriptors can be chained we need to look at the stored number of used descriptors to find out the length of the chain.
--- drivers/net/virtio/virtqueue.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/net/virtio/virtqueue.c +21 -0
@@ -58,12 +58,33 @@ virtqueue_detach_unused(struct virtqueue *vq)void virtqueue_rxvq_flush (struct virtqueue *vq) { +struct vring_desc_packed *descs = vq->vq_ring.desc_packed;struct virtnet_rx *rxq = &vq->rxq;struct virtio_hw *hw = vq->hw;struct vring_used_elem *uep;struct vq_desc_extra *dxp;uint16_t used_idx, desc_idx;uint16_t nb_used, i; +uint16_t size = vq->vq_nentries; + +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx; +if (i >= vq->vq_used_cons_idx) { +PMD_INIT_LOG (ERR ,"vq_used_cons_idx out of range" ); +return ; + } +while (desc_is_used (&descs[i], &vq->vq_ring) && + i < vq->vq_nentries) { + dxp = &vq->vq_descx[i]; +if (dxp->cookie !=NULL ) +rte_pktmbuf_free (dxp->cookie); + vq->vq_free_cnt += dxp->ndescs; + i = i + dxp->ndescs; + i = i >= size ? i - size : i; + dxp->ndescs =0 ; + } +return ; + } nb_used =VIRTQUEUE_NUSED (vq);
Signature · 1 line
2.17.1
PATCH v6 5/11 net/virtio: dump packed virtqueue data
In reply to Jens FreimannAdd support to dump packed virtqueue data to theVIRTQUEUE_DUMP() macro.
--- drivers/net/virtio/virtqueue.h | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/virtio/virtqueue.h +9 -0
@@ -376,6 +376,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)->vq_ring.avail_wrap_counter, \ + (vq)->vq_ring.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.1
PATCH v6 6/11 net/virtio: implement transmit path for packed queues
In reply to Jens FreimannThis implements the transmit path for devices with support for packed virtqueues.
Add the feature bit and enable code to
add buffers to vring and mark descriptors as available.
--- drivers/net/virtio/virtio_ethdev.c | 8 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_ring.h | 15 +- drivers/net/virtio/virtio_rxtx.c | 243 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 17 +- 5 files changed, 280 insertions(+), 5 deletions(-)
drivers/net/virtio/virtio_ethdev.c +7 -1
@@ -384,6 +384,8 @@ 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; +if (vtpci_packed_queue (hw)) + vq->vq_ring.avail_wrap_counter =1 ;/* * Reserve a memzone for vring elements
@@ -1338,7 +1340,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_inorder_tx) { +if (vtpci_packed_queue (hw)) { +PMD_INIT_LOG (INFO ,"virtio: using virtio 1.1 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;
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -79,6 +79,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_ring.h +13 -2
@@ -108,14 +108,25 @@ set_desc_avail(struct vring *vr, struct vring_desc_packed *desc) }static inline int -desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +_desc_is_used (struct vring_desc_packed *desc) {uint16_t used, avail; used = !!(desc->flags &VRING_DESC_F_USED (1 )); avail = !!(desc->flags &VRING_DESC_F_AVAIL (1 )); -return used == avail && used == vr->used_wrap_counter; +return used == avail; + +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used; + + used = !!(desc->flags &VRING_DESC_F_USED (1 )); + +return _desc_is_used (desc) && used == vr->used_wrap_counter; }/* The standard layout for the ring is a continuous chunk of memory which
drivers/net/virtio/virtio_rxtx.c +243 -0
273 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +15 -2
@@ -241,8 +241,12 @@ struct virtio_net_hdr_mrg_rxbuf {#define VIRTIO_MAX_TX_INDIRECT 8struct 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_desc_packed tx_indir_pq[VIRTIO_MAX_TX_INDIRECT ] + __attribute__((__aligned__ (16 ))); + }; }; static inline uint16_t
@@ -360,6 +364,15 @@ 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; + + flags = vq->vq_ring.device_event->desc_event_flags &RING_EVENT_FLAGS_DESC ; +return (flags !=RING_EVENT_FLAGS_DISABLE ); +} +static inline void virtqueue_notify (struct virtqueue *vq) {
Signature · 1 line
2.17.1
Re: [PATCH v6 06/11] net/virtio: implement transmit path for packed queues
On Fri, Sep 21, 2018 at 12:33:03PM +0200, Jens Freimann wrote:
[...]
Quoted 42 lines
static inline int
drivers/net/virtio/virtio_ring.h +13
-2-desc_is_used(struct vring_desc_packed *desc, struct vring *vr) +_desc_is_used(struct vring_desc_packed *desc) {uint16_t used, avail; used = !!(desc->flags &VRING_DESC_F_USED (1 )); avail = !!(desc->flags &VRING_DESC_F_AVAIL (1 )); -return used == avail && used == vr->used_wrap_counter; +return used == avail; + +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used; + + used = !!(desc->flags &VRING_DESC_F_USED (1 )); + +return _desc_is_used (desc) && used == vr->used_wrap_counter; }/* The standard layout for the ring is a continuous chunk of memory which drivers/net/virtio/virtio_rxtx.c +1
-0@@ -38,6 +38,7 @@#define VIRTIO_DUMP_PACKET (m, len) do { } while (0)#endif +int virtio_dev_rx_queue_done (void *rxq,uint16_t offset) {@@ -165,6 +166,31 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,#endif /* Cleanup from completed transmits. */
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 178
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+static void +virtio_xmit_cleanup_packed (struct virtqueue *vq) +{ +uint16_t idx; +uint16_t size = vq->vq_nentries; +struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct vq_desc_extra *dxp; + + idx = vq->vq_used_cons_idx; + while (_desc_is_used(&desc[idx]) &&
We can't just compare the AVAIL bit and USED bit to check whether a desc is used.
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 180
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+ vq->vq_free_cnt < size) { + dxp = &vq->vq_descx[idx];
The code is still assuming the descs will be written back by device in order. The vq->vq_descx[] needs to be managed e.g. as a list to support the out-of-order processing. IOW, we can't assume vq->vq_descx[idx] is corresponding to desc[idx] when device may write back the descs out of order.
Quoted 12 lines
drivers/net/virtio/virtio_rxtx.c +12
-0+ vq->vq_free_cnt += dxp->ndescs; + idx += dxp->ndescs; + idx = idx >= size ? idx - size : idx; +if (idx ==0 ) { + vq->vq_ring.used_wrap_counter ^=1 ; + } +if (dxp->cookie !=NULL ) { +rte_pktmbuf_free (dxp->cookie); + dxp->cookie =NULL ; + } + } +}
[...]
Re: [PATCH v6 06/11] net/virtio: implement transmit path for packed queues
Quoted 43 lines · Tiwei Bie
On Fri, Sep 21, 2018 at 12:33:03PM +0200, Jens Freimann wrote:
[...]Quoted 41 lines
static inline int
drivers/net/virtio/virtio_ring.h +13
-2-desc_is_used(struct vring_desc_packed *desc, struct vring *vr) +_desc_is_used(struct vring_desc_packed *desc) {uint16_t used, avail; used = !!(desc->flags &VRING_DESC_F_USED (1 )); avail = !!(desc->flags &VRING_DESC_F_AVAIL (1 )); -return used == avail && used == vr->used_wrap_counter; +return used == avail; + +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used; + + used = !!(desc->flags &VRING_DESC_F_USED (1 )); + +return _desc_is_used (desc) && used == vr->used_wrap_counter; }/* The standard layout for the ring is a continuous chunk of memory which drivers/net/virtio/virtio_rxtx.c +1
-0@@ -38,6 +38,7 @@#define VIRTIO_DUMP_PACKET (m, len) do { } while (0)#endif +int virtio_dev_rx_queue_done (void *rxq,uint16_t offset) {@@ -165,6 +166,31 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,#endif
Quoted 14 lines
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 178
Quoted 11 lines
drivers/net/virtio/virtio_rxtx.c +10
-0/* Cleanup from completed transmits. */ +static void +virtio_xmit_cleanup_packed (struct virtqueue *vq) +{ +uint16_t idx; +uint16_t size = vq->vq_nentries; +struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct vq_desc_extra *dxp; + + idx = vq->vq_used_cons_idx; + while (_desc_is_used(&desc[idx]) &&We can't just compare the AVAIL bit and USED bit to check whether a desc is used.
We can't compare with the current wrap counter value as well because it won't match the flags in descriptors. So check against used_wrap_counter ^= 1 then?
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 180
Quoted 3 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+ vq->vq_free_cnt < size) { + dxp = &vq->vq_descx[idx];The code is still assuming the descs will be written back by device in order. The vq->vq_descx[] needs to be managed e.g. as a list to support the out-of-order processing. IOW, we can't assume vq->vq_descx[idx] is corresponding to desc[idx] when device may write back the descs out of order.
I changed it to not assume this in other spots but missed this one. I will check more carefully and add code to make vq_descx entries a list.
Thanks for the review!
regards,
Jens
Re: [PATCH v6 06/11] net/virtio: implement transmit path for packed queues
Quoted 59 lines · Jens Freimann
Quoted 43 lines · Tiwei Bie
On Fri, Sep 21, 2018 at 12:33:03PM +0200, Jens Freimann wrote:
[...]Quoted 41 lines
static inline int
drivers/net/virtio/virtio_ring.h +13
-2-desc_is_used(struct vring_desc_packed *desc, struct vring *vr) +_desc_is_used(struct vring_desc_packed *desc) {uint16_t used, avail; used = !!(desc->flags &VRING_DESC_F_USED (1 )); avail = !!(desc->flags &VRING_DESC_F_AVAIL (1 )); -return used == avail && used == vr->used_wrap_counter; +return used == avail; + +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used; + + used = !!(desc->flags &VRING_DESC_F_USED (1 )); + +return _desc_is_used (desc) && used == vr->used_wrap_counter; }/* The standard layout for the ring is a continuous chunk of memory which drivers/net/virtio/virtio_rxtx.c +1
-0@@ -38,6 +38,7 @@#define VIRTIO_DUMP_PACKET (m, len) do { } while (0)#endif +int virtio_dev_rx_queue_done (void *rxq,uint16_t offset) {@@ -165,6 +166,31 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,#endif Quoted 14 lines
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 178
Quoted 11 lines
drivers/net/virtio/virtio_rxtx.c +10
-0/* Cleanup from completed transmits. */ +static void +virtio_xmit_cleanup_packed (struct virtqueue *vq) +{ +uint16_t idx; +uint16_t size = vq->vq_nentries; +struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct vq_desc_extra *dxp; + + idx = vq->vq_used_cons_idx; + while (_desc_is_used(&desc[idx]) &&We can't just compare the AVAIL bit and USED bit to check whether a desc is used.
Quoted 3 lines
We can't compare with the current wrap counter value as well because it won't match the flags in descriptors. So check against
used_wrap_counter^= 1 then?
I haven't looked into this series yet, so I'm not sure what's the best way to get the wrap-counter we need here. But, yes, you need some way to get the wrap-counter we should use here.
Quoted 11 lines
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 180
Quoted 3 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+ vq->vq_free_cnt < size) { + dxp = &vq->vq_descx[idx];The code is still assuming the descs will be written back by device in order. The vq->vq_descx[] needs to be managed e.g. as a list to support the out-of-order processing. IOW, we can't assume vq->vq_descx[idx] is corresponding to desc[idx] when device may write back the descs out of order.
Quoted 2 lines
I changed it to not assume this in other spots but missed this one. I will check more carefully and add code to make
vq_descxentries a list.
After making it support the out-of-order, we may want to do some performance test for the Tx path only. Because I suspect we may not be able to get the expected performance improvements in packed ring due to this when device is faster than driver.
Thanks
PATCH v6 7/11 net/virtio: implement receive path for packed queues
In reply to Jens FreimannImplement the receive part.
--- drivers/net/virtio/virtio_ethdev.c | 15 +++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 130 +++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 3 deletions(-)
drivers/net/virtio/virtio_ethdev.c +12 -3
@@ -384,8 +384,10 @@ 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; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ; + }/* * Reserve a memzone for vring elements
@@ -1320,7 +1322,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private; -if (hw->use_simple_rx) { +/* +* workarount for packed vqs which don't support +* mrg_rxbuf at this point +*/ +if (vtpci_packed_queue (hw)) { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; + }else 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;
@@ -1484,7 +1492,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 );
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -70,6 +70,8 @@ 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);
drivers/net/virtio/virtio_rxtx.c +130 -0
154 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 8/11 net/virtio: add support for mergeable buffers with packed virtqueues
In reply to Jens FreimannImplement support for receiving merged buffers in virtio when packed virtqueues are enabled.
--- drivers/net/virtio/virtio_ethdev.c | 8 +- drivers/net/virtio/virtio_rxtx.c | 117 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.h | 1 + 3 files changed, 113 insertions(+), 13 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -1322,12 +1322,12 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private; -/* -* workarount for packed vqs which don't support -* mrg_rxbuf at this point -*/ if (vtpci_packed_queue (hw)) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts; + }else { eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; + } }else if (hw->use_simple_rx) {PMD_INIT_LOG (INFO ,"virtio: using simple Rx path on port %u" , eth_dev->data->port_id);
drivers/net/virtio/virtio_rxtx.c +108 -9
170 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +1 -0
@@ -171,6 +171,7 @@ struct virtqueue {* trails vq_ring.used->idx. */ uint16_t vq_used_cons_idx; +uint16_t vq_used_idx;uint16_t vq_nentries;/**< vring desc numbers */ uint16_t vq_free_cnt;/**< num of desc available */ uint16_t vq_avail_idx;/**< sync until needed */
Signature · 1 line
2.17.1
PATCH v6 9/11 net/virtio: add virtio send command packed queue support
In reply to Jens FreimannUse 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
@@ -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_desc_packed *desc = vq->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.avail_wrap_counter ^=1 ; + } + +virtqueue_notify (vq); + +/* wait for used descriptors in virtqueue */ +do { +rte_rmb (); +usleep (100 ); + }while (!_desc_is_used (&desc[head])); + +/* now get used descriptors */ +while (desc_is_used (&desc[vq->vq_used_cons_idx], &vq->vq_ring)) { + vq->vq_free_cnt++; +if (++vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_ring.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.1
Re: [PATCH v6 09/11] net/virtio: add virtio send command packed queue support
drivers/net/virtio/virtio_ethdev.c
Quoted 12 lines · Jens Freimann
Use packed virtqueue format when reading and writing descriptors to/from the ring.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)drivers/net/virtio/virtio_ethdev.c +0
-0
The support for virtio-user is missing. And virtio-user will break when packed ring is enabled. FYI, below is the relvelant code in virtio-user:
Quoted 114 lines
drivers/net/virtio/virtio_ethdev.c +90
-0@@ -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_desc_packed *desc = vq->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.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->vq_ring.avail_wrap_counter ^=1 ; + } + +virtqueue_notify (vq); + +/* wait for used descriptors in virtqueue */ +do { +rte_rmb (); +usleep (100 ); + }while (!_desc_is_used (&desc[head])); + +/* now get used descriptors */ +while (desc_is_used (&desc[vq->vq_used_cons_idx], &vq->vq_ring)) { + vq->vq_free_cnt++; +if (++vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_ring.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.1
PATCH v6 10/11 net/virtio-user: add option to use packed queues
In reply to Jens FreimannFrom: Yuanhan Liu <[email protected]>
Add option to enable packed queue support for virtio-user devices.
--- drivers/net/virtio/virtio_user/virtio_user_dev.c | 10 ++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/net/virtio/virtio_user_ethdev.c | 14 +++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +8 -2
@@ -391,12 +391,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);
@@ -451,6 +452,11 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, dev->unsupported_features |= (1ull <<VIRTIO_F_IN_ORDER ); } +if (!packed_vq) { + dev->device_features &= ~(1ull <<VIRTIO_F_RING_PACKED ); + dev->unsupported_features |= (1ull <<VIRTIO_F_RING_PACKED ); + } +if (dev->mac_specified) { dev->device_features |= (1ull <<VIRTIO_NET_F_MAC ); }else {
drivers/net/virtio/virtio_user/virtio_user_dev.h +1 -1
@@ -49,7 +49,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
@@ -364,6 +364,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 };
@@ -473,6 +475,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) {
@@ -556,6 +559,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;
@@ -603,7 +615,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.1
PATCH v6 11/11 net/virtio: enable packed virtqueues by default
In reply to Jens Freimann--- drivers/net/virtio/virtio_ethdev.h | 1 + 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_ethdev.h +1 -0
@@ -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 \
Signature · 1 line
2.17.1
Quoted 15 lines · Jens Freimann
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.pdfA 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 buffer.
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.
Quoted 5 lines
The idea behind this is to 1. improve performance by avoiding cache misses and 2. be easier for devices to implement.
Regarding performance: with these patches I get 21.13 Mpps on my system as compared to 18.8 Mpps with the virtio 1.0 code. Packet size was 64
Did you enable multiple-queue and use multiple cores on vhost side? If not, I guess the above performance gain is the gain in vhost side instead of virtio side.
If you use more cores on vhost side or virtio side, will you see any performance changes?
Did you do any performance test with the kernel vhost-net backend (with zero-copy enabled and disabled)? I think we also need some performance data for these two cases. And it can help us to make sure that it works with the kernel backends.
And for the "virtio-PMD + vhost-PMD" test cases, I think we need below performance data:
#1. The maximum 1 core performance of virtio PMD when using split ring. #2. The maximum 1 core performance of virtio PMD when using packed ring. #3. The maximum 1 core performance of vhost PMD when using split ring. #4. The maximum 1 core performance of vhost PMD when using packed ring.
And then we can have a clear understanding of the performance gain in DPDK with packed ring.
And FYI, the maximum 1 core performance of virtio PMD can be got in below steps:
1. Launch vhost-PMD with multiple queues, and use multiple CPU cores for forwarding.
2. Launch virtio-PMD with multiple queues and use 1 CPU core for forwarding.
3. Repeat above two steps with adding more CPU cores for forwarding in vhost-PMD side until we can't see performance increase anymore.
Besides, I just did a quick glance at the Tx implementation, it still assumes the descs will be written back in order by device. You can find more details from my comments on that patch.
Thanks
Quoted 96 lines
bytes, 0.05% acceptable loss. Test setup is described as in
http://dpdk.org/doc/guides/howto/pvp_reference_benchmark.htmlPacket generator:
MoonGen
Intel(R) Xeon(R) CPU E5-2665 0 @ 2.40GHz
Intel X710 NIC
RHEL 7.4Device under test:
Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
Intel X710 NIC
RHEL 7.4VM on DuT: RHEL7.4
I plan to do more performance test with bigger frame sizes.
changes from
v5->v6:
* fixVIRTQUEUE_DUMPmacro
* rework mergeable rx buffer path, support out of order (not sure if I need a .next field to support chains)
* move wmb invirtio_receive_pkts_packed()(Gavin)
* rename to virtio_init_split/_packed (Maxime)
* add support for ctrl virtqueues (Tiwei, thx Max for fixing)
* rework tx path to supportupdate_packet_statsandvirtqueue_xmit_offload, TODO: merge with split-ring code to avoid a lot of duplicate code
* remove unnecessary check for avoiding to callVIRTQUEUE_DUMP(Maxime)changes from
v4->v5:
* fixVIRTQUEUE_DUMPmacro
* fix wrap counter logic in transmit and receive functionschanges from
v3->v4:
* added helpers to increment index and set available/used flags
* driver keeps track of number of descriptors used
* change logic inset_rxtx_funcs()
* add patch for ctrl virtqueue with support for packed virtqueues
* renamevirtio-1.1.htovirtio-packed.h
* fix wrongsizeof()in "vhost: vring address setup for packed queues"
* fix coding style of function definition in "net/virtio: add packed virtqueue helpers"
* fix padding invring_size()
* move patches to enable packed virtqueues end of series
* v4 has two open problems: I'm sending it out anyway for feedback/help:
* whenVIRTIO_NET_F_MRG_RXBUFenabled only 128 packets are send in guest, i.e. when ring is full for the first time. I suspect a bug in setting the avail/used flagschanges from
v2->v3:
* implement event suppression
* add code do dump packed virtqueues
* don't use assert in vhost code
* rename virtio-user parameter to packed-vq
* support rxvf flushchanges from
v1->v2:
* don't useVIRTQ_DESC_F_NEXTin used descriptors (Jason)
* norte_panice()in guest triggerable code (Maxime)
* use unlikely when checking for vq (Maxime)
* rename everything from _1_1 to_packed(Yuanhan)
* add two more patches to implement mergeable receive buffers*** BLURB HERE ***
Jens Freimann (10):
net/virtio: vring init for packed queues
net/virtio: add packed virtqueue defines
net/virtio: add packed virtqueue helpers
net/virtio: flush packed receive virtqueues
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 support for mergeable buffers with packed virtqueues net/virtio: add virtio send command packed queue support net/virtio: enable packed virtqueues by defaultYuanhan Liu (1):
net/virtio-user: add option to use packed queuesdrivers/net/virtio/virtio_ethdev.c | 135 ++++- drivers/net/virtio/virtio_ethdev.h | 5 + drivers/net/virtio/virtio_pci.h | 8 + drivers/net/virtio/virtio_ring.h | 96 +++- drivers/net/virtio/virtio_rxtx.c | 490 +++++++++++++++++- .../net/virtio/virtio_user/virtio_user_dev.c | 10 +- .../net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/net/virtio/virtio_user_ethdev.c | 14 +- drivers/net/virtio/virtqueue.c | 21 + drivers/net/virtio/virtqueue.h | 50 +- 10 files changed, 796 insertions(+), 35 deletions(-)Signature · 1 line
2.17.1
Quoted 19 lines · Tiwei Bie
Quoted 18 lines · Jens Freimann
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.pdfA 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 buffer.
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.
The idea behind this is to 1. improve performance by avoiding cache misses and 2. be easier for devices to implement.
Quoted 6 lines
Quoted 2 lines
Regarding performance: with these patches I get 21.13 Mpps on my system as compared to 18.8 Mpps with the virtio 1.0 code. Packet size was 64
Did you enable multiple-queue and use multiple cores on vhost side? If not, I guess the above performance gain is the gain in vhost side instead of virtio side.
I tested several variations back then and they all looked very good. But code change a lot meanwhile and I need to do more benchmarking in any case.
Quoted 9 lines
If you use more cores on vhost side or virtio side, will you see any performance changes?
Did you do any performance test with the kernel vhost-net backend (with zero-copy enabled and disabled)? I think we also need some performance data for these two cases. And it can help us to make sure that it works with the kernel backends.
I tested against vhost-kernel but only to test functionality not to benchmark.
Quoted 15 lines
And for the "virtio-PMD + vhost-PMD" test cases, I think we need below performance data:
#1. The maximum 1 core performance of virtio PMD when using split ring. #2. The maximum 1 core performance of virtio PMD when using packed ring. #3. The maximum 1 core performance of vhost PMD when using split ring. #4. The maximum 1 core performance of vhost PMD when using packed ring.
And then we can have a clear understanding of the performance gain in DPDK with packed ring.
And FYI, the maximum 1 core performance of virtio PMD can be got in below steps:
Quoted 7 lines
1. Launch vhost-PMD with multiple queues, and use multiple CPU cores for forwarding.
2. Launch virtio-PMD with multiple queues and use 1 CPU core for forwarding.
3. Repeat above two steps with adding more CPU cores for forwarding in vhost-PMD side until we can't see performance increase anymore.
Thanks for the suggestions, I'll come back with more numbers.
Quoted 5 lines
Besides, I just did a quick glance at the Tx implementation, it still assumes the descs will be written back in order by device. You can find more details from my comments on that patch.
Saw it and noted. I had hoped to be able to avoid the list but I see no way around it now.
Thanks for your review Tiwei!
regards,
Jens