implement packed virtqueues
v9 cover implement packed virtqueues
This is a basic implementation of packed virtqueues as specified in the Virtio 1.1 draft. A compiled version of the current draft is available at https://github.com/oasis-tcs/virtio-docs.git (or as .pdf at
https://github.com/oasis-tcs/virtio-docs/blob/master/virtio-v1.1-packed-wd10.pdf
A packed virtqueue is different from a split virtqueue in that it consists of only a single descriptor ring that replaces available and used ring, index and descriptor pointers.
Each descriptor is readable and writable and has a flags field. These flags will mark if a descriptor is available or used. To detect new available descriptors even after the ring has wrapped, device and driver each have a single-bit wrap counter that is flipped from 0 to 1 and vice versa every time the last descriptor in the ring is used/made available.
v8-v9:
* fix virtio_ring_free_chain_packed() to handle descriptors correctly in case of out-of-order
* fix check in virtqueue_xmit_cleanup_packed() to improve performance
v7->v8:
* move desc_is_used change to correct patch
* remove trailing newline
* correct xmit code, flags update and memory barrier
* move packed desc init to dedicated function, split and packed variant
Jens Freimann (8):
net/virtio: vring init for packed queues net/virtio: add packed virtqueue defines net/virtio: add packed virtqueue helpers net/virtio: dump packed virtqueue data net/virtio: implement transmit path for packed queues net/virtio: implement receive path for packed queues net/virtio: add virtio send command packed queue support net/virtio: enable packed virtqueues by default
drivers/net/virtio/virtio_ethdev.c | 154 ++++++-- drivers/net/virtio/virtio_ethdev.h | 5 + drivers/net/virtio/virtio_pci.h | 7 + drivers/net/virtio/virtio_ring.h | 105 +++++- drivers/net/virtio/virtio_rxtx.c | 560 +++++++++++++++++++++++++++-- drivers/net/virtio/virtqueue.c | 22 ++ drivers/net/virtio/virtqueue.h | 42 ++- 7 files changed, 841 insertions(+), 54 deletions(-)
Signature · 1 line
2.17.1
PATCH v9 1/8 net/virtio: vring init for packed queues
Add and initialize descriptor data structures.
--- drivers/net/virtio/virtio_ethdev.c | 18 ++++---- drivers/net/virtio/virtio_pci.h | 7 +++ drivers/net/virtio/virtio_ring.h | 74 ++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 15 +++++- 4 files changed, 95 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio_ethdev.c +10 -8
@@ -299,19 +299,21 @@ virtio_init_vring(struct virtqueue *vq)PMD_INIT_FUNC_TRACE (); -/* -* Reinitialise since virtio port might have been stopped and restarted -*/ memset (ring_mem,0 , vq->vq_ring_size); -vring_init (vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); +vring_init (vq->hw, vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_used_cons_idx =0 ; vq->vq_desc_head_idx =0 ; vq->vq_avail_idx =0 ; vq->vq_desc_tail_idx = (uint16_t )(vq->vq_nentries -1 ); vq->vq_free_cnt = vq->vq_nentries;memset (vq->vq_descx,0 ,sizeof (struct vq_desc_extra ) * vq->vq_nentries); - -vring_desc_init (vr->desc, size); +if (vtpci_packed_queue (vq->hw)) { +if (!vtpci_with_feature (vq->hw,VIRTIO_F_IN_ORDER )) +vring_desc_init_packed (vq, size); + }else { +vring_desc_init_split (vr->desc, size); + }/* * Disable device(host) interrupting guest
@@ -386,7 +388,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)/* * Reserve a memzone for vring elements */ - size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + size =vring_size (hw, vq_size,VIRTIO_PCI_VRING_ALIGN ); vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN );PMD_INIT_LOG (DEBUG ,"vring_size: %d, rounded_vring_size: %d" , size, vq->vq_ring_size);
@@ -489,7 +491,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; -vring_desc_init (start_dp,RTE_DIM (txr[i].tx_indir)); +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir));/* first indirect descriptor is always the tx header */ start_dp->addr = txvq->virtio_net_hdr_mem
drivers/net/virtio/virtio_pci.h +7 -0
@@ -113,6 +113,7 @@ struct virtnet_ctl;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34/* * Some VirtIO feature bits (currently bits 28 through 31) are
@@ -314,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_packed_queue (struct virtio_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/net/virtio/virtio_ring.h +64 -10
102 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +14 -1
@@ -161,6 +161,7 @@ struct virtio_pmd_ctrl {struct vq_desc_extra {void *cookie;uint16_t ndescs; +uint16_t next; };struct virtqueue {
@@ -245,9 +246,21 @@ struct virtio_tx_region { __attribute__((__aligned__(16))); }; +static inline void +vring_desc_init_packed (struct virtqueue *vq,int n) +{ +int i; +for (i =0 ; i < n -1 ; i++) { + vq->vq_ring.desc_packed[i].index = i; + vq->vq_descx[i].next = i +1 ; + } + vq->vq_ring.desc_packed[i].index = i; + vq->vq_descx[i].next =VQ_RING_DESC_CHAIN_END ; +} +/* Chain all the descriptors in the ring with an END */ static inline void -vring_desc_init (struct vring_desc *dp,uint16_t n) +vring_desc_init_split (struct vring_desc *dp,uint16_t n) {uint16_t i;
Signature · 1 line
2.17.1
PATCH v9 2/8 net/virtio: add packed virtqueue 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
@@ -15,7 +15,10 @@#define VRING_DESC_F_WRITE 2/* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 - +/* This flag means the descriptor was made available by the driver */ +#define VRING_DESC_F_AVAIL (b) ((uint16_t)(b) << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (b) ((uint16_t)(b) << 15)/* The Host uses this in used->flags to advise the Guest: don't kick me * when you add a buffer. It's unreliable, so it's simply an * optimization. Guest will still kick if it's out of buffers. */
Signature · 1 line
2.17.1
PATCH v9 3/8 net/virtio: add packed virtqueue helpers
In reply to Jens FreimannAdd helper functions to set/clear and check descriptor flags.
--- drivers/net/virtio/virtio_ring.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/net/virtio/virtio_ring.h +26 -0
@@ -77,6 +77,8 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter; +unsigned int used_wrap_counter;union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;
@@ -91,6 +93,30 @@ struct vring { }; }; +static inline void +_set_desc_avail (struct vring_desc_packed *desc,int wrap_counter) +{ + desc->flags |=VRING_DESC_F_AVAIL (wrap_counter) | +VRING_DESC_F_USED (!wrap_counter); +} + +static inline void +set_desc_avail (struct vring *vr,struct vring_desc_packed *desc) +{ +_set_desc_avail (desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used, flags; + + flags = desc->flags; + used = !!(flags &VRING_DESC_F_USED (1 )); + +return used == vr->used_wrap_counter; +} +/* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. *
Signature · 1 line
2.17.1
PATCH v9 4/8 net/virtio: dump packed virtqueue data
In reply to Jens FreimannAdd support to dump packed virtqueue data to theVIRTQUEUE_DUMP() macro.
--- drivers/net/virtio/virtqueue.h | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/virtio/virtqueue.h +9 -0
@@ -368,6 +368,15 @@ virtqueue_notify(struct virtqueue *vq)uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t )(used_idx - (vq)->vq_used_cons_idx); \ +if (vtpci_packed_queue ((vq)->hw)) { \ +PMD_INIT_LOG (DEBUG , \ +"VQ: - size=%d; free=%d; used_cons_idx=%d; avail_idx=%d;" \ +"VQ: - avail_wrap_counter=%d; used_wrap_counter=%d" , \ + (vq)->vq_nentries, (vq)->vq_free_cnt, (vq)->vq_used_cons_idx, \ + (vq)->vq_avail_idx, (vq)->vq_ring.avail_wrap_counter, \ + (vq)->vq_ring.used_wrap_counter); \ +break ; \ + } \PMD_INIT_LOG (DEBUG , \"VQ: - size=%d; free=%d; used=%d; desc_head_idx=%d;" \ " avail.idx=%d; used_cons_idx=%d; used.idx=%d;" \
Signature · 1 line
2.17.1
PATCH v9 5/8 net/virtio: implement transmit path for packed queues
In reply to Jens FreimannThis implements the transmit path for devices with support for packed virtqueues.
--- drivers/net/virtio/virtio_ethdev.c | 32 +++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 284 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 18 +- 4 files changed, 324 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_ethdev.c +22 -10
@@ -384,6 +384,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; +if (vtpci_packed_queue (hw)) + vq->vq_ring.avail_wrap_counter =1 ;/* * Reserve a memzone for vring elements
@@ -490,16 +492,22 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)memset (txr,0 , vq_size *sizeof (*txr));for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; - -vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); - +struct vring_desc_packed *start_dp_packed = txr[i].tx_indir_pq; +/* first indirect descriptor is always the tx header */ - start_dp->addr = txvq->virtio_net_hdr_mem - + i *sizeof (*txr) - + offsetof(struct virtio_tx_region , tx_hdr); - - start_dp->len = hw->vtnet_hdr_size; - start_dp->flags =VRING_DESC_F_NEXT ; +if (vtpci_packed_queue (hw)) { + start_dp_packed->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp_packed->len = hw->vtnet_hdr_size; + }else { +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); + start_dp->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp->len = hw->vtnet_hdr_size; + start_dp->flags =VRING_DESC_F_NEXT ; + } } }
@@ -1338,7 +1346,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_inorder_tx) { +if (vtpci_packed_queue (hw)) { +PMD_INIT_LOG (INFO ,"virtio: using virtio 1.1 Tx path on port %u" , + eth_dev->data->port_id); + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; + }else if (hw->use_inorder_tx) {PMD_INIT_LOG (INFO ,"virtio: using inorder Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -82,6 +82,8 @@ uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,uint16_t virtio_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t virtio_xmit_pkts_inorder (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);
drivers/net/virtio/virtio_rxtx.c +284 -0
308 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +16 -2
@@ -242,8 +242,12 @@ struct virtio_net_hdr_mrg_rxbuf {#define VIRTIO_MAX_TX_INDIRECT 8struct virtio_tx_region {struct virtio_net_hdr_mrg_rxbuf tx_hdr; -struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT ] - __attribute__((__aligned__ (16 ))); +union { +struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT ] + __attribute__((__aligned__ (16 ))); +struct vring_desc_packed tx_indir_pq[VIRTIO_MAX_TX_INDIRECT ] + __attribute__((__aligned__ (16 ))); + }; }; static inline void
@@ -319,6 +323,7 @@ virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)#define VIRTQUEUE_NUSED (vq) ((uint16_t)((vq)->vq_ring.used->idx - (vq)->vq_used_cons_idx))void vq_ring_free_chain (struct virtqueue *vq,uint16_t desc_idx); +void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx);void vq_ring_free_inorder (struct virtqueue *vq,uint16_t desc_idx,uint16_t num);
@@ -352,6 +357,15 @@ virtqueue_kick_prepare(struct virtqueue *vq)return !(vq->vq_ring.used->flags &VRING_USED_F_NO_NOTIFY ); } +static inline int +virtqueue_kick_prepare_packed (struct virtqueue *vq) +{ +uint16_t flags; + + flags = vq->vq_ring.device_event->desc_event_flags &RING_EVENT_FLAGS_DESC ; +return (flags !=RING_EVENT_FLAGS_DISABLE ); +} +static inline void virtqueue_notify (struct virtqueue *vq) {
Signature · 1 line
2.17.1
PATCH v9 6/8 net/virtio: implement receive path for packed queues
In reply to Jens FreimannImplement the receive part.
--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 280 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 297 insertions(+), 27 deletions(-)
drivers/net/virtio/virtio_ethdev.c +14 -4
@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ; + }/* * Reserve a memzone for vring elements
@@ -1326,7 +1328,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private; -if (hw->use_simple_rx) { +if (vtpci_packed_queue (hw)) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts; + }else { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; + } + }else if (hw->use_simple_rx) {PMD_INIT_LOG (INFO ,"virtio: using simple Rx path on port %u" , eth_dev->data->port_id); eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
@@ -1490,7 +1498,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 );
@@ -1918,7 +1927,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)rte_spinlock_init (&hw->state_lock); - hw->use_simple_rx =1 ; +if (!vtpci_packed_queue (hw)) + hw->use_simple_rx =1 ;if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { hw->use_inorder_tx =1 ;
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -73,6 +73,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 +258 -22
371 lines not on this page · raw message
drivers/net/virtio/virtqueue.c +22 -0
@@ -58,12 +58,34 @@ virtqueue_detach_unused(struct virtqueue *vq)void virtqueue_rxvq_flush (struct virtqueue *vq) { +struct vring_desc_packed *descs = vq->vq_ring.desc_packed;struct virtnet_rx *rxq = &vq->rxq;struct virtio_hw *hw = vq->hw;struct vring_used_elem *uep;struct vq_desc_extra *dxp;uint16_t used_idx, desc_idx;uint16_t nb_used, i; +uint16_t size = vq->vq_nentries; + +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx; +if (i > size) { +PMD_INIT_LOG (ERR ,"vq_used_cons_idx out of range, %d" , vq->vq_used_cons_idx); +return ; + } +while (desc_is_used (&descs[i], &vq->vq_ring) && + i < size) { + dxp = &vq->vq_descx[descs[i].index]; +if (dxp->cookie !=NULL ) { +rte_pktmbuf_free (dxp->cookie); + dxp->cookie =NULL ; + } +vq_ring_free_chain_packed (vq, descs[i].index, i); + i = dxp->next; + vq->vq_used_cons_idx++; + } +return ; + } nb_used =VIRTQUEUE_NUSED (vq);
drivers/net/virtio/virtqueue.h +1 -1
@@ -323,7 +323,7 @@ virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)#define VIRTQUEUE_NUSED (vq) ((uint16_t)((vq)->vq_ring.used->idx - (vq)->vq_used_cons_idx))void vq_ring_free_chain (struct virtqueue *vq,uint16_t desc_idx); -void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx); +void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,uint16_t used_idx);void vq_ring_free_inorder (struct virtqueue *vq,uint16_t desc_idx,uint16_t num);
Signature · 1 line
2.17.1
PATCH v9 7/8 net/virtio: add virtio send command packed queue support
In reply to Jens FreimannUse packed virtqueue format when reading and writing descriptors to/from the ring.
--- drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
drivers/net/virtio/virtio_ethdev.c +90 -0
@@ -141,6 +141,90 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS ]; +static struct virtio_pmd_ctrl * +virtio_pq_send_command (struct virtnet_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num) +{ +struct virtqueue *vq = cvq->vq; +int head; +struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct virtio_pmd_ctrl *result; +int wrap_counter; +int sum =0 ; +int k; + +/* +* Format is enforced in qemu code: +* One TX packet for header; +* At least one TX packet per argument; +* One RX packet for ACK. +*/ + head = vq->vq_avail_idx; + wrap_counter = vq->vq_ring.avail_wrap_counter; + desc[head].flags =VRING_DESC_F_NEXT ; + desc[head].addr = cvq->virtio_net_hdr_mem; + desc[head].len =sizeof (struct virtio_net_ctrl_hdr ); + vq->vq_free_cnt--; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + +for (k =0 ; k < pkt_num; k++) { + desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem + +sizeof (struct virtio_net_ctrl_hdr ) + +sizeof (ctrl->status) +sizeof (uint8_t ) * sum; + desc[vq->vq_avail_idx].len = dlen[k]; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_NEXT ; + sum += dlen[k]; + vq->vq_free_cnt--; +_set_desc_avail (&desc[vq->vq_avail_idx], + vq->vq_ring.avail_wrap_counter); +rte_smp_wmb (); + vq->vq_free_cnt--; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + } + + + desc[vq->vq_avail_idx].addr = cvq->virtio_net_hdr_mem + +sizeof (struct virtio_net_ctrl_hdr ); + desc[vq->vq_avail_idx].len =sizeof (ctrl->status); + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; +_set_desc_avail (&desc[vq->vq_avail_idx], + vq->vq_ring.avail_wrap_counter); +_set_desc_avail (&desc[head], wrap_counter); +rte_smp_wmb (); + + vq->vq_free_cnt--; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + +virtqueue_notify (vq); + +/* wait for used descriptors in virtqueue */ +do { +rte_rmb (); +usleep (100 ); + }while (!desc_is_used (&desc[head], &vq->vq_ring)); + +/* now get used descriptors */ +while (desc_is_used (&desc[vq->vq_used_cons_idx], &vq->vq_ring)) { + vq->vq_free_cnt++; +if (++vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_ring.used_wrap_counter ^=1 ; + } + } + + result = cvq->virtio_net_hdr_mz->addr; +return result; +} +static int virtio_send_command (struct virtnet_ctl *cvq,struct virtio_pmd_ctrl *ctrl,int *dlen,int pkt_num)
@@ -174,6 +258,11 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,memcpy (cvq->virtio_net_hdr_mz->addr, ctrl,sizeof (struct virtio_pmd_ctrl )); +if (vtpci_packed_queue (vq->hw)) { + result =virtio_pq_send_command (cvq, ctrl, dlen, pkt_num); + goto out_unlock; + } +/* * Format is enforced in qemu code: * One TX packet for header;
@@ -245,6 +334,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, result = cvq->virtio_net_hdr_mz->addr; +out_unlock:rte_spinlock_unlock (&cvq->lock);return result->status; }
Signature · 1 line
2.17.1
PATCH v9 8/8 net/virtio: enable packed virtqueues by default
In reply to Jens Freimann--- drivers/net/virtio/virtio_ethdev.h | 1 + 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_ethdev.h +1 -0
@@ -34,6 +34,7 @@1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \1ULL <<VIRTIO_F_IN_ORDER | \ +1ULL <<VIRTIO_F_RING_PACKED | \ 1ULL << VIRTIO_F_IOMMU_PLATFORM) #define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \
Signature · 1 line
2.17.1
Re: [PATCH v9 5/8] net/virtio: implement transmit path for packed queues
In reply to Jens FreimannQuoted 17 lines · Jens Freimann
drivers/net/virtio/virtio_rxtx.c +9
-0@@ -88,6 +88,42 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; } +void +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx ) +{ +struct vring_desc_packed *dp; +struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ; +uint16_t desc_idx_last = desc_idx; +int i =0 ; + + dp = &vq->vq_ring.desc_packed[used_idx];
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 109
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+ dxp = &vq->vq_descx[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 && i < dxp->ndescs) { + desc_idx_last = dxp->next; + dp = &vq->vq_ring.desc_packed[dxp->next]; + dxp = &vq->vq_descx[dxp->next]; + i++; + } + }
Haven't you missed to squash some changes you did?
It seems you made some changes on your github branch to take Tiwei's comment on v8 into account, but it is not here (i.e. you can't use VRING_DESC_F_NEXT here).
Re: [PATCH v9 1/8] net/virtio: vring init for packed queues
In reply to Jens FreimannQuoted 15 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 ++++---- drivers/net/virtio/virtio_pci.h | 7 +++ drivers/net/virtio/virtio_ring.h | 74 ++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 15 +++++- 4 files changed, 95 insertions(+), 19 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0
drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 304
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +0
-3@@ -299,19 +299,21 @@ virtio_init_vring(struct virtqueue *vq)PMD_INIT_FUNC_TRACE (); -/* -* Reinitialise since virtio port might have been stopped and restarted -*/
Why above comments are removed?
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +2
-1memset (ring_mem,0 , vq->vq_ring_size); -vring_init (vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); +vring_init (vq->hw, vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_used_cons_idx =0 ;
drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 313
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +3
-2vq->vq_desc_head_idx =0 ; vq->vq_avail_idx =0 ; vq->vq_desc_tail_idx = (uint16_t )(vq->vq_nentries -1 ); vq->vq_free_cnt = vq->vq_nentries;memset (vq->vq_descx,0 ,sizeof (struct vq_desc_extra ) * vq->vq_nentries); - -vring_desc_init (vr->desc, size); +if (vtpci_packed_queue (vq->hw)) { +if (!vtpci_with_feature (vq->hw,VIRTIO_F_IN_ORDER )) +vring_desc_init_packed (vq, size);
Don't we need to initialize descs in IN-ORDER case?
Quoted 54 lines
drivers/net/virtio/virtio_ethdev.c +5
-2+ }else { +vring_desc_init_split (vr->desc, size); + }/* * Disable device(host) interrupting guest @@ -386,7 +388,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)/* * Reserve a memzone for vring elements */ - size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + size =vring_size (hw, vq_size,VIRTIO_PCI_VRING_ALIGN ); vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN );PMD_INIT_LOG (DEBUG ,"vring_size: %d, rounded_vring_size: %d" , size, vq->vq_ring_size);@@ -489,7 +491,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; -vring_desc_init (start_dp,RTE_DIM (txr[i].tx_indir)); +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir));/* first indirect descriptor is always the tx header */ start_dp->addr = txvq->virtio_net_hdr_memdrivers/net/virtio/virtio_pci.h +7
-0@@ -113,6 +113,7 @@ struct virtnet_ctl;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34/* * Some VirtIO feature bits (currently bits 28 through 31) are @@ -314,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_packed_queue (struct virtio_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */ drivers/net/virtio/virtio_ring.h +0
-0
drivers/net/virtio/virtio_ring.h struct vring_used { · line 63
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +7
-0@@ -54,11 +54,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;
s/index/id/
drivers/net/virtio/virtio_ring.h struct vring_used { · line 65
Quoted 2 lines
drivers/net/virtio/virtio_ring.h +2
-0+uint16_t flags; +} __attribute__ ((aligned(16)));
We don't need the "__attribute__ ((aligned(16)))" in descriptor structure's definition.
drivers/net/virtio/virtio_ring.h struct vring_used { · line 69
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +4
-0+ +#define RING_EVENT_FLAGS_ENABLE 0x0 +#define RING_EVENT_FLAGS_DISABLE 0x1 +#define RING_EVENT_FLAGS_DESC 0x2
Please add an empty line here.
Quoted 14 lines
drivers/net/virtio/virtio_ring.h +9
-3+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; + };
drivers/net/virtio/virtio_ring.h struct vring_used { · line 90
Quoted 10 lines
drivers/net/virtio/virtio_ring.h +8
-0+union { +struct vring_avail *avail; +struct vring_packed_desc_event *driver_event; + }; +union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + }; };
We should define a new vring structure for packed ring.
Thanks
Re: [PATCH v9 2/8] net/virtio: add packed virtqueue 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 21
Quoted 8 lines
drivers/net/virtio/virtio_ring.h +4
-1@@ -15,7 +15,10 @@#define VRING_DESC_F_WRITE 2/* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 - +/* This flag means the descriptor was made available by the driver */ +#define VRING_DESC_F_AVAIL (b) ((uint16_t)(b) << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (b) ((uint16_t)(b) << 15)
Please add an empty line here.
Quoted 6 lines
drivers/net/virtio/virtio_ring.h +0
-0/* The Host uses this in used->flags to advise the Guest: don't kick me * when you add a buffer. It's unreliable, so it's simply an * optimization. Guest will still kick if it's out of buffers. */ Signature · 1 line
2.17.1
Re: [PATCH v9 3/8] net/virtio: add packed virtqueue helpers
In reply to Jens FreimannQuoted 12 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/net/virtio/virtio_ring.h +0
-0
drivers/net/virtio/virtio_ring.h struct vring_packed_desc_event { · line 81
Quoted 5 lines
drivers/net/virtio/virtio_ring.h +2
-0@@ -77,6 +77,8 @@ struct vring_packed_desc_event {struct vring {unsigned int num; +unsigned int avail_wrap_counter; +unsigned int used_wrap_counter;
Above fields should be defined in struct virtqueue.
Quoted 37 lines
drivers/net/virtio/virtio_ring.h +24
-0union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;@@ -91,6 +93,30 @@ struct vring { }; }; +static inline void +_set_desc_avail (struct vring_desc_packed *desc,int wrap_counter) +{ + desc->flags |=VRING_DESC_F_AVAIL (wrap_counter) | +VRING_DESC_F_USED (!wrap_counter); +} + +static inline void +set_desc_avail (struct vring *vr,struct vring_desc_packed *desc) +{ +_set_desc_avail (desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used, flags; + + flags = desc->flags; + used = !!(flags &VRING_DESC_F_USED (1 )); + +return used == vr->used_wrap_counter; +} +/* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. * Signature · 1 line
2.17.1
Re: [PATCH v9 4/8] net/virtio: dump packed virtqueue data
In reply to Jens FreimannQuoted 14 lines · Jens Freimann
Add support to dump packed virtqueue data to the
VIRTQUEUE_DUMP()macro.Signed-off-by Jens Freimann <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- drivers/net/virtio/virtqueue.h | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/net/virtio/virtqueue.h +0
-0
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 374
Quoted 7 lines
drivers/net/virtio/virtqueue.h +4
-0@@ -368,6 +368,15 @@ virtqueue_notify(struct virtqueue *vq)uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t )(used_idx - (vq)->vq_used_cons_idx); \ +if (vtpci_packed_queue ((vq)->hw)) { \ + PMD_INIT_LOG(DEBUG, \ + "VQ: - size=%d; free=%d; used_cons_idx=%d; avail_idx=%d;" \ + "VQ: - avail_wrap_counter=%d; used_wrap_counter=%d", \
Please remove the second "VQ: -" as they are on the same line.
Quoted 11 lines
drivers/net/virtio/virtqueue.h +5
-0+ (vq)->vq_nentries, (vq)->vq_free_cnt, (vq)->vq_used_cons_idx, \ + (vq)->vq_avail_idx, (vq)->vq_ring.avail_wrap_counter, \ + (vq)->vq_ring.used_wrap_counter); \ +break ; \ + } \PMD_INIT_LOG (DEBUG , \"VQ: - size=%d; free=%d; used=%d; desc_head_idx=%d;" \ " avail.idx=%d; used_cons_idx=%d; used.idx=%d;" \Signature · 1 line
2.17.1
Re: [PATCH v9 5/8] net/virtio: implement transmit path for packed queues
In reply to Jens FreimannQuoted 25 lines · Jens Freimann
This implements the transmit path for devices with support for packed virtqueues.
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 32 +++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 284 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 18 +- 4 files changed, 324 insertions(+), 12 deletions(-)drivers/net/virtio/virtio_ethdev.c +2
-0@@ -384,6 +384,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; +if (vtpci_packed_queue (hw)) + vq->vq_ring.avail_wrap_counter =1 ;/* * Reserve a memzone for vring elements
drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 495
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +1
-3@@ -490,16 +492,22 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)memset (txr,0 , vq_size *sizeof (*txr));for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; - -vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); - +struct vring_desc_packed *start_dp_packed = txr[i].tx_indir_pq;
A space is missing before *start_dp_packed
Quoted 25 lines
drivers/net/virtio/virtio_ethdev.c +14
-6+/* first indirect descriptor is always the tx header */ - start_dp->addr = txvq->virtio_net_hdr_mem - + i *sizeof (*txr) - + offsetof(struct virtio_tx_region , tx_hdr); - - start_dp->len = hw->vtnet_hdr_size; - start_dp->flags =VRING_DESC_F_NEXT ; +if (vtpci_packed_queue (hw)) { + start_dp_packed->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp_packed->len = hw->vtnet_hdr_size; + }else { +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); + start_dp->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp->len = hw->vtnet_hdr_size; + start_dp->flags =VRING_DESC_F_NEXT ; + } } }
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1353
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.c +5
-1@@ -1338,7 +1346,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_inorder_tx) { +if (vtpci_packed_queue (hw)) { +PMD_INIT_LOG (INFO ,"virtio: using virtio 1.1 Tx path on port %u" , + eth_dev->data->port_id); + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; + }else if (hw->use_inorder_tx) {
Please make the structure more clear, e.g. something like:
if (vtpci_packed_queue(hw)) {
// packed ring
} else {
// split ring
}Quoted 21 lines
drivers/net/virtio/virtio_ethdev.c +0
-0PMD_INIT_LOG (INFO ,"virtio: using inorder Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;drivers/net/virtio/virtio_ethdev.h +2
-0@@ -82,6 +82,8 @@ uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,uint16_t virtio_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t virtio_xmit_pkts_inorder (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);drivers/net/virtio/virtio_rxtx.c +0
-0
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 92
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +2
-0@@ -88,6 +88,42 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; } +void +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx )
Does above code pass the build test? (Type is missing for used_idx)
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 95
Quoted 3 lines
drivers/net/virtio/virtio_rxtx.c +3
-0+{ +struct vring_desc_packed *dp; +struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ;
Do we really need to initialize them?
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 103
Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c +8
-0+uint16_t desc_idx_last = desc_idx; +int i =0 ; + + dp = &vq->vq_ring.desc_packed[used_idx]; + dxp = &vq->vq_descx[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 && i < dxp->ndescs) {
NEXT can't be used here.
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 105
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+ desc_idx_last = dxp->next; + dp = &vq->vq_ring.desc_packed[dxp->next];
dxp->next is used to link the dxps, it's not supposed to be desc ring's index.
Quoted 33 lines
drivers/net/virtio/virtio_rxtx.c +26
-0+ dxp = &vq->vq_descx[dxp->next]; + i++; + } + } + +/* +* We must append the existing free chain, if any, to the end of +* newly freed chain. If the virtqueue was completely used, then +* head would be VQ_RING_DESC_CHAIN_END (ASSERTed above). +*/ +if (vq->vq_desc_tail_idx ==VQ_RING_DESC_CHAIN_END ) { + vq->vq_desc_head_idx = desc_idx; + }else { + dxp_tail = &vq->vq_descx[vq->vq_desc_tail_idx]; + dxp_tail->next = desc_idx; + } + + vq->vq_desc_tail_idx = desc_idx_last; + dxp->next =VQ_RING_DESC_CHAIN_END ; +} +static uint16_t virtqueue_dequeue_burst_rx (struct virtqueue *vq,struct rte_mbuf **rx_pkts,uint32_t *len,uint16_t num)@@ -165,6 +201,33 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,#endif /* Cleanup from completed transmits. */ +static void +virtio_xmit_cleanup_packed (struct virtqueue *vq,int num) +{ +uint16_t used_idx, id; +uint16_t size = vq->vq_nentries;
drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 218
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct vq_desc_extra *dxp; + + used_idx = vq->vq_used_cons_idx; +while (num &&desc_is_used (&desc[used_idx], &vq->vq_ring)) { + num --; + used_idx = vq->vq_used_cons_idx; + id = desc[used_idx].index; + dxp = &vq->vq_descx[id]; +if (++vq->vq_used_cons_idx >= size) {
We need to skip dxp->ndescs descriptors here.
Quoted 33 lines
drivers/net/virtio/virtio_rxtx.c +26
-0+ vq->vq_used_cons_idx -= size; + vq->vq_ring.used_wrap_counter ^=1 ; + } +vq_ring_free_chain_packed (vq, id, used_idx); +if (dxp->cookie !=NULL ) { +rte_pktmbuf_free (dxp->cookie); + dxp->cookie =NULL ; + } + used_idx = vq->vq_used_cons_idx; + } +} +static void virtio_xmit_cleanup (struct virtqueue *vq,uint16_t num) {@@ -456,6 +519,134 @@ virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq, vq->vq_desc_head_idx = idx & (vq->vq_nentries -1 ); } +static inline void +virtqueue_enqueue_xmit_packed (struct virtnet_tx *txvq,struct rte_mbuf *cookie, +uint16_t needed,int use_indirect,int can_push, +int in_order) +{ +struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr; +struct vq_desc_extra *dxp, *head_dxp; +struct virtqueue *vq = txvq->vq; +struct vring_desc_packed *start_dp, *head_dp; +uint16_t seg_num = cookie->nb_segs; +uint16_t idx, head_id, head_flags; +uint16_t head_size = vq->hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +uint16_t prev;
drivers/net/virtio/virtio_rxtx.c virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq, · line 545
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+ + head_id = vq->vq_desc_head_idx; + idx = head_id; + prev = idx; + start_dp = vq->vq_ring.desc_packed; + dxp = &vq->vq_descx[idx]; + dxp->ndescs = needed; + + head_dp = &vq->vq_ring.desc_packed[head_id]; + head_dxp = &vq->vq_descx[head_id];
I don't think desc and descx can always have the same index.
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +5
-0+ head_dxp->cookie = (void *) cookie; + head_flags = cookie->next ?VRING_DESC_F_NEXT :0 ; + head_flags |=VRING_DESC_F_AVAIL (vq->vq_ring.avail_wrap_counter) | +VRING_DESC_F_USED (!vq->vq_ring.avail_wrap_counter); +
[...]
drivers/net/virtio/virtio_rxtx.c
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +6
-0+static inline int +virtqueue_kick_prepare_packed (struct virtqueue *vq) +{ +uint16_t flags; + + flags = vq->vq_ring.device_event->desc_event_flags &RING_EVENT_FLAGS_DESC ;
We can't "& RING_EVENT_FLAGS_DESC" here.
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +3
-0+return (flags !=RING_EVENT_FLAGS_DISABLE ); +} +static inline void virtqueue_notify (struct virtqueue *vq) {Signature · 1 line
2.17.1
Re: [PATCH v9 6/8] net/virtio: implement receive path for packed queues
In reply to Jens FreimannQuoted 16 lines · Jens Freimann
Implement the receive part.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 280 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 297 insertions(+), 27 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0
drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 389
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ;
Why just use used_wrap_counter in receive path?
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +1
-0+ }/* * Reserve a memzone for vring elements
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1335
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.c +5
-1@@ -1326,7 +1328,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private; -if (hw->use_simple_rx) { +if (vtpci_packed_queue (hw)) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts; + }else { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed;
The indent is wrong.
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1337
Quoted 2 lines
drivers/net/virtio/virtio_ethdev.c +2
-0+ } + }else if (hw->use_simple_rx) {
Please make the structure more clear, e.g.
if (vtpci_packed_queue(hw)) {
// packed ring
} else {
// split ring
}Quoted 58 lines
drivers/net/virtio/virtio_ethdev.c +4
-2PMD_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;@@ -1490,7 +1498,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 );@@ -1918,7 +1927,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)rte_spinlock_init (&hw->state_lock); - hw->use_simple_rx =1 ; +if (!vtpci_packed_queue (hw)) + hw->use_simple_rx =1 ;if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { hw->use_inorder_tx =1 ;drivers/net/virtio/virtio_ethdev.h +2
-0@@ -73,6 +73,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 +2
-1@@ -31,6 +31,7 @@#include "virtqueue.h" #include "virtio_rxtx.h" #include "virtio_rxtx_simple.h" +#include "virtio_ring.h" #ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTIO_DUMP_PACKET (m, len) rte_pktmbuf_dump(stdout, m, len)@@ -89,7 +90,7 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) }void -vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx ) +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,uint16_t used_idx) {struct vring_desc_packed *dp;struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ;
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx) · line 105
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c +0
-1@@ -102,7 +103,6 @@ vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx)if ((dp->flags &VRING_DESC_F_INDIRECT ) ==0 ) {while (dp->flags &VRING_DESC_F_NEXT && i < dxp->ndescs) { desc_idx_last = dxp->next; - dp = &vq->vq_ring.desc_packed[dxp->next];
Why above line was added before this patch?
Quoted 81 lines
drivers/net/virtio/virtio_rxtx.c +67
-0dxp = &vq->vq_descx[dxp->next]; i++; }@@ -124,6 +124,47 @@ vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx) dxp->next =VQ_RING_DESC_CHAIN_END ; } +static uint16_t +virtqueue_dequeue_burst_rx_packed (struct virtqueue *vq, +struct rte_mbuf **rx_pkts, +uint32_t *len, +uint16_t num) +{ +struct rte_mbuf *cookie; +uint16_t used_idx; +uint16_t id; +struct vring_desc_packed *desc; +uint16_t i; + +for (i =0 ; i < num; i++) { + used_idx = vq->vq_used_cons_idx; + desc = (struct vring_desc_packed *) vq->vq_ring.desc_packed; +if (!desc_is_used (&desc[used_idx], &vq->vq_ring)) +return i; + len[i] = desc[used_idx].len; + id = desc[used_idx].index; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; + +if (unlikely (cookie ==NULL )) { +PMD_DRV_LOG (ERR ,"vring descriptor with no mbuf cookie at %u" , + vq->vq_used_cons_idx); +break ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + rx_pkts[i] = cookie; +vq_ring_free_chain_packed (vq, id, used_idx); + + vq->vq_used_cons_idx += vq->vq_descx[id].ndescs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_ring.used_wrap_counter ^=1 ; + } + } + +return i; +} +static uint16_t virtqueue_dequeue_burst_rx (struct virtqueue *vq,struct rte_mbuf **rx_pkts,uint32_t *len,uint16_t num)@@ -369,6 +410,55 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)return 0 ; } +static inline int +virtqueue_enqueue_recv_refill_packed (struct virtqueue *vq,struct rte_mbuf *cookie) +{ +struct vq_desc_extra *dxp; +struct virtio_hw *hw = vq->hw; +struct vring_desc_packed *start_dp; +uint16_t needed =1 ; +uint16_t head_idx, idx; +uint16_t flags; + +if (unlikely (vq->vq_free_cnt ==0 )) +return -ENOSPC ; +if (unlikely (vq->vq_free_cnt < needed)) +return -EMSGSIZE ; + + head_idx = vq->vq_desc_head_idx; +if (unlikely (head_idx >= vq->vq_nentries)) +return -EFAULT ; + + idx = head_idx; + dxp = &vq->vq_descx[idx]; + dxp->cookie = (void *)cookie; + dxp->ndescs = needed; + + start_dp = vq->vq_ring.desc_packed; + start_dp[idx].addr =
drivers/net/virtio/virtio_rxtx.c virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie) · line 448
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+VIRTIO_MBUF_ADDR (cookie, vq) + +RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size; + start_dp[idx].len = + cookie->buf_len -RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size; + flags =VRING_DESC_F_WRITE ; + flags |=VRING_DESC_F_AVAIL (vq->vq_ring.avail_wrap_counter) | +VRING_DESC_F_USED (!vq->vq_ring.avail_wrap_counter); +rte_smp_wmb (); + start_dp[idx].flags = flags; + idx = dxp->next;
We should always use the descriptors in packed ring in the ring order (we have to use the elements in vq_descx[] out of order if device processes descriptors out of order).
Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c +13
-0+ vq->vq_desc_head_idx = idx; +if (vq->vq_desc_head_idx ==VQ_RING_DESC_CHAIN_END ) + vq->vq_desc_tail_idx = idx; + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - needed); + + vq->vq_avail_idx += needed; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx =0 ; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + +return 0 ; +}
[...]
Quoted 26 lines
uint16_tvirtio_recv_mergeable_pkts_inorder(void*rx_queue,drivers/net/virtio/virtio_rxtx.c +9
-1struct rte_mbuf **rx_pkts,@@ -1385,12 +1582,20 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint16_t extra_idx;uint32_t seg_res;uint32_t hdr_size; +uint32_t rx_num =0 ; nb_rx =0 ;if (unlikely (hw->started ==0 ))return nb_rx; - nb_used =VIRTQUEUE_NUSED (vq); +if (vtpci_packed_queue (vq->hw)) { +if (!desc_is_used (&vq->vq_ring.desc_packed[vq->vq_used_cons_idx], + &vq->vq_ring)) +return 0 ; + nb_used =VIRTIO_MBUF_BURST_SZ ; + }else { + nb_used =VIRTQUEUE_NUSED (vq); + }virtio_rmb ();
drivers/net/virtio/virtio_rxtx.c virtio_recv_mergeable_pkts(void *rx_queue, · line 1611
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c +1
-0@@ -1403,13 +1608,20 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_res =0 ; hdr_size = hw->vtnet_hdr_size; +
No need to add above empty line.
Quoted 17 lines
drivers/net/virtio/virtio_rxtx.c +7
-1while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;if (nb_rx == nb_pkts)break ; - num =virtqueue_dequeue_burst_rx (vq, rcv_pkts, len,1 ); +if (vtpci_packed_queue (vq->hw)) + num =virtqueue_dequeue_burst_rx_packed (vq, rcv_pkts, + len,1 ); +else + num =virtqueue_dequeue_burst_rx (vq, rcv_pkts, len,1 ); +if (num ==0 ) +return nb_rx;if (num !=1 )continue ;
[...]
Quoted 9 lines · Jens Freimann
This is a basic implementation of packed virtqueues as specified in the Virtio 1.1 draft. A compiled version of the current draft is available at https://github.com/oasis-tcs/virtio-docs.git (or as .pdf at
https://github.com/oasis-tcs/virtio-docs/blob/master/virtio-v1.1-packed-wd10.pdfA packed virtqueue is different from a split virtqueue in that it consists of only a single descriptor ring that replaces available and used ring, index and descriptor pointers.
Quoted 5 lines
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.
Do we have the performance numbers which can show the performance improvements in driver and vhost?
Thanks
Quoted 36 lines
v8-v9:
* fixvirtio_ring_free_chain_packed()to handle descriptors correctly in case of out-of-order
* fix check invirtqueue_xmit_cleanup_packed()to improve performance
v7->v8:
* movedesc_is_usedchange to correct patch
* remove trailing newline
* correct xmit code, flags update and memory barrier
* move packed desc init to dedicated function, split and packed variantJens Freimann (8):
net/virtio: vring init for packed queues net/virtio: add packed virtqueue defines net/virtio: add packed virtqueue helpers net/virtio: dump packed virtqueue data net/virtio: implement transmit path for packed queues net/virtio: implement receive path for packed queues net/virtio: add virtio send command packed queue support net/virtio: enable packed virtqueues by defaultdrivers/net/virtio/virtio_ethdev.c | 154 ++++++-- drivers/net/virtio/virtio_ethdev.h | 5 + drivers/net/virtio/virtio_pci.h | 7 + drivers/net/virtio/virtio_ring.h | 105 +++++- drivers/net/virtio/virtio_rxtx.c | 560 +++++++++++++++++++++++++++-- drivers/net/virtio/virtqueue.c | 22 ++ drivers/net/virtio/virtqueue.h | 42 ++- 7 files changed, 841 insertions(+), 54 deletions(-)Signature · 1 line
2.17.1
PATCH v9 5/8 net/virtio: implement transmit path for packed queues
In reply to Jens FreimannThis implements the transmit path for devices with support for packed virtqueues.
--- drivers/net/virtio/virtio_ethdev.c | 32 +++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 285 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 18 +- 4 files changed, 325 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_ethdev.c +22 -10
@@ -384,6 +384,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; +if (vtpci_packed_queue (hw)) + vq->vq_ring.avail_wrap_counter =1 ;/* * Reserve a memzone for vring elements
@@ -490,16 +492,22 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)memset (txr,0 , vq_size *sizeof (*txr));for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; - -vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); - +struct vring_desc_packed *start_dp_packed = txr[i].tx_indir_pq; +/* first indirect descriptor is always the tx header */ - start_dp->addr = txvq->virtio_net_hdr_mem - + i *sizeof (*txr) - + offsetof(struct virtio_tx_region , tx_hdr); - - start_dp->len = hw->vtnet_hdr_size; - start_dp->flags =VRING_DESC_F_NEXT ; +if (vtpci_packed_queue (hw)) { + start_dp_packed->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp_packed->len = hw->vtnet_hdr_size; + }else { +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); + start_dp->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp->len = hw->vtnet_hdr_size; + start_dp->flags =VRING_DESC_F_NEXT ; + } } }
@@ -1338,7 +1346,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_inorder_tx) { +if (vtpci_packed_queue (hw)) { +PMD_INIT_LOG (INFO ,"virtio: using virtio 1.1 Tx path on port %u" , + eth_dev->data->port_id); + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; + }else if (hw->use_inorder_tx) {PMD_INIT_LOG (INFO ,"virtio: using inorder Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -82,6 +82,8 @@ uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,uint16_t virtio_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t virtio_xmit_pkts_inorder (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);
drivers/net/virtio/virtio_rxtx.c +285 -0
309 lines not on this page · raw message
drivers/net/virtio/virtqueue.h +16 -2
@@ -242,8 +242,12 @@ struct virtio_net_hdr_mrg_rxbuf {#define VIRTIO_MAX_TX_INDIRECT 8struct virtio_tx_region {struct virtio_net_hdr_mrg_rxbuf tx_hdr; -struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT ] - __attribute__((__aligned__ (16 ))); +union { +struct vring_desc tx_indir[VIRTIO_MAX_TX_INDIRECT ] + __attribute__((__aligned__ (16 ))); +struct vring_desc_packed tx_indir_pq[VIRTIO_MAX_TX_INDIRECT ] + __attribute__((__aligned__ (16 ))); + }; }; static inline void
@@ -319,6 +323,7 @@ virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)#define VIRTQUEUE_NUSED (vq) ((uint16_t)((vq)->vq_ring.used->idx - (vq)->vq_used_cons_idx))void vq_ring_free_chain (struct virtqueue *vq,uint16_t desc_idx); +void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx);void vq_ring_free_inorder (struct virtqueue *vq,uint16_t desc_idx,uint16_t num);
@@ -352,6 +357,15 @@ virtqueue_kick_prepare(struct virtqueue *vq)return !(vq->vq_ring.used->flags &VRING_USED_F_NO_NOTIFY ); } +static inline int +virtqueue_kick_prepare_packed (struct virtqueue *vq) +{ +uint16_t flags; + + flags = vq->vq_ring.device_event->desc_event_flags &RING_EVENT_FLAGS_DESC ; +return (flags !=RING_EVENT_FLAGS_DISABLE ); +} +static inline void virtqueue_notify (struct virtqueue *vq) {
Signature · 1 line
2.17.1
PATCH v9 6/8 net/virtio: implement receive path for packed queues
In reply to Jens FreimannImplement the receive part.
--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 278 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 296 insertions(+), 26 deletions(-)
drivers/net/virtio/virtio_ethdev.c +14 -4
@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ; + }/* * Reserve a memzone for vring elements
@@ -1326,7 +1328,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private; -if (hw->use_simple_rx) { +if (vtpci_packed_queue (hw)) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts; + }else { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed; + } + }else if (hw->use_simple_rx) {PMD_INIT_LOG (INFO ,"virtio: using simple Rx path on port %u" , eth_dev->data->port_id); eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
@@ -1490,7 +1498,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 );
@@ -1918,7 +1927,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)rte_spinlock_init (&hw->state_lock); - hw->use_simple_rx =1 ; +if (!vtpci_packed_queue (hw)) + hw->use_simple_rx =1 ;if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { hw->use_inorder_tx =1 ;
drivers/net/virtio/virtio_ethdev.h +2 -0
@@ -73,6 +73,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 +257 -21
363 lines not on this page · raw message
drivers/net/virtio/virtqueue.c +22 -0
@@ -58,12 +58,34 @@ virtqueue_detach_unused(struct virtqueue *vq)void virtqueue_rxvq_flush (struct virtqueue *vq) { +struct vring_desc_packed *descs = vq->vq_ring.desc_packed;struct virtnet_rx *rxq = &vq->rxq;struct virtio_hw *hw = vq->hw;struct vring_used_elem *uep;struct vq_desc_extra *dxp;uint16_t used_idx, desc_idx;uint16_t nb_used, i; +uint16_t size = vq->vq_nentries; + +if (vtpci_packed_queue (vq->hw)) { + i = vq->vq_used_cons_idx; +if (i > size) { +PMD_INIT_LOG (ERR ,"vq_used_cons_idx out of range, %d" , vq->vq_used_cons_idx); +return ; + } +while (desc_is_used (&descs[i], &vq->vq_ring) && + i < size) { + dxp = &vq->vq_descx[descs[i].index]; +if (dxp->cookie !=NULL ) { +rte_pktmbuf_free (dxp->cookie); + dxp->cookie =NULL ; + } +vq_ring_free_chain_packed (vq, i); + i = dxp->next; + vq->vq_used_cons_idx++; + } +return ; + } nb_used =VIRTQUEUE_NUSED (vq);
drivers/net/virtio/virtqueue.h +1 -1
@@ -323,7 +323,7 @@ virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)#define VIRTQUEUE_NUSED (vq) ((uint16_t)((vq)->vq_ring.used->idx - (vq)->vq_used_cons_idx))void vq_ring_free_chain (struct virtqueue *vq,uint16_t desc_idx); -void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx); +void vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t used_idx);void vq_ring_free_inorder (struct virtqueue *vq,uint16_t desc_idx,uint16_t num);
Signature · 1 line
2.17.1
Re: [PATCH v9 5/8] net/virtio: implement transmit path for packed queues
In reply to Maxime CoquelinQuoted 26 lines · Maxime Coquelin
Quoted 23 lines · Jens Freimann
drivers/net/virtio/virtio_rxtx.c +16
-0@@ -88,6 +88,42 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; } +void +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx ) +{ +struct vring_desc_packed *dp; +struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ; +uint16_t desc_idx_last = desc_idx; +int i =0 ; + + dp = &vq->vq_ring.desc_packed[used_idx]; + dxp = &vq->vq_descx[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 && i < dxp->ndescs) { + desc_idx_last = dxp->next; + dp = &vq->vq_ring.desc_packed[dxp->next]; + dxp = &vq->vq_descx[dxp->next];
Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 109
Quoted 3 lines
drivers/net/virtio/virtio_rxtx.c +3
-0+ i++; + } + }Haven't you missed to squash some changes you did?
It seems you made some changes on your github branch to take Tiwei's comment on v8 into account, but it is not here (i.e. you can't useVRING_DESC_F_NEXThere).
I sent updated versions of patch 5 and 6 and added a new branch on github https://github.com/jensfr/dpdk/tree/virtio-1.1-v10
regards,
Jens
Re: [PATCH v9 5/8] net/virtio: implement transmit path for packed queues
In reply to Tiwei BieQuoted 104 lines · Tiwei Bie
Quoted 25 lines · Jens Freimann
This implements the transmit path for devices with support for packed virtqueues.
Signed-off-by Jens Freiman <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 32 +++- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 284 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 18 +- 4 files changed, 324 insertions(+), 12 deletions(-)drivers/net/virtio/virtio_ethdev.c +2
-0@@ -384,6 +384,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; +if (vtpci_packed_queue (hw)) + vq->vq_ring.avail_wrap_counter =1 ;/* * Reserve a memzone for vring elements drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 495
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +1
-3@@ -490,16 +492,22 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)memset (txr,0 , vq_size *sizeof (*txr));for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; - -vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); - +struct vring_desc_packed *start_dp_packed = txr[i].tx_indir_pq;A space is missing before
*start_dp_packedQuoted 25 lines
drivers/net/virtio/virtio_ethdev.c +14
-6+/* first indirect descriptor is always the tx header */ - start_dp->addr = txvq->virtio_net_hdr_mem - + i *sizeof (*txr) - + offsetof(struct virtio_tx_region , tx_hdr); - - start_dp->len = hw->vtnet_hdr_size; - start_dp->flags =VRING_DESC_F_NEXT ; +if (vtpci_packed_queue (hw)) { + start_dp_packed->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp_packed->len = hw->vtnet_hdr_size; + }else { +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir)); + start_dp->addr = txvq->virtio_net_hdr_mem + + i *sizeof (*txr) + + offsetof(struct virtio_tx_region , tx_hdr); + start_dp->len = hw->vtnet_hdr_size; + start_dp->flags =VRING_DESC_F_NEXT ; + } } }drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1353
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.c +5
-1@@ -1338,7 +1346,11 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } -if (hw->use_inorder_tx) { +if (vtpci_packed_queue (hw)) { +PMD_INIT_LOG (INFO ,"virtio: using virtio 1.1 Tx path on port %u" , + eth_dev->data->port_id); + eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed; + }else if (hw->use_inorder_tx) {Please make the structure more clear, e.g. something like:
if (vtpci_packed_queue(hw)) { // packed ring } else { // split ring }Quoted 24 lines
drivers/net/virtio/virtio_ethdev.c +0
-0PMD_INIT_LOG (INFO ,"virtio: using inorder Tx path on port %u" , eth_dev->data->port_id); eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;drivers/net/virtio/virtio_ethdev.h +2
-0@@ -82,6 +82,8 @@ uint16_t virtio_recv_mergeable_pkts_inorder(void *rx_queue,uint16_t virtio_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t virtio_xmit_pkts_packed (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t virtio_xmit_pkts_inorder (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts);drivers/net/virtio/virtio_rxtx.c +0
-0@@ -88,6 +88,42 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next =VQ_RING_DESC_CHAIN_END ; }
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 92
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+void +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx )Does above code pass the build test? (Type is missing for
used_idx)
As maxime noted a made a mistake when squashing in fixes to this patch. I sent a new version and updated my branch on github.
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 95
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c +3
-0+{ +struct vring_desc_packed *dp; +struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ;Do we really need to initialize them?
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 103
Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c +8
-0+uint16_t desc_idx_last = desc_idx; +int i =0 ; + + dp = &vq->vq_ring.desc_packed[used_idx]; + dxp = &vq->vq_descx[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 && i < dxp->ndescs) {NEXT can't be used here.
Also fixed in the new version of this patch.
I'll also fix your other findings. Thanks for the review!
regards,
Jens
Quoted 123 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 105
Quoted 2 lines
drivers/net/virtio/virtio_rxtx.c +2
-0+ desc_idx_last = dxp->next; + dp = &vq->vq_ring.desc_packed[dxp->next];
dxp->nextis used to link the dxps, it's not supposed to be desc ring's index.Quoted 33 lines
drivers/net/virtio/virtio_rxtx.c +26
-0+ dxp = &vq->vq_descx[dxp->next]; + i++; + } + } + +/* +* We must append the existing free chain, if any, to the end of +* newly freed chain. If the virtqueue was completely used, then +* head would be VQ_RING_DESC_CHAIN_END (ASSERTed above). +*/ +if (vq->vq_desc_tail_idx ==VQ_RING_DESC_CHAIN_END ) { + vq->vq_desc_head_idx = desc_idx; + }else { + dxp_tail = &vq->vq_descx[vq->vq_desc_tail_idx]; + dxp_tail->next = desc_idx; + } + + vq->vq_desc_tail_idx = desc_idx_last; + dxp->next =VQ_RING_DESC_CHAIN_END ; +} +static uint16_t virtqueue_dequeue_burst_rx (struct virtqueue *vq,struct rte_mbuf **rx_pkts,uint32_t *len,uint16_t num)@@ -165,6 +201,33 @@ virtqueue_dequeue_rx_inorder(struct virtqueue *vq,#endif /* Cleanup from completed transmits. */ +static void +virtio_xmit_cleanup_packed (struct virtqueue *vq,int num) +{ +uint16_t used_idx, id; +uint16_t size = vq->vq_nentries;drivers/net/virtio/virtio_rxtx.c virtqueue_dequeue_rx_inorder(struct virtqueue *vq, · line 218
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+struct vring_desc_packed *desc = vq->vq_ring.desc_packed; +struct vq_desc_extra *dxp; + + used_idx = vq->vq_used_cons_idx; +while (num &&desc_is_used (&desc[used_idx], &vq->vq_ring)) { + num --; + used_idx = vq->vq_used_cons_idx; + id = desc[used_idx].index; + dxp = &vq->vq_descx[id]; +if (++vq->vq_used_cons_idx >= size) {We need to skip
dxp->ndescsdescriptors here.Quoted 33 lines
drivers/net/virtio/virtio_rxtx.c +26
-0+ vq->vq_used_cons_idx -= size; + vq->vq_ring.used_wrap_counter ^=1 ; + } +vq_ring_free_chain_packed (vq, id, used_idx); +if (dxp->cookie !=NULL ) { +rte_pktmbuf_free (dxp->cookie); + dxp->cookie =NULL ; + } + used_idx = vq->vq_used_cons_idx; + } +} +static void virtio_xmit_cleanup (struct virtqueue *vq,uint16_t num) {@@ -456,6 +519,134 @@ virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq, vq->vq_desc_head_idx = idx & (vq->vq_nentries -1 ); } +static inline void +virtqueue_enqueue_xmit_packed (struct virtnet_tx *txvq,struct rte_mbuf *cookie, +uint16_t needed,int use_indirect,int can_push, +int in_order) +{ +struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr; +struct vq_desc_extra *dxp, *head_dxp; +struct virtqueue *vq = txvq->vq; +struct vring_desc_packed *start_dp, *head_dp; +uint16_t seg_num = cookie->nb_segs; +uint16_t idx, head_id, head_flags; +uint16_t head_size = vq->hw->vtnet_hdr_size; +struct virtio_net_hdr *hdr; +uint16_t prev;drivers/net/virtio/virtio_rxtx.c virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq, · line 545
Quoted 10 lines
drivers/net/virtio/virtio_rxtx.c +10
-0+ + head_id = vq->vq_desc_head_idx; + idx = head_id; + prev = idx; + start_dp = vq->vq_ring.desc_packed; + dxp = &vq->vq_descx[idx]; + dxp->ndescs = needed; + + head_dp = &vq->vq_ring.desc_packed[head_id]; + head_dxp = &vq->vq_descx[head_id];I don't think desc and descx can always have the same index.
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +5
-0+ head_dxp->cookie = (void *) cookie; + head_flags = cookie->next ?VRING_DESC_F_NEXT :0 ; + head_flags |=VRING_DESC_F_AVAIL (vq->vq_ring.avail_wrap_counter) | +VRING_DESC_F_USED (!vq->vq_ring.avail_wrap_counter); +[...]
drivers/net/virtio/virtio_rxtx.c
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +6
-0+static inline int +virtqueue_kick_prepare_packed (struct virtqueue *vq) +{ +uint16_t flags; + + flags = vq->vq_ring.device_event->desc_event_flags &RING_EVENT_FLAGS_DESC ;We can't "&
RING_EVENT_FLAGS_DESC" here.Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +3
-1+return (flags !=RING_EVENT_FLAGS_DISABLE ); +} +static inline void virtqueue_notify (struct virtqueue *vq) { --2.17.1
Re: [PATCH v9 1/8] net/virtio: vring init for packed queues
In reply to Tiwei BieQuoted 17 lines · Tiwei Bie
Quoted 16 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 ++++---- drivers/net/virtio/virtio_pci.h | 7 +++ drivers/net/virtio/virtio_ring.h | 74 ++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 15 +++++- 4 files changed, 95 insertions(+), 19 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0@@ -299,19 +299,21 @@ virtio_init_vring(struct virtqueue *vq)
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 304
Quoted 5 lines
drivers/net/virtio/virtio_ethdev.c +0
-3PMD_INIT_FUNC_TRACE (); -/* -* Reinitialise since virtio port might have been stopped and restarted -*/ Why above comments are removed?
by mistake, I'll put them back in next version.
Quoted 10 lines
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +2
-1memset (ring_mem,0 , vq->vq_ring_size); -vring_init (vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); +vring_init (vq->hw, vr, size, ring_mem,VIRTIO_PCI_VRING_ALIGN ); + vq->vq_used_cons_idx =0 ; vq->vq_desc_head_idx =0 ; vq->vq_avail_idx =0 ; vq->vq_desc_tail_idx = (uint16_t )(vq->vq_nentries -1 ); vq->vq_free_cnt = vq->vq_nentries;
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 313
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +3
-2memset (vq->vq_descx,0 ,sizeof (struct vq_desc_extra ) * vq->vq_nentries); - -vring_desc_init (vr->desc, size); +if (vtpci_packed_queue (vq->hw)) { +if (!vtpci_with_feature (vq->hw,VIRTIO_F_IN_ORDER )) +vring_desc_init_packed (vq, size);Don't we need to initialize descs in IN-ORDER case?
Yes, I missed this here. I'll fix it.
Quoted 58 lines
Quoted 58 lines
drivers/net/virtio/virtio_ethdev.c +5
-2+ }else { +vring_desc_init_split (vr->desc, size); + }/* * Disable device(host) interrupting guest @@ -386,7 +388,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)/* * Reserve a memzone for vring elements */ - size =vring_size (vq_size,VIRTIO_PCI_VRING_ALIGN ); + size =vring_size (hw, vq_size,VIRTIO_PCI_VRING_ALIGN ); vq->vq_ring_size =RTE_ALIGN_CEIL (size,VIRTIO_PCI_VRING_ALIGN );PMD_INIT_LOG (DEBUG ,"vring_size: %d, rounded_vring_size: %d" , size, vq->vq_ring_size);@@ -489,7 +491,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)for (i =0 ; i < vq_size; i++) {struct vring_desc *start_dp = txr[i].tx_indir; -vring_desc_init (start_dp,RTE_DIM (txr[i].tx_indir)); +vring_desc_init_split (start_dp,RTE_DIM (txr[i].tx_indir));/* first indirect descriptor is always the tx header */ start_dp->addr = txvq->virtio_net_hdr_memdrivers/net/virtio/virtio_pci.h +7
-0@@ -113,6 +113,7 @@ struct virtnet_ctl;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34/* * Some VirtIO feature bits (currently bits 28 through 31) are @@ -314,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_packed_queue (struct virtio_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */ drivers/net/virtio/virtio_ring.h +0
-0@@ -54,11 +54,38 @@ struct vring_used {struct vring_used_elem ring[0 ]; };
Quoted 9 lines
drivers/net/virtio/virtio_ring.h struct vring_used { · line 63
Quoted 7 lines
drivers/net/virtio/virtio_ring.h +7
-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;s/index/id/
ok
Quoted 6 lines
drivers/net/virtio/virtio_ring.h struct vring_used { · line 65
Quoted 3 lines
drivers/net/virtio/virtio_ring.h +2
-0+uint16_t flags; +} __attribute__ ((aligned(16)));We don't need the "
__attribute__((aligned(16)))" in descriptor structure's definition.
Someone requested this in an earlier round of reviews, but I'll check again.
Quoted 7 lines
drivers/net/virtio/virtio_ring.h struct vring_used { · line 69
Quoted 5 lines
drivers/net/virtio/virtio_ring.h +4
-0+ +#define RING_EVENT_FLAGS_ENABLE 0x0 +#define RING_EVENT_FLAGS_DISABLE 0x1 +#define RING_EVENT_FLAGS_DESC 0x2Please add an empty line here.
ok
Quoted 19 lines
Quoted 19 lines
drivers/net/virtio/virtio_ring.h +13
-3+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 90
Quoted 6 lines
drivers/net/virtio/virtio_ring.h +4
-0+union { +struct vring_used *used; +struct vring_packed_desc_event *device_event; + }; };We should define a new
vringstructure for packed ring.
I think it was requested to have it as a union before, but I can do it.
Thanks for your review!
regards,
Jens
Quoted 2 lines
Thanks
Re: [PATCH v9 1/8] net/virtio: vring init for packed queues
Quoted 169 lines · Jens Freimann
Quoted 17 lines · Tiwei Bie
Quoted 16 lines · Jens Freimann
Add and initialize descriptor data structures.
Signed-off-by Jens Freimann <[email protected]>---
drivers/net/virtio/virtio_ethdev.c | 18 ++++---- drivers/net/virtio/virtio_pci.h | 7 +++ drivers/net/virtio/virtio_ring.h | 74 ++++++++++++++++++++++++++---- drivers/net/virtio/virtqueue.h | 15 +++++-4 files changed, 95 insertions(+), 19 deletions(-)drivers/net/virtio/virtio_ethdev.c +0
-0@@ -299,19 +299,21 @@ virtio_init_vring(struct virtqueue *vq)Quoted 8 lines
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +0
-2PMD_INIT_FUNC_TRACE(); - /* -* Reinitialise since virtio port might have been stopped and restarted
- */Why above comments are removed?
by mistake, I'll put them back in next version.
Quoted 10 lines
Quoted 10 lines
memset(ring_mem, 0, vq->vq_ring_size);
-vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN); +vring_init(vq->hw, vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN); +
vq->vq_used_cons_idx= 0;
vq->vq_desc_head_idx= 0;
vq->vq_avail_idx= 0;
vq->vq_desc_tail_idx= (uint16_t)(vq->vq_nentries - 1);vq->vq_free_cnt=vq->vq_nentries;Quoted 8 lines
Quoted 6 lines
memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries); -
-vring_desc_init(vr->desc, size);
+ if (vtpci_packed_queue(vq->hw)) {
+ if (!vtpci_with_feature(vq->hw,VIRTIO_F_IN_ORDER))
+vring_desc_init_packed(vq, size);Don't we need to initialize descs in IN-ORDER case?
Yes, I missed this here. I'll fix it.
Quoted 61 lines
Quoted 61 lines
+ } else {
+vring_desc_init_split(vr->desc, size);
+ }/*
* Disable device(host) interrupting guestdrivers/net/virtio/virtio_ethdev.c +1
-1@@ -386,7 +388,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) /* * Reserve a memzone for vring elements */ - size = vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN); + size = vring_size(hw, vq_size, VIRTIO_PCI_VRING_ALIGN); vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN); PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d",size,
vq->vq_ring_size);drivers/net/virtio/virtio_ethdev.c +1
-1@@ -489,7 +491,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) for (i = 0; i < vq_size; i++) { struct vring_desc *start_dp = txr[i].tx_indir; - vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir)); + vring_desc_init_split(start_dp, RTE_DIM(txr[i].tx_indir)); /* first indirect descriptor is always the tx header */
start_dp->addr=txvq->virtio_net_hdr_memdrivers/net/virtio/virtio_pci.h +7
-0@@ -113,6 +113,7 @@ struct virtnet_ctl; #define VIRTIO_F_VERSION_1 32 #define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 /** Some VirtIO feature bits (currently bits 28 through 31) are @@ -314,6 +315,12 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit) return (hw->guest_features & (1ULL << bit)) != 0; } +static inline int +vtpci_packed_queue (struct virtio_hw *hw) +{ + return vtpci_with_feature(hw, VIRTIO_F_RING_PACKED); +} + /** Function declaration from virtio_pci.c */
drivers/net/virtio/virtio_ring.h +0
-0@@ -54,11 +54,38 @@ struct vring_used { struct vring_used_elem ring[0]; };Quoted 10 lines
Quoted 8 lines
drivers/net/virtio/virtio_ring.h +1
-0+/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
+ * looks like this.
+ */
+structvring_desc_packed{
+uint64_taddr;
+uint32_tlen;
+uint16_tindex;s/index/id/
ok
Quoted 6 lines
Quoted 3 lines
+
uint16_tflags;
+}__attribute__((aligned(16)));We don't need the "
__attribute__((aligned(16)))" in descriptor structure's definition.Someone requested this in an earlier round of reviews, but I'll check again.
Quoted 7 lines
drivers/net/virtio/virtio_ring.h struct vring_used { · line 69
Quoted 5 lines
drivers/net/virtio/virtio_ring.h +4
-0+ +#define RING_EVENT_FLAGS_ENABLE 0x0 +#define RING_EVENT_FLAGS_DISABLE 0x1 +#define RING_EVENT_FLAGS_DESC 0x2Please add an empty line here.
ok
Quoted 19 lines
Quoted 19 lines
drivers/net/virtio/virtio_ring.h +5
-0+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;
- structvring_avail*avail;
- struct vring_used *used;
+ union {
+ structvring_desc_packed*desc_packed; + structvring_desc*desc;
+ };
+ union {
+ structvring_avail*avail;
+ structvring_packed_desc_event*driver_event; + };Quoted 8 lines
Quoted 6 lines
+ union {
+ struct vring_used *used;
+ structvring_packed_desc_event*device_event; + };
};We should define a new
vringstructure for packed ring.
Quoted 2 lines
I think it was requested to have it as a union before, but I can do it.
I guess oyu vcan have a union between struct vring and struct vring_packed?
Quoted 6 lines
Thanks for your review!
regards,
JensQuoted 2 lines
Thanks
Re: [PATCH v9 6/8] net/virtio: implement receive path for packed queues
In reply to Tiwei BieQuoted 12 lines · Tiwei Bie
Quoted 11 lines · Jens Freimann
Implement the receive part.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 280 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 297 insertions(+), 27 deletions(-)
Quoted 14 lines
drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 389
Quoted 12 lines
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ;Why just use
used_wrap_counterin receive path?
You mean add it in a previous patch?
Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.c +1
-0+ }/* * Reserve a memzone for vring elements @@ -1326,7 +1328,13 @@ set_rxtx_funcs(struct rte_eth_dev *eth_dev) {struct virtio_hw *hw = eth_dev->data->dev_private;
Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1335
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +5
-1-if (hw->use_simple_rx) { +if (vtpci_packed_queue (hw)) { +if (vtpci_with_feature (hw,VIRTIO_NET_F_MRG_RXBUF )) { + eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts; + }else { + eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed;The indent is wrong.
ok
Quoted 11 lines
drivers/net/virtio/virtio_ethdev.c set_rxtx_funcs(struct rte_eth_dev *eth_dev) · line 1337
Quoted 3 lines
drivers/net/virtio/virtio_ethdev.c +2
-0+ } + }else if (hw->use_simple_rx) {Please make the structure more clear, e.g.
if (vtpci_packed_queue(hw)) { // packed ring } else { // split ring }
ok
Quoted 52 lines
Quoted 52 lines
drivers/net/virtio/virtio_ethdev.c +4
-2PMD_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;@@ -1490,7 +1498,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 );@@ -1918,7 +1927,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)rte_spinlock_init (&hw->state_lock); - hw->use_simple_rx =1 ; +if (!vtpci_packed_queue (hw)) + hw->use_simple_rx =1 ;if (vtpci_with_feature (hw,VIRTIO_F_IN_ORDER )) { hw->use_inorder_tx =1 ;drivers/net/virtio/virtio_ethdev.h +2
-0@@ -73,6 +73,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 +1
-0@@ -31,6 +31,7 @@#include "virtqueue.h" #include "virtio_rxtx.h" #include "virtio_rxtx_simple.h" +#include "virtio_ring.h" #ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTIO_DUMP_PACKET (m, len) rte_pktmbuf_dump(stdout, m, len)@@ -89,7 +90,7 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) }
Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx) · line 105
Quoted 11 lines
drivers/net/virtio/virtio_rxtx.c +1
-2void -vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,used_idx ) +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx,uint16_t used_idx) {struct vring_desc_packed *dp;struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ;@@ -102,7 +103,6 @@ vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx)if ((dp->flags &VRING_DESC_F_INDIRECT ) ==0 ) {while (dp->flags &VRING_DESC_F_NEXT && i < dxp->ndescs) { desc_idx_last = dxp->next; - dp = &vq->vq_ring.desc_packed[dxp->next];Why above line was added before this patch?
rebase mistake, will fix.
Quoted 88 lines
Quoted 88 lines
drivers/net/virtio/virtio_rxtx.c +73
-0dxp = &vq->vq_descx[dxp->next]; i++; }@@ -124,6 +124,47 @@ vq_ring_free_chain_packed(struct virtqueue *vq, uint16_t desc_idx, used_idx) dxp->next =VQ_RING_DESC_CHAIN_END ; } +static uint16_t +virtqueue_dequeue_burst_rx_packed (struct virtqueue *vq, +struct rte_mbuf **rx_pkts, +uint32_t *len, +uint16_t num) +{ +struct rte_mbuf *cookie; +uint16_t used_idx; +uint16_t id; +struct vring_desc_packed *desc; +uint16_t i; + +for (i =0 ; i < num; i++) { + used_idx = vq->vq_used_cons_idx; + desc = (struct vring_desc_packed *) vq->vq_ring.desc_packed; +if (!desc_is_used (&desc[used_idx], &vq->vq_ring)) +return i; + len[i] = desc[used_idx].len; + id = desc[used_idx].index; + cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie; + +if (unlikely (cookie ==NULL )) { +PMD_DRV_LOG (ERR ,"vring descriptor with no mbuf cookie at %u" , + vq->vq_used_cons_idx); +break ; + } +rte_prefetch0 (cookie); +rte_packet_prefetch (rte_pktmbuf_mtod(cookie ,void *)); + rx_pkts[i] = cookie; +vq_ring_free_chain_packed (vq, id, used_idx); + + vq->vq_used_cons_idx += vq->vq_descx[id].ndescs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_ring.used_wrap_counter ^=1 ; + } + } + +return i; +} +static uint16_t virtqueue_dequeue_burst_rx (struct virtqueue *vq,struct rte_mbuf **rx_pkts,uint32_t *len,uint16_t num)@@ -369,6 +410,55 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)return 0 ; } +static inline int +virtqueue_enqueue_recv_refill_packed (struct virtqueue *vq,struct rte_mbuf *cookie) +{ +struct vq_desc_extra *dxp; +struct virtio_hw *hw = vq->hw; +struct vring_desc_packed *start_dp; +uint16_t needed =1 ; +uint16_t head_idx, idx; +uint16_t flags; + +if (unlikely (vq->vq_free_cnt ==0 )) +return -ENOSPC ; +if (unlikely (vq->vq_free_cnt < needed)) +return -EMSGSIZE ; + + head_idx = vq->vq_desc_head_idx; +if (unlikely (head_idx >= vq->vq_nentries)) +return -EFAULT ; + + idx = head_idx; + dxp = &vq->vq_descx[idx]; + dxp->cookie = (void *)cookie; + dxp->ndescs = needed; + + start_dp = vq->vq_ring.desc_packed; + start_dp[idx].addr = +VIRTIO_MBUF_ADDR (cookie, vq) + +RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size; + start_dp[idx].len = + cookie->buf_len -RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size; + flags =VRING_DESC_F_WRITE ; + flags |= VRING_DESC_F_AVAIL(vq->vq_ring.avail_wrap_counter) |
Quoted 8 lines
drivers/net/virtio/virtio_rxtx.c virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie) · line 448
Quoted 4 lines
drivers/net/virtio/virtio_rxtx.c +4
-0+VRING_DESC_F_USED (!vq->vq_ring.avail_wrap_counter); +rte_smp_wmb (); + start_dp[idx].flags = flags; + idx = dxp->next;We should always use the descriptors in packed ring in the ring order (we have to use the elements in vq_descx[] out of order if device processes descriptors out of order).
Yes, I think you're right. I'll try to fix it.
Quoted 40 lines
Quoted 14 lines
drivers/net/virtio/virtio_rxtx.c +13
-0+ vq->vq_desc_head_idx = idx; +if (vq->vq_desc_head_idx ==VQ_RING_DESC_CHAIN_END ) + vq->vq_desc_tail_idx = idx; + vq->vq_free_cnt = (uint16_t )(vq->vq_free_cnt - needed); + + vq->vq_avail_idx += needed; +if (vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx =0 ; + vq->vq_ring.avail_wrap_counter ^=1 ; + } + +return 0 ; +}[...]
Quoted 25 lines
uint16_tvirtio_recv_mergeable_pkts_inorder(void*rx_queue,drivers/net/virtio/virtio_rxtx.c +9
-1struct rte_mbuf **rx_pkts,@@ -1385,12 +1582,20 @@ virtio_recv_mergeable_pkts(void *rx_queue,uint16_t extra_idx;uint32_t seg_res;uint32_t hdr_size; +uint32_t rx_num =0 ; nb_rx =0 ;if (unlikely (hw->started ==0 ))return nb_rx; - nb_used =VIRTQUEUE_NUSED (vq); +if (vtpci_packed_queue (vq->hw)) { +if (!desc_is_used (&vq->vq_ring.desc_packed[vq->vq_used_cons_idx], + &vq->vq_ring)) +return 0 ; + nb_used =VIRTIO_MBUF_BURST_SZ ; + }else { + nb_used =VIRTQUEUE_NUSED (vq); + }virtio_rmb ();
Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c virtio_recv_mergeable_pkts(void *rx_queue, · line 1611
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +1
-0@@ -1403,13 +1608,20 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_res =0 ; hdr_size = hw->vtnet_hdr_size; +No need to add above empty line.
ok
thanks for the review!
regards,
Jens
Quoted 19 lines
Quoted 18 lines
drivers/net/virtio/virtio_rxtx.c +7
-1while (i < nb_used) {struct virtio_net_hdr_mrg_rxbuf *header;if (nb_rx == nb_pkts)break ; - num =virtqueue_dequeue_burst_rx (vq, rcv_pkts, len,1 ); +if (vtpci_packed_queue (vq->hw)) + num =virtqueue_dequeue_burst_rx_packed (vq, rcv_pkts, + len,1 ); +else + num =virtqueue_dequeue_burst_rx (vq, rcv_pkts, len,1 ); +if (num ==0 ) +return nb_rx;if (num !=1 )continue ;[...]
Re: [PATCH v9 4/8] net/virtio: dump packed virtqueue data
In reply to Tiwei BieQuoted 10 lines · Tiwei Bie
Quoted 9 lines · Jens Freimann
Add support to dump packed virtqueue data to the
VIRTQUEUE_DUMP()macro.Signed-off-by Jens Freimann <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- drivers/net/virtio/virtqueue.h | 9 +++++++++ 1 file changed, 9 insertions(+)
Quoted 14 lines
drivers/net/virtio/virtqueue.h virtqueue_notify(struct virtqueue *vq) · line 374
Quoted 12 lines
drivers/net/virtio/virtqueue.h +4
-0@@ -368,6 +368,15 @@ virtqueue_notify(struct virtqueue *vq)uint16_t used_idx, nused; \ used_idx = (vq)->vq_ring.used->idx; \ nused = (uint16_t )(used_idx - (vq)->vq_used_cons_idx); \ +if (vtpci_packed_queue ((vq)->hw)) { \ + PMD_INIT_LOG(DEBUG, \ + "VQ: - size=%d; free=%d; used_cons_idx=%d; avail_idx=%d;" \ + "VQ: - avail_wrap_counter=%d; used_wrap_counter=%d", \Please remove the second "VQ: -" as they are on the same line.
ok
regards,
Jens
Re: [PATCH v9 3/8] net/virtio: add packed virtqueue helpers
In reply to Tiwei BieQuoted 14 lines · Tiwei Bie
Quoted 13 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/net/virtio/virtio_ring.h +0
-0@@ -77,6 +77,8 @@ struct vring_packed_desc_event {
Quoted 6 lines
drivers/net/virtio/virtio_ring.h struct vring_packed_desc_event { · line 81
Quoted 4 lines
drivers/net/virtio/virtio_ring.h +2
-0struct vring {unsigned int num; +unsigned int avail_wrap_counter; +unsigned int used_wrap_counter;Above fields should be defined in struct virtqueue.
ok
regards,
Jens
Quoted 38 lines
Quoted 38 lines
drivers/net/virtio/virtio_ring.h +24
-1union {struct vring_desc_packed *desc_packed;struct vring_desc *desc;@@ -91,6 +93,30 @@ struct vring { }; }; +static inline void +_set_desc_avail (struct vring_desc_packed *desc,int wrap_counter) +{ + desc->flags |=VRING_DESC_F_AVAIL (wrap_counter) | +VRING_DESC_F_USED (!wrap_counter); +} + +static inline void +set_desc_avail (struct vring *vr,struct vring_desc_packed *desc) +{ +_set_desc_avail (desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used, flags; + + flags = desc->flags; + used = !!(flags &VRING_DESC_F_USED (1 )); + +return used == vr->used_wrap_counter; +} +/* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. * -- 2.17.1
Re: [PATCH v9 2/8] net/virtio: add packed virtqueue defines
In reply to Tiwei BieQuoted 6 lines · Tiwei Bie
Quoted 5 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ring.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 15 lines
drivers/net/virtio/virtio_ring.h line 21
Quoted 13 lines
drivers/net/virtio/virtio_ring.h +4
-1@@ -15,7 +15,10 @@#define VRING_DESC_F_WRITE 2/* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4 - +/* This flag means the descriptor was made available by the driver */ +#define VRING_DESC_F_AVAIL (b) ((uint16_t)(b) << 7) +/* This flag means the descriptor was used by the device */ +#define VRING_DESC_F_USED (b) ((uint16_t)(b) << 15)Please add an empty line here.
ok
regards,
Jens
Quoted 7 lines
Quoted 7 lines
drivers/net/virtio/virtio_ring.h +0
-1/* 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.17.1
Re: [PATCH v9 1/8] net/virtio: vring init for packed queues
In reply to Maxime CoquelinQuoted 26 lines · Maxime Coquelin
Quoted 23 lines · Jens Freimann
Quoted 22 lines · Tiwei Bie
Quoted 20 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>??struct vring {
???????? unsigned int num;
-?????? structvring_desc?? *desc;
-?????? structvring_avail*avail;
-?????? structvring_used?? *used;
+?????? union {
+?????????????? structvring_desc_packed*desc_packed; +?????????????? structvring_desc*desc;
+?????? };
+?????? union {
+?????????????? structvring_avail*avail; +?????????????? structvring_packed_desc_event*driver_event; +?????? };
+?????? union {
+?????????????? structvring_used?? *used; +?????????????? structvring_packed_desc_event*device_event; +?????? };
??};
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
We should define a new
vringstructure for packed ring.I think it was requested to have it as a union before, but I can do it.
I guess oyu vcan have a union between struct vring and struct
vring_packed?
Like this?
struct vring {
unsigned int num;
union {
struct vring_split *split;
_ struct vring_packed *packed;
};};
We will have to write vq->vq_ring.split.avail->flags and vq->vq_ring.packed.desc[xx] and similar things in a lot of places, no?
Should we just add both vring_split and vring_packed to struct virtqueue instead? Only one of them will have memory allocated per virtqueue anyway.
regards,
Jens
Re: [PATCH v9 6/8] net/virtio: implement receive path for packed queues
In reply to Jens FreimannQuoted 28 lines · Jens Freimann
Quoted 12 lines · Tiwei Bie
Quoted 11 lines · Jens Freimann
Implement the receive part.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 280 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 297 insertions(+), 27 deletions(-)Quoted 14 lines
drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 389
Quoted 12 lines
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ;Why just use
used_wrap_counterin receive path?
Quoted 2 lines
You mean add it in a previous patch?
Hmm, the used_wrap_counter is already used in the previous patch, but it wasn't initialized until the receive path is added. We should have a patch to introduce these packed ring related generic fields (e.g. the wrap counters and vring) in struct virtqueue and also do the corresponding initializations in that patch too (maybe we can do this in the current 1/8 patch).
Re: [PATCH v9 1/8] net/virtio: vring init for packed queues
In reply to Jens FreimannQuoted 43 lines · Jens Freimann
Quoted 26 lines · Maxime Coquelin
Quoted 23 lines · Jens Freimann
Quoted 22 lines · Tiwei Bie
Quoted 20 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>??struct vring {
???????? unsigned int num;
-?????? structvring_desc?? *desc;
-?????? structvring_avail*avail;
-?????? structvring_used?? *used;
+?????? union {
+?????????????? structvring_desc_packed*desc_packed; +?????????????? structvring_desc*desc;
+?????? };
+?????? union {
+?????????????? structvring_avail*avail; +?????????????? structvring_packed_desc_event*driver_event; +?????? };
+?????? union {
+?????????????? structvring_used?? *used; +?????????????? structvring_packed_desc_event*device_event; +?????? };
??};Quoted 7 lines
Quoted 4 lines
Quoted 1 line
We should define a new
vringstructure for packed ring.I think it was requested to have it as a union before, but I can do it.
I guess oyu vcan have a union between struct vring and struct
vring_packed?Like this?
struct vring { unsigned int num; union { struct vring_split *split; _ struct vring_packed *packed; };
Quoted 8 lines
};
We will have to write
vq->vq_ring.split.avail->flagsand vq->vq_ring.packed.desc[xx] and similar things in a lot of places, no?Should we just add both
vring_splitandvring_packedto struct virtqueue instead? Only one of them will have memory allocated per virtqueue anyway.
Yeah, we can add both to struct virtqueue.
Re: [PATCH v9 8/8] net/virtio: enable packed virtqueues by default
In reply to Jens FreimannQuoted 10 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.h | 1 + 1 file changed, 1 insertion(+)drivers/net/virtio/virtio_ethdev.h +0
-0
drivers/net/virtio/virtio_ethdev.h line 37
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +1
-0@@ -34,6 +34,7 @@1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \1ULL <<VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \
Virtio-user will be broken when packed ring and CQ are negotiated. We need to fix this.
Re: [PATCH v9 6/8] net/virtio: implement receive path for packed queues
In reply to Tiwei BieQuoted 32 lines · Tiwei Bie
Quoted 28 lines · Jens Freimann
Quoted 12 lines · Tiwei Bie
Quoted 11 lines · Jens Freimann
Implement the receive part.
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 18 +- drivers/net/virtio/virtio_ethdev.h | 2 + drivers/net/virtio/virtio_rxtx.c | 280 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 22 +++ drivers/net/virtio/virtqueue.h | 2 +- 5 files changed, 297 insertions(+), 27 deletions(-)Quoted 14 lines
drivers/net/virtio/virtio_ethdev.c virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) · line 389
Quoted 12 lines
drivers/net/virtio/virtio_ethdev.c +2
-1@@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx) vq->hw = hw; vq->vq_queue_index = vtpci_queue_idx; vq->vq_nentries = vq_size; -if (vtpci_packed_queue (hw)) +if (vtpci_packed_queue (hw)) { vq->vq_ring.avail_wrap_counter =1 ; + vq->vq_ring.used_wrap_counter =1 ;Why just use
used_wrap_counterin receive path?Quoted 2 lines
You mean add it in a previous patch?
Quoted 7 lines
Hmm, the
used_wrap_counteris already used in the previous patch, but it wasn't initialized until the receive path is added. We should have a patch to introduce these packed ring related generic fields (e.g. the wrap counters and vring) in struct virtqueue and also do the corresponding initializations in that patch too (maybe we can do this in the current 1/8 patch).
sounds good, will do it like this.
regards,
Jens
Re: [PATCH v9 8/8] net/virtio: enable packed virtqueues by default
In reply to Tiwei BieQuoted 6 lines · Tiwei Bie
Quoted 5 lines · Jens Freimann
Signed-off-by Jens Freimann <[email protected]>--- drivers/net/virtio/virtio_ethdev.h | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
drivers/net/virtio/virtio_ethdev.h line 37
Quoted 9 lines
drivers/net/virtio/virtio_ethdev.h +1
-0@@ -34,6 +34,7 @@1u <<VIRTIO_RING_F_INDIRECT_DESC | \1ULL <<VIRTIO_F_VERSION_1 | \1ULL <<VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \Virtio-user will be broken when packed ring and CQ are negotiated. We need to fix this.
How would you fix this? Is it acceptable to disable packed virtqueues for now in virtio-user when both RING_PACKED and CQ is requested?
Like this:
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -0
@@ -474,6 +474,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)* so if necessary, we just claim to support CQ */ dev->frontend_features |= (1ull <<VIRTIO_NET_F_CTRL_VQ ); + dev->unsupported_features |= (1ULL <<VIRTIO_F_RING_PACKED ); }else { dev->unsupported_features |= (1ull <<VIRTIO_NET_F_CTRL_VQ );/* Also disable features that depend on VIRTIO_NET_F_CTRL_VQ */
regards,
Jens