implement packed virtqueues
v8 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.
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 | 110 +++++- drivers/net/virtio/virtio_rxtx.c | 545 +++++++++++++++++++++++++++-- drivers/net/virtio/virtqueue.c | 23 ++ drivers/net/virtio/virtqueue.h | 42 ++- 7 files changed, 832 insertions(+), 54 deletions(-)
Signature · 1 line
2.17.1
PATCH v8 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 v8 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 v8 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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/net/virtio/virtio_ring.h +31 -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,35 @@ struct vring { }; }; +static inline void +_set_desc_avail (struct vring_desc_packed *desc,int wrap_counter) +{ + desc->flags |=VRING_DESC_F_AVAIL (wrap_counter) | +VRING_DESC_F_USED (!wrap_counter); +} + +static inline void +set_desc_avail (struct vring *vr,struct vring_desc_packed *desc) +{ +_set_desc_avail (desc, vr->avail_wrap_counter); +} + +static inline int +desc_is_used (struct vring_desc_packed *desc,struct vring *vr) +{ +uint16_t used, avail, flags; +bool is_used; + +rte_smp_mb (); + flags = desc->flags; + avail = !!(flags &VRING_DESC_F_AVAIL (1 )); + used = !!(flags &VRING_DESC_F_USED (1 )); + is_used = used == avail && used == vr->used_wrap_counter; +rte_smp_rmb (); + +return is_used; +} +/* The standard layout for the ring is a continuous chunk of memory which * looks like this. We assume num is a power of 2. *
Signature · 1 line
2.17.1
PATCH v8 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 v8 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 | 276 +++++++++++++++++++++++++++++ drivers/net/virtio/virtqueue.h | 18 +- 4 files changed, 316 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 +276 -0
300 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 v8 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 | 269 ++++++++++++++++++++++++++--- drivers/net/virtio/virtqueue.c | 23 +++ 4 files changed, 288 insertions(+), 24 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 +249 -20
348 lines not on this page · raw message
drivers/net/virtio/virtqueue.c +23 -0
@@ -58,12 +58,35 @@ 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)) { +return ; + 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);
Signature · 1 line
2.17.1
PATCH v8 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 v8 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 v8 5/8] net/virtio: implement transmit path for packed queues
In reply to Jens FreimannOn Tue, Oct 16, 2018 at 11:01:31AM +0200, Jens Freimann wrote:
[...]
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 99
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +9
-0+void +vq_ring_free_chain_packed (struct virtqueue *vq,uint16_t desc_idx) +{ +struct vring_desc_packed *dp; +struct vq_desc_extra *dxp =NULL , *dxp_tail =NULL ; +uint16_t desc_idx_last = desc_idx; + + dp = &vq->vq_ring.desc_packed[desc_idx]; + dxp = &vq->vq_descx[desc_idx];
In the out-of-order case, we can't assume the desc and desc_extra have the same index.
drivers/net/virtio/virtio_rxtx.c vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) · line 102
Quoted 3 lines
drivers/net/virtio/virtio_rxtx.c +3
-0+ 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 ) {
https://github.com/oasis-tcs/virtio-spec/blob/89dd55f5e606/packed-ring.tex#L222-L226
The device only writes out a single used descriptor for the whole list. It then skips forward according to the number of descriptors in the list. The driver needs to keep track of the size of the list corresponding to each buffer ID, to be able to skip to where the next used descriptor is written by the device.
IOW, we can't use the VRING_DESC_F_NEXT here.
Quoted 5 lines
drivers/net/virtio/virtio_rxtx.c +5
-0+ desc_idx_last = dxp->next; + dp = &vq->vq_ring.desc_packed[dxp->next]; + dxp = &vq->vq_descx[dxp->next]; + } + }