implement packed virtqueues
v3 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
It does not implement yet indirect descriptors and checksum offloading.
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.
This patch series is based on a prototype implemented by Yuanhan Liu and Tiwei Bie.
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
regards,
Jens
Jens Freimann (17):
net/virtio: by default disable packed virtqueues net/virtio: vring init for packed queues
net/virtio: add virtio 1.1 defines
net/virtio: add packed virtqueue helpers
net/virtio: dump packed virtqueue data
net/virtio: implement transmit path for packed queues
vhost: disable packed virtqueues by default
vhost: turn of indirect descriptors for packed virtqueues
vhost: add virtio 1.1 defines
vhost: add helpers for packed virtqueues
vhost: dequeue for packed queues
vhost: packed queue enqueue path
net/virtio: disable ctrl virtqueue for packed rings net/virtio: add support for mergeable buffers with packed virtqueues
vhost: support mergeable rx buffers with packed queues net/virtio: add support for event suppression
vhost: add event suppression for packed queues
Yuanhan Liu (4):
net/virtio-user: add option to use packed queues net/virtio: implement receive path for packed queues
vhost: vring address setup for packed queues
vhost: enable packed virtqueues
config/common_base | 2 + drivers/net/virtio/virtio_ethdev.c | 51 ++- drivers/net/virtio/virtio_ethdev.h | 7 +- drivers/net/virtio/virtio_pci.h | 8 + drivers/net/virtio/virtio_ring.h | 91 +++- drivers/net/virtio/virtio_rxtx.c | 359 +++++++++++++++- drivers/net/virtio/virtio_user/virtio_user_dev.c | 12 +- drivers/net/virtio/virtio_user/virtio_user_dev.h | 3 +- drivers/net/virtio/virtio_user_ethdev.c | 15 +- drivers/net/virtio/virtqueue.c | 10 + drivers/net/virtio/virtqueue.h | 91 +++- lib/librte_vhost/socket.c | 5 + lib/librte_vhost/vhost.c | 16 +- lib/librte_vhost/vhost.h | 69 ++- lib/librte_vhost/vhost_user.c | 40 +- lib/librte_vhost/virtio-1.1.h | 62 +++ lib/librte_vhost/virtio_net.c | 507 +++++++++++++++++++++-- 17 files changed, 1271 insertions(+), 77 deletions(-) create mode 100644 lib/librte_vhost/virtio-1.1.h
Signature · 1 line
2.14.3
PATCH v3 1/21 net/virtio: by default disable packed virtqueues
Disable packed virtqueues for now and make it dependend on a build-time config option. This can be reverted once we have missing features like indirect descriptors implemented.
--- config/common_base | 1 + drivers/net/virtio/virtio_ethdev.c | 4 ++++ 2 files changed, 5 insertions(+)
config/common_base +1 -0
@@ -346,6 +346,7 @@ CONFIG_RTE_LIBRTE_VIRTIO_PMD=y CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n +CONFIG_RTE_LIBRTE_VIRTIO_PQ=n # # Compile virtio device emulation inside virtio PMD driver
drivers/net/virtio/virtio_ethdev.c +4 -0
@@ -1149,6 +1149,10 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ULL <<VIRTIO_NET_F_MTU ); } +#ifndef RTE_LIBRTE_VIRTIO_PQ + req_features &= ~(1ull <<VIRTIO_F_RING_PACKED ); +#endif +/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Signature · 1 line
2.14.3
PATCH v3 2/21 net/virtio: vring init for packed queues
In reply to Jens FreimannAdd and initialize descriptor data structures.
--- drivers/net/virtio/virtio_ethdev.c | 22 +++++++++------- drivers/net/virtio/virtio_pci.h | 8 ++++++ drivers/net/virtio/virtio_ring.h | 53 ++++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 10 +++++++ 4 files changed, 78 insertions(+), 15 deletions(-)
drivers/net/virtio/virtio_ethdev.c +12 -10
@@ -298,19 +298,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 (vr->desc, size); + }/* * Disable device(host) interrupting guest
@@ -385,7 +387,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);
drivers/net/virtio/virtio_pci.h +8 -0
@@ -112,6 +112,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
@@ -304,6 +306,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 +48 -5
85 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +10 -0
@@ -245,6 +245,16 @@ 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)
Signature · 1 line
2.14.3
PATCH v3 3/21 net/virtio: add virtio 1.1 defines
In reply to Jens Freimann--- drivers/net/virtio/virtio_ring.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_ring.h +4 -1
@@ -16,7 +16,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 (1ULL << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (1ULL << 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.14.3
PATCH v3 4/21 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 | 33 +++++++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.c | 10 ++++++++++ 2 files changed, 43 insertions(+)
drivers/net/virtio/virtio_ring.h +33 -0
@@ -78,6 +78,7 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter;union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;
@@ -92,6 +93,38 @@ struct vring { }; }; +static inline void toggle_wrap_counter (struct vring *vr) +{ + vr->avail_wrap_counter ^=1 ; +} + +static inline void _set_desc_avail (struct vring_desc_packed *desc, +int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter) { + flags |=VRING_DESC_F_AVAIL ; + flags &= ~VRING_DESC_F_USED ; + }else { + flags &= ~VRING_DESC_F_AVAIL ; + flags |=VRING_DESC_F_USED ; + } + + desc->flags = flags; +} + +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) +{ +return !(desc->flags &VRING_DESC_F_AVAIL ) == !(desc->flags &VRING_DESC_F_USED ); +} +/* 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.c +10 -0
@@ -58,6 +58,7 @@ 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;
@@ -65,6 +66,15 @@ virtqueue_rxvq_flush(struct virtqueue *vq)uint16_t used_idx, desc_idx;uint16_t nb_used, i; +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); +while (desc_is_used (&descs[i])) { +rte_pktmbuf_free (vq->sw_ring[i]); + vq->vq_free_cnt++; + } +return ; + } + nb_used =VIRTQUEUE_NUSED (vq);for (i =0 ; i < nb_used; i++) {
Signature · 1 line
2.14.3
PATCH v3 5/21 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 | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/virtio/virtqueue.h +7 -0
@@ -360,6 +360,13 @@ virtqueue_notify(struct virtqueue *vq)#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTQUEUE_DUMP (vq) do { \ + if (vtpci_packed_queue((vq)->hw)) { \ + PMD_INIT_LOG(DEBUG, \ + "VQ: - size=%d; free=%d; last_used_idx=%d;" \ + (vq)->vq_nentries, (vq)->vq_free_cnt, nused); \ + break; \ + } \ + if (vtpci_packed_queue((vq)->hw)) break; \ uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t)(used_idx - (vq)->vq_used_cons_idx); \
Signature · 1 line
2.14.3
PATCH v3 6/21 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 | 12 ++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 3 ++- drivers/net/virtio/virtio_user_ethdev.c | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +10 -2
@@ -314,11 +314,13 @@ virtio_user_dev_setup(struct virtio_user_dev *dev) 1ULL << VIRTIO_NET_F_GUEST_CSUM | \ 1ULL << VIRTIO_NET_F_GUEST_TSO4 | \ 1ULL << VIRTIO_NET_F_GUEST_TSO6 | \ - 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 cq,int queue_size,const char *mac,char **ifname, +int packed_vq) {snprintf (dev->path,PATH_MAX ,"%s" , path); dev->max_queue_pairs = queues;
@@ -347,6 +349,12 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,PMD_INIT_LOG (ERR ,"get_features failed: %s" ,strerror (errno));return -1 ; } + +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 );
drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -1
@@ -42,7 +42,8 @@ int is_vhost_user_by_type(const char *path);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 cq,int queue_size,const char *mac,char **ifname, +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);#endif
drivers/net/virtio/virtio_user_ethdev.c +14 -1
@@ -278,6 +278,8 @@ static const char *valid_args[] = {VIRTIO_USER_ARG_QUEUE_SIZE , #define VIRTIO_USER_ARG_INTERFACE_NAME "iface"VIRTIO_USER_ARG_INTERFACE_NAME , +#define VIRTIO_USER_ARG_PACKED_VQ "packed_vq" +VIRTIO_USER_ARG_PACKED_VQ , NULL };
@@ -382,6 +384,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) {
@@ -456,6 +459,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;
@@ -477,7 +489,8 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) hw = eth_dev->data->dev_private;if (virtio_user_dev_init (hw->virtio_user_dev, path, queues, cq, - queue_size, mac_addr, &ifname) <0 ) { + queue_size, mac_addr, &ifname, + 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.14.3
PATCH v3 7/21 net/virtio: implement transmit path for packed queues
In reply to Jens FreimannThis implements the transmit path for devices with support for Virtio 1.1.
Add the feature bit for Virtio 1.1 and enable code to add buffers to vring and mark descriptors as available.
This is based on a patch by Yuanhan Liu.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++- drivers/net/virtio/virtio_ethdev.h | 3 ++ drivers/net/virtio/virtio_rxtx.c | 102 ++++++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +7 -1
@@ -383,6 +383,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
@@ -1328,7 +1330,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_simple_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_simple_tx) {PMD_INIT_LOG (INFO ,"virtio: using simple Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;
drivers/net/virtio/virtio_ethdev.h +3 -0
@@ -36,6 +36,7 @@1ULL <<VIRTIO_NET_F_GUEST_ANNOUNCE | \1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \ +1ULL <<VIRTIO_F_RING_PACKED | \ 1ULL << VIRTIO_F_IOMMU_PLATFORM) #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \
@@ -85,6 +86,8 @@ uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,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_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts);
drivers/net/virtio/virtio_rxtx.c +101 -1
120 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v3 8/21 net/virtio: implement receive path for packed queues
In reply to Jens FreimannFrom: Yuanhan Liu <[email protected]>
Implement the receive part here. No support for mergeable buffers yet.
--- drivers/net/virtio/virtio_ethdev.c | 10 ++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 137 ++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 3 deletions(-)
drivers/net/virtio/virtio_ethdev.c +8 -2
@@ -1315,10 +1315,15 @@ 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) &&vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + 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; + }else if (vtpci_packed_queue (hw)) { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; }else if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { PMD_INIT_LOG(INFO, "virtio: using mergeable buffer Rx path on port %u",
@@ -1474,7 +1479,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
@@ -80,6 +80,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 +136 -1
164 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v3 9/21 vhost: disable packed virtqueues by default
In reply to Jens Freimann--- config/common_base | 1 + lib/librte_vhost/socket.c | 4 ++++ 2 files changed, 5 insertions(+)
config/common_base +1 -0
@@ -783,6 +783,7 @@ CONFIG_RTE_LIBRTE_PDUMP=y CONFIG_RTE_LIBRTE_VHOST=n CONFIG_RTE_LIBRTE_VHOST_NUMA=n CONFIG_RTE_LIBRTE_VHOST_DEBUG=n +CONFIG_RTE_LIBRTE_VHOST_PQ=n # # Compile vhost PMD
lib/librte_vhost/socket.c +4 -0
@@ -850,6 +850,10 @@ rte_vhost_driver_register(const char *path, uint64_t flags) vsocket->features &= ~(1ULL <<VIRTIO_F_IOMMU_PLATFORM ); } +#ifndef RTE_LIBRTE_VHOST_PQ + vsocket->features &= ~(1ULL <<VIRTIO_F_RING_PACKED ); +#endif +if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) { vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {
Signature · 1 line
2.14.3
PATCH v3 10/21 vhost: turn of indirect descriptors for packed virtqueues
In reply to Jens Freimann--- lib/librte_vhost/socket.c | 1 + 1 file changed, 1 insertion(+)
lib/librte_vhost/socket.c +1 -0
@@ -852,6 +852,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)#ifndef RTE_LIBRTE_VHOST_PQ vsocket->features &= ~(1ULL <<VIRTIO_F_RING_PACKED ); + vsocket->features &= ~(1ULL <<VIRTIO_RING_F_INDIRECT_DESC );#endif if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) {
Signature · 1 line
2.14.3
PATCH v3 11/21 vhost: add virtio 1.1 defines
In reply to Jens FreimannThis should actually be in the kernel header file, but it isn't yet. For now let's use our own headers.
--- lib/librte_vhost/vhost.h | 4 ++++ lib/librte_vhost/virtio-1.1.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/librte_vhost/virtio-1.1.h
lib/librte_vhost/vhost.h +4 -0
@@ -177,6 +177,10 @@ struct vhost_msg {#ifndef VIRTIO_F_VERSION_1 #define VIRTIO_F_VERSION_1 32#endif +#ifndef VIRTIO_F_RING_PACKED +#define VIRTIO_F_RING_PACKED 34 +#endif +#define VHOST_USER_F_PROTOCOL_FEATURES 30/* Features supported by this builtin vhost-user net driver. */ #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \
lib/librte_vhost/virtio-1.1.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __VIRTIO_PACKED_H +#define __VIRTIO_PACKED_H + +#define VRING_DESC_F_NEXT 1 +#define VRING_DESC_F_WRITE 2 +#define VRING_DESC_F_INDIRECT 4 + +#define VRING_DESC_F_AVAIL (1ULL << 7) +#define VRING_DESC_F_USED (1ULL << 15) + +struct vring_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +uint16_t flags; +}; + +#endif /* __VIRTIO_PACKED_H */
Signature · 1 line
2.14.3
PATCH v3 12/21 vhost: vring address setup for packed queues
In reply to Jens FreimannFrom: Yuanhan Liu <[email protected]>
Add code to set up packed queues when enabled.
--- lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/vhost_user.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost.h +1 -0
@@ -74,6 +74,7 @@ struct batch_copy_elem {*/ struct vhost_virtqueue {struct vring_desc *desc; +struct vring_desc_packed *desc_packed;struct vring_avail *avail;struct vring_used *used;uint32_t size;
lib/librte_vhost/vhost_user.c +20 -1
@@ -469,6 +469,23 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)struct vhost_virtqueue *vq = dev->virtqueue[vq_index];struct vhost_vring_addr *addr = &vq->ring_addrs; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + vq->desc_packed = (struct vring_desc_packed *)ring_addr_to_vva + (dev, vq, addr->desc_user_addr,sizeof (vq->desc_packed)); + vq->desc =NULL ; + vq->avail =NULL ; + vq->used =NULL ; + vq->log_guest_addr =0 ; + +if (vq->last_used_idx !=0 ) { +RTE_LOG (WARNING ,VHOST_CONFIG , +"last_used_idx (%u) not 0\n" , + vq->last_used_idx); + vq->last_used_idx =0 ; + } +return dev; + } +/* The addresses are converted from QEMU virtual to Vhost virtual. */ if (vq->desc && vq->avail && vq->used)return dev;
@@ -481,6 +498,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) dev->vid);return dev; } + vq->desc_packed =NULL ; dev =numa_realloc (dev, vq_index); vq = dev->virtqueue[vq_index];
@@ -853,7 +871,8 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)static int vq_is_ready (struct vhost_virtqueue *vq) { -return vq && vq->desc && vq->avail && vq->used && +return vq && + (vq->desc_packed || (vq->desc && vq->avail && vq->used)) && vq->kickfd !=VIRTIO_UNINITIALIZED_EVENTFD && vq->callfd !=VIRTIO_UNINITIALIZED_EVENTFD ; }
Signature · 1 line
2.14.3
PATCH v3 13/21 vhost: add helpers for packed virtqueues
In reply to Jens FreimannAdd some helper functions to set/check descriptor flags and toggle the used wrap counter.
--- lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
lib/librte_vhost/virtio-1.1.h +44 -0
@@ -15,4 +15,48 @@ struct vring_desc_packed {uint16_t flags; }; +static inline void +toggle_wrap_counter (struct vhost_virtqueue *vq) +{ + vq->used_wrap_counter ^=1 ; +} + +static inline int +desc_is_avail (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +if (vq->used_wrap_counter ==1 ) { +if ((desc->flags &VRING_DESC_F_AVAIL ) && + !(desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +if (vq->used_wrap_counter ==0 ) { +if (!(desc->flags &VRING_DESC_F_AVAIL ) && + (desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +return 0 ; +} + +static inline void +_set_desc_used (struct vring_desc_packed *desc,int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter ==1 ) { + flags |=VRING_DESC_F_USED ; + flags |=VRING_DESC_F_AVAIL ; + }else { + flags &= ~VRING_DESC_F_USED ; + flags &= ~VRING_DESC_F_AVAIL ; + } + + desc->flags = flags; +} + +static inline void +set_desc_used (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +_set_desc_used (desc, vq->used_wrap_counter); +} +#endif /* __VIRTIO_PACKED_H */
Signature · 1 line
2.14.3
PATCH v3 14/21 vhost: dequeue for packed queues
In reply to Jens FreimannImplement code to dequeue and process descriptors from the vring if VIRTIO_F_RING_PACKED is enabled.
Check if descriptor was made available by driver by looking at VIRTIO_F_DESC_AVAIL flag in descriptor. If so dequeue and set the used flag VIRTIO_F_DESC_USED to the current value of the used wrap counter.
Used ring wrap counter needs to be toggled when last descriptor is written out. This allows the host/guest to detect new descriptors even after the ring has wrapped.
--- lib/librte_vhost/vhost.c | 1 + lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/virtio_net.c | 228 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+)
lib/librte_vhost/vhost.c +1 -0
@@ -185,6 +185,7 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->kickfd =VIRTIO_UNINITIALIZED_EVENTFD ; vq->callfd =VIRTIO_UNINITIALIZED_EVENTFD ; + vq->used_wrap_counter =1 ;vhost_user_iotlb_init (dev, vring_idx);/* Backends are set to -1 indicating an inactive device. */
lib/librte_vhost/vhost.h +1 -0
@@ -112,6 +112,7 @@ struct vhost_virtqueue {struct batch_copy_elem *batch_copy_elems;uint16_t batch_copy_nb_elems; +uint16_t used_wrap_counter;rte_rwlock_t iotlb_lock;rte_rwlock_t iotlb_pending_lock;
lib/librte_vhost/virtio_net.c +228 -0
240 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v3 15/21 vhost: packed queue enqueue path
In reply to Jens FreimannImplement enqueue of packets to the receive virtqueue.
Set descriptor flag VIRTQ_DESC_F_USED and toggle used wrap counter if last descriptor in ring is used. Perform a write memory barrier before flags are written to descriptor.
Chained descriptors are not supported with this patch.
--- lib/librte_vhost/virtio_net.c | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
lib/librte_vhost/virtio_net.c +129 -0
@@ -695,6 +695,135 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return pkt_idx; } +static inline uint32_t __attribute__((always_inline)) +vhost_enqueue_burst_packed (struct virtio_net *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +struct vhost_virtqueue *vq; +struct vring_desc_packed *descs; +uint16_t idx; +uint16_t mask; +uint16_t i; + + vq = dev->virtqueue[queue_id]; + +rte_spinlock_lock (&vq->access_lock); + +if (unlikely (vq->enabled ==0 )) { + i =0 ; + goto out_access_unlock; + } + +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + + descs = vq->desc_packed; + mask = vq->size -1 ; + +for (i =0 ; i < count; i++) { +uint32_t desc_avail, desc_offset; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len; +struct vring_desc_packed *desc; +uint64_t desc_addr; +struct virtio_net_hdr_mrg_rxbuf *hdr; +struct rte_mbuf *m = pkts[i]; + +/* XXX: there is an assumption that no desc will be chained */ + idx = vq->last_used_idx & mask; + desc = &descs[idx]; + +if (!desc_is_avail (vq, desc)) +break ; +rte_smp_rmb (); + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RW ); +/* +* Checking of 'desc_addr' placed outside of 'unlikely' macro +* to avoid performance issue with some versions of gcc (4.8.4 +* and 5.3.0) which otherwise stores offset on the stack instead +* of in a register. +*/ +if (unlikely (desc->len < dev->vhost_hlen) || !desc_addr) +break ; + + hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t )desc_addr; +virtio_enqueue_offload (m, &hdr->hdr); +vhost_log_write (dev, desc->addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); + + desc_offset = dev->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; + + mbuf_avail =rte_pktmbuf_data_len (m); + mbuf_offset =0 ; +while (mbuf_avail !=0 || m->next !=NULL ) { +/* done with current mbuf, fetch next */ +if (mbuf_avail ==0 ) { + m = m->next; + + mbuf_offset =0 ; + mbuf_avail =rte_pktmbuf_data_len (m); + } + +/* done with current desc buf, fetch next */ +if (desc_avail ==0 ) { +if ((desc->flags &VRING_DESC_F_NEXT ) ==0 ) { +/* Room in vring buffer is not enough */ + goto out; + } + + idx = (idx+1 ) & (vq->size -1 ); + desc = &descs[idx]; +if (unlikely (!desc_is_avail (vq, desc))) + goto out ; + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc), +VHOST_ACCESS_RW ); +if (unlikely (!desc_addr)) + goto out; + + desc_offset =0 ; + desc_avail = desc->len; + } + + cpy_len =RTE_MIN (desc_avail, mbuf_avail); +rte_memcpy ((void *)((uintptr_t )(desc_addr + desc_offset)), + rte_pktmbuf_mtod_offset(m, void *, mbuf_offset), + cpy_len); +vhost_log_write (dev, desc->addr + desc_offset, cpy_len); +PRINT_PACKET (dev, (uintptr_t )(desc_addr + desc_offset), + cpy_len,0 ); + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + desc_avail -= cpy_len; + desc_offset += cpy_len; + } + + descs[idx].len = pkts[i]->pkt_len + dev->vhost_hlen; +rte_smp_wmb (); +set_desc_used (vq, desc); + + vq->last_used_idx++; +if ((vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + } + +out: +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_unlock (vq); + +out_access_unlock: +rte_spinlock_unlock (&vq->access_lock); + + count = i; + +return count; +} +uint16_t rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count)
Signature · 1 line
2.14.3
PATCH v3 16/21 vhost: enable packed virtqueues
In reply to Jens FreimannFrom: Yuanhan Liu <[email protected]>
This patch enables the code do enqueue and dequeue packed to/from a packed virtqueue. Add feature bit for packed virtqueues as defined in Virtio 1.1 draft.
--- lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/virtio_net.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost.h +1 -0
@@ -192,6 +192,7 @@ struct vhost_msg { (1ULL <<VIRTIO_NET_F_GUEST_ANNOUNCE ) | \ (1ULL <<VIRTIO_NET_F_MQ ) | \ (1ULL <<VIRTIO_F_VERSION_1 ) | \ + (1ULL <<VIRTIO_F_RING_PACKED ) | \ (1ULL <<VHOST_F_LOG_ALL ) | \ (1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ) | \ (1ULL << VIRTIO_NET_F_GSO) | \
lib/librte_vhost/virtio_net.c +6 -1
@@ -840,7 +840,9 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,return 0 ; } -if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_enqueue_burst_packed (dev, queue_id, pkts, count); +else if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF ))return virtio_dev_merge_rx (dev, queue_id, pkts, count);else return virtio_dev_rx (dev, queue_id, pkts, count);
@@ -1513,6 +1515,9 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,if (unlikely (vq->enabled ==0 )) goto out_access_unlock; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_dequeue_burst_packed (dev, vq, mbuf_pool, pkts, count); + vq->batch_copy_nb_elems =0 ;if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM ))
Signature · 1 line
2.14.3
PATCH v3 17/21 net/virtio: disable ctrl virtqueue for packed rings
In reply to Jens Freimann--- drivers/net/virtio/virtio_ethdev.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/virtio/virtio_ethdev.c +7 -0
@@ -1157,6 +1157,13 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ull <<VIRTIO_F_RING_PACKED );#endif +if (req_features & (1ULL <<VIRTIO_F_RING_PACKED )) { + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_MAC_ADDR ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VQ ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_RX ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VLAN ); + } +/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Signature · 1 line
2.14.3
PATCH v3 18/21 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 | 10 ++-- drivers/net/virtio/virtio_rxtx.c | 107 +++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 1 + 3 files changed, 104 insertions(+), 14 deletions(-)
drivers/net/virtio/virtio_ethdev.c +5 -5
@@ -1322,15 +1322,15 @@ 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) &&vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; - }else if (hw->use_simple_rx) { +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 (vtpci_packed_queue (hw)) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; +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 (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { PMD_INIT_LOG(INFO, "virtio: using mergeable buffer Rx path on port %u",
drivers/net/virtio/virtio_rxtx.c +98 -9
160 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.14.3
PATCH v3 19/21 vhost: support mergeable rx buffers with packed queues
In reply to Jens FreimannThis implements support for mergeable receive buffers in vhost when using packed virtqueues. The difference to split virtqueues is not big, it differs mostly where descriptor flags are touched and virtio features are checked.
--- lib/librte_vhost/vhost.c | 2 + lib/librte_vhost/virtio_net.c | 160 +++++++++++++++++++++++++++++++++--------- 2 files changed, 127 insertions(+), 35 deletions(-)
lib/librte_vhost/vhost.c +2 -0
@@ -580,6 +580,8 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)if (dev ==NULL )return -1 ; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return -1 ;if (enable) { RTE_LOG(ERR, VHOST_CONFIG,
lib/librte_vhost/virtio_net.c +125 -35
268 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v3 20/21 net/virtio: add support for event suppression
In reply to Jens Freimann--- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_ethdev.h | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++++- drivers/net/virtio/virtqueue.h | 73 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -1
@@ -727,7 +727,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];struct virtqueue *vq = rxvq->vq; -virtqueue_enable_intr (vq); +virtqueue_enable_intr (vq,0 ,0 );return 0 ; }
drivers/net/virtio/virtio_ethdev.h +1 -1
@@ -37,7 +37,7 @@ 1u << VIRTIO_RING_F_INDIRECT_DESC | \ 1ULL << VIRTIO_F_VERSION_1 | \ 1ULL << VIRTIO_F_RING_PACKED | \ - 1ULL << VIRTIO_F_IOMMU_PLATFORM) + 1ULL << VIRTIO_RING_F_EVENT_IDX)#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \
drivers/net/virtio/virtio_rxtx.c +14 -1
@@ -127,6 +127,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,rte_smp_wmb ();_set_desc_avail (&desc[head_idx], wrap_counter); +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } } txvq->stats.packets += i;
@@ -998,6 +1002,10 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, } rxvq->stats.packets += nb_rx; +if (nb_rx >0 &&unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } vq->vq_used_cons_idx = used_idx;
@@ -1276,8 +1284,13 @@ virtio_recv_mergeable_pkts(void *rx_queue, rxvq->stats.packets += nb_rx; -if (vtpci_packed_queue (vq->hw)) +if (vtpci_packed_queue (vq->hw)) { +if (unlikely (virtqueue_kick_prepare (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + }return nb_rx; + }/* Allocate new mbuf for the used descriptor */ error =ENOSPC ;
drivers/net/virtio/virtqueue.h +70 -3
104 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v3 21/21 vhost: add event suppression for packed queues
In reply to Jens Freimann--- lib/librte_vhost/vhost.c | 17 +++++++++--- lib/librte_vhost/vhost.h | 62 ++++++++++++++++++++++++++++++++++++------- lib/librte_vhost/vhost_user.c | 19 +++++++++++++ lib/librte_vhost/virtio_net.c | 1 + 4 files changed, 86 insertions(+), 13 deletions(-)
lib/librte_vhost/vhost.c +14 -3
@@ -577,11 +577,21 @@ int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) { struct virtio_net *dev = get_device(vid); +struct vhost_virtqueue *vq;if (dev ==NULL )return -1 ; -if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) -return -1 ; + + vq = dev->virtqueue[queue_id]; +if (!vq->enabled) +return 0 ; + +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { +if (!enable) { + vq->driver_event->desc_event_flags |=RING_EVENT_FLAGS_DISABLE ; + }else + vq->driver_event->desc_event_flags |=RING_EVENT_FLAGS_ENABLE ; + }if (enable) { RTE_LOG(ERR, VHOST_CONFIG,
@@ -589,7 +599,8 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)return -1 ; } - dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ; +if (!(dev->features & (1ULL <<VIRTIO_F_RING_PACKED ))) + dev->virtqueue[queue_id]->used->flags =VRING_USED_F_NO_NOTIFY ;return 0 ; }
lib/librte_vhost/vhost.h +52 -10
101 lines not on this page · raw message
lib/librte_vhost/vhost_user.c +19 -0
@@ -39,6 +39,7 @@#include "iotlb.h" #include "vhost.h" #include "vhost_user.h" +#include "virtio-1.1.h" #define VIRTIO_MIN_MTU 68#define VIRTIO_MAX_MTU 65535
@@ -476,6 +477,24 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) vq->avail =NULL ; vq->used =NULL ; vq->log_guest_addr =0 ; + vq->driver_event = (struct vring_packed_desc_event *)(uintptr_t )ring_addr_to_vva (dev, + vq, addr->avail_user_addr,sizeof (struct vring_packed_desc_event )); +if (vq->driver_event ==0 ) { +RTE_LOG (DEBUG ,VHOST_CONFIG , +"(%d) failed to find driver area address.\n" , + dev->vid); +return dev; + } + + vq->device_event = (struct vring_packed_desc_event *)(uintptr_t )ring_addr_to_vva (dev, + vq, addr->used_user_addr,sizeof (struct vring_packed_desc_event )); +if (vq->device_event ==0 ) { +RTE_LOG (DEBUG ,VHOST_CONFIG , +"(%d) failed to find device area address.\n" , + dev->vid); +return dev; + } +if (vq->last_used_idx !=0 ) { RTE_LOG(WARNING, VHOST_CONFIG,
lib/librte_vhost/virtio_net.c +1 -0
@@ -770,6 +770,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if ((i & (vq->size -1 )) ==0 )toggle_wrap_counter (vq);set_desc_used (vq, &descs[i & (vq->size -1 )]); +vhost_vring_call (dev, vq); } }
Signature · 1 line
2.14.3
Re: [PATCH v3 01/21] net/virtio: by default disable packed virtqueues
In reply to Jens FreimannQuoted 27 lines · Jens Freimann
Disable packed virtqueues for now and make it dependend on a build-time config option. This can be reverted once we have missing features like indirect descriptors implemented.
Signed-off-by Jens Freimann <[email protected]>--- config/common_base | 1 + drivers/net/virtio/virtio_ethdev.c | 4 ++++ 2 files changed, 5 insertions(+)config/common_base +1
-0@@ -346,6 +346,7 @@ CONFIG_RTE_LIBRTE_VIRTIO_PMD=y CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n +CONFIG_RTE_LIBRTE_VIRTIO_PQ=n # # Compile virtio device emulation inside virtio PMD driverdrivers/net/virtio/virtio_ethdev.c +0
-0
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) · line 1153
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +2
-0@@ -1149,6 +1149,10 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ULL <<VIRTIO_NET_F_MTU ); } +#ifndef RTE_LIBRTE_VIRTIO_PQ + req_features &= ~(1ull <<VIRTIO_F_RING_PACKED );
Is VIRTIO_F_RING_PACKED already declared here?
I don't think it is, so would break build when bisecting.
Maybe the thing to do is to not have VIRTIO_F_RING_PACKED in the feature set by default. And when RTE_LIBRTE_VIRTIO_PQ is set, enable it and explicitly disable indirect descs.
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +2
-0+#endif +/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Re: [PATCH v3 02/21] net/virtio: vring init for packed queues
In reply to Jens FreimannQuoted 85 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 22 +++++++++------- drivers/net/virtio/virtio_pci.h | 8 ++++++ drivers/net/virtio/virtio_ring.h | 53 ++++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 10 +++++++ 4 files changed, 78 insertions(+), 15 deletions(-)drivers/net/virtio/virtio_ethdev.c +12
-10@@ -298,19 +298,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 (vr->desc, size); + }/* * Disable device(host) interrupting guest @@ -385,7 +387,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);drivers/net/virtio/virtio_pci.h +8
-0@@ -112,6 +112,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 @@ -304,6 +306,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 +0
-0
drivers/net/virtio/virtio_ring.h line 12
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -9,6 +9,7 @@#include <rte_common.h> +
Remove new line
Quoted 32 lines
drivers/net/virtio/virtio_ring.h +20
-3/* This marks a buffer as continuing via the next field. */ #define VRING_DESC_F_NEXT 1/* This marks a buffer as write-only (otherwise read-only). */ @@ -54,11 +55,38 @@ 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_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +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 {unsigned int num; -struct vring_desc *desc; -struct vring_avail *avail; -struct vring_used *used; +union { +struct vring_desc_packed *desc_packed;
drivers/net/virtio/virtio_ring.h struct vring_used { · line 89
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +10
-0+struct vring_desc *desc; + }; +union { +struct vring_avail *avail; +struct vring_packed_desc_event *driver_event; + }; +union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + };
Not a must, but I wonder if it wouldn't be cleaner to have a unique union of two structs, one for packed rings, and one for the legacy. I may be wrong, though.
Quoted 64 lines
drivers/net/virtio/virtio_ring.h +17
-2};/* The standard layout for the ring is a continuous chunk of memory which @@ -95,10 +123,16 @@ 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_desc_packed ); + size +=2 *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);@@ -108,10 +142,19 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, +vring_init (struct virtio_hw *hw,struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) { vr->num = num; +if (vtpci_packed_queue (hw)) { + vr->desc_packed = (struct vring_desc_packed *)p; + vr->driver_event = (struct vring_packed_desc_event *) (p + + num *sizeof (struct vring_desc_packed )); + vr->device_event = (struct vring_packed_desc_event *) (vr->driver_event + +sizeof (struct vring_packed_desc_event )); +return ; + } + vr->desc = (struct vring_desc *) p; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc ));drivers/net/virtio/virtqueue.h +10
-0@@ -245,6 +245,16 @@ 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)
Re: [PATCH v3 03/21] net/virtio: add virtio 1.1 defines
In reply to Jens FreimannQuoted 12 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/virtio/virtio_ring.h +0
-0@@ -16,7 +16,10 @@#define VRING_DESC_F_WRITE 2
drivers/net/virtio/virtio_ring.h line 25
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +4
-1/* 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 (1ULL << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (1ULL << 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. */
Thanks,
Maxime
Re: [PATCH v3 01/21] net/virtio: by default disable packed virtqueues
In reply to Maxime CoquelinQuoted 27 lines · Maxime Coquelin
Quoted 24 lines · Jens Freimann
Disable packed virtqueues for now and make it dependend on a build-time config option. This can be reverted once we have missing features like indirect descriptors implemented.
Signed-off-by Jens Freimann <[email protected]>--- config/common_base | 1 + drivers/net/virtio/virtio_ethdev.c | 4 ++++ 2 files changed, 5 insertions(+)config/common_base +1
-0@@ -346,6 +346,7 @@ CONFIG_RTE_LIBRTE_VIRTIO_PMD=y CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n +CONFIG_RTE_LIBRTE_VIRTIO_PQ=n # # Compile virtio device emulation inside virtio PMD driverdrivers/net/virtio/virtio_ethdev.c +0
-1--- a/drivers/net/virtio/virtio_ethdev.c
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) · line 1152
Quoted 6 lines
+++
b/drivers/net/virtio/virtio_ethdev.cdrivers/net/virtio/virtio_ethdev.c +2
-0@@ -1149,6 +1149,10 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ULL <<VIRTIO_NET_F_MTU ); } +#ifndef RTE_LIBRTE_VIRTIO_PQ + req_features &= ~(1ull <<VIRTIO_F_RING_PACKED );Is
VIRTIO_F_RING_PACKEDalready declared here?
I don't think it is, so would break build when bisecting.
yes, you are right it is not. I pushed this patch to far up during git rebase.
Quoted 3 lines
Maybe the thing to do is to not have
VIRTIO_F_RING_PACKEDin the feature set by default. And whenRTE_LIBRTE_VIRTIO_PQis set, enable it and explicitly disable indirect descs.
Yes, both would work. I'll go with your suggestion. Thanks!
regards,
Jens
Quoted 7 lines
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +2
-0+#endif +/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Re: [PATCH v3 02/21] net/virtio: vring init for packed queues
In reply to Maxime CoquelinQuoted 122 lines · Maxime Coquelin
Quoted 78 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 22 +++++++++------- drivers/net/virtio/virtio_pci.h | 8 ++++++ drivers/net/virtio/virtio_ring.h | 53 ++++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 10 +++++++ 4 files changed, 78 insertions(+), 15 deletions(-)drivers/net/virtio/virtio_ethdev.c +12
-10@@ -298,19 +298,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 (vr->desc, size); + }/* * Disable device(host) interrupting guest @@ -385,7 +387,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);drivers/net/virtio/virtio_pci.h +8
-0@@ -112,6 +112,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 @@ -304,6 +306,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 +0
-0drivers/net/virtio/virtio_ring.h line 10
Quoted 2 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -9,6 +9,7 @@#include <rte_common.h> +Remove new line
Quoted 37 lines
drivers/net/virtio/virtio_ring.h +26
-3/* This marks a buffer as continuing via the next field. */ #define VRING_DESC_F_NEXT 1/* This marks a buffer as write-only (otherwise read-only). */ @@ -54,11 +55,38 @@ 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_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +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 {unsigned int num; -struct vring_desc *desc; -struct vring_avail *avail; -struct vring_used *used; +union { +struct vring_desc_packed *desc_packed; +struct vring_desc *desc; + }; +union { +struct vring_avail *avail; +struct vring_packed_desc_event *driver_event; + };
Quoted 8 lines
drivers/net/virtio/virtio_ring.h struct vring_used { · line 89
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +4
-0+union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + };Not a must, but I wonder if it wouldn't be cleaner to have a unique union of two structs, one for packed rings, and one for the legacy. I may be wrong, though.
I'm not sure either but this looked best to me.
Thanks!
regards,
Jens
Quoted 60 lines
Quoted 60 lines
drivers/net/virtio/virtio_ring.h +17
-2};/* The standard layout for the ring is a continuous chunk of memory which @@ -95,10 +123,16 @@ 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_desc_packed ); + size +=2 *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);@@ -108,10 +142,19 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, +vring_init (struct virtio_hw *hw,struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) { vr->num = num; +if (vtpci_packed_queue (hw)) { + vr->desc_packed = (struct vring_desc_packed *)p; + vr->driver_event = (struct vring_packed_desc_event *) (p + + num *sizeof (struct vring_desc_packed )); + vr->device_event = (struct vring_packed_desc_event *) (vr->driver_event + +sizeof (struct vring_packed_desc_event )); +return ; + } + vr->desc = (struct vring_desc *) p; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc ));drivers/net/virtio/virtqueue.h +10
-0@@ -245,6 +245,16 @@ 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)
Re: [PATCH v3 02/21] net/virtio: vring init for packed queues
In reply to Jens FreimannQuoted 4 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>---
[...]
drivers/net/virtio/virtio_ring.h line 12
Quoted 9 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -9,6 +9,7 @@#include <rte_common.h> +
There is no need to add this empty line.
Quoted 46 lines
drivers/net/virtio/virtio_ring.h +30
-3/* This marks a buffer as continuing via the next field. */ #define VRING_DESC_F_NEXT 1/* This marks a buffer as write-only (otherwise read-only). */ @@ -54,11 +55,38 @@ 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_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +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 {unsigned int num; -struct vring_desc *desc; -struct vring_avail *avail; -struct vring_used *used; +union { +struct vring_desc_packed *desc_packed; +struct vring_desc *desc; + }; +union { +struct vring_avail *avail; +struct vring_packed_desc_event *driver_event; + }; +union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + }; };/* The standard layout for the ring is a continuous chunk of memory which
drivers/net/virtio/virtio_ring.h struct vring { · line 131
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +3
-1@@ -95,10 +123,16 @@ 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_desc_packed );
I think you need to add paddings based on the alignment.
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +4
-0+ size +=2 *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);@@ -108,10 +142,19 @@ vring_size(unsigned int num, unsigned long align) }
drivers/net/virtio/virtio_ring.h vring_size(unsigned int num, unsigned long align) · line 152
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +5
-1static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, +vring_init (struct virtio_hw *hw,struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) { vr->num = num; +if (vtpci_packed_queue (hw)) { + vr->desc_packed = (struct vring_desc_packed *)p; + vr->driver_event = (struct vring_packed_desc_event *) (p + + num *sizeof (struct vring_desc_packed ));
I think paddings are needed here.
Quoted 32 lines
drivers/net/virtio/virtio_ring.h +5
-0+ vr->device_event = (struct vring_packed_desc_event *) (vr->driver_event + +sizeof (struct vring_packed_desc_event )); +return ; + } + vr->desc = (struct vring_desc *) p; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc ));drivers/net/virtio/virtqueue.h +10
-0@@ -245,6 +245,16 @@ 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)Signature · 1 line
2.14.3
Re: [PATCH v3 04/21] net/virtio: add packed virtqueue helpers
In reply to Jens FreimannQuoted 21 lines · Jens Freimann
Add helper functions to set/clear and check descriptor flags.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 33 +++++++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.c | 10 ++++++++++ 2 files changed, 43 insertions(+)drivers/net/virtio/virtio_ring.h +1
-0@@ -78,6 +78,7 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter;union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;
drivers/net/virtio/virtio_ring.h struct vring { · line 96
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -92,6 +93,38 @@ struct vring { }; }; +static inline void toggle_wrap_counter (struct vring *vr)
Please follow the coding style of the driver:
static inline voidtoggle_wrap_counter(struct vring *vr)
I would also prefix the functions with vring_ to keep consistency.
Quoted 53 lines
drivers/net/virtio/virtio_ring.h +31
-0+{ + vr->avail_wrap_counter ^=1 ; +} + +static inline void _set_desc_avail (struct vring_desc_packed *desc, +int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter) { + flags |=VRING_DESC_F_AVAIL ; + flags &= ~VRING_DESC_F_USED ; + }else { + flags &= ~VRING_DESC_F_AVAIL ; + flags |=VRING_DESC_F_USED ; + } + + desc->flags = flags; +} + +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) +{ +return !(desc->flags &VRING_DESC_F_AVAIL ) == !(desc->flags &VRING_DESC_F_USED ); +} +/* 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.c +3
-0@@ -58,6 +58,7 @@ 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;@@ -65,6 +66,15 @@ virtqueue_rxvq_flush(struct virtqueue *vq)uint16_t used_idx, desc_idx;uint16_t nb_used, i; +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx & (vq->vq_nentries -1 );
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq) · line 80
Quoted 10 lines
drivers/net/virtio/virtqueue.c +7
-0+while (desc_is_used (&descs[i])) { +rte_pktmbuf_free (vq->sw_ring[i]); + vq->vq_free_cnt++; + } +return ; + } + nb_used =VIRTQUEUE_NUSED (vq);for (i =0 ; i < nb_used; i++) {
With style comments taken into account:
Re: [PATCH v3 03/21] net/virtio: add virtio 1.1 defines
In reply to Jens FreimannQuoted 10 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/virtio/virtio_ring.h +0
-0
drivers/net/virtio/virtio_ring.h line 19
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +0
-1@@ -16,7 +16,10 @@#define VRING_DESC_F_WRITE 2/* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 -
Why remove this empty line?
VRING_DESC_F_* and VRING_USED_F_NO_NOTIFY/VRING_AVAIL_F_NO_INTERRUPT are unrelated. I think we still need this to make the code more readable.
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +4
-0+/* This flag means the descriptor was made available by the driver */ +#define VRING_DESC_F_AVAIL (1ULL << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (1ULL << 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.14.3
Re: [PATCH v3 05/21] net/virtio: dump packed virtqueue data
In reply to Jens FreimannQuoted 17 lines · Jens Freimann
Add support to dump packed virtqueue data to the
VIRTQUEUE_DUMP()macro.Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtqueue.h | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/virtio/virtqueue.h +0
-0@@ -360,6 +360,13 @@ virtqueue_notify(struct virtqueue *vq)#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTQUEUE_DUMP (vq) do { \
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 372
Quoted 10 lines
drivers/net/virtio/virtqueue.h +7
-0+if (vtpci_packed_queue ((vq)->hw)) { \ +PMD_INIT_LOG (DEBUG , \ +"VQ: - size=%d; free=%d; last_used_idx=%d;" \ + (vq)->vq_nentries, (vq)->vq_free_cnt, nused); \ +break ; \ + } \ +if (vtpci_packed_queue ((vq)->hw))break ; \uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t )(used_idx - (vq)->vq_used_cons_idx); \
Thanks,
Maxime
Re: [PATCH v3 03/21] net/virtio: add virtio 1.1 defines
In reply to Tiwei BieQuoted 18 lines · Tiwei Bie
Quoted 10 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/virtio/virtio_ring.h +0
-0drivers/net/virtio/virtio_ring.h line 19
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +0
-1@@ -16,7 +16,10 @@#define VRING_DESC_F_WRITE 2/* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 -Why remove this empty line?
Quoted 3 lines
VRING_DESC_F_* and VRING_USED_F_NO_NOTIFY/VRING_AVAIL_F_NO_INTERRUPT are unrelated. I think we still need this to make the code more readable.
Figured it was unnecessary, but I'll add it back.
Thanks!
regards,
Jens
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio/virtio_ring.h +4
-1+/* This flag means the descriptor was made available by the driver */ +#define VRING_DESC_F_AVAIL (1ULL << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (1ULL << 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. */ --2.14.3
Re: [PATCH v3 04/21] net/virtio: add packed virtqueue helpers
In reply to Maxime CoquelinQuoted 27 lines · Maxime Coquelin
Quoted 20 lines · Jens Freimann
Add helper functions to set/clear and check descriptor flags.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 33 +++++++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.c | 10 ++++++++++ 2 files changed, 43 insertions(+)drivers/net/virtio/virtio_ring.h +1
-0@@ -78,6 +78,7 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter;union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;drivers/net/virtio/virtio_ring.h struct vring { · line 95
Quoted 3 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -92,6 +93,38 @@ struct vring { }; }; +static inline void toggle_wrap_counter (struct vring *vr)Please follow the coding style of the driver:
Quoted 4 lines
static inline void
toggle_wrap_counter(struct vring *vr)I would also prefix the functions with
vring_to keep consistency.
ok
Quoted 55 lines
Quoted 55 lines
drivers/net/virtio/virtio_ring.h +31
-0+{ + vr->avail_wrap_counter ^=1 ; +} + +static inline void _set_desc_avail (struct vring_desc_packed *desc, +int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter) { + flags |=VRING_DESC_F_AVAIL ; + flags &= ~VRING_DESC_F_USED ; + }else { + flags &= ~VRING_DESC_F_AVAIL ; + flags |=VRING_DESC_F_USED ; + } + + desc->flags = flags; +} + +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) +{ +return !(desc->flags &VRING_DESC_F_AVAIL ) == !(desc->flags &VRING_DESC_F_USED ); +} +/* 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.c +7
-0@@ -58,6 +58,7 @@ 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;@@ -65,6 +66,15 @@ virtqueue_rxvq_flush(struct virtqueue *vq)uint16_t used_idx, desc_idx;uint16_t nb_used, i; +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); +while (desc_is_used (&descs[i])) { +rte_pktmbuf_free (vq->sw_ring[i]); + vq->vq_free_cnt++; + }
Quoted 8 lines
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq)
Quoted 6 lines
drivers/net/virtio/virtqueue.c +3
-0+return ; + } + nb_used =VIRTQUEUE_NUSED (vq);for (i =0 ; i < nb_used; i++) {With style comments taken into account:
I'll fix it.
Thanks!
regards,
Jens
Quoted 3 lines
Reviewed-by Maxime Coquelin <[email protected]>
Re: [PATCH v3 06/21] net/virtio-user: add option to use packed queues
In reply to Jens FreimannQuoted 5 lines · Jens Freimann
From: Yuanhan Liu <[email protected]>
Add option to enable packed queue support for virtio-user devices.
Quoted 7 lines
Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/virtio/virtio_user/virtio_user_dev.c | 12 ++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 3 ++- drivers/net/virtio/virtio_user_ethdev.c | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-)
Thanks,
Maxime
Re: [PATCH v3 04/21] net/virtio: add packed virtqueue helpers
In reply to Maxime CoquelinQuoted 8 lines · Maxime Coquelin
Quoted 7 lines · Jens Freimann
Add helper functions to set/clear and check descriptor flags.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 33 +++++++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.c | 10 ++++++++++ 2 files changed, 43 insertions(+)
[...]
Quoted 13 lines
Quoted 13 lines
drivers/net/virtio/virtqueue.c +1
-0@@ -58,6 +58,7 @@ 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;@@ -65,6 +66,15 @@ virtqueue_rxvq_flush(struct virtqueue *vq)
Quoted 8 lines
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq) · line 74
Quoted 8 lines
drivers/net/virtio/virtqueue.c +6
-0uint16_t used_idx, desc_idx;uint16_t nb_used, i; +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); +while (desc_is_used (&descs[i])) { +rte_pktmbuf_free (vq->sw_ring[i]); + vq->vq_free_cnt++; + }
You need to increase i here. Otherwise you are looping on the same entry. To increase i, you also need to keep track of the number of descriptors need to be skipped for each used descriptor.
Quoted 11 lines
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq)
Quoted 6 lines
drivers/net/virtio/virtqueue.c +3
-0+return ; + } + nb_used =VIRTQUEUE_NUSED (vq);for (i =0 ; i < nb_used; i++) {With style comments taken into account:
Reviewed-by Maxime Coquelin <[email protected]>
Re: [PATCH v3 04/21] net/virtio: add packed virtqueue helpers
Quoted 28 lines · Tiwei Bie
Quoted 8 lines · Maxime Coquelin
Quoted 7 lines · Jens Freimann
Add helper functions to set/clear and check descriptor flags.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 33 +++++++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.c | 10 ++++++++++ 2 files changed, 43 insertions(+)[...]
Quoted 18 lines
Quoted 18 lines
drivers/net/virtio/virtqueue.c +4
-0@@ -58,6 +58,7 @@ 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;@@ -65,6 +66,15 @@ virtqueue_rxvq_flush(struct virtqueue *vq)uint16_t used_idx, desc_idx;uint16_t nb_used, i; +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx & (vq->vq_nentries -1 ); +while (desc_is_used (&descs[i])) {
Quoted 8 lines
Quoted 3 lines
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq) · line 74
Quoted 3 lines
drivers/net/virtio/virtqueue.c +3
-0+rte_pktmbuf_free (vq->sw_ring[i]); + vq->vq_free_cnt++; + }You need to increase i here. Otherwise you are looping on the same entry. To increase i, you also need to keep track of the number of descriptors need to be skipped for each used descriptor.
Hmm, you are right. Seems like this code never ran. I'll be more careful testing even last minute changes now.
regards,
Jens
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio/virtqueue.c virtqueue_rxvq_flush(struct virtqueue *vq)
Quoted 7 lines
drivers/net/virtio/virtqueue.c +3
-0+return ; + } + nb_used =VIRTQUEUE_NUSED (vq);for (i =0 ; i < nb_used; i++) {With style comments taken into account:
Reviewed-by Maxime Coquelin <[email protected]>
Re: [PATCH v3 02/21] net/virtio: vring init for packed queues
In reply to Tiwei BieQuoted 87 lines · Tiwei Bie
Quoted 4 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>---
[...]
drivers/net/virtio/virtio_ring.h line 12
Quoted 9 lines
drivers/net/virtio/virtio_ring.h +1
-0@@ -9,6 +9,7 @@#include <rte_common.h> +There is no need to add this empty line.
Quoted 46 lines
drivers/net/virtio/virtio_ring.h +30
-3/* This marks a buffer as continuing via the next field. */ #define VRING_DESC_F_NEXT 1/* This marks a buffer as write-only (otherwise read-only). */ @@ -54,11 +55,38 @@ 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_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +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 {unsigned int num; -struct vring_desc *desc; -struct vring_avail *avail; -struct vring_used *used; +union { +struct vring_desc_packed *desc_packed; +struct vring_desc *desc; + }; +union { +struct vring_avail *avail; +struct vring_packed_desc_event *driver_event; + }; +union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + }; };/* The standard layout for the ring is a continuous chunk of memory which drivers/net/virtio/virtio_ring.h struct vring { · line 131
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +3
-1@@ -95,10 +123,16 @@ 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_desc_packed );I think you need to add paddings based on the alignment.
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +4
-0+ size +=2 *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);@@ -108,10 +142,19 @@ vring_size(unsigned int num, unsigned long align) }
Quoted 12 lines
drivers/net/virtio/virtio_ring.h vring_size(unsigned int num, unsigned long align) · line 152
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +5
-1static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, +vring_init (struct virtio_hw *hw,struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) { vr->num = num; +if (vtpci_packed_queue (hw)) { + vr->desc_packed = (struct vring_desc_packed *)p; + vr->driver_event = (struct vring_packed_desc_event *) (p + + num *sizeof (struct vring_desc_packed ));I think paddings are needed here.
I'll align it with RTE_ALIGN_CEIL, like it's done for the used ring address.
Thanks!
regards,
Jens
Quoted 33 lines
Quoted 33 lines
drivers/net/virtio/virtio_ring.h +5
-0+ vr->device_event = (struct vring_packed_desc_event *) (vr->driver_event + +sizeof (struct vring_packed_desc_event )); +return ; + } + vr->desc = (struct vring_desc *) p; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc ));drivers/net/virtio/virtqueue.h +10
-1@@ -245,6 +245,16 @@ 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) --2.14.3
Re: [PATCH v3 08/21] net/virtio: implement receive path for packed queues
In reply to Jens FreimannHi Jens,
Quoted 17 lines · Jens Freimann
From: Yuanhan Liu <[email protected]>
Implement the receive part here. No support for mergeable buffers yet.
Signed-off-by Jens Freimann <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 10 ++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 137 ++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 3 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1318
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +1
-1@@ -1315,10 +1315,15 @@ 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 */
I don't think you need such workarounds, just advertise the packed ring layout feature once full support is introduced.
Also I'm not cleat what the workaround is needed here, as you set to virtio_recv_pkts_packed whatever mrg is on or not.
Re: [PATCH v3 07/21] net/virtio: implement transmit path for packed queues
In reply to Jens FreimannQuoted 46 lines · Jens Freimann
This implements the transmit path for devices with support for Virtio 1.1.
Add the feature bit for Virtio 1.1 and enable code to add buffers to vring and mark descriptors as available.
This is based on a patch by Yuanhan Liu.
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 8 ++- drivers/net/virtio/virtio_ethdev.h | 3 ++ drivers/net/virtio/virtio_rxtx.c | 102 ++++++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 2 deletions(-)drivers/net/virtio/virtio_ethdev.c +7
-1@@ -383,6 +383,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 @@ -1328,7 +1330,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_simple_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_simple_tx) {PMD_INIT_LOG (INFO ,"virtio: using simple Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;drivers/net/virtio/virtio_ethdev.h +0
-0
drivers/net/virtio/virtio_ethdev.h line 39
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +1
-0@@ -36,6 +36,7 @@1ULL <<VIRTIO_NET_F_GUEST_ANNOUNCE | \1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_RING_PACKED | \
Should it really advertise VIRTIO_F_RING_PACKED unconditionally, as it is not yet fully supported? (non-pow2, indirect descs, etc...)
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.h +0
-01ULL << VIRTIO_F_IOMMU_PLATFORM)#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \
Re: [PATCH v3 07/21] net/virtio: implement transmit path for packed queues
Quoted 46 lines · Maxime Coquelin
Quoted 43 lines · Jens Freimann
This implements the transmit path for devices with support for Virtio 1.1.
Add the feature bit for Virtio 1.1 and enable code to add buffers to vring and mark descriptors as available.
This is based on a patch by Yuanhan Liu.
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 8 ++- drivers/net/virtio/virtio_ethdev.h | 3 ++ drivers/net/virtio/virtio_rxtx.c | 102 ++++++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 2 deletions(-)drivers/net/virtio/virtio_ethdev.c +7
-1@@ -383,6 +383,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 @@ -1328,7 +1330,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_simple_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_simple_tx) {PMD_INIT_LOG (INFO ,"virtio: using simple Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;drivers/net/virtio/virtio_ethdev.h +0
-0
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.h line 39
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.h +1
-0@@ -36,6 +36,7 @@1ULL <<VIRTIO_NET_F_GUEST_ANNOUNCE | \1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_RING_PACKED | \Should it really advertise
VIRTIO_F_RING_PACKEDunconditionally, as it is not yet fully supported? (non-pow2, indirect descs, etc...)
We can advertise packed ring but have VIRTIO_F_INDIRECT_DESC disabled. non-pow2 needs to be integrated thoug and will be in v4.
regards,
Jens
Quoted 3 lines
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.h +0
-01ULL << VIRTIO_F_IOMMU_PLATFORM)#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \
Re: [PATCH v3 10/21] vhost: turn of indirect descriptors for packed virtqueues
In reply to Jens FreimannQuoted 10 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/socket.c | 1 + 1 file changed, 1 insertion(+)lib/librte_vhost/socket.c +0
-0
lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path, uint64_t flags) · line 855
Quoted 4 lines
lib/librte_vhost/socket.c +1
-0@@ -852,6 +852,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)#ifndef RTE_LIBRTE_VHOST_PQ vsocket->features &= ~(1ULL <<VIRTIO_F_RING_PACKED ); + vsocket->features &= ~(1ULL <<VIRTIO_RING_F_INDIRECT_DESC );
hmm.. Shouldn't be the opposite?
Quoted 4 lines
lib/librte_vhost/socket.c +0
-0#endif if ((flags &RTE_VHOST_USER_CLIENT ) !=0 ) {
Re: [PATCH v3 08/21] net/virtio: implement receive path for packed queues
In reply to Maxime CoquelinQuoted 28 lines · Maxime Coquelin
Hi Jens,
Quoted 17 lines · Jens Freimann
From: Yuanhan Liu <[email protected]>
Implement the receive part here. No support for mergeable buffers yet.
Signed-off-by Jens Freimann <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 10 ++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 137 ++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 3 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1317
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +1
-1@@ -1315,10 +1315,15 @@ 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 */ I don't think you need such workarounds, just advertise the packed ring layout feature once full support is introduced.
Quoted 2 lines
Also I'm not cleat what the workaround is needed here, as you set to
virtio_recv_pkts_packedwhatever mrg is on or not.
yes, I'll change it in v4 to advertise packed virtqueues as the last patch.
Thanks!
regards,
Jens
Quoted 2 lines
Re: [PATCH v3 11/21] vhost: add virtio 1.1 defines
In reply to Jens FreimannQuoted 2 lines · Jens Freimann
This should actually be in the kernel header file, but it isn't yet. For now let's use our own headers.
I think it is not just temporary, as we will always want to be able to build with older kernels.
lib/librte_vhost/virtio-1.1.h
Quoted 28 lines
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.h | 4 ++++ lib/librte_vhost/virtio-1.1.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+)create mode 100644
lib/librte_vhost/virtio-1.1.hlib/librte_vhost/vhost.h +4
-0@@ -177,6 +177,10 @@ struct vhost_msg {#ifndef VIRTIO_F_VERSION_1 #define VIRTIO_F_VERSION_1 32#endif +#ifndef VIRTIO_F_RING_PACKED +#define VIRTIO_F_RING_PACKED 34 +#endif +#define VHOST_USER_F_PROTOCOL_FEATURES 30/* Features supported by this builtin vhost-user net driver. */ #define VIRTIO_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \lib/librte_vhost/virtio-1.1.h new file +0
-0@@ -0,0 +1,18 @@
You need to add a license for the file.
Quoted 19 lines
lib/librte_vhost/virtio-1.1.h new file +18
-0+#ifndef __VIRTIO_PACKED_H +#define __VIRTIO_PACKED_H + +#define VRING_DESC_F_NEXT 1 +#define VRING_DESC_F_WRITE 2 +#define VRING_DESC_F_INDIRECT 4 + +#define VRING_DESC_F_AVAIL (1ULL << 7) +#define VRING_DESC_F_USED (1ULL << 15) + +struct vring_desc_packed { +uint64_t addr; +uint32_t len; +uint16_t index; +uint16_t flags; +}; + +#endif /* __VIRTIO_PACKED_H */
Re: [PATCH v3 12/21] vhost: vring address setup for packed queues
In reply to Jens FreimannQuoted 28 lines · Jens Freimann
From: Yuanhan Liu <[email protected]>
Add code to set up packed queues when enabled.
Signed-off-by Yuanhan Liu <[email protected]>Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/vhost_user.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)lib/librte_vhost/vhost.h +1
-0@@ -74,6 +74,7 @@ struct batch_copy_elem {*/ struct vhost_virtqueue {struct vring_desc *desc; +struct vring_desc_packed *desc_packed;struct vring_avail *avail;struct vring_used *used;uint32_t size;lib/librte_vhost/vhost_user.c +0
-0
lib/librte_vhost/vhost_user.c translate_ring_addresses(struct virtio_net *dev, int vq_index) · line 474
Quoted 6 lines
lib/librte_vhost/vhost_user.c +3
-0@@ -469,6 +469,23 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)struct vhost_virtqueue *vq = dev->virtqueue[vq_index];struct vhost_vring_addr *addr = &vq->ring_addrs; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + vq->desc_packed = (struct vring_desc_packed *)ring_addr_to_vva + (dev, vq, addr->desc_user_addr,sizeof (vq->desc_packed));
sizeof(*vq->desc_packed)
orsizeof(struct vring_desc_packed) for consitency.
Quoted 36 lines
lib/librte_vhost/vhost_user.c +17
-1+ vq->desc =NULL ; + vq->avail =NULL ; + vq->used =NULL ; + vq->log_guest_addr =0 ; + +if (vq->last_used_idx !=0 ) { +RTE_LOG (WARNING ,VHOST_CONFIG , +"last_used_idx (%u) not 0\n" , + vq->last_used_idx); + vq->last_used_idx =0 ; + } +return dev; + } +/* The addresses are converted from QEMU virtual to Vhost virtual. */ if (vq->desc && vq->avail && vq->used)return dev;@@ -481,6 +498,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) dev->vid);return dev; } + vq->desc_packed =NULL ; dev =numa_realloc (dev, vq_index); vq = dev->virtqueue[vq_index];@@ -853,7 +871,8 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)static int vq_is_ready (struct vhost_virtqueue *vq) { -return vq && vq->desc && vq->avail && vq->used && +return vq && + (vq->desc_packed || (vq->desc && vq->avail && vq->used)) && vq->kickfd !=VIRTIO_UNINITIALIZED_EVENTFD && vq->callfd !=VIRTIO_UNINITIALIZED_EVENTFD ; }
Re: [PATCH v3 12/21] vhost: vring address setup for packed queues
Quoted 31 lines · Maxime Coquelin
Quoted 28 lines · Jens Freimann
From: Yuanhan Liu <[email protected]>
Add code to set up packed queues when enabled.
Signed-off-by Yuanhan Liu <[email protected]>Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/vhost_user.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)lib/librte_vhost/vhost.h +1
-0@@ -74,6 +74,7 @@ struct batch_copy_elem {*/ struct vhost_virtqueue {struct vring_desc *desc; +struct vring_desc_packed *desc_packed;struct vring_avail *avail;struct vring_used *used;uint32_t size;lib/librte_vhost/vhost_user.c +0
-0@@ -469,6 +469,23 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
Quoted 8 lines
lib/librte_vhost/vhost_user.c translate_ring_addresses(struct virtio_net *dev, int vq_index) · line 474
Quoted 5 lines
lib/librte_vhost/vhost_user.c +3
-0struct vhost_virtqueue *vq = dev->virtqueue[vq_index];struct vhost_vring_addr *addr = &vq->ring_addrs; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + vq->desc_packed = (struct vring_desc_packed *)ring_addr_to_vva + (dev, vq, addr->desc_user_addr,sizeof (vq->desc_packed));
sizeof(*vq->desc_packed)
orsizeof(struct vring_desc_packed)for consitency.
yes, will fix. thanks!
regards,
Jens
Quoted 36 lines
Quoted 36 lines
lib/librte_vhost/vhost_user.c +17
-1+ vq->desc =NULL ; + vq->avail =NULL ; + vq->used =NULL ; + vq->log_guest_addr =0 ; + +if (vq->last_used_idx !=0 ) { +RTE_LOG (WARNING ,VHOST_CONFIG , +"last_used_idx (%u) not 0\n" , + vq->last_used_idx); + vq->last_used_idx =0 ; + } +return dev; + } +/* The addresses are converted from QEMU virtual to Vhost virtual. */ if (vq->desc && vq->avail && vq->used)return dev;@@ -481,6 +498,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) dev->vid);return dev; } + vq->desc_packed =NULL ; dev =numa_realloc (dev, vq_index); vq = dev->virtqueue[vq_index];@@ -853,7 +871,8 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)static int vq_is_ready (struct vhost_virtqueue *vq) { -return vq && vq->desc && vq->avail && vq->used && +return vq && + (vq->desc_packed || (vq->desc && vq->avail && vq->used)) && vq->kickfd !=VIRTIO_UNINITIALIZED_EVENTFD && vq->callfd !=VIRTIO_UNINITIALIZED_EVENTFD ; }
Re: [PATCH v3 13/21] vhost: add helpers for packed virtqueues
In reply to Jens Freimannlib/librte_vhost/virtio-1.1.h
Quoted 12 lines · Jens Freimann
Add some helper functions to set/check descriptor flags and toggle the used wrap counter.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)lib/librte_vhost/virtio-1.1.h +0
-0
Shouldn't the file be named virtio-packed.h?
Quoted 38 lines
lib/librte_vhost/virtio-1.1.h +34
-0@@ -15,4 +15,48 @@ struct vring_desc_packed {uint16_t flags; }; +static inline void +toggle_wrap_counter (struct vhost_virtqueue *vq) +{ + vq->used_wrap_counter ^=1 ; +} + +static inline int +desc_is_avail (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +if (vq->used_wrap_counter ==1 ) { +if ((desc->flags &VRING_DESC_F_AVAIL ) && + !(desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +if (vq->used_wrap_counter ==0 ) { +if (!(desc->flags &VRING_DESC_F_AVAIL ) && + (desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +return 0 ; +} + +static inline void +_set_desc_used (struct vring_desc_packed *desc,int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter ==1 ) { + flags |=VRING_DESC_F_USED ; + flags |=VRING_DESC_F_AVAIL ; + }else { + flags &= ~VRING_DESC_F_USED ; + flags &= ~VRING_DESC_F_AVAIL ; + }
lib/librte_vhost/virtio-1.1.h struct vring_desc_packed { · line 61
Quoted 10 lines
lib/librte_vhost/virtio-1.1.h +10
-0+ + desc->flags = flags; +} + +static inline void +set_desc_used (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +_set_desc_used (desc, vq->used_wrap_counter); +} +
Maybe prefix all with vring_
Quoted 2 lines
lib/librte_vhost/virtio-1.1.h +0
-0#endif /* __VIRTIO_PACKED_H */
Re: [PATCH v3 13/21] vhost: add helpers for packed virtqueues
Quoted 11 lines · Maxime Coquelin
Quoted 8 lines · Jens Freimann
Add some helper functions to set/check descriptor flags and toggle the used wrap counter.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
Quoted 5 lines
lib/librte_vhost/virtio-1.1.h
Quoted 4 lines
lib/librte_vhost/virtio-1.1.h +0
-0Shouldn't the file be named
virtio-packed.h?
yes, will rename it.
Quoted 41 lines
Quoted 41 lines
lib/librte_vhost/virtio-1.1.h +38
-0@@ -15,4 +15,48 @@ struct vring_desc_packed {uint16_t flags; }; +static inline void +toggle_wrap_counter (struct vhost_virtqueue *vq) +{ + vq->used_wrap_counter ^=1 ; +} + +static inline int +desc_is_avail (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +if (vq->used_wrap_counter ==1 ) { +if ((desc->flags &VRING_DESC_F_AVAIL ) && + !(desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +if (vq->used_wrap_counter ==0 ) { +if (!(desc->flags &VRING_DESC_F_AVAIL ) && + (desc->flags &VRING_DESC_F_USED )) +return 1 ; + } +return 0 ; +} + +static inline void +_set_desc_used (struct vring_desc_packed *desc,int wrap_counter) +{ +uint16_t flags = desc->flags; + +if (wrap_counter ==1 ) { + flags |=VRING_DESC_F_USED ; + flags |=VRING_DESC_F_AVAIL ; + }else { + flags &= ~VRING_DESC_F_USED ; + flags &= ~VRING_DESC_F_AVAIL ; + } + + desc->flags = flags; +} +
Quoted 9 lines
lib/librte_vhost/virtio-1.1.h struct vring_desc_packed { · line 61
Quoted 6 lines
lib/librte_vhost/virtio-1.1.h +6
-0+static inline void +set_desc_used (struct vhost_virtqueue *vq,struct vring_desc_packed *desc) +{ +_set_desc_used (desc, vq->used_wrap_counter); +} +Maybe prefix all with
vring_Quoted 1 line
lib/librte_vhost/virtio-1.1.h +0
-0#endif /* __VIRTIO_PACKED_H */
ok
Thanks!
regards,
Jens
Quoted 1 line
Quoted 1 line
Re: [PATCH v3 14/21] vhost: dequeue for packed queues
In reply to Jens FreimannQuoted 69 lines · Jens Freimann
Implement code to dequeue and process descriptors from the vring if
VIRTIO_F_RING_PACKEDis enabled.Check if descriptor was made available by driver by looking at
VIRTIO_F_DESC_AVAILflag in descriptor. If so dequeue and set the used flagVIRTIO_F_DESC_USEDto the current value of the used wrap counter.Used ring wrap counter needs to be toggled when last descriptor is written out. This allows the host/guest to detect new descriptors even after the ring has wrapped.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.c | 1 + lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/virtio_net.c | 228 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+)lib/librte_vhost/vhost.c +1
-0@@ -185,6 +185,7 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->kickfd =VIRTIO_UNINITIALIZED_EVENTFD ; vq->callfd =VIRTIO_UNINITIALIZED_EVENTFD ; + vq->used_wrap_counter =1 ;vhost_user_iotlb_init (dev, vring_idx);/* Backends are set to -1 indicating an inactive device. */ lib/librte_vhost/vhost.h +1
-0@@ -112,6 +112,7 @@ struct vhost_virtqueue {struct batch_copy_elem *batch_copy_elems;uint16_t batch_copy_nb_elems; +uint16_t used_wrap_counter;rte_rwlock_t iotlb_lock;rte_rwlock_t iotlb_pending_lock;lib/librte_vhost/virtio_net.c +11
-0@@ -19,6 +19,7 @@#include "iotlb.h" #include "vhost.h" +#include "virtio-1.1.h" #define MAX_PKT_BURST 32@@ -1118,6 +1119,233 @@ restore_mbuf(struct rte_mbuf *m) } } +static inline uint16_t +dequeue_desc_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct rte_mempool *mbuf_pool,struct rte_mbuf *m, +struct vring_desc_packed *descs) +{ +struct vring_desc_packed *desc; +uint64_t desc_addr; +uint32_t desc_avail, desc_offset; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len;
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1141
Quoted 10 lines
lib/librte_vhost/virtio_net.c +10
-0+struct rte_mbuf *cur = m, *prev = m; +struct virtio_net_hdr *hdr =NULL ; +uint16_t head_idx = vq->last_used_idx & (vq->size -1 ); +int wrap_counter = vq->used_wrap_counter; +int rc =0 ; + +rte_spinlock_lock (&vq->access_lock); + +if (unlikely (vq->enabled ==0 )) + goto out;
It is unbalanced as it would unlock iotlb_rd_lock that isn't locked yet.
Quoted 106 lines
lib/librte_vhost/virtio_net.c +106
-0+if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + + desc = &descs[vq->last_used_idx & (vq->size -1 )]; +if (unlikely ((desc->len < dev->vhost_hlen)) || + (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA , +"INDIRECT not supported yet\n" ); + rc =-1 ; + goto out; + } + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); + +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out; + } + +if (virtio_net_with_host_offload (dev)) { + hdr = (struct virtio_net_hdr *)((uintptr_t )desc_addr); +rte_prefetch0 (hdr); + } + +/* +* A virtio driver normally uses at least 2 desc buffers +* for Tx: the first for storing the header, and others +* for storing the data. +*/ +if (likely ((desc->len == dev->vhost_hlen) && + (desc->flags &VRING_DESC_F_NEXT ) !=0 )) { +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + + desc = &descs[vq->last_used_idx & (vq->size -1 )]; + +if (unlikely (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA , +"INDIRECT not supported yet\n" ); + rc =-1 ; + goto out; + } + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out; + } + + desc_offset =0 ; + desc_avail = desc->len; + }else { + desc_avail = desc->len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; + } + +rte_prefetch0 ((void *)(uintptr_t )(desc_addr + desc_offset)); + +PRINT_PACKET (dev, (uintptr_t )(desc_addr + desc_offset), desc_avail,0 ); + + mbuf_offset =0 ; + mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ; +while (1 ) { +uint64_t hpa; + + cpy_len =RTE_MIN (desc_avail, mbuf_avail); + +/* +* A desc buf might across two host physical pages that are +* not continuous. In such case (gpa_to_hpa returns 0), data +* will be copied even though zero copy is enabled. +*/ +if (unlikely (dev->dequeue_zero_copy && (hpa =gpa_to_hpa (dev, + desc->addr + desc_offset, cpy_len)))) { + cur->data_len = cpy_len; + cur->data_off =0 ; + cur->buf_addr = (void *)(uintptr_t )desc_addr; + cur->buf_physaddr = hpa; + +/* +* In zero copy mode, one mbuf can only reference data +* for one or partial of one desc buff. +*/ + mbuf_avail = cpy_len; + }else { +rte_memcpy (rte_pktmbuf_mtod_offset (cur ,void *, + mbuf_offset), + (void *)((uintptr_t)(desc_addr + desc_offset)), + cpy_len); + } + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + desc_avail -= cpy_len; + desc_offset += cpy_len; + +/* This desc reaches to its end, get the next one */ +if (desc_avail ==0 ) { +if ((desc->flags &VRING_DESC_F_NEXT ) ==0 ) +break ; + +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); +
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1258
Quoted 10 lines
lib/librte_vhost/virtio_net.c +10
-0+ desc = &descs[vq->last_used_idx & (vq->size -1 )]; +if (unlikely (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA ,"INDIRECT not supported yet" ); + } + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out;
Not sure, but, shouldn't you break here instead so rings gets updated if some of the descs have been processed?
Quoted 76 lines
lib/librte_vhost/virtio_net.c +76
-0+ } + +rte_prefetch0 ((void *)(uintptr_t )desc_addr); + + desc_offset =0 ; + desc_avail = desc->len; + +PRINT_PACKET (dev, (uintptr_t )desc_addr, desc->len,0 ); + } + +/* +* This mbuf reaches to its end, get a new one +* to hold more data. +*/ +if (mbuf_avail ==0 ) { + cur =rte_pktmbuf_alloc (mbuf_pool); +if (unlikely (cur ==NULL )) { +RTE_LOG (ERR ,VHOST_DATA ,"Failed to " +"allocate memory for mbuf.\n" ); + rc =-1 ; + goto out; + } + + prev->next = cur; + prev->data_len = mbuf_offset; + m->nb_segs +=1 ; + m->pkt_len += mbuf_offset; + prev = cur; + + mbuf_offset =0 ; + mbuf_avail = cur->buf_len -RTE_PKTMBUF_HEADROOM ; + } + } + +if (hdr) +vhost_dequeue_offload (hdr, m); + +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + +rte_smp_wmb (); +_set_desc_used (&descs[head_idx], wrap_counter); + + prev->data_len = mbuf_offset; + m->pkt_len += mbuf_offset; + +out: +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_unlock (vq); +rte_spinlock_unlock (&vq->access_lock); + +return rc; +} + +static inline uint16_t +vhost_dequeue_burst_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts, +uint16_t count) +{ +uint16_t i; +uint16_t idx; +struct vring_desc_packed *desc = vq->desc_packed; +int err; + + count =RTE_MIN (MAX_PKT_BURST , count); +for (i =0 ; i < count; i++) { + idx = vq->last_used_idx & (vq->size -1 ); +if (!desc_is_avail (vq, &desc[idx])) +break ; +rte_smp_rmb (); + + pkts[i] =rte_pktmbuf_alloc (mbuf_pool); +if (unlikely (pkts[i] ==NULL )) { +RTE_LOG (ERR ,VHOST_DATA , +"Failed to allocate memory for mbuf.\n" ); +break ;
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1344
Quoted 10 lines
lib/librte_vhost/virtio_net.c +10
-0+ } + + err =dequeue_desc_packed (dev, vq, mbuf_pool, pkts[i], desc); +if (unlikely (err)) { +rte_pktmbuf_free (pkts[i]); +break ; + } + } + +rte_spinlock_unlock (&vq->access_lock);
I think you forgot to remove this line.
Quoted 8 lines
lib/librte_vhost/virtio_net.c +4
-0+ +return i; +} +uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count)
Re: [PATCH v3 15/21] vhost: packed queue enqueue path
In reply to Jens FreimannQuoted 46 lines · Jens Freimann
Implement enqueue of packets to the receive virtqueue.
Set descriptor flag
VIRTQ_DESC_F_USEDand toggle used wrap counter if last descriptor in ring is used. Perform a write memory barrier before flags are written to descriptor.Chained descriptors are not supported with this patch.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/virtio_net.c | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)lib/librte_vhost/virtio_net.c +25
-0@@ -695,6 +695,135 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return pkt_idx; } +static inline uint32_t __attribute__((always_inline)) +vhost_enqueue_burst_packed (struct virtio_net *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +struct vhost_virtqueue *vq; +struct vring_desc_packed *descs; +uint16_t idx; +uint16_t mask; +uint16_t i; + + vq = dev->virtqueue[queue_id]; + +rte_spinlock_lock (&vq->access_lock); + +if (unlikely (vq->enabled ==0 )) { + i =0 ; + goto out_access_unlock; + } + +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + + descs = vq->desc_packed; + mask = vq->size -1 ; +
lib/librte_vhost/virtio_net.c virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, · line 732
Quoted 10 lines
lib/librte_vhost/virtio_net.c +10
-0+for (i =0 ; i < count; i++) { +uint32_t desc_avail, desc_offset; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len; +struct vring_desc_packed *desc; +uint64_t desc_addr; +struct virtio_net_hdr_mrg_rxbuf *hdr; +struct rte_mbuf *m = pkts[i]; + +/* XXX: there is an assumption that no desc will be chained */
Is this assumption still true?
If not what are the plan to fix this?
lib/librte_vhost/virtio_net.c virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, · line 736
Quoted 4 lines
lib/librte_vhost/virtio_net.c +4
-0+ idx = vq->last_used_idx & mask; + desc = &descs[idx]; + +if (!desc_is_avail (vq, desc))
IIUC, it means the ring is full.
I think this is an unlikely case, so maybe better to use the unlikely macro here.
Quoted 94 lines
lib/librte_vhost/virtio_net.c +90
-0+break ; +rte_smp_rmb (); + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RW ); +/* +* Checking of 'desc_addr' placed outside of 'unlikely' macro +* to avoid performance issue with some versions of gcc (4.8.4 +* and 5.3.0) which otherwise stores offset on the stack instead +* of in a register. +*/ +if (unlikely (desc->len < dev->vhost_hlen) || !desc_addr) +break ; + + hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t )desc_addr; +virtio_enqueue_offload (m, &hdr->hdr); +vhost_log_write (dev, desc->addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); + + desc_offset = dev->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; + + mbuf_avail =rte_pktmbuf_data_len (m); + mbuf_offset =0 ; +while (mbuf_avail !=0 || m->next !=NULL ) { +/* done with current mbuf, fetch next */ +if (mbuf_avail ==0 ) { + m = m->next; + + mbuf_offset =0 ; + mbuf_avail =rte_pktmbuf_data_len (m); + } + +/* done with current desc buf, fetch next */ +if (desc_avail ==0 ) { +if ((desc->flags &VRING_DESC_F_NEXT ) ==0 ) { +/* Room in vring buffer is not enough */ + goto out; + } + + idx = (idx+1 ) & (vq->size -1 ); + desc = &descs[idx]; +if (unlikely (!desc_is_avail (vq, desc))) + goto out ; + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc), +VHOST_ACCESS_RW ); +if (unlikely (!desc_addr)) + goto out; + + desc_offset =0 ; + desc_avail = desc->len; + } + + cpy_len =RTE_MIN (desc_avail, mbuf_avail); +rte_memcpy ((void *)((uintptr_t )(desc_addr + desc_offset)), + rte_pktmbuf_mtod_offset(m, void *, mbuf_offset), + cpy_len); +vhost_log_write (dev, desc->addr + desc_offset, cpy_len); +PRINT_PACKET (dev, (uintptr_t )(desc_addr + desc_offset), + cpy_len,0 ); + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + desc_avail -= cpy_len; + desc_offset += cpy_len; + } + + descs[idx].len = pkts[i]->pkt_len + dev->vhost_hlen; +rte_smp_wmb (); +set_desc_used (vq, desc); + + vq->last_used_idx++; +if ((vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + } + +out: +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_unlock (vq); + +out_access_unlock: +rte_spinlock_unlock (&vq->access_lock); + + count = i; + +return count; +} +uint16_t rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count)
Re: [PATCH v3 17/21] net/virtio: disable ctrl virtqueue for packed rings
In reply to Jens FreimannQuoted 10 lines · Jens Freimann
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/virtio/virtio_ethdev.c +0
-0
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) · line 1166
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +7
-0@@ -1157,6 +1157,13 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ull <<VIRTIO_F_RING_PACKED );#endif +if (req_features & (1ULL <<VIRTIO_F_RING_PACKED )) { + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_MAC_ADDR ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VQ ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_RX ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VLAN ); + } +
Does packed ring not support ctrl vqs, or is it just a workaround while it is implemented?
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +0
-0/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Re: [PATCH v3 17/21] net/virtio: disable ctrl virtqueue for packed rings
Quoted 17 lines · Maxime Coquelin
Quoted 14 lines · Jens Freimann
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/virtio/virtio_ethdev.c +2
-0@@ -1157,6 +1157,13 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ull <<VIRTIO_F_RING_PACKED );#endif +if (req_features & (1ULL <<VIRTIO_F_RING_PACKED )) { + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_MAC_ADDR );
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) · line 1166
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +5
-0+ req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VQ ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_RX ); + req_features &= ~(1ull <<VIRTIO_NET_F_CTRL_VLAN ); + } +Does packed ring not support ctrl vqs, or is it just a workaround while it is implemented?
packed queues support virtqueues, but I had not implemented it yet. I have a patch for it though and will include it in v4.
regards,
Jens
Quoted 5 lines
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +0
-0/* * Negotiate features: Subset of device feature bits are written back * guest feature bits.
Re: [PATCH v3 17/21] net/virtio: disable ctrl virtqueue for packed rings
Quoted 28 lines · Jens Freimann
Quoted 18 lines · Maxime Coquelin
Quoted 15 lines · Jens Freimann
Signed-off-by Jens Freiman <[email protected]>---
drivers/net/virtio/virtio_ethdev.c | 7 +++++++1 file changed, 7 insertions(+)drivers/net/virtio/virtio_ethdev.c +2
-0@@ -1157,6 +1157,13 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) req_features &= ~(1ull << VIRTIO_F_RING_PACKED); #endif + if (req_features & (1ULL << VIRTIO_F_RING_PACKED)) { + req_features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR);Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) · line 1166
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +5
-0+ req_features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); + req_features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); + req_features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN); + } +Does packed ring not support ctrl vqs, or is it just a workaround while it is implemented?
Quoted 2 lines
packed queues support virtqueues, but I had not implemented it yet. I have a patch for it though and will include it in v4.
Great, so if you hadn't the patch, I think that a comment would be welcome. But it does not apply as you have the patch in your queue!
Thanks,
Maxime
Quoted 8 lines
regards,
JensQuoted 5 lines
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +0
-0/** Negotiate features: Subset of device feature bits are written back * guest feature bits.
Re: [PATCH v3 18/21] net/virtio: add support for mergeable buffers with packed virtqueues
In reply to Jens FreimannMaybe better to place this patch right after the non-mrg one.
Quoted 40 lines · Jens Freimann
Implement support for receiving merged buffers in virtio when packed virtqueues are enabled.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 10 ++-- drivers/net/virtio/virtio_rxtx.c | 107 +++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 1 + 3 files changed, 104 insertions(+), 14 deletions(-)drivers/net/virtio/virtio_ethdev.c +5
-5@@ -1322,15 +1322,15 @@ 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) &&vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; - }else if (hw->use_simple_rx) { +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 (vtpci_packed_queue (hw)) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; +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 (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { PMD_INIT_LOG(INFO, "virtio: using mergeable buffer Rx path on port %u",drivers/net/virtio/virtio_rxtx.c +0
-0
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 159
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2
-2@@ -155,8 +155,8 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt + dxp->ndescs);if ((dp->flags &VRING_DESC_F_INDIRECT ) ==0 ) {while (dp->flags &VRING_DESC_F_NEXT ) { - desc_idx_last = dp->next; - dp = &vq->vq_ring.desc[dp->next]; + desc_idx_last = desc_idx++; + dp = &vq->vq_ring.desc[desc_idx];
Are you sure this change is in the right patch?
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +0
-0} } dxp->ndescs =0 ;@@ -177,6 +177,76 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; }
Re: [PATCH v3 14/21] vhost: dequeue for packed queues
In reply to Maxime CoquelinQuoted 68 lines · Maxime Coquelin
Quoted 65 lines · Jens Freimann
Implement code to dequeue and process descriptors from the vring if
VIRTIO_F_RING_PACKEDis enabled.Check if descriptor was made available by driver by looking at
VIRTIO_F_DESC_AVAILflag in descriptor. If so dequeue and set the used flagVIRTIO_F_DESC_USEDto the current value of the used wrap counter.Used ring wrap counter needs to be toggled when last descriptor is written out. This allows the host/guest to detect new descriptors even after the ring has wrapped.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.c | 1 + lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/virtio_net.c | 228 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+)lib/librte_vhost/vhost.c +1
-0@@ -185,6 +185,7 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->kickfd =VIRTIO_UNINITIALIZED_EVENTFD ; vq->callfd =VIRTIO_UNINITIALIZED_EVENTFD ; + vq->used_wrap_counter =1 ;vhost_user_iotlb_init (dev, vring_idx);/* Backends are set to -1 indicating an inactive device. */ lib/librte_vhost/vhost.h +1
-0@@ -112,6 +112,7 @@ struct vhost_virtqueue {struct batch_copy_elem *batch_copy_elems;uint16_t batch_copy_nb_elems; +uint16_t used_wrap_counter;rte_rwlock_t iotlb_lock;rte_rwlock_t iotlb_pending_lock;lib/librte_vhost/virtio_net.c +15
-0@@ -19,6 +19,7 @@#include "iotlb.h" #include "vhost.h" +#include "virtio-1.1.h" #define MAX_PKT_BURST 32@@ -1118,6 +1119,233 @@ restore_mbuf(struct rte_mbuf *m) } } +static inline uint16_t +dequeue_desc_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct rte_mempool *mbuf_pool,struct rte_mbuf *m, +struct vring_desc_packed *descs) +{ +struct vring_desc_packed *desc; +uint64_t desc_addr; +uint32_t desc_avail, desc_offset; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len; +struct rte_mbuf *cur = m, *prev = m; +struct virtio_net_hdr *hdr =NULL ; +uint16_t head_idx = vq->last_used_idx & (vq->size -1 ); +int wrap_counter = vq->used_wrap_counter;
Quoted 8 lines
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1141
Quoted 6 lines
lib/librte_vhost/virtio_net.c +6
-0+int rc =0 ; + +rte_spinlock_lock (&vq->access_lock); + +if (unlikely (vq->enabled ==0 )) + goto out;It is unbalanced as it would unlock
iotlb_rd_lockthat isn't locked yet.
yes, will fix
Quoted 111 lines
Quoted 111 lines
lib/librte_vhost/virtio_net.c +110
-0+if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + + desc = &descs[vq->last_used_idx & (vq->size -1 )]; +if (unlikely ((desc->len < dev->vhost_hlen)) || + (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA , +"INDIRECT not supported yet\n" ); + rc =-1 ; + goto out; + } + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); + +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out; + } + +if (virtio_net_with_host_offload (dev)) { + hdr = (struct virtio_net_hdr *)((uintptr_t )desc_addr); +rte_prefetch0 (hdr); + } + +/* +* A virtio driver normally uses at least 2 desc buffers +* for Tx: the first for storing the header, and others +* for storing the data. +*/ +if (likely ((desc->len == dev->vhost_hlen) && + (desc->flags &VRING_DESC_F_NEXT ) !=0 )) { +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + + desc = &descs[vq->last_used_idx & (vq->size -1 )]; + +if (unlikely (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA , +"INDIRECT not supported yet\n" ); + rc =-1 ; + goto out; + } + + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out; + } + + desc_offset =0 ; + desc_avail = desc->len; + }else { + desc_avail = desc->len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; + } + +rte_prefetch0 ((void *)(uintptr_t )(desc_addr + desc_offset)); + +PRINT_PACKET (dev, (uintptr_t )(desc_addr + desc_offset), desc_avail,0 ); + + mbuf_offset =0 ; + mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ; +while (1 ) { +uint64_t hpa; + + cpy_len =RTE_MIN (desc_avail, mbuf_avail); + +/* +* A desc buf might across two host physical pages that are +* not continuous. In such case (gpa_to_hpa returns 0), data +* will be copied even though zero copy is enabled. +*/ +if (unlikely (dev->dequeue_zero_copy && (hpa =gpa_to_hpa (dev, + desc->addr + desc_offset, cpy_len)))) { + cur->data_len = cpy_len; + cur->data_off =0 ; + cur->buf_addr = (void *)(uintptr_t )desc_addr; + cur->buf_physaddr = hpa; + +/* +* In zero copy mode, one mbuf can only reference data +* for one or partial of one desc buff. +*/ + mbuf_avail = cpy_len; + }else { +rte_memcpy (rte_pktmbuf_mtod_offset (cur ,void *, + mbuf_offset), + (void *)((uintptr_t)(desc_addr + desc_offset)), + cpy_len); + } + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + desc_avail -= cpy_len; + desc_offset += cpy_len; + +/* This desc reaches to its end, get the next one */ +if (desc_avail ==0 ) { +if ((desc->flags &VRING_DESC_F_NEXT ) ==0 ) +break ; + +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + + desc = &descs[vq->last_used_idx & (vq->size -1 )]; +if (unlikely (desc->flags &VRING_DESC_F_INDIRECT )) { +RTE_LOG (ERR ,VHOST_DATA ,"INDIRECT not supported yet" ); + }
Quoted 8 lines
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1160
Quoted 6 lines
lib/librte_vhost/virtio_net.c +6
-0+ + desc_addr =vhost_iova_to_vva (dev, vq, desc->addr, +sizeof (*desc),VHOST_ACCESS_RO ); +if (unlikely (!desc_addr)) { + rc =-1 ; + goto out;Not sure, but, shouldn't you break here instead so rings gets updated if some of the descs have been processed?
It should break here and in other places in this loop as well. will fix it.
Quoted 79 lines
Quoted 79 lines
lib/librte_vhost/virtio_net.c +79
-0+ } + +rte_prefetch0 ((void *)(uintptr_t )desc_addr); + + desc_offset =0 ; + desc_avail = desc->len; + +PRINT_PACKET (dev, (uintptr_t )desc_addr, desc->len,0 ); + } + +/* +* This mbuf reaches to its end, get a new one +* to hold more data. +*/ +if (mbuf_avail ==0 ) { + cur =rte_pktmbuf_alloc (mbuf_pool); +if (unlikely (cur ==NULL )) { +RTE_LOG (ERR ,VHOST_DATA ,"Failed to " +"allocate memory for mbuf.\n" ); + rc =-1 ; + goto out; + } + + prev->next = cur; + prev->data_len = mbuf_offset; + m->nb_segs +=1 ; + m->pkt_len += mbuf_offset; + prev = cur; + + mbuf_offset =0 ; + mbuf_avail = cur->buf_len -RTE_PKTMBUF_HEADROOM ; + } + } + +if (hdr) +vhost_dequeue_offload (hdr, m); + +if ((++vq->last_used_idx & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); + +rte_smp_wmb (); +_set_desc_used (&descs[head_idx], wrap_counter); + + prev->data_len = mbuf_offset; + m->pkt_len += mbuf_offset; + +out: +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_unlock (vq); +rte_spinlock_unlock (&vq->access_lock); + +return rc; +} + +static inline uint16_t +vhost_dequeue_burst_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts, +uint16_t count) +{ +uint16_t i; +uint16_t idx; +struct vring_desc_packed *desc = vq->desc_packed; +int err; + + count =RTE_MIN (MAX_PKT_BURST , count); +for (i =0 ; i < count; i++) { + idx = vq->last_used_idx & (vq->size -1 ); +if (!desc_is_avail (vq, &desc[idx])) +break ; +rte_smp_rmb (); + + pkts[i] =rte_pktmbuf_alloc (mbuf_pool); +if (unlikely (pkts[i] ==NULL )) { +RTE_LOG (ERR ,VHOST_DATA , +"Failed to allocate memory for mbuf.\n" ); +break ; + } + + err =dequeue_desc_packed (dev, vq, mbuf_pool, pkts[i], desc);
Quoted 8 lines
lib/librte_vhost/virtio_net.c restore_mbuf(struct rte_mbuf *m) · line 1344
Quoted 7 lines
lib/librte_vhost/virtio_net.c +7
-0+if (unlikely (err)) { +rte_pktmbuf_free (pkts[i]); +break ; + } + } + +rte_spinlock_unlock (&vq->access_lock);I think you forgot to remove this line.
yes
Thanks!
regards,
Jens
Re: [PATCH v3 15/21] vhost: packed queue enqueue path
In reply to Maxime CoquelinQuoted 52 lines · Maxime Coquelin
Quoted 49 lines · Jens Freimann
Implement enqueue of packets to the receive virtqueue.
Set descriptor flag
VIRTQ_DESC_F_USEDand toggle used wrap counter if last descriptor in ring is used. Perform a write memory barrier before flags are written to descriptor.Chained descriptors are not supported with this patch.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/virtio_net.c | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)lib/librte_vhost/virtio_net.c +29
-0@@ -695,6 +695,135 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return pkt_idx; } +static inline uint32_t __attribute__((always_inline)) +vhost_enqueue_burst_packed (struct virtio_net *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +struct vhost_virtqueue *vq; +struct vring_desc_packed *descs; +uint16_t idx; +uint16_t mask; +uint16_t i; + + vq = dev->virtqueue[queue_id]; + +rte_spinlock_lock (&vq->access_lock); + +if (unlikely (vq->enabled ==0 )) { + i =0 ; + goto out_access_unlock; + } + +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + + descs = vq->desc_packed; + mask = vq->size -1 ; + +for (i =0 ; i < count; i++) { +uint32_t desc_avail, desc_offset; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len;
Quoted 8 lines
lib/librte_vhost/virtio_net.c virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, · line 732
Quoted 6 lines
lib/librte_vhost/virtio_net.c +6
-0+struct vring_desc_packed *desc; +uint64_t desc_addr; +struct virtio_net_hdr_mrg_rxbuf *hdr; +struct rte_mbuf *m = pkts[i]; + +/* XXX: there is an assumption that no desc will be chained */ Is this assumption still true?
If not what are the plan to fix this?
This is a leftover from the prototype code. I checked the code and don't see what it could still relate to except if it is supposed to mean indirect instead of chained. I think the comment can be removed.
Quoted 8 lines
lib/librte_vhost/virtio_net.c virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, · line 736
Quoted 5 lines
lib/librte_vhost/virtio_net.c +4
-0+ idx = vq->last_used_idx & mask; + desc = &descs[idx]; + +if (!desc_is_avail (vq, desc))IIUC, it means the ring is full.
I think this is an unlikely case, so maybe better to use the unlikely macro here.
yes, we can use unlikely here, will fix.
thanks!
regards,
Jens
Re: [PATCH v3 19/21] vhost: support mergeable rx buffers with packed queues
In reply to Jens FreimannQuoted 15 lines · Jens Freimann
This implements support for mergeable receive buffers in vhost when using packed virtqueues. The difference to split virtqueues is not big, it differs mostly where descriptor flags are touched and virtio features are checked.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.c | 2 + lib/librte_vhost/virtio_net.c | 160 +++++++++++++++++++++++++++++++++--------- 2 files changed, 127 insertions(+), 35 deletions(-)lib/librte_vhost/vhost.c +0
-0
lib/librte_vhost/vhost.c rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) · line 584
Quoted 5 lines
lib/librte_vhost/vhost.c +2
-0@@ -580,6 +580,8 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)if (dev ==NULL )return -1 ; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return -1 ;
Is this change really related to mergeable buffers?
Quoted 134 lines
lib/librte_vhost/vhost.c +0
-0if (enable) { RTE_LOG(ERR, VHOST_CONFIG,lib/librte_vhost/virtio_net.c +83
-15@@ -401,17 +401,53 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, } static __rte_always_inline int -fill_vec_buf (struct virtio_net *dev,struct vhost_virtqueue *vq, -uint32_t avail_idx,uint32_t *vec_idx, -struct buf_vector *buf_vec,uint16_t *desc_chain_head, -uint16_t *desc_chain_len) +__fill_vec_buf_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct buf_vector *buf_vec, +uint32_t *len,uint32_t *vec_id) +{ +uint16_t idx = vq->last_avail_idx & (vq->size -1 ); +struct vring_desc_packed *descs= vq->desc_packed; +uint32_t _vec_id = *vec_id; + +if (vq->desc_packed[idx].flags &VRING_DESC_F_INDIRECT ) { + descs = (struct vring_desc_packed *)(uintptr_t ) +vhost_iova_to_vva (dev, vq, vq->desc_packed[idx].addr, + vq->desc_packed[idx].len, +VHOST_ACCESS_RO ); +if (unlikely (!descs)) +return -1 ; + + idx =0 ; + } + +while (1 ) { +if (unlikely (_vec_id >=BUF_VECTOR_MAX || idx >= vq->size)) +return -1 ; + + *len += descs[idx & (vq->size -1 )].len; + buf_vec[_vec_id].buf_addr = descs[idx].addr; + buf_vec[_vec_id].buf_len = descs[idx].len; + buf_vec[_vec_id].desc_idx = idx; + _vec_id++; + +if ((descs[idx & (vq->size -1 )].flags &VRING_DESC_F_NEXT ) ==0 ) +break ; + + idx++; + } + *vec_id = _vec_id; + +return 0 ; +} + +static __rte_always_inline int +__fill_vec_buf_split (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct buf_vector *buf_vec, +uint32_t *len,uint32_t *vec_id,uint32_t avail_idx) {uint16_t idx = vq->avail->ring[avail_idx & (vq->size -1 )]; -uint32_t vec_id = *vec_idx; -uint32_t len =0 ;struct vring_desc *descs = vq->desc; - - *desc_chain_head = idx; +uint32_t _vec_id = *vec_id;if (vq->desc[idx].flags &VRING_DESC_F_INDIRECT ) { descs = (struct vring_desc *)(uintptr_t)@@ -425,20 +461,53 @@ fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq, }while (1 ) { -if (unlikely (vec_id >=BUF_VECTOR_MAX || idx >= vq->size)) +if (unlikely (_vec_id >=BUF_VECTOR_MAX || idx >= vq->size))return -1 ; - len += descs[idx].len; - buf_vec[vec_id].buf_addr = descs[idx].addr; - buf_vec[vec_id].buf_len = descs[idx].len; - buf_vec[vec_id].desc_idx = idx; - vec_id++; + *len += descs[idx].len; + buf_vec[_vec_id].buf_addr = descs[idx].addr; + buf_vec[_vec_id].buf_len = descs[idx].len; + buf_vec[_vec_id].desc_idx = idx; + _vec_id++;if ((descs[idx].flags &VRING_DESC_F_NEXT ) ==0 )break ; idx = descs[idx].next; } + *vec_id = _vec_id; + +return 0 ; +} + +static __rte_always_inline int +fill_vec_buf (struct virtio_net *dev,struct vhost_virtqueue *vq, +uint32_t avail_idx,uint32_t *vec_idx, +struct buf_vector *buf_vec,uint16_t *desc_chain_head, +uint16_t *desc_chain_len) +{ +uint16_t idx; +uint32_t vec_id = *vec_idx; +uint32_t len =0 ; + +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + idx = vq->last_avail_idx & (vq->size -1 ); + }else { + idx = vq->avail->ring[avail_idx & (vq->size -1 )]; + } + + + *desc_chain_head = idx; + +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { +if (__fill_vec_buf_packed (dev, vq, + buf_vec, &len, &vec_id)) +return -1 ; + }else { +if (__fill_vec_buf_split (dev, vq, + buf_vec, &len, &vec_id, avail_idx)) +return -1 ; + } *desc_chain_len = len; *vec_idx = vec_id;@@ -465,14 +534,16 @@ reserve_avail_buf_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, cur_idx = vq->last_avail_idx;while (size >0 ) { -if (unlikely (cur_idx == avail_head))
lib/librte_vhost/virtio_net.c reserve_avail_buf_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 545
Quoted 10 lines
lib/librte_vhost/virtio_net.c +3
-1+if (unlikely (cur_idx == avail_head) && + !(dev->features & (1ull <VIRTIO_F_RING_PACKED )))return -1 ;if (unlikely (fill_vec_buf (dev, vq, cur_idx, &vec_idx, buf_vec, &head_idx, &len) <0 ))return -1 ; len =RTE_MIN (len, size); -update_shadow_used_ring (vq, head_idx, len); +if (!(dev->features & (1ULL <<VIRTIO_F_RING_PACKED )))
This is cosmetics, but I wonder if we could have a helper like:
static inline bool
vring_is_packed(struct virtio_net *dev) {
return dev->features & (1ULL << VIRTIO_F_RING_PACKED);
}Quoted 84 lines
lib/librte_vhost/virtio_net.c +28
-10+update_shadow_used_ring (vq, head_idx, len); size -= len; cur_idx++;@@ -620,6 +691,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t num_buffers;struct buf_vector buf_vec[BUF_VECTOR_MAX ];uint16_t avail_head; +uint16_t i; +struct vring_desc_packed *descs =NULL ;VHOST_LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {@@ -634,7 +707,6 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (unlikely (vq->enabled ==0 )) goto out_access_unlock; -if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM ))vhost_user_iotlb_rd_lock (vq);@@ -648,10 +720,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, vq->batch_copy_nb_elems =0 ; -rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size -1 )]); - - vq->shadow_used_idx =0 ; - avail_head = *((volatile uint16_t *)&vq->avail->idx); +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + avail_head = vq->last_avail_idx; + descs = vq->desc_packed; + }else { +rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size -1 )]); + avail_head = *((volatile uint16_t *)&vq->avail->idx); + vq->shadow_used_idx =0 ; + }for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) {uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;@@ -661,7 +737,9 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,VHOST_LOG_DEBUG (VHOST_DATA ,"(%d) failed to get enough desc from vring\n" , dev->vid); - vq->shadow_used_idx -= num_buffers; + +if (!dev->features & (1ULL &VIRTIO_F_RING_PACKED )) + vq->shadow_used_idx -= num_buffers;break ; }@@ -671,7 +749,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (copy_mbuf_to_desc_mergeable (dev, vq, pkts[pkt_idx], buf_vec, num_buffers) <0 ) { - vq->shadow_used_idx -= num_buffers; +if (!dev->features & (1ULL &VIRTIO_F_RING_PACKED )) + vq->shadow_used_idx -= num_buffers;break ; }@@ -680,9 +759,18 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,do_data_copy_enqueue (dev, vq); -if (likely (vq->shadow_used_idx)) { -flush_shadow_used_ring (dev, vq); -vhost_vring_call (dev, vq); +if (!(dev->features & (1ULL <<VIRTIO_F_RING_PACKED ))) { +if (likely (vq->shadow_used_idx)) { +flush_shadow_used_ring (dev, vq); +vhost_vring_call (dev, vq); + } + }else { +rte_smp_wmb (); +for (i = avail_head; i < vq->last_avail_idx; i++) { +if ((i & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); +set_desc_used (vq, &descs[i & (vq->size -1 )]); + } } out:
lib/librte_vhost/virtio_net.c vhost_enqueue_burst_packed(struct virtio_net *dev, uint16_t queue_id, · line 865
Quoted 5 lines
lib/librte_vhost/virtio_net.c +1
-1@@ -774,7 +862,7 @@ vhost_enqueue_burst_packed(struct virtio_net *dev, uint16_t queue_id, goto out; } - idx = (idx+1 ) & (vq->size -1 ); + idx = (idx +1 ) & mask;
Are you sure this change is in the right patch?
Quoted 19 lines
lib/librte_vhost/virtio_net.c +4
-3desc = &descs[idx];if (unlikely (!desc_is_avail (vq, desc))) goto out ;@@ -840,10 +928,11 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,return 0 ; } -if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) -return vhost_enqueue_burst_packed (dev, queue_id, pkts, count); -else if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) +if ((dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) && + (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )))return virtio_dev_merge_rx (dev, queue_id, pkts, count); +else if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_enqueue_burst_packed (dev, queue_id, pkts, count);else return virtio_dev_rx (dev, queue_id, pkts, count); }
lib/librte_vhost/virtio_net.c dequeue_desc_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 1270
Quoted 5 lines
lib/librte_vhost/virtio_net.c +0
-2@@ -1266,8 +1355,6 @@ dequeue_desc_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,int wrap_counter = vq->used_wrap_counter;int rc =0 ; -rte_spinlock_lock (&vq->access_lock); -
hmm
Quoted 23 lines
lib/librte_vhost/virtio_net.c +6
-0if (unlikely (vq->enabled ==0 )) goto out;@@ -1451,6 +1538,9 @@ vhost_dequeue_burst_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,struct vring_desc_packed *desc = vq->desc_packed;int err; +if (unlikely (rte_spinlock_trylock (&vq->access_lock) ==0 )) +return 0 ; + count =RTE_MIN (MAX_PKT_BURST , count);for (i =0 ; i < count; i++) { idx = vq->last_used_idx & (vq->size -1 );@@ -1509,15 +1599,15 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_dequeue_burst_packed (dev, vq, mbuf_pool, pkts, count); +if (unlikely (rte_spinlock_trylock (&vq->access_lock) ==0 ))return 0 ;
lib/librte_vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id, · line 1613
Quoted 10 lines
lib/librte_vhost/virtio_net.c +0
-3if (unlikely (vq->enabled ==0 )) goto out_access_unlock; -if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) -return vhost_dequeue_burst_packed (dev, vq, mbuf_pool, pkts, count); - vq->batch_copy_nb_elems =0 ;if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM ))
all above changes, if valid, are for dequeue, so 'tx', so certainly in the wrong patch.
Re: [PATCH v3 20/21] net/virtio: add support for event suppression
In reply to Jens FreimannQuoted 170 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_ethdev.h | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++++- drivers/net/virtio/virtqueue.h | 73 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 6 deletions(-)drivers/net/virtio/virtio_ethdev.c +1
-1@@ -727,7 +727,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];struct virtqueue *vq = rxvq->vq; -virtqueue_enable_intr (vq); +virtqueue_enable_intr (vq,0 ,0 );return 0 ; }drivers/net/virtio/virtio_ethdev.h +1
-1@@ -37,7 +37,7 @@ 1u << VIRTIO_RING_F_INDIRECT_DESC | \ 1ULL << VIRTIO_F_VERSION_1 | \ 1ULL << VIRTIO_F_RING_PACKED | \ - 1ULL << VIRTIO_F_IOMMU_PLATFORM) + 1ULL << VIRTIO_RING_F_EVENT_IDX)#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \drivers/net/virtio/virtio_rxtx.c +14
-1@@ -127,6 +127,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,rte_smp_wmb ();_set_desc_avail (&desc[head_idx], wrap_counter); +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } } txvq->stats.packets += i;@@ -998,6 +1002,10 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, } rxvq->stats.packets += nb_rx; +if (nb_rx >0 &&unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } vq->vq_used_cons_idx = used_idx;@@ -1276,8 +1284,13 @@ virtio_recv_mergeable_pkts(void *rx_queue, rxvq->stats.packets += nb_rx; -if (vtpci_packed_queue (vq->hw)) +if (vtpci_packed_queue (vq->hw)) { +if (unlikely (virtqueue_kick_prepare (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + }return nb_rx; + }/* Allocate new mbuf for the used descriptor */ error =ENOSPC ;drivers/net/virtio/virtqueue.h +57
-3@@ -176,6 +176,8 @@ struct virtqueue {uint16_t vq_free_cnt;/**< num of desc available */ uint16_t vq_avail_idx;/**< sync until needed */ uint16_t vq_free_thresh;/**< free threshold */ +uint16_t vq_signalled_avail; +int vq_signalled_avail_valid;void *vq_ring_virt_mem;/**< linear address of vring*/ unsigned int vq_ring_size;@@ -273,16 +275,34 @@ vring_desc_init(struct vring_desc *dp, uint16_t n)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) &&vtpci_with_feature (vq->hw, +VIRTIO_RING_F_EVENT_IDX )) + vq->vq_ring.device_event->desc_event_flags =RING_EVENT_FLAGS_DISABLE ; +else + vq->vq_ring.avail->flags |=VRING_AVAIL_F_NO_INTERRUPT ; }/** * Tell the backend to interrupt us. */ static inline void -virtqueue_enable_intr (struct virtqueue *vq) +virtqueue_enable_intr (struct virtqueue *vq,uint16_t off,uint16_t wrap_counter) { - vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT ); +uint16_t *flags = &vq->vq_ring.device_event->desc_event_flags; +uint16_t *event_off_wrap = &vq->vq_ring.device_event->desc_event_off_wrap; +if (vtpci_packed_queue (vq->hw)) { + *flags =0 ; + *event_off_wrap =0 ; +if (*event_off_wrap &RING_EVENT_FLAGS_DESC ) { + *event_off_wrap = off |0x7FFF ; + *event_off_wrap |= wrap_counter <<15 ; + *flags |=RING_EVENT_FLAGS_DESC ; + }else + *event_off_wrap =0 ; + *flags |=RING_EVENT_FLAGS_ENABLE ; + }else { + vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT ); + } }/** @@ -342,12 +362,59 @@ vq_update_avail_ring(struct virtqueue *vq, uint16_t desc_idx) vq->vq_avail_idx++; } +static int vhost_idx_diff (struct virtqueue *vq,uint16_t old,uint16_t new) +{ +if (new > old) +return new - old; +return (new + vq->vq_nentries - old); +} + +static int vring_packed_need_event (struct virtqueue *vq, +uint16_t event_off,uint16_t new, +uint16_t old) +{ +return (uint16_t )(vhost_idx_diff (vq, new, event_off) -1 ) < + (uint16_t )vhost_idx_diff (vq, new, old); +} + +static inline int 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 notify_offset, flags, wrap; +uint16_t old, new; +int v; + +if (vtpci_packed_queue (vq->hw)) { + flags = vq->vq_ring.device_event->desc_event_flags; +if (!(flags &RING_EVENT_FLAGS_DESC )) +return flags &RING_EVENT_FLAGS_ENABLE ; +virtio_rmb (); + notify_offset = vq->vq_ring.device_event->desc_event_off_wrap; + wrap = notify_offset &0x1 ; + notify_offset >>=1 ; + + old = vq->vq_signalled_avail; + v = vq->vq_signalled_avail_valid;
drivers/net/virtio/virtqueue.h vq_update_avail_ring(struct virtqueue *vq, uint16_t desc_idx) · line 414
Quoted 10 lines
drivers/net/virtio/virtqueue.h +10
-0+ new = vq->vq_signalled_avail = vq->vq_avail_idx; + vq->vq_signalled_avail_valid =1 ; + +if (unlikely (!v)) +return 0 ; + +return (vring_packed_need_event (vq, new, old, notify_offset) && + wrap == vq->vq_ring.avail_wrap_counter); + }else { +return !(vq->vq_ring.used->flags &VRING_USED_F_NO_NOTIFY );
Maybe I didn't gezt it, but it looks confusing that the function name contains packed, and that it seems it handles non-packed queue case.
Quoted 7 lines
drivers/net/virtio/virtqueue.h +3
-0+ } +} +static inline void virtqueue_notify (struct virtqueue *vq) {
Re: [PATCH v3 19/21] vhost: support mergeable rx buffers with packed queues
In reply to Maxime CoquelinQuoted 13 lines · Maxime Coquelin
Quoted 10 lines · Jens Freimann
This implements support for mergeable receive buffers in vhost when using packed virtqueues. The difference to split virtqueues is not big, it differs mostly where descriptor flags are touched and virtio features are checked.
Signed-off-by Jens Freimann <[email protected]>--- lib/librte_vhost/vhost.c | 2 + lib/librte_vhost/virtio_net.c | 160 +++++++++++++++++++++++++++++++++--------- 2 files changed, 127 insertions(+), 35 deletions(-)
Quoted 11 lines
lib/librte_vhost/vhost.c rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable) · line 583
Quoted 9 lines
lib/librte_vhost/vhost.c +2
-0@@ -580,6 +580,8 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)if (dev ==NULL )return -1 ; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return -1 ;Is this change really related to mergeable buffers?
no, will fix
Quoted 138 lines
Quoted 125 lines
lib/librte_vhost/vhost.c +0
-0if (enable) { RTE_LOG(ERR, VHOST_CONFIG,lib/librte_vhost/virtio_net.c +83
-14@@ -401,17 +401,53 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, } static __rte_always_inline int -fill_vec_buf (struct virtio_net *dev,struct vhost_virtqueue *vq, -uint32_t avail_idx,uint32_t *vec_idx, -struct buf_vector *buf_vec,uint16_t *desc_chain_head, -uint16_t *desc_chain_len) +__fill_vec_buf_packed (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct buf_vector *buf_vec, +uint32_t *len,uint32_t *vec_id) +{ +uint16_t idx = vq->last_avail_idx & (vq->size -1 ); +struct vring_desc_packed *descs= vq->desc_packed; +uint32_t _vec_id = *vec_id; + +if (vq->desc_packed[idx].flags &VRING_DESC_F_INDIRECT ) { + descs = (struct vring_desc_packed *)(uintptr_t ) +vhost_iova_to_vva (dev, vq, vq->desc_packed[idx].addr, + vq->desc_packed[idx].len, +VHOST_ACCESS_RO ); +if (unlikely (!descs)) +return -1 ; + + idx =0 ; + } + +while (1 ) { +if (unlikely (_vec_id >=BUF_VECTOR_MAX || idx >= vq->size)) +return -1 ; + + *len += descs[idx & (vq->size -1 )].len; + buf_vec[_vec_id].buf_addr = descs[idx].addr; + buf_vec[_vec_id].buf_len = descs[idx].len; + buf_vec[_vec_id].desc_idx = idx; + _vec_id++; + +if ((descs[idx & (vq->size -1 )].flags &VRING_DESC_F_NEXT ) ==0 ) +break ; + + idx++; + } + *vec_id = _vec_id; + +return 0 ; +} + +static __rte_always_inline int +__fill_vec_buf_split (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct buf_vector *buf_vec, +uint32_t *len,uint32_t *vec_id,uint32_t avail_idx) {uint16_t idx = vq->avail->ring[avail_idx & (vq->size -1 )]; -uint32_t vec_id = *vec_idx; -uint32_t len =0 ;struct vring_desc *descs = vq->desc; - - *desc_chain_head = idx; +uint32_t _vec_id = *vec_id;if (vq->desc[idx].flags &VRING_DESC_F_INDIRECT ) { descs = (struct vring_desc *)(uintptr_t)@@ -425,20 +461,53 @@ fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq, }while (1 ) { -if (unlikely (vec_id >=BUF_VECTOR_MAX || idx >= vq->size)) +if (unlikely (_vec_id >=BUF_VECTOR_MAX || idx >= vq->size))return -1 ; - len += descs[idx].len; - buf_vec[vec_id].buf_addr = descs[idx].addr; - buf_vec[vec_id].buf_len = descs[idx].len; - buf_vec[vec_id].desc_idx = idx; - vec_id++; + *len += descs[idx].len; + buf_vec[_vec_id].buf_addr = descs[idx].addr; + buf_vec[_vec_id].buf_len = descs[idx].len; + buf_vec[_vec_id].desc_idx = idx; + _vec_id++;if ((descs[idx].flags &VRING_DESC_F_NEXT ) ==0 )break ; idx = descs[idx].next; } + *vec_id = _vec_id; + +return 0 ; +} + +static __rte_always_inline int +fill_vec_buf (struct virtio_net *dev,struct vhost_virtqueue *vq, +uint32_t avail_idx,uint32_t *vec_idx, +struct buf_vector *buf_vec,uint16_t *desc_chain_head, +uint16_t *desc_chain_len) +{ +uint16_t idx; +uint32_t vec_id = *vec_idx; +uint32_t len =0 ; + +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + idx = vq->last_avail_idx & (vq->size -1 ); + }else { + idx = vq->avail->ring[avail_idx & (vq->size -1 )]; + } + + + *desc_chain_head = idx; + +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { +if (__fill_vec_buf_packed (dev, vq, + buf_vec, &len, &vec_id)) +return -1 ; + }else { +if (__fill_vec_buf_split (dev, vq, + buf_vec, &len, &vec_id, avail_idx)) +return -1 ; + } *desc_chain_len = len; *vec_idx = vec_id;@@ -465,14 +534,16 @@ reserve_avail_buf_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, cur_idx = vq->last_avail_idx;while (size >0 ) {lib/librte_vhost/virtio_net.c reserve_avail_buf_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 543
Quoted 10 lines
lib/librte_vhost/virtio_net.c +3
-2-if (unlikely (cur_idx == avail_head)) +if (unlikely (cur_idx == avail_head) && + !(dev->features & (1ull <VIRTIO_F_RING_PACKED )))return -1 ;if (unlikely (fill_vec_buf (dev, vq, cur_idx, &vec_idx, buf_vec, &head_idx, &len) <0 ))return -1 ; len =RTE_MIN (len, size); -update_shadow_used_ring (vq, head_idx, len); +if (!(dev->features & (1ULL <<VIRTIO_F_RING_PACKED )))This is cosmetics, but I wonder if we could have a helper like:
Quoted 4 lines
static inline bool
vring_is_packed(struct virtio_net *dev) { return dev->features & (1ULL << VIRTIO_F_RING_PACKED); }
Yes, I will add one
Quoted 69 lines
Quoted 69 lines
lib/librte_vhost/virtio_net.c +28
-10+update_shadow_used_ring (vq, head_idx, len); size -= len; cur_idx++;@@ -620,6 +691,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t num_buffers;struct buf_vector buf_vec[BUF_VECTOR_MAX ];uint16_t avail_head; +uint16_t i; +struct vring_desc_packed *descs =NULL ;VHOST_LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->nr_vring))) {@@ -634,7 +707,6 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (unlikely (vq->enabled ==0 )) goto out_access_unlock; -if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM ))vhost_user_iotlb_rd_lock (vq);@@ -648,10 +720,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, vq->batch_copy_nb_elems =0 ; -rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size -1 )]); - - vq->shadow_used_idx =0 ; - avail_head = *((volatile uint16_t *)&vq->avail->idx); +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) { + avail_head = vq->last_avail_idx; + descs = vq->desc_packed; + }else { +rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size -1 )]); + avail_head = *((volatile uint16_t *)&vq->avail->idx); + vq->shadow_used_idx =0 ; + }for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) {uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;@@ -661,7 +737,9 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,VHOST_LOG_DEBUG (VHOST_DATA ,"(%d) failed to get enough desc from vring\n" , dev->vid); - vq->shadow_used_idx -= num_buffers; + +if (!dev->features & (1ULL &VIRTIO_F_RING_PACKED )) + vq->shadow_used_idx -= num_buffers;break ; }@@ -671,7 +749,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (copy_mbuf_to_desc_mergeable (dev, vq, pkts[pkt_idx], buf_vec, num_buffers) <0 ) { - vq->shadow_used_idx -= num_buffers; +if (!dev->features & (1ULL &VIRTIO_F_RING_PACKED )) + vq->shadow_used_idx -= num_buffers;break ; }@@ -680,9 +759,18 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,do_data_copy_enqueue (dev, vq); -if (likely (vq->shadow_used_idx)) { -flush_shadow_used_ring (dev, vq); -vhost_vring_call (dev, vq); +if (!(dev->features & (1ULL <<VIRTIO_F_RING_PACKED ))) { +if (likely (vq->shadow_used_idx)) { +flush_shadow_used_ring (dev, vq); +vhost_vring_call (dev, vq); + } + }else { +rte_smp_wmb (); +for (i = avail_head; i < vq->last_avail_idx; i++) { +if ((i & (vq->size -1 )) ==0 ) +toggle_wrap_counter (vq); +set_desc_used (vq, &descs[i & (vq->size -1 )]); + }
Quoted 8 lines
lib/librte_vhost/virtio_net.c vhost_enqueue_burst_packed(struct virtio_net *dev, uint16_t queue_id, · line 864
Quoted 7 lines
lib/librte_vhost/virtio_net.c +1
-1} out:@@ -774,7 +862,7 @@ vhost_enqueue_burst_packed(struct virtio_net *dev, uint16_t queue_id, goto out; } - idx = (idx+1 ) & (vq->size -1 ); + idx = (idx +1 ) & mask;Are you sure this change is in the right patch?
Pretty sure it's not :)
Quoted 45 lines
Quoted 19 lines
lib/librte_vhost/virtio_net.c +4
-3desc = &descs[idx];if (unlikely (!desc_is_avail (vq, desc))) goto out ;@@ -840,10 +928,11 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,return 0 ; } -if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) -return vhost_enqueue_burst_packed (dev, queue_id, pkts, count); -else if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) +if ((dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) && + (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )))return virtio_dev_merge_rx (dev, queue_id, pkts, count); +else if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_enqueue_burst_packed (dev, queue_id, pkts, count);else return virtio_dev_rx (dev, queue_id, pkts, count); }lib/librte_vhost/virtio_net.c dequeue_desc_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 1269
Quoted 4 lines
lib/librte_vhost/virtio_net.c +0
-2@@ -1266,8 +1355,6 @@ dequeue_desc_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,int wrap_counter = vq->used_wrap_counter;int rc =0 ; -rte_spinlock_lock (&vq->access_lock); -hmm
Quoted 20 lines
lib/librte_vhost/virtio_net.c +6
-0if (unlikely (vq->enabled ==0 )) goto out;@@ -1451,6 +1538,9 @@ vhost_dequeue_burst_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,struct vring_desc_packed *desc = vq->desc_packed;int err; +if (unlikely (rte_spinlock_trylock (&vq->access_lock) ==0 )) +return 0 ; + count =RTE_MIN (MAX_PKT_BURST , count);for (i =0 ; i < count; i++) { idx = vq->last_used_idx & (vq->size -1 );@@ -1509,15 +1599,15 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; +if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) +return vhost_dequeue_burst_packed (dev, vq, mbuf_pool, pkts, count); +if (unlikely (rte_spinlock_trylock (&vq->access_lock) ==0 ))return 0 ;if (unlikely (vq->enabled ==0 )) goto out_access_unlock;
Quoted 8 lines
lib/librte_vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 6 lines
lib/librte_vhost/virtio_net.c +0
-3-if (dev->features & (1ULL <<VIRTIO_F_RING_PACKED )) -return vhost_dequeue_burst_packed (dev, vq, mbuf_pool, pkts, count); - vq->batch_copy_nb_elems =0 ;if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM ))all above changes, if valid, are for dequeue, so 'tx', so certainly in the wrong patch.
yes, I'll move them. Thanks!
regards,
Jens
Re: [PATCH v3 20/21] net/virtio: add support for event suppression
In reply to Maxime CoquelinQuoted 162 lines · Maxime Coquelin
Quoted 159 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_ethdev.h | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++++- drivers/net/virtio/virtqueue.h | 73 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 6 deletions(-)drivers/net/virtio/virtio_ethdev.c +1
-1@@ -727,7 +727,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];struct virtqueue *vq = rxvq->vq; -virtqueue_enable_intr (vq); +virtqueue_enable_intr (vq,0 ,0 );return 0 ; }drivers/net/virtio/virtio_ethdev.h +1
-1@@ -37,7 +37,7 @@ 1u << VIRTIO_RING_F_INDIRECT_DESC | \ 1ULL << VIRTIO_F_VERSION_1 | \ 1ULL << VIRTIO_F_RING_PACKED | \ - 1ULL << VIRTIO_F_IOMMU_PLATFORM) + 1ULL << VIRTIO_RING_F_EVENT_IDX)#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \drivers/net/virtio/virtio_rxtx.c +14
-1@@ -127,6 +127,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,rte_smp_wmb ();_set_desc_avail (&desc[head_idx], wrap_counter); +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } } txvq->stats.packets += i;@@ -998,6 +1002,10 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, } rxvq->stats.packets += nb_rx; +if (nb_rx >0 &&unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + } vq->vq_used_cons_idx = used_idx;@@ -1276,8 +1284,13 @@ virtio_recv_mergeable_pkts(void *rx_queue, rxvq->stats.packets += nb_rx; -if (vtpci_packed_queue (vq->hw)) +if (vtpci_packed_queue (vq->hw)) { +if (unlikely (virtqueue_kick_prepare (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" ); + }return nb_rx; + }/* Allocate new mbuf for the used descriptor */ error =ENOSPC ;drivers/net/virtio/virtqueue.h +62
-3@@ -176,6 +176,8 @@ struct virtqueue {uint16_t vq_free_cnt;/**< num of desc available */ uint16_t vq_avail_idx;/**< sync until needed */ uint16_t vq_free_thresh;/**< free threshold */ +uint16_t vq_signalled_avail; +int vq_signalled_avail_valid;void *vq_ring_virt_mem;/**< linear address of vring*/ unsigned int vq_ring_size;@@ -273,16 +275,34 @@ vring_desc_init(struct vring_desc *dp, uint16_t n)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) &&vtpci_with_feature (vq->hw, +VIRTIO_RING_F_EVENT_IDX )) + vq->vq_ring.device_event->desc_event_flags =RING_EVENT_FLAGS_DISABLE ; +else + vq->vq_ring.avail->flags |=VRING_AVAIL_F_NO_INTERRUPT ; }/** * Tell the backend to interrupt us. */ static inline void -virtqueue_enable_intr (struct virtqueue *vq) +virtqueue_enable_intr (struct virtqueue *vq,uint16_t off,uint16_t wrap_counter) { - vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT ); +uint16_t *flags = &vq->vq_ring.device_event->desc_event_flags; +uint16_t *event_off_wrap = &vq->vq_ring.device_event->desc_event_off_wrap; +if (vtpci_packed_queue (vq->hw)) { + *flags =0 ; + *event_off_wrap =0 ; +if (*event_off_wrap &RING_EVENT_FLAGS_DESC ) { + *event_off_wrap = off |0x7FFF ; + *event_off_wrap |= wrap_counter <<15 ; + *flags |=RING_EVENT_FLAGS_DESC ; + }else + *event_off_wrap =0 ; + *flags |=RING_EVENT_FLAGS_ENABLE ; + }else { + vq->vq_ring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT ); + } }/** @@ -342,12 +362,59 @@ vq_update_avail_ring(struct virtqueue *vq, uint16_t desc_idx) vq->vq_avail_idx++; } +static int vhost_idx_diff (struct virtqueue *vq,uint16_t old,uint16_t new) +{ +if (new > old) +return new - old; +return (new + vq->vq_nentries - old); +} + +static int vring_packed_need_event (struct virtqueue *vq, +uint16_t event_off,uint16_t new, +uint16_t old) +{ +return (uint16_t )(vhost_idx_diff (vq, new, event_off) -1 ) < + (uint16_t )vhost_idx_diff (vq, new, old); +} + +static inline int 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 notify_offset, flags, wrap; +uint16_t old, new; +int v; + +if (vtpci_packed_queue (vq->hw)) { + flags = vq->vq_ring.device_event->desc_event_flags; +if (!(flags &RING_EVENT_FLAGS_DESC )) +return flags &RING_EVENT_FLAGS_ENABLE ; +virtio_rmb (); + notify_offset = vq->vq_ring.device_event->desc_event_off_wrap; + wrap = notify_offset &0x1 ; + notify_offset >>=1 ; + + old = vq->vq_signalled_avail; + v = vq->vq_signalled_avail_valid; + new = vq->vq_signalled_avail = vq->vq_avail_idx; + vq->vq_signalled_avail_valid =1 ; + +if (unlikely (!v)) +return 0 ;
Quoted 8 lines
drivers/net/virtio/virtqueue.h vq_update_avail_ring(struct virtqueue *vq, uint16_t desc_idx) · line 414
Quoted 5 lines
drivers/net/virtio/virtqueue.h +5
-0+ +return (vring_packed_need_event (vq, new, old, notify_offset) && + wrap == vq->vq_ring.avail_wrap_counter); + }else { +return !(vq->vq_ring.used->flags &VRING_USED_F_NO_NOTIFY );Maybe I didn't gezt it, but it looks confusing that the function name contains packed, and that it seems it handles non-packed queue case.
No, the else part is not needed here. I'll remove it and make sure to call the right function.
Thanks!
regards,
Jens
Quoted 8 lines
Quoted 8 lines
drivers/net/virtio/virtqueue.h +3
-0+ } +} +static inline void virtqueue_notify (struct virtqueue *vq) {
Re: [PATCH v3 05/21] net/virtio: dump packed virtqueue data
In reply to Jens FreimannQuoted 13 lines · Jens Freimann
Add support to dump packed virtqueue data to the
VIRTQUEUE_DUMP()macro.Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtqueue.h | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/virtio/virtqueue.h +0
-0
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 365
Quoted 6 lines
drivers/net/virtio/virtqueue.h +3
-0@@ -360,6 +360,13 @@ virtqueue_notify(struct virtqueue *vq)#ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTQUEUE_DUMP (vq) do { \ + if (vtpci_packed_queue((vq)->hw)) { \ + PMD_INIT_LOG(DEBUG, \ + "VQ: - size=%d; free=%d; last_used_idx=%d;" \
You missed the , after the format string.
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 366
Quoted 1 line
drivers/net/virtio/virtqueue.h +1
-0+ (vq)->vq_nentries, (vq)->vq_free_cnt, nused); \
There is no way to make sure that nused (the last param in PMD_INIT_LOG()) will be defined and have the meaning of last_used_idx. It's not the right way to use a variable in MACRO.
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 369
Quoted 3 lines
drivers/net/virtio/virtqueue.h +3
-0+break ; \ + } \ +if (vtpci_packed_queue ((vq)->hw))break ; \
Why do the check twice?
Quoted 6 lines
drivers/net/virtio/virtqueue.h +0
-0uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t )(used_idx - (vq)->vq_used_cons_idx); \Signature · 1 line
2.14.3
Re: [PATCH v3 07/21] net/virtio: implement transmit path for packed queues
In reply to Jens FreimannOn Thu, Apr 05, 2018 at 12:10:17PM +0200, Jens Freimann wrote:
[...]
drivers/net/virtio/virtio_rxtx.c line 42
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +2
-0@@ -38,6 +38,101 @@#define VIRTIO_DUMP_PACKET (m, len) do { } while (0)#endif +#define VIRTIO_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \ + ETH_TXQ_FLAGS_NOOFFLOADS)
Why add this?
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c +4
-0+ +/* Cleanup from completed transmits. */ +static void +virtio_xmit_cleanup_packed (struct virtqueue *vq)
drivers/net/virtio/virtio_rxtx.c line 56
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+{ +uint16_t idx; +uint16_t size = vq->vq_nentries; +struct vring_desc_packed *desc = vq->vq_ring.desc_packed; + + idx = vq->vq_used_cons_idx & (size -1 ); +while (desc_is_used (&desc[idx]) && + vq->vq_free_cnt < size) { + vq->vq_free_cnt++; + idx = ++vq->vq_used_cons_idx & (size -1 );
Driver needs to keep track of the number of descriptors to be skipped for each used descriptor.
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +7
-0+ } +} + +uint16_t +virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts) +{
[...]
Quoted 4 lines
+}
int
virtio_dev_rx_queue_done(void *rxq, uint16_t offset){
Please add an empty line between the functions.
drivers/net/virtio/virtio_rxtx.c virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, · line 646
Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +2
-0@@ -547,6 +642,10 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,PMD_INIT_FUNC_TRACE (); +if (vtpci_packed_queue (hw)) { + vq->vq_ring.avail_wrap_counter =1 ;
virtio_dev_tx_queue_setup_finish() will be called during a dev_stop()/dev_start(). The problem is that, the dev_stop() doesn't really stop the device. So we can't reset the wrap counter to 1 in dev_start().
drivers/net/virtio/virtio_rxtx.c virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, · line 669
Quoted 11 lines
drivers/net/virtio/virtio_rxtx.c +3
-1+ } +if (hw->use_simple_tx) {for (desc_idx =0 ; desc_idx < mid_idx; desc_idx++) { vq->vq_ring.avail->ring[desc_idx] =@@ -567,7 +666,8 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, vq->vq_ring.avail->ring[desc_idx] = desc_idx; } -VIRTQUEUE_DUMP (vq); +if (!vtpci_packed_queue (hw))
The check isn't needed.
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +1
-0+VIRTQUEUE_DUMP (vq);return 0 ; }Signature · 1 line
2.14.3
Re: [PATCH v3 18/21] net/virtio: add support for mergeable buffers with packed virtqueues
In reply to Jens FreimannQuoted 16 lines · Jens Freimann
Implement support for receiving merged buffers in virtio when packed virtqueues are enabled.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 10 ++-- drivers/net/virtio/virtio_rxtx.c | 107 +++++++++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 1 + 3 files changed, 104 insertions(+), 14 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0@@ -1322,15 +1322,15 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1328
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +1
-4struct 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) &&vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; - }else if (hw->use_simple_rx) { +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;
The logic isn't right here. It means when hw->use_simple_rx is true, virtio_recv_pkts_vec() will be selected as the rx function for packed ring. But virtio_recv_pkts_vec() doesn't support packed ring now.
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.c +4
-1}else if (vtpci_packed_queue (hw)) { - eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; +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 (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { PMD_INIT_LOG(INFO, "virtio: using mergeable buffer Rx path on port %u",
[...]
Re: [PATCH v3 20/21] net/virtio: add support for event suppression
In reply to Jens FreimannQuoted 26 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_ethdev.h | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++++- drivers/net/virtio/virtqueue.h | 73 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 6 deletions(-)drivers/net/virtio/virtio_ethdev.c +1
-1@@ -727,7 +727,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];struct virtqueue *vq = rxvq->vq; -virtqueue_enable_intr (vq); +virtqueue_enable_intr (vq,0 ,0 );return 0 ; }drivers/net/virtio/virtio_ethdev.h +0
-0
drivers/net/virtio/virtio_ethdev.h line 40
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +0
-1@@ -37,7 +37,7 @@1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \ 1ULL << VIRTIO_F_RING_PACKED | \ - 1ULL << VIRTIO_F_IOMMU_PLATFORM)
Why remove this feature bit?
drivers/net/virtio/virtio_ethdev.h line 40
Quoted 1 line
drivers/net/virtio/virtio_ethdev.h +1
-0+ 1ULL << VIRTIO_RING_F_EVENT_IDX)
Supporting event suppression doesn't means supporting F_EVENT_IDX. Event suppression is mandatory and not a negotiable feature. F_EVENT_IDX is just an optional enhancement for event suppression.
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.h +0
-0#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \drivers/net/virtio/virtio_rxtx.c +0
-0
drivers/net/virtio/virtio_rxtx.c virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts, · line 132
Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +3
-0@@ -127,6 +127,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,rte_smp_wmb ();_set_desc_avail (&desc[head_idx], wrap_counter); +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" );
The indent isn't right.
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +1
-0+ } }
[...]
Re: [PATCH v3 20/21] net/virtio: add support for event suppression
Quoted 22 lines · Tiwei Bie
Quoted 21 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 2 +- drivers/net/virtio/virtio_ethdev.h | 2 +- drivers/net/virtio/virtio_rxtx.c | 15 +++++++- drivers/net/virtio/virtqueue.h | 73 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 6 deletions(-)drivers/net/virtio/virtio_ethdev.c +1
-1@@ -727,7 +727,7 @@ virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];struct virtqueue *vq = rxvq->vq; -virtqueue_enable_intr (vq); +virtqueue_enable_intr (vq,0 ,0 );return 0 ; }
Quoted 11 lines
drivers/net/virtio/virtio_ethdev.h line 40
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.h +0
-1@@ -37,7 +37,7 @@1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \ 1ULL << VIRTIO_F_RING_PACKED | \ - 1ULL << VIRTIO_F_IOMMU_PLATFORM)Why remove this feature bit?
my mistake. will fix it.
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.h line 40
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.h +1
-0+ 1ULL << VIRTIO_RING_F_EVENT_IDX)Supporting event suppression doesn't means supporting
F_EVENT_IDX. Event suppression is mandatory and not a negotiable feature.F_EVENT_IDXis just an optional enhancement for event suppression.
I understand, will fix that too.
Quoted 11 lines
Quoted 11 lines
drivers/net/virtio/virtio_ethdev.h +0
-0#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \ (VIRTIO_PMD_DEFAULT_GUEST_FEATURES | \drivers/net/virtio/virtio_rxtx.c +0
-0@@ -127,6 +127,10 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts, · line 132
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +3
-0rte_smp_wmb ();_set_desc_avail (&desc[head_idx], wrap_counter); +if (unlikely (virtqueue_kick_prepare_packed (vq))) { +virtqueue_notify (vq); +PMD_RX_LOG (DEBUG ,"Notified" );The indent isn't right.
will fix. Thanks!
regards,
Jens
Re: [PATCH v3 07/21] net/virtio: implement transmit path for packed queues
In reply to Tiwei BieQuoted 10 lines · Tiwei Bie
On Thu, Apr 05, 2018 at 12:10:17PM +0200, Jens Freimann wrote:
[...]Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c +0
-0@@ -38,6 +38,101 @@#define VIRTIO_DUMP_PACKET (m, len) do { } while (0)#endif
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c line 42
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+#define VIRTIO_SIMPLE_FLAGS ((uint32_t)ETH_TXQ_FLAGS_NOMULTSEGS | \ + ETH_TXQ_FLAGS_NOOFFLOADS)Why add this?
mistake during rebase, will fix.
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +9
-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; +
Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c line 56
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +5
-0+ idx = vq->vq_used_cons_idx & (size -1 ); +while (desc_is_used (&desc[idx]) && + vq->vq_free_cnt < size) { + vq->vq_free_cnt++; + idx = ++vq->vq_used_cons_idx & (size -1 );Driver needs to keep track of the number of descriptors to be skipped for each used descriptor.
I've added support for this due already (because of your comment on the rxvq flush). Will be in v4.
Quoted 8 lines
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +7
-0+ } +} + +uint16_t +virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts) +{[...]
Quoted 6 lines
Quoted 4 lines
+}
int
virtio_dev_rx_queue_done(void *rxq, uint16_t offset){Please add an empty line between the functions.
ok.
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +0
-0@@ -547,6 +642,10 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,PMD_INIT_FUNC_TRACE ();
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, · line 646
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+if (vtpci_packed_queue (hw)) { + vq->vq_ring.avail_wrap_counter =1 ;
virtio_dev_tx_queue_setup_finish()will be called during a dev_stop()/dev_start(). The problem is that, thedev_stop()doesn't really stop the device. So we can't reset the wrap counter to 1 indev_start().
I see, would virtio_init_device() work?
thanks!
regards,
Jens
Quoted 23 lines
drivers/net/virtio/virtio_rxtx.c virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, · line 669
Quoted 12 lines
drivers/net/virtio/virtio_rxtx.c +3
-1+ } +if (hw->use_simple_tx) {for (desc_idx =0 ; desc_idx < mid_idx; desc_idx++) { vq->vq_ring.avail->ring[desc_idx] =@@ -567,7 +666,8 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev, vq->vq_ring.avail->ring[desc_idx] = desc_idx; } -VIRTQUEUE_DUMP (vq); +if (!vtpci_packed_queue (hw))The check isn't needed.
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +1
-1+VIRTQUEUE_DUMP (vq);return 0 ; } --2.14.3