lib/vhost: support async dequeue for split ring
cover lib/vhost: support async dequeue for split ring
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
Yuan Wang (1):
lib/vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 10 + examples/vhost/ioat.c | 30 +- examples/vhost/ioat.h | 3 + examples/vhost/main.c | 60 +-- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 549 ++++++++++++++++++++++++++++ 7 files changed, 664 insertions(+), 35 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/1 lib/vhost: support async dequeue for split ring
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 10 + examples/vhost/ioat.c | 30 +- examples/vhost/ioat.h | 3 + examples/vhost/main.c | 60 +-- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 549 ++++++++++++++++++++++++++++ 7 files changed, 664 insertions(+), 35 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +10 -0
@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------
examples/vhost/ioat.c +19 -11
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -61,18 +60,30 @@ open_ioat(const char *value) goto out; }while (i < args_nr) { +char *txd, *rxd; +bool is_txd;char *arg_temp = dma_arg[i];uint8_t sub_nr; + sub_nr =rte_strsplit (arg_temp,strlen (arg_temp), ptrs,2 ,'@' );if (sub_nr !=2 ) { ret =-1 ; goto out; } - start =strstr (ptrs[0 ],"txd" ); -if (start ==NULL ) { + txd =strstr (ptrs[0 ],"txd" ); + rxd =strstr (ptrs[0 ],"rxd" ); +if (txd ==NULL && rxd ==NULL ) { ret =-1 ; goto out; + }else if (txd) { + is_txd = true; + start = txd; + ret |=ASYNC_RX_VHOST ; + }else { + is_txd = false; + start = rxd; + ret |=ASYNC_TX_VHOST ; } start +=3 ;
@@ -82,7 +93,8 @@ open_ioat(const char *value) goto out; } - vring_id =0 +VIRTIO_RXQ ; + vring_id = is_txd ?VIRTIO_RXQ :VIRTIO_TXQ ; +if (rte_pci_addr_parse (ptrs[1 ], &(dma_info + vid)->dmas[vring_id].addr) <0 ) { ret =-1 ;
@@ -113,7 +125,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -128,7 +139,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t count) { uint32_t i_desc; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 +VIRTIO_RXQ ].dev_id; +uint16_t dev_id = dma_bind[vid].dmas[queue_id].dev_id;struct rte_vhost_iov_iter *src =NULL ;struct rte_vhost_iov_iter *dst =NULL ;unsigned long i_seg;
@@ -140,7 +151,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +166,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -181,8 +191,7 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,unsigned short mask =MAX_ENQUEUED_SIZE -1 ;unsigned short i; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 - +VIRTIO_RXQ ].dev_id; +uint16_t dev_id = dma_bind[vid].dmas[queue_id].dev_id; n_seg =rte_ioat_completed_ops (dev_id,255 ,NULL ,NULL , dump, dump);if (n_seg <0 ) { RTE_LOG(ERR,
@@ -194,7 +203,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
examples/vhost/ioat.h +3 -0
@@ -13,6 +13,9 @@#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2 +struct dma_info {struct rte_pci_addr addr;uint16_t dev_id;
examples/vhost/main.c +39 -21
132 lines not on this page · raw message
lib/vhost/rte_vhost_async.h +41 -3
58 lines not on this page · raw message
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_try_dequeue_burst; };
lib/vhost/virtio_net.c +549 -0
552 lines not on this page · raw message
Signature · 1 line
2.25.1
Hi Yuan,
This is a first review, I will certainly have more comments later.
Quoted 5 lines · Yuan Wang
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
Do you have any number to share?
Quoted 12 lines
Signed-off-by Wenwu Ma <[email protected]>Signed-off-by Yuan Wang <[email protected]>Signed-off-by Jiayu Hu <[email protected]>--- doc/guides/prog_guide/vhost_lib.rst | 10 + examples/vhost/ioat.c | 30 +- examples/vhost/ioat.h | 3 + examples/vhost/main.c | 60 +-- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 549 ++++++++++++++++++++++++++++ 7 files changed, 664 insertions(+), 35 deletions(-)
Please split the patch in multple parts.
At least don't mix example and lib changes in the same patch.
doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions: · line 284
Quoted 9 lines
doc/guides/prog_guide/vhost_lib.rst +1
-0@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)``
The function should contain async in its name.
BTW, I think we should also rename below APIs while they are experimental to highlight it is async related:
rte_vhost_submit_enqueue_burstrte_vhost_poll_enqueue_completed
Quoted 76 lines
doc/guides/prog_guide/vhost_lib.rst +9
-0+ + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------examples/vhost/ioat.c +16
-5@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];@@ -61,18 +60,30 @@ open_ioat(const char *value) goto out; }while (i < args_nr) { +char *txd, *rxd; +bool is_txd;char *arg_temp = dma_arg[i];uint8_t sub_nr; + sub_nr =rte_strsplit (arg_temp,strlen (arg_temp), ptrs,2 ,'@' );if (sub_nr !=2 ) { ret =-1 ; goto out; } - start =strstr (ptrs[0 ],"txd" ); -if (start ==NULL ) { + txd =strstr (ptrs[0 ],"txd" ); + rxd =strstr (ptrs[0 ],"rxd" ); +if (txd ==NULL && rxd ==NULL ) { ret =-1 ; goto out; + }else if (txd) { + is_txd = true; + start = txd; + ret |=ASYNC_RX_VHOST ; + }else { + is_txd = false; + start = rxd; + ret |=ASYNC_TX_VHOST ; } start +=3 ;@@ -82,7 +93,8 @@ open_ioat(const char *value) goto out; } - vring_id =0 +VIRTIO_RXQ ; + vring_id = is_txd ?VIRTIO_RXQ :VIRTIO_TXQ ; +if (rte_pci_addr_parse (ptrs[1 ], &(dma_info + vid)->dmas[vring_id].addr) <0 ) { ret =-1 ;@@ -113,7 +125,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
examples/vhost/ioat.c ioat_transfer_data_cb(int vid, uint16_t queue_id, · line 142
Quoted 5 lines
examples/vhost/ioat.c +1
-1@@ -128,7 +139,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t count) { uint32_t i_desc; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 +VIRTIO_RXQ ].dev_id; +uint16_t dev_id = dma_bind[vid].dmas[queue_id].dev_id;
It looks broken with regards to multiqueue (it was before this patch).
In open_ioat(), only dma_bind[vid].dmas[VIRTIO_RXQ] and dma_bind[vid].dmas[VIRTIO_TXQ] are set.
As it seems that the application does not support multiqueue, it may be a good idea to check queue_id value before using it.
examples/vhost/ioat.c ioat_transfer_data_cb(int vid, uint16_t queue_id, · line 154
Quoted 9 lines
examples/vhost/ioat.c +1
-1struct rte_vhost_iov_iter *src =NULL ;struct rte_vhost_iov_iter *dst =NULL ;unsigned long i_seg;@@ -140,7 +151,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)
This change should be in a dedicated patch, it is not related to dequeue support.
Quoted 78 lines
examples/vhost/ioat.c +1
-4break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,@@ -155,7 +166,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {@@ -181,8 +191,7 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,unsigned short mask =MAX_ENQUEUED_SIZE -1 ;unsigned short i; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 - +VIRTIO_RXQ ].dev_id; +uint16_t dev_id = dma_bind[vid].dmas[queue_id].dev_id; n_seg =rte_ioat_completed_ops (dev_id,255 ,NULL ,NULL , dump, dump);if (n_seg <0 ) { RTE_LOG(ERR,@@ -194,7 +203,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;examples/vhost/ioat.h +3
-0@@ -13,6 +13,9 @@#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2 +struct dma_info {struct rte_pci_addr addr;uint16_t dev_id;examples/vhost/main.c +8
-3@@ -93,7 +93,8 @@ static int client_mode;static int builtin_net_driver; -static int async_vhost_driver; +static int async_rx_vhost_driver; +static int async_tx_vhost_driver;static char *dma_type;@@ -671,13 +672,17 @@ us_vhost_parse_args(int argc, char **argv)break ;case OPT_DMAS_NUM : -if (open_dma (optarg) ==-1 ) { + ret =open_dma (optarg); +if (ret ==-1 ) {RTE_LOG (INFO ,VHOST_CONFIG ,"Wrong DMA args\n" );us_vhost_usage (prgname);return -1 ; } - async_vhost_driver =1 ; +if (ret &ASYNC_RX_VHOST ) + async_rx_vhost_driver =1 ; +if (ret &ASYNC_TX_VHOST ) + async_tx_vhost_driver =1 ;break ;case OPT_CLIENT_NUM :
examples/vhost/main.c drain_vhost(struct vhost_dev *vdev) · line 895
Quoted 5 lines
examples/vhost/main.c +1
-1@@ -887,7 +892,7 @@ drain_vhost(struct vhost_dev *vdev)if (builtin_net_driver) { ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { + }else if (async_rx_vhost_driver) {
I think we should consider having ops for async and sync instead of all these if/else. It could be refactored as preliminary patch for this series.
Quoted 12 lines
examples/vhost/main.c +1
-1uint32_t cpu_cpl_nr =0 ;uint16_t enqueue_fail =0 ;struct rte_mbuf *m_cpu_cpl[nr_xmit];@@ -914,7 +919,7 @@ drain_vhost(struct vhost_dev *vdev) __ATOMIC_SEQ_CST); } -if (!async_vhost_driver) +if (!async_rx_vhost_driver)free_pkts (m, nr_xmit); }
Hi Maxime,
Quoted 13 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, June 8, 2021 12:17 AM
To: Wang, YuanX <[email protected]>; [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Hu, Jiayu <[email protected]>
Subject: Re: [PATCH 1/1] lib/vhost: support async dequeue for split ringHi Yuan,
This is a first review, I will certainly have more comments later.
Quoted 8 lines
Quoted 5 lines · Yuan Wang
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
Do you have any number to share?
We cannot share the exact numbers without legal approval. There are some relative values:
in PV cases, testpmd macfwd throughput of one core with async dequeue enabled is around 1.25x of SW vhost; when enabling both async enqueue and dequeue, one core macfwd throughput is up to 2x of SW vhost.
Quoted 30 lines
Quoted 4 lines
Signed-off-by Wenwu Ma <[email protected]>Signed-off-by Yuan Wang <[email protected]>Signed-off-by Jiayu Hu <[email protected]>Quoted 9 lines
--- doc/guides/prog_guide/vhost_lib.rst | 10 + examples/vhost/ioat.c | 30 +- examples/vhost/ioat.h | 3 + examples/vhost/main.c | 60 +-- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 549 ++++++++++++++++++++++++++++ 7 files changed, 664 insertions(+), 35 deletions(-)Please split the patch in multple parts.
At least don't mix example and lib changes in the same patch.Review
Quoted 1 line
(quoted diff) +0
-0
b/doc/guides/prog_guide/vhost_lib.rstdoc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost
Quoted 4 lines
index
6b7206bc1d..785ab0fb34100644doc/guides/prog_guide/vhost_lib.rst +0
-0@@ -281,6 +281,16 @@ The following is an overview of some key VhostAPI functions:
doc/guides/prog_guide/vhost_lib.rst The following is an overview of some key Vhost API functions:
Quoted 4 lines
doc/guides/prog_guide/vhost_lib.rst +1
-0Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count,nr_inflight)``
Quoted 7 lines
The function should contain async in its name.
BTW, I think we should also rename below APIs while they are experimental to highlight it is async related:
rte_vhost_submit_enqueue_burstrte_vhost_poll_enqueue_completed
Yes, it's better to add "async" in related functions. How about:rte_vhost_async_submit_enqueue_burst rte_vhost_async_poll_enqueue_completed rte_vhost_async_try_dequeue_burst
Any suggestions?
Thanks,
Jiayu
v2 cover vhost: support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths. examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 10 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 40 +- examples/vhost/ioat.h | 4 + examples/vhost/main.c | 225 +++++++---- examples/vhost/main.h | 38 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 553 ++++++++++++++++++++++++++++ 10 files changed, 839 insertions(+), 103 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths.
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
PATCH v2 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
PATCH v2 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 10 + lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 553 ++++++++++++++++++++++++++++ 4 files changed, 607 insertions(+), 3 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +10 -0
@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +41 -3
58 lines not on this page · raw message
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +553 -0
556 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 34 +++++-- examples/vhost/ioat.h | 4 + examples/vhost/main.c | 141 ++++++++++++++++++++--------- examples/vhost/main.h | 5 + 5 files changed, 140 insertions(+), 53 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +26 -8
@@ -21,6 +21,8 @@ struct packet_tracker {struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ]; +int vid2txd[MAX_VHOST_DEVICE ]; +int open_ioat (const char *value) {
@@ -60,6 +62,8 @@ open_ioat(const char *value) goto out; }while (i < args_nr) { +char *txd, *rxd; +bool is_txd;char *arg_temp = dma_arg[i];uint8_t sub_nr; sub_nr =rte_strsplit (arg_temp,strlen (arg_temp), ptrs,2 ,'@' );
@@ -68,10 +72,20 @@ open_ioat(const char *value) goto out; } - start =strstr (ptrs[0 ],"txd" ); -if (start ==NULL ) { +int async_flag; + txd =strstr (ptrs[0 ],"txd" ); + rxd =strstr (ptrs[0 ],"rxd" ); +if (txd ==NULL && rxd ==NULL ) { ret =-1 ; goto out; + }else if (txd) { + is_txd = true; + start = txd; + async_flag =ASYNC_RX_VHOST ; + }else { + is_txd = false; + start = rxd; + async_flag =ASYNC_TX_VHOST ; } start +=3 ;
@@ -81,7 +95,8 @@ open_ioat(const char *value) goto out; } - vring_id =0 +VIRTIO_RXQ ; + vring_id = is_txd ?VIRTIO_RXQ :VIRTIO_TXQ ; +if (rte_pci_addr_parse (ptrs[1 ], &(dma_info + vid)->dmas[vring_id].addr) <0 ) { ret =-1 ;
@@ -105,6 +120,7 @@ open_ioat(const char *value) (dma_info + vid)->dmas[vring_id].dev_id = dev_id; (dma_info + vid)->dmas[vring_id].is_valid = true; + (dma_info + vid)->async_flag |= async_flag; config.ring_size =IOAT_RING_SIZE ; config.hdls_disable = true;if (rte_rawdev_configure (dev_id, &info,sizeof (config)) <0 ) {
@@ -126,13 +142,16 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t count) { uint32_t i_desc; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 +VIRTIO_RXQ ].dev_id;struct rte_vhost_iov_iter *src =NULL ;struct rte_vhost_iov_iter *dst =NULL ;unsigned long i_seg;unsigned short mask =MAX_ENQUEUED_SIZE -1 ; -unsigned short write = cb_tracker[dev_id].next_write; +if (queue_id >=MAX_RING_COUNT ) +return -1 ; + +uint16_t dev_id = dma_bind[vid2txd[vid]].dmas[queue_id].dev_id; +unsigned short write = cb_tracker[dev_id].next_write;if (!opaque_data) {for (i_desc =0 ; i_desc < count; i_desc++) { src = descs[i_desc].src;
@@ -170,7 +189,7 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets) { -if (!opaque_data) { +if (!opaque_data && (queue_id <MAX_RING_COUNT )) {uintptr_t dump[255 ];int n_seg;unsigned short read, write;
@@ -178,8 +197,7 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,unsigned short mask =MAX_ENQUEUED_SIZE -1 ;unsigned short i; -uint16_t dev_id = dma_bind[vid].dmas[queue_id *2 - +VIRTIO_RXQ ].dev_id; +uint16_t dev_id = dma_bind[vid2txd[vid]].dmas[queue_id].dev_id; n_seg =rte_ioat_completed_ops (dev_id,255 ,NULL ,NULL , dump, dump);if (n_seg <0 ) { RTE_LOG(ERR,
examples/vhost/ioat.h +4 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
examples/vhost/main.c +99 -42
208 lines not on this page · raw message
examples/vhost/main.h +5 -0
@@ -9,6 +9,8 @@#include <rte_ether.h> +#include "ioat.h" +/* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER2
@@ -18,6 +20,9 @@ enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};#define MAX_PKT_BURST 32/* Max burst size for RX/TX */ +extern struct dma_for_vhost dma_bind[MAX_VHOST_DEVICE ]; +extern int vid2txd[MAX_VHOST_DEVICE ]; +struct device_statistics {uint64_t tx;uint64_t tx_total;
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v2 0/4] vhost: support async dequeue for split ring
In reply to Wenwu MaHi,
It seems the series does not build:
http://mails.dpdk.org/archives/test-report/2021-June/199414.html
Could you please look at it?
Thanks,
Maxime
Quoted 37 lines · Wenwu Ma
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Checkqueue_idvalue before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change fromrte_vhost_try_dequeue_bursttorte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths. examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data pathYuan Wang (1):
vhost: support async dequeue for split ringdoc/guides/prog_guide/vhost_lib.rst | 10 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 40 +- examples/vhost/ioat.h | 4 + examples/vhost/main.c | 225 +++++++---- examples/vhost/main.h | 38 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 553 ++++++++++++++++++++++++++++ 10 files changed, 839 insertions(+), 103 deletions(-)
v3 cover vhost: support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v3:
- Fix compilation warning and error in arm platform.
- Restore the removed function virtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths. examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 10 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 579 ++++++++++++++++++++++++++++ 10 files changed, 902 insertions(+), 108 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths.
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
PATCH v3 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
PATCH v3 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 10 + lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 579 ++++++++++++++++++++++++++++ 4 files changed, 633 insertions(+), 3 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +10 -0
@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +41 -3
58 lines not on this page · raw message
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +579 -0
588 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +47 -14
134 lines not on this page · raw message
examples/vhost/ioat.h +25 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
@@ -36,6 +40,10 @@ uint32_t ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets); + +uint32_t get_async_flag_by_vid (int vid); +uint32_t get_async_flag_by_socketid (int socketid); +void init_vid2socketid_array (int vid,int socketid);#else static int open_ioat(const char *value __rte_unused) {
@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused, {return -1 ; } + +static uint32_t +get_async_flag_by_vid(int vid __rte_unused) +{ +return 0 ; +} + +static uint32_t +get_async_flag_by_socketid(int socketid __rte_unused) +{ +return 0 ; +} + +static void +init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused) +{ +}#endif #endif /* _IOAT_H_ */
examples/vhost/main.c +99 -41
201 lines not on this page · raw message
Signature · 1 line
2.25.1
v4 cover support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
note: PATCH v4 3/4 depends on IOMMU patch from Ding,Xuan
(http://patches.dpdk.org/project/dpdk/patch/[email protected]/)
v4:
- Fix wrong packet index issue in async dequeue improve the performance of small packet copies.
v3:
- Fix compilation warning and error in arm platform.
- Restore the removed function virtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths. examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 10 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 579 ++++++++++++++++++++++++++++ 10 files changed, 902 insertions(+), 108 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths.
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
PATCH v4 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
PATCH v4 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 10 + lib/vhost/rte_vhost_async.h | 44 ++- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 579 ++++++++++++++++++++++++++++ 4 files changed, 633 insertions(+), 3 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +10 -0
@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +41 -3
58 lines not on this page · raw message
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +579 -0
588 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +47 -14
134 lines not on this page · raw message
examples/vhost/ioat.h +25 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
@@ -36,6 +40,10 @@ uint32_t ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets); + +uint32_t get_async_flag_by_vid (int vid); +uint32_t get_async_flag_by_socketid (int socketid); +void init_vid2socketid_array (int vid,int socketid);#else static int open_ioat(const char *value __rte_unused) {
@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused, {return -1 ; } + +static uint32_t +get_async_flag_by_vid(int vid __rte_unused) +{ +return 0 ; +} + +static uint32_t +get_async_flag_by_socketid(int socketid __rte_unused) +{ +return 0 ; +} + +static void +init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused) +{ +}#endif #endif /* _IOAT_H_ */
examples/vhost/main.c +99 -41
201 lines not on this page · raw message
Signature · 1 line
2.25.1
v5 cover support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v5:
- DMA address use IOVA instead of VA.
v4:
- Fix wrong packet index issue in async dequeue improve the performance of small packet copies.
v3:
- Fix compilation warning and error in arm platform.
- Restore the removed function virtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths. examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 10 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 44 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 601 ++++++++++++++++++++++++++++ 10 files changed, 924 insertions(+), 108 deletions(-)
Signature · 1 line
2.25.1
PATCH v5 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths.
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 1/4] examples/vhost: refactor vhost enqueue and dequeue datapaths.
Hi Wenwu,
Please do not add dot in the commit title.
Quoted 7 lines · Wenwu Ma
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
Quoted 7 lines
Signed-off-by Wenwu Ma <[email protected]>--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
Other than that, it looks good to me.
The typo in the title can be fixed while applying:
Thanks,
Maxime
PATCH v5 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 2/4] examples/vhost: use a new API to query remaining ring space
Quoted 47 lines · Wenwu Ma
A new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
Signed-off-by Wenwu Ma <[email protected]>--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)examples/vhost/ioat.c +1
-4@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
examples/vhost/ioat.c ioat_check_completed_copies_cb(int vid, uint16_t queue_id, · line 196
Quoted 7 lines
examples/vhost/ioat.c +0
-1@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Thanks,
Maxime
PATCH v5 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 10 + lib/vhost/rte_vhost_async.h | 44 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 601 ++++++++++++++++++++++++++++ 4 files changed, 655 insertions(+), 3 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +10 -0
@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +41 -3
58 lines not on this page · raw message
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +601 -0
610 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 44 lines · Wenwu Ma
From: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
Signed-off-by Yuan Wang <[email protected]>Signed-off-by Jiayu Hu <[email protected]>Signed-off-by Wenwu Ma <[email protected]>--- doc/guides/prog_guide/vhost_lib.rst | 10 + lib/vhost/rte_vhost_async.h | 44 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 601 ++++++++++++++++++++++++++++ 4 files changed, 655 insertions(+), 3 deletions(-)doc/guides/prog_guide/vhost_lib.rst +10
-0@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + Try to receive packets from the guest with offloading large packets + to the DMA engine. Successfully dequeued packets are transfer + completed and returned in ``pkts``. But there may be other packets + that are sent from the guest but being transferred by the DMA engine, + called in-flight packets. This function will return in-flight packets + only after the DMA engine finishes transferring. The amount of + in-flight packets by now is returned in ``nr_inflight``. + Vhost-user Implementations --------------------------lib/vhost/rte_vhost_async.h +0
-0
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 89
Quoted 7 lines
lib/vhost/rte_vhost_async.h +2
-1@@ -84,13 +84,21 @@ struct rte_vhost_async_channel_ops { };/** -* inflight async packet information +* in-flight async packet information */ +struct async_nethdr {
Please prefix with rte_vhost_
Quoted 4 lines
lib/vhost/rte_vhost_async.h +4
-0+struct virtio_net_hdr hdr; +bool valid; +}; +
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 101
Quoted 10 lines
lib/vhost/rte_vhost_async.h +5
-2struct async_inflight_info {struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -}; +} __rte_cache_aligned;
Does it really need to be cache aligned?
Quoted 6 lines
lib/vhost/rte_vhost_async.h +0
-0/** * dma channel feature bit definition @@ -193,4 +201,34 @@ __rte_experimentaluint16_t rte_vhost_poll_enqueue_completed (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count);
lib/vhost/rte_vhost_async.h __rte_experimental · line 212
Quoted 10 lines
lib/vhost/rte_vhost_async.h +9
-0+/** +* This function tries to receive packets from the guest with offloading +* large copies to the DMA engine. Successfully dequeued packets are +* transfer completed, either by the CPU or the DMA engine, and they are +* returned in "pkts". There may be other packets that are sent from +* the guest but being transferred by the DMA engine, called in-flight +* packets. The amount of in-flight packets by now is returned in +* "nr_inflight". This function will return in-flight packets only after +* the DMA engine finishes transferring.
I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
Are we ensuring packets are not reordered with this way of working?
Quoted 58 lines
lib/vhost/rte_vhost_async.h +21
-0+* +* @param vid +* id of vhost device to dequeue data +* @param queue_id +* queue id to dequeue data +* @param pkts +* blank array to keep successfully dequeued packets +* @param count +* size of the packet array +* @param nr_inflight +* the amount of in-flight packets by now. If error occurred, its +* value is set to -1. +* @return +* num of successfully dequeued packets +*/ +__rte_experimental +uint16_t +rte_vhost_async_try_dequeue_burst (int vid,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count, +int *nr_inflight); +#endif /* _RTE_VHOST_ASYNC_H_ */ lib/vhost/version.map +3
-0@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };lib/vhost/virtio_net.c +16
-0@@ -2673,6 +2673,32 @@ virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt,return -1 ; } +/* +* Allocate a host supported pktmbuf. +*/ +static __rte_always_inline struct rte_mbuf * +virtio_dev_pktmbuf_alloc (struct virtio_net *dev,struct rte_mempool *mp, +uint32_t data_len) +{ +struct rte_mbuf *pkt =rte_pktmbuf_alloc (mp); + +if (unlikely (pkt ==NULL )) { +VHOST_LOG_DATA (ERR , +"Failed to allocate memory for mbuf.\n" ); +return NULL ; + } + +if (virtio_dev_pktmbuf_prep (dev, pkt, data_len)) {
lib/vhost/virtio_net.c virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt, · line 2701
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+/* Data doesn't fit into the buffer and the host supports +* only linear buffers +*/ +rte_pktmbuf_free (pkt); +return NULL ; + } + +return pkt; +} +
I think you should be able to use rte_pktmbuf_alloc_bulk and virtio_dev_pktmbuf_prep instead of re-introducing the function that was removed by Balazs. It should help perf a bit.
Quoted 443 lines
lib/vhost/virtio_net.c +436
-0__rte_always_inline static uint16_t virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,@@ -3147,3 +3173,578 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,return count; } + +static __rte_always_inline int +async_desc_to_mbuf (struct virtio_net *dev,struct vhost_virtqueue *vq, +struct buf_vector *buf_vec,uint16_t nr_vec, +struct rte_mbuf *m,struct rte_mempool *mbuf_pool, +struct iovec *src_iovec,struct iovec *dst_iovec, +struct rte_vhost_iov_iter *src_it, +struct rte_vhost_iov_iter *dst_it, +struct async_nethdr *nethdr, +bool legacy_ol_flags) +{ +uint64_t buf_addr, buf_iova; +uint64_t mapped_len; +uint32_t tlen =0 ; +uint32_t buf_avail, buf_offset, buf_len; +uint32_t mbuf_avail, mbuf_offset; +uint32_t cpy_len, cpy_threshold; +/* A counter to avoid desc dead loop chain */ +uint16_t vec_idx =0 ; +int tvec_idx =0 ; +struct rte_mbuf *cur = m, *prev = m; +struct virtio_net_hdr tmp_hdr; +struct virtio_net_hdr *hdr =NULL ; +struct batch_copy_elem *batch_copy = vq->batch_copy_elems; + + buf_addr = buf_vec[vec_idx].buf_addr; + buf_len = buf_vec[vec_idx].buf_len; + buf_iova = buf_vec[vec_idx].buf_iova; + +if (unlikely (buf_len < dev->vhost_hlen && nr_vec <=1 )) +return -1 ; + + cpy_threshold = vq->async_threshold; + +if (virtio_net_with_host_offload (dev)) { +if (unlikely (buf_len <sizeof (struct virtio_net_hdr ))) { +/* +* No luck, the virtio-net header doesn't fit +* in a contiguous virtual area. +*/ +copy_vnet_hdr_from_desc (&tmp_hdr, buf_vec); + hdr = &tmp_hdr; + }else { + hdr = (struct virtio_net_hdr *)((uintptr_t )buf_addr); + } + } + +/* +* A virtio driver normally uses at least 2 desc buffers +* for Tx: the first for storing the header, and others +* for storing the data. +*/ +if (unlikely (buf_len < dev->vhost_hlen)) { + buf_offset = dev->vhost_hlen - buf_len; + vec_idx++; + buf_addr = buf_vec[vec_idx].buf_addr; + buf_len = buf_vec[vec_idx].buf_len; + buf_avail = buf_len - buf_offset; + }else if (buf_len == dev->vhost_hlen) { +if (unlikely (++vec_idx >= nr_vec)) +return -1 ; + buf_addr = buf_vec[vec_idx].buf_addr; + buf_len = buf_vec[vec_idx].buf_len; + + buf_offset =0 ; + buf_avail = buf_len; + }else { + buf_offset = dev->vhost_hlen; + buf_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen; + } + +PRINT_PACKET (dev, (uintptr_t )(buf_addr + buf_offset), + (uint32_t )buf_avail,0 ); + + mbuf_offset =0 ; + mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ; +while (1 ) { + cpy_len =RTE_MIN (buf_avail, mbuf_avail); + +while (cpy_len && cpy_len >= cpy_threshold) { +void *hpa = (void *)(uintptr_t )gpa_to_first_hpa (dev, + buf_iova + buf_offset, cpy_len, + &mapped_len); + +if (unlikely (!hpa || mapped_len < cpy_threshold)) +break ; + +async_fill_vec (src_iovec + tvec_idx, hpa, + (size_t )mapped_len); +async_fill_vec (dst_iovec + tvec_idx, + (void *)(uintptr_t )rte_pktmbuf_iova_offset (cur, + mbuf_offset), + (size_t )mapped_len); + + tvec_idx++; + tlen += (uint32_t )mapped_len; + cpy_len -= (uint32_t )mapped_len; + mbuf_avail -= (uint32_t )mapped_len; + mbuf_offset += (uint32_t )mapped_len; + buf_avail -= (uint32_t )mapped_len; + buf_offset += (uint32_t )mapped_len; + } + +if (cpy_len) { +if (vq->batch_copy_nb_elems >= vq->size || + (hdr && cur == m)) { +rte_memcpy ( +rte_pktmbuf_mtod_offset (cur ,void *, + mbuf_offset), + (void *)((uintptr_t)(buf_addr + + buf_offset)), + cpy_len); + }else { + batch_copy[vq->batch_copy_nb_elems].dst = + rte_pktmbuf_mtod_offset(cur, void *, + mbuf_offset); + batch_copy[vq->batch_copy_nb_elems].src = + (void *)((uintptr_t )(buf_addr + + buf_offset)); + batch_copy[vq->batch_copy_nb_elems].len = + cpy_len; + vq->batch_copy_nb_elems++; + } + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + buf_avail -= cpy_len; + buf_offset += cpy_len; + } + +/* This buf reaches to its end, get the next one */ +if (buf_avail ==0 ) { +if (++vec_idx >= nr_vec) +break ; + + buf_addr = buf_vec[vec_idx].buf_addr; + buf_len = buf_vec[vec_idx].buf_len; + + buf_offset =0 ; + buf_avail = buf_len; + +PRINT_PACKET (dev, (uintptr_t )buf_addr, + (uint32_t )buf_avail,0 ); + } + +/* +* This mbuf reaches to its end, get a new one +* to hold more data. +*/ +if (mbuf_avail ==0 ) { + cur =rte_pktmbuf_alloc (mbuf_pool); +if (unlikely (cur ==NULL )) { +VHOST_LOG_DATA (ERR ,"Failed to " +"allocate memory for mbuf.\n" ); +return -1 ; + } + + prev->next = cur; + prev->data_len = mbuf_offset; + m->nb_segs +=1 ; + m->pkt_len += mbuf_offset; + prev = cur; + + mbuf_offset =0 ; + mbuf_avail = cur->buf_len -RTE_PKTMBUF_HEADROOM ; + } + } + + prev->data_len = mbuf_offset; + m->pkt_len += mbuf_offset; + +if (hdr && tlen) { + nethdr->valid = true; + nethdr->hdr = *hdr; + }else if (hdr) +vhost_dequeue_offload (hdr, m, legacy_ol_flags); + +if (tlen) { +async_fill_iter (src_it, tlen, src_iovec, tvec_idx); +async_fill_iter (dst_it, tlen, dst_iovec, tvec_idx); + }else + src_it->count =0 ; + +return 0 ; +} + +static __rte_always_inline uint16_t +async_poll_dequeue_completed_split (struct virtio_net *dev, +struct vhost_virtqueue *vq,uint16_t queue_id, +struct rte_mbuf **pkts,uint16_t count,bool legacy_ol_flags) +{ +uint16_t n_pkts_cpl =0 , n_pkts_put =0 ; +uint16_t start_idx, pkt_idx, from; +struct async_inflight_info *pkts_info; + + pkt_idx = vq->async_pkts_idx & (vq->size -1 ); + pkts_info = vq->async_pkts_info; + start_idx =virtio_dev_rx_async_get_info_idx (pkt_idx, vq->size, + vq->async_pkts_inflight_n); + +if (count > vq->async_last_pkts_n) { + n_pkts_cpl = vq->async_ops.check_completed_copies (dev->vid, + queue_id,0 , count - vq->async_last_pkts_n); + } + + n_pkts_cpl += vq->async_last_pkts_n; +if (unlikely (n_pkts_cpl ==0 )) +return 0 ; + + n_pkts_put =RTE_MIN (count, n_pkts_cpl); + +for (pkt_idx =0 ; pkt_idx < n_pkts_put; pkt_idx++) { + from = (start_idx + pkt_idx) & (vq->size -1 ); + pkts[pkt_idx] = pkts_info[from].mbuf; + +if (pkts_info[from].nethdr.valid) { +vhost_dequeue_offload (&pkts_info[from].nethdr.hdr, + pkts[pkt_idx], legacy_ol_flags); + } + } + vq->async_last_pkts_n = n_pkts_cpl - n_pkts_put; + +if (n_pkts_put) { +/* write back completed descs to used ring */ +write_back_completed_descs_split (vq, n_pkts_put); +/* update used ring */ +__atomic_add_fetch (&vq->used->idx, + n_pkts_put, __ATOMIC_RELEASE); + + vq->async_pkts_inflight_n -= n_pkts_put; + } + +return n_pkts_put; +} + +static __rte_always_inline uint16_t +virtio_dev_tx_async_split (struct virtio_net *dev, +struct vhost_virtqueue *vq,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts, +uint16_t count,bool legacy_ol_flags) +{ +static bool allocerr_warned; +uint16_t pkt_idx; +uint16_t free_entries; +uint16_t slot_idx =0 ; +uint16_t segs_await =0 ; +uint16_t nr_done_pkts =0 , nr_async_pkts =0 , nr_async_cmpl_pkts =0 ; +uint16_t nr_async_burst =0 ; +uint16_t pkt_err =0 ; +uint16_t iovec_idx =0 , it_idx =0 ; + +struct rte_vhost_iov_iter *it_pool = vq->it_pool; +struct iovec *vec_pool = vq->vec_pool; +struct iovec *src_iovec = vec_pool; +struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1 ); +struct rte_vhost_async_desc tdes[MAX_PKT_BURST ]; +struct async_inflight_info *pkts_info = vq->async_pkts_info; + +struct async_pkt_index { +uint16_t last_avail_idx; + } async_pkts_log[MAX_PKT_BURST ]; + +/** +* The ordering between avail index and +* desc reads needs to be enforced. +*/ + free_entries =__atomic_load_n (&vq->avail->idx, __ATOMIC_ACQUIRE) - + vq->last_avail_idx; +if (free_entries ==0 ) + goto out; + +rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size -1 )]); + + count =RTE_MIN (count,MAX_PKT_BURST ); + count =RTE_MIN (count, free_entries); +VHOST_LOG_DATA (DEBUG ,"(%d) about to dequeue %u buffers\n" , + dev->vid, count); + +for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { +uint16_t head_idx =0 ; +uint16_t nr_vec =0 ; +uint32_t buf_len; +int err; +struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct rte_mbuf *pkt; + +if (unlikely (fill_vec_buf_split (dev, vq, vq->last_avail_idx, + &nr_vec, buf_vec, + &head_idx, &buf_len, +VHOST_ACCESS_RO ) <0 )) +break ; + + pkt =virtio_dev_pktmbuf_alloc (dev, mbuf_pool, buf_len); +if (unlikely (pkt ==NULL )) { +/** +* mbuf allocation fails for jumbo packets when external +* buffer allocation is not allowed and linear buffer +* is required. Drop this packet. +*/ +if (!allocerr_warned) { +VHOST_LOG_DATA (ERR , +"Failed mbuf alloc of size %d from %s on %s.\n" , + buf_len, mbuf_pool->name, dev->ifname); + allocerr_warned = true; + } +break ; + } + + slot_idx = (vq->async_pkts_idx + nr_async_pkts) & + (vq->size -1 ); + err =async_desc_to_mbuf (dev, vq, buf_vec, nr_vec, pkt, + mbuf_pool, &src_iovec[iovec_idx], + &dst_iovec[iovec_idx], &it_pool[it_idx], + &it_pool[it_idx +1 ], + &pkts_info[slot_idx].nethdr, legacy_ol_flags); +if (unlikely (err)) { +rte_pktmbuf_free (pkt); +if (!allocerr_warned) { +VHOST_LOG_DATA (ERR , +"Failed to copy desc to mbuf on %s.\n" , + dev->ifname); + allocerr_warned = true; + } +break ; + } + +if (it_pool[it_idx].count) { +uint16_t to = vq->async_desc_idx_split & (vq->size -1 ); + +async_fill_desc (&tdes[nr_async_burst], &it_pool[it_idx], + &it_pool[it_idx +1 ]); + pkts_info[slot_idx].mbuf = pkt; + async_pkts_log[nr_async_pkts++].last_avail_idx = + vq->last_avail_idx; + nr_async_burst++; + iovec_idx += it_pool[it_idx].nr_segs; + it_idx +=2 ; + segs_await += it_pool[it_idx].nr_segs; + +/* keep used desc */ + vq->async_descs_split[to].id = head_idx; + vq->async_descs_split[to].len =0 ; + vq->async_desc_idx_split++; + }else { +update_shadow_used_ring_split (vq, head_idx,0 ); + pkts[nr_done_pkts++] = pkt; + } + + vq->last_avail_idx++; + +if (unlikely ((nr_async_burst >=VHOST_ASYNC_BATCH_THRESHOLD ) || + ((VHOST_MAX_ASYNC_VEC >>1 ) - + segs_await <BUF_VECTOR_MAX ))) { +uint16_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, + queue_id, tdes,0 , nr_async_burst); + src_iovec = vec_pool; + dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1 ); + it_idx =0 ; + segs_await =0 ; + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) { + pkt_err = nr_async_burst - nr_pkts; + nr_async_burst =0 ; +break ; + } + nr_async_burst =0 ; + } + } + +if (nr_async_burst) { +uint32_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, queue_id, + tdes,0 , nr_async_burst); + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) + pkt_err = nr_async_burst - nr_pkts; + } + +do_data_copy_dequeue (vq); + +if (unlikely (pkt_err)) { +uint16_t nr_err_dma = pkt_err; +uint16_t nr_err_sw; + + nr_async_pkts -= nr_err_dma; + +/** +* revert shadow used ring and free pktmbufs for +* CPU-copied pkts after the first DMA-error pkt. +*/ + nr_err_sw = vq->last_avail_idx - + async_pkts_log[nr_async_pkts].last_avail_idx - + nr_err_dma; + vq->shadow_used_idx -= nr_err_sw; +while (nr_err_sw-- >0 ) +rte_pktmbuf_free (pkts[--nr_done_pkts]); + +/** +* recover DMA-copy related structures and free pktmbufs +* for DMA-error pkts. +*/ + vq->async_desc_idx_split -= nr_err_dma; +while (nr_err_dma-- >0 ) { +rte_pktmbuf_free ( + pkts_info[slot_idx & (vq->size -1 )].mbuf); + slot_idx--; + } + +/* recover available ring */ + vq->last_avail_idx = + async_pkts_log[nr_async_pkts].last_avail_idx; + } + + vq->async_pkts_idx += nr_async_pkts; + +if (likely (vq->shadow_used_idx)) +flush_shadow_used_ring_split (dev, vq); + +out: +if (nr_done_pkts < count && vq->async_pkts_inflight_n >0 ) { + nr_async_cmpl_pkts =async_poll_dequeue_completed_split (dev, vq, + queue_id, &pkts[nr_done_pkts], + count - nr_done_pkts, + legacy_ol_flags); + nr_done_pkts += nr_async_cmpl_pkts; + } +if (likely (nr_done_pkts)) +vhost_vring_call_split (dev, vq); + +return nr_done_pkts; +}
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id, · line 3621
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ +__rte_noinline +static uint16_t +virtio_dev_tx_async_split_legacy (struct virtio_net *dev, +struct vhost_virtqueue *vq,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts, +uint16_t count) +{ +return virtio_dev_tx_async_split (dev, vq, queue_id, mbuf_pool, + pkts, count, true);
I think we don't need to support legacy offload.
It may be better to have the Vhost example to support the compliant way, what do you think?
Quoted 130 lines
lib/vhost/virtio_net.c +129
-0+} + +__rte_noinline +static uint16_t +virtio_dev_tx_async_split_compliant (struct virtio_net *dev, +struct vhost_virtqueue *vq,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts, +uint16_t count) +{ +return virtio_dev_tx_async_split (dev, vq, queue_id, mbuf_pool, + pkts, count, false); +} + +uint16_t +rte_vhost_async_try_dequeue_burst (int vid,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count, +int *nr_inflight) +{ +struct virtio_net *dev; +struct rte_mbuf *rarp_mbuf =NULL ; +struct vhost_virtqueue *vq; +int16_t success =1 ; + + *nr_inflight =-1 ; + + dev =get_device (vid); +if (!dev) +return 0 ; + +if (unlikely (!(dev->flags &VIRTIO_DEV_BUILTIN_VIRTIO_NET ))) { +VHOST_LOG_DATA (ERR , +"(%d) %s: built-in vhost net backend is disabled.\n" , + dev->vid, __func__); +return 0 ; + } + +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->nr_vring))) { +VHOST_LOG_DATA (ERR , +"(%d) %s: invalid virtqueue idx %d.\n" , + dev->vid, __func__, queue_id); +return 0 ; + } + + vq = dev->virtqueue[queue_id]; + +if (unlikely (rte_spinlock_trylock (&vq->access_lock) ==0 )) +return 0 ; + +if (unlikely (vq->enabled ==0 )) { + count =0 ; + goto out_access_unlock; + } + +if (unlikely (!vq->async_registered)) { +VHOST_LOG_DATA (ERR ,"(%d) %s: async not registered for queue id %d.\n" , + dev->vid, __func__, queue_id); + count =0 ; + goto out_access_unlock; + } + +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_lock (vq); + +if (unlikely (vq->access_ok ==0 )) +if (unlikely (vring_translate (dev, vq) <0 )) { + count =0 ; + goto out_access_unlock; + } + +/* +* Construct a RARP broadcast packet, and inject it to the "pkts" +* array, to looks like that guest actually send such packet. +* +* Check user_send_rarp() for more information. +* +* broadcast_rarp shares a cacheline in the virtio_net structure +* with some fields that are accessed during enqueue and +* __atomic_compare_exchange_n causes a write if performed compare +* and exchange. This could result in false sharing between enqueue +* and dequeue. +* +* Prevent unnecessary false sharing by reading broadcast_rarp first +* and only performing compare and exchange if the read indicates it +* is likely to be set. +*/ +if (unlikely (__atomic_load_n (&dev->broadcast_rarp, __ATOMIC_ACQUIRE) && +__atomic_compare_exchange_n (&dev->broadcast_rarp, + &success,0 ,0 , __ATOMIC_RELEASE, __ATOMIC_RELAXED))) { + + rarp_mbuf =rte_net_make_rarp_packet (mbuf_pool, &dev->mac); +if (rarp_mbuf ==NULL ) { +VHOST_LOG_DATA (ERR ,"Failed to make RARP packet.\n" ); + count =0 ; + goto out; + } + count -=1 ; + } + +if (unlikely (vq_is_packed (dev))) +return 0 ; + +if (dev->flags &VIRTIO_DEV_LEGACY_OL_FLAGS ) + count =virtio_dev_tx_async_split_legacy (dev, vq, queue_id, + mbuf_pool, pkts, count); +else + count =virtio_dev_tx_async_split_compliant (dev, vq, queue_id, + mbuf_pool, pkts, count); + +out: + *nr_inflight = vq->async_pkts_inflight_n; + +if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) +vhost_user_iotlb_rd_unlock (vq); + +out_access_unlock: +rte_spinlock_unlock (&vq->access_lock); + +if (unlikely (rarp_mbuf !=NULL )) { +/* +* Inject it to the head of "pkts" array, so that switch's mac +* learning table will get updated first. +*/ +memmove (&pkts[1 ], pkts, count *sizeof (struct rte_mbuf *)); + pkts[0 ] = rarp_mbuf; + count +=1 ; + } + +return count; +}
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 8 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 12 lines
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 101
Quoted 10 lines
struct
async_inflight_info{lib/vhost/rte_vhost_async.h +5
-2struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -}; +} __rte_cache_aligned;Does it really need to be cache aligned?
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Quoted 8 lines
Quoted 8 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,
structrte_mbuf**pkts,uint16_tcount);
Quoted 16 lines
Review
Quoted 13 lines
(quoted diff) +13
-0+/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets are + * transfer completed, either by the CPU or the DMA engine, and they +are + * returned in "pkts". There may be other packets that are sent from + * the guest but being transferred by the DMA engine, called +in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets only +after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 2 lines
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Quoted 303 lines
Quoted 15 lines
+ *
+ * @param vid
+ * id of vhost device to dequeue data
+ * @paramqueue_id
+ * queue id to dequeue data
+ * @param pkts
+ * blank array to keep successfully dequeued packets
+ * @param count
+ * size of the packet array
+ * @paramnr_inflight
+ * the amount of in-flight packets by now. If error occurred, its
+ * value is set to -1.
+ * @return
+ * num of successfully dequeued packets */__rte_experimentalReview
Quoted 3 lines
(quoted diff) +3
-0+uint16_t rte_vhost_async_try_dequeue_burst(int vid, uint16_t +queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_tcount,
lib/vhost/virtio_net.c virtio_dev_pktmbuf_prep(struct virtio_net *dev,
Quoted 20 lines
lib/vhost/rte_vhost_async.h +2
-0+ int *nr_inflight); +#endif /* _RTE_VHOST_ASYNC_H_ */ lib/vhost/version.map index renamed from lib/vhost/version.map +0
-0
9103a23cd4..a320f889cd100644lib/vhost/version.map +3
-0@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0
-0
b93482587c..52237e8600100644lib/vhost/virtio_net.c +0
-0@@ -2673,6 +2673,32 @@ virtio_dev_pktmbuf_prep(struct virtio_net *dev,struct
rte_mbuf*pkt,Quoted 19 lines
lib/vhost/virtio_net.c +16
-0return -1 ; } +/* +* Allocate a host supported pktmbuf. +*/ +static __rte_always_inline struct rte_mbuf * +virtio_dev_pktmbuf_alloc (struct virtio_net *dev,struct rte_mempool *mp, +uint32_t data_len) +{ +struct rte_mbuf *pkt =rte_pktmbuf_alloc (mp); + +if (unlikely (pkt ==NULL )) { +VHOST_LOG_DATA (ERR , +"Failed to allocate memory for mbuf.\n" ); +return NULL ; + } + +if (virtio_dev_pktmbuf_prep (dev, pkt, data_len)) {lib/vhost/virtio_net.c virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt, · line 2701
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+/* Data doesn't fit into the buffer and the host supports +* only linear buffers +*/ +rte_pktmbuf_free (pkt); +return NULL ; + } + +return pkt; +} +I think you should be able to use
rte_pktmbuf_alloc_bulkandvirtio_dev_pktmbuf_prepinstead of re-introducing the function that was removed by Balazs. It should help perf a bit.Quoted 4 lines
lib/vhost/virtio_net.c +0
-0__rte_always_inline static uint16_t virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue*vq, @@ -3147,3 +3173,578 @@ rte_vhost_dequeue_burst(int vid,
uint16_tQuoted 7 lines
queue_id,lib/vhost/virtio_net.c +3
-0return count; } + + +static __rte_always_inline uint16_tlib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+virtio_dev_tx_async_split(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, + uint16_t count, bool legacy_ol_flags) { + static bool allocerr_warned; +uint16_t pkt_idx; +uint16_t free_entries; +uint16_t slot_idx =0 ; +uint16_t segs_await =0 ; + uint16_t nr_done_pkts = 0, nr_async_pkts = 0, nr_async_cmpl_pkts =0;
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+uint16_t nr_async_burst =0 ; +uint16_t pkt_err =0 ; +uint16_t iovec_idx =0 , it_idx =0 ; + +struct rte_vhost_iov_iter *it_pool = vq->it_pool; +struct iovec *vec_pool = vq->vec_pool; +struct iovec *src_iovec = vec_pool; +struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1 ); +struct rte_vhost_async_desc tdes[MAX_PKT_BURST ]; +struct async_inflight_info *pkts_info = vq->async_pkts_info;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ +struct async_pkt_index { +uint16_t last_avail_idx; + } async_pkts_log[MAX_PKT_BURST ]; + +/** +* The ordering between avail index and +* desc reads needs to be enforced. +*/ + free_entries = __atomic_load_n(&vq->avail->idx,
__ATOMIC_ACQUIRE) -Quoted 20 lines
lib/vhost/virtio_net.c +20
-0+ vq->last_avail_idx; +if (free_entries ==0 ) + goto out; + +rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size - +1 )]); + + count =RTE_MIN (count,MAX_PKT_BURST ); + count =RTE_MIN (count, free_entries); +VHOST_LOG_DATA (DEBUG ,"(%d) about to dequeue %u buffers\n" , + dev->vid, count); + +for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { +uint16_t head_idx =0 ; +uint16_t nr_vec =0 ; +uint32_t buf_len; +int err; +struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct rte_mbuf *pkt; +lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+if (unlikely (fill_vec_buf_split (dev, vq, vq->last_avail_idx, + &nr_vec, buf_vec, + &head_idx, &buf_len, +VHOST_ACCESS_RO ) <0 )) +break ; + + pkt =virtio_dev_pktmbuf_alloc (dev, mbuf_pool, buf_len); +if (unlikely (pkt ==NULL )) { +/** +* mbuf allocation fails for jumbo packets when external
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 6 lines
lib/vhost/virtio_net.c +6
-0+* buffer allocation is not allowed and linear buffer +* is required. Drop this packet. +*/ +if (!allocerr_warned) { + VHOST_LOG_DATA(ERR, + "Failed mbuf alloc of size %d from %son %s.\n",
Quoted 9 lines
lib/vhost/virtio_net.c +1
-0+ buf_len, mbuf_pool->name, dev-ifname);
lib/vhost/virtio_net.c +7
-0+ allocerr_warned = true; + } +break ; + } + + slot_idx = (vq->async_pkts_idx + nr_async_pkts) & + (vq->size -1 );lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ err =async_desc_to_mbuf (dev, vq, buf_vec, nr_vec, pkt, + mbuf_pool, &src_iovec[iovec_idx], + &dst_iovec[iovec_idx], &it_pool[it_idx], + &it_pool[it_idx +1 ], + &pkts_info[slot_idx].nethdr, legacy_ol_flags); +if (unlikely (err)) { +rte_pktmbuf_free (pkt); +if (!allocerr_warned) { + VHOST_LOG_DATA(ERR, + "Failed to copy desc to mbufon %s.\n",
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 8 lines
lib/vhost/virtio_net.c +8
-0+ dev->ifname); + allocerr_warned = true; + } +break ; + } + +if (it_pool[it_idx].count) { + uint16_t to = vq->async_desc_idx_split & (vq->size -1);
lib/vhost/virtio_net.c
Quoted 2 lines
lib/vhost/virtio_net.c +2
-0+ + async_fill_desc(&tdes[nr_async_burst],&it_pool[it_idx],
Quoted 11 lines
lib/vhost/virtio_net.c +11
-0+ &it_pool[it_idx + 1]); + pkts_info[slot_idx].mbuf = pkt; + async_pkts_log[nr_async_pkts++].last_avail_idx = + vq->last_avail_idx; + nr_async_burst++; + iovec_idx += it_pool[it_idx].nr_segs; + it_idx +=2 ; + segs_await += it_pool[it_idx].nr_segs; + +/* keep used desc */ + vq->async_descs_split[to].id = head_idx;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ vq->async_descs_split[to].len =0 ; + vq->async_desc_idx_split++; + }else { +update_shadow_used_ring_split (vq, head_idx,0 ); + pkts[nr_done_pkts++] = pkt; + } + + vq->last_avail_idx++; + + if (unlikely((nr_async_burst >=
VHOST_ASYNC_BATCH_THRESHOLD) ||lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 8 lines
lib/vhost/virtio_net.c +8
-0+ ((VHOST_MAX_ASYNC_VEC >> 1) - + segs_await < BUF_VECTOR_MAX))) { +uint16_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, + queue_id, tdes,0 , nr_async_burst); + src_iovec = vec_pool; + dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1);
Quoted 57 lines
lib/vhost/virtio_net.c +57
-0+ it_idx =0 ; + segs_await =0 ; + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) { + pkt_err = nr_async_burst - nr_pkts; + nr_async_burst =0 ; +break ; + } + nr_async_burst =0 ; + } + } + +if (nr_async_burst) { +uint32_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, queue_id, + tdes,0 , nr_async_burst); + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) + pkt_err = nr_async_burst - nr_pkts; + } + +do_data_copy_dequeue (vq); + +if (unlikely (pkt_err)) { +uint16_t nr_err_dma = pkt_err; +uint16_t nr_err_sw; + + nr_async_pkts -= nr_err_dma; + +/** +* revert shadow used ring and free pktmbufs for +* CPU-copied pkts after the first DMA-error pkt. +*/ + nr_err_sw = vq->last_avail_idx - + async_pkts_log[nr_async_pkts].last_avail_idx - + nr_err_dma; + vq->shadow_used_idx -= nr_err_sw; +while (nr_err_sw-- >0 ) +rte_pktmbuf_free (pkts[--nr_done_pkts]); + +/** +* recover DMA-copy related structures and free pktmbufs +* for DMA-error pkts. +*/ + vq->async_desc_idx_split -= nr_err_dma; +while (nr_err_dma-- >0 ) { +rte_pktmbuf_free ( + pkts_info[slot_idx & (vq->size -1 )].mbuf); + slot_idx--; + } + +/* recover available ring */ + vq->last_avail_idx = + async_pkts_log[nr_async_pkts].last_avail_idx;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ } + + vq->async_pkts_idx += nr_async_pkts; + +if (likely (vq->shadow_used_idx)) +flush_shadow_used_ring_split (dev, vq); + +out: +if (nr_done_pkts < count && vq->async_pkts_inflight_n >0 ) { + nr_async_cmpl_pkts =async_poll_dequeue_completed_split(dev, vq,
Quoted 16 lines
lib/vhost/virtio_net.c +16
-0+ queue_id, &pkts[nr_done_pkts], + count - nr_done_pkts, + legacy_ol_flags); + nr_done_pkts += nr_async_cmpl_pkts; + } +if (likely (nr_done_pkts)) +vhost_vring_call_split (dev, vq); + +return nr_done_pkts; +} + +__rte_noinline +static uint16_t +virtio_dev_tx_async_split_legacy(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts,
Quoted 8 lines
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id, · line 3621
Quoted 4 lines
lib/vhost/virtio_net.c +4
-0+ uint16_t count) +{ +return virtio_dev_tx_async_split (dev, vq, queue_id, mbuf_pool, + pkts, count, true);I think we don't need to support legacy offload.
It may be better to have the Vhost example to support the compliant way, what do you think?
The legacy offload is disabled by RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS, and compliant mode is disabled by default. If we don't implement legacy mode in the async dequeue code, how to handle the case that users don't set the flag?
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 25 lines · Jiayu
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 8 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 12 lines
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 101
Quoted 10 lines
struct
async_inflight_info{lib/vhost/rte_vhost_async.h +5
-2struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -}; +} __rte_cache_aligned;Does it really need to be cache aligned?
Quoted 1 line
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Or not forcing any alignment at all? Would there really be a performance regression?
Quoted 29 lines
Quoted 8 lines
Quoted 8 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,
structrte_mbuf**pkts,uint16_tcount);Quoted 16 lines
Review
Quoted 13 lines
(quoted diff) +13
-0+/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets are + * transfer completed, either by the CPU or the DMA engine, and they +are + * returned in "pkts". There may be other packets that are sent from + * the guest but being transferred by the DMA engine, called +in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets only +after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Reordering packets is bad in my opinion. We cannot expect the user to know that he should set the threshold to zero to have packets ordered.
Maybe we should consider not having threshold, and so have every descriptors handled either by the CPU (sync datapath) or by the DMA (async datapath). Doing so would simplify a lot the code, and would make performance/latency more predictable.
I understand that we might not get the best performance for every packet size doing that, but that may be a tradeoff we would make to have the feature maintainable and easily useable by the user.
Quoted 312 lines
Quoted 303 lines
Quoted 15 lines
+ *
+ * @param vid
+ * id of vhost device to dequeue data
+ * @paramqueue_id
+ * queue id to dequeue data
+ * @param pkts
+ * blank array to keep successfully dequeued packets
+ * @param count
+ * size of the packet array
+ * @paramnr_inflight
+ * the amount of in-flight packets by now. If error occurred, its
+ * value is set to -1.
+ * @return
+ * num of successfully dequeued packets */__rte_experimentalReview
Quoted 3 lines
(quoted diff) +3
-0+uint16_t rte_vhost_async_try_dequeue_burst(int vid, uint16_t +queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_tcount,
lib/vhost/virtio_net.c virtio_dev_pktmbuf_prep(struct virtio_net *dev,
Quoted 20 lines
lib/vhost/rte_vhost_async.h +2
-0+ int *nr_inflight); +#endif /* _RTE_VHOST_ASYNC_H_ */ lib/vhost/version.map index renamed from lib/vhost/version.map +0
-0
9103a23cd4..a320f889cd100644lib/vhost/version.map +3
-0@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0
-0
b93482587c..52237e8600100644lib/vhost/virtio_net.c +0
-0@@ -2673,6 +2673,32 @@ virtio_dev_pktmbuf_prep(struct virtio_net *dev,struct
rte_mbuf*pkt,Quoted 19 lines
lib/vhost/virtio_net.c +16
-0return -1 ; } +/* +* Allocate a host supported pktmbuf. +*/ +static __rte_always_inline struct rte_mbuf * +virtio_dev_pktmbuf_alloc (struct virtio_net *dev,struct rte_mempool *mp, +uint32_t data_len) +{ +struct rte_mbuf *pkt =rte_pktmbuf_alloc (mp); + +if (unlikely (pkt ==NULL )) { +VHOST_LOG_DATA (ERR , +"Failed to allocate memory for mbuf.\n" ); +return NULL ; + } + +if (virtio_dev_pktmbuf_prep (dev, pkt, data_len)) {lib/vhost/virtio_net.c virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt, · line 2701
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+/* Data doesn't fit into the buffer and the host supports +* only linear buffers +*/ +rte_pktmbuf_free (pkt); +return NULL ; + } + +return pkt; +} +I think you should be able to use
rte_pktmbuf_alloc_bulkandvirtio_dev_pktmbuf_prepinstead of re-introducing the function that was removed by Balazs. It should help perf a bit.Quoted 4 lines
lib/vhost/virtio_net.c +0
-0__rte_always_inline static uint16_t virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue*vq, @@ -3147,3 +3173,578 @@ rte_vhost_dequeue_burst(int vid,
uint16_tQuoted 7 lines
queue_id,lib/vhost/virtio_net.c +3
-0return count; } + + +static __rte_always_inline uint16_tlib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+virtio_dev_tx_async_split(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, + uint16_t count, bool legacy_ol_flags) { + static bool allocerr_warned; +uint16_t pkt_idx; +uint16_t free_entries; +uint16_t slot_idx =0 ; +uint16_t segs_await =0 ; + uint16_t nr_done_pkts = 0, nr_async_pkts = 0, nr_async_cmpl_pkts =0;
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+uint16_t nr_async_burst =0 ; +uint16_t pkt_err =0 ; +uint16_t iovec_idx =0 , it_idx =0 ; + +struct rte_vhost_iov_iter *it_pool = vq->it_pool; +struct iovec *vec_pool = vq->vec_pool; +struct iovec *src_iovec = vec_pool; +struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1 ); +struct rte_vhost_async_desc tdes[MAX_PKT_BURST ]; +struct async_inflight_info *pkts_info = vq->async_pkts_info;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ +struct async_pkt_index { +uint16_t last_avail_idx; + } async_pkts_log[MAX_PKT_BURST ]; + +/** +* The ordering between avail index and +* desc reads needs to be enforced. +*/ + free_entries = __atomic_load_n(&vq->avail->idx,
__ATOMIC_ACQUIRE) -Quoted 20 lines
lib/vhost/virtio_net.c +20
-0+ vq->last_avail_idx; +if (free_entries ==0 ) + goto out; + +rte_prefetch0 (&vq->avail->ring[vq->last_avail_idx & (vq->size - +1 )]); + + count =RTE_MIN (count,MAX_PKT_BURST ); + count =RTE_MIN (count, free_entries); +VHOST_LOG_DATA (DEBUG ,"(%d) about to dequeue %u buffers\n" , + dev->vid, count); + +for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { +uint16_t head_idx =0 ; +uint16_t nr_vec =0 ; +uint32_t buf_len; +int err; +struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct rte_mbuf *pkt; +lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+if (unlikely (fill_vec_buf_split (dev, vq, vq->last_avail_idx, + &nr_vec, buf_vec, + &head_idx, &buf_len, +VHOST_ACCESS_RO ) <0 )) +break ; + + pkt =virtio_dev_pktmbuf_alloc (dev, mbuf_pool, buf_len); +if (unlikely (pkt ==NULL )) { +/** +* mbuf allocation fails for jumbo packets when external
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 6 lines
lib/vhost/virtio_net.c +6
-0+* buffer allocation is not allowed and linear buffer +* is required. Drop this packet. +*/ +if (!allocerr_warned) { + VHOST_LOG_DATA(ERR, + "Failed mbuf alloc of size %d from %son %s.\n",
Quoted 9 lines
lib/vhost/virtio_net.c +1
-0+ buf_len, mbuf_pool->name, dev-ifname);
lib/vhost/virtio_net.c +7
-0+ allocerr_warned = true; + } +break ; + } + + slot_idx = (vq->async_pkts_idx + nr_async_pkts) & + (vq->size -1 );lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ err =async_desc_to_mbuf (dev, vq, buf_vec, nr_vec, pkt, + mbuf_pool, &src_iovec[iovec_idx], + &dst_iovec[iovec_idx], &it_pool[it_idx], + &it_pool[it_idx +1 ], + &pkts_info[slot_idx].nethdr, legacy_ol_flags); +if (unlikely (err)) { +rte_pktmbuf_free (pkt); +if (!allocerr_warned) { + VHOST_LOG_DATA(ERR, + "Failed to copy desc to mbufon %s.\n",
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 8 lines
lib/vhost/virtio_net.c +8
-0+ dev->ifname); + allocerr_warned = true; + } +break ; + } + +if (it_pool[it_idx].count) { + uint16_t to = vq->async_desc_idx_split & (vq->size -1);
lib/vhost/virtio_net.c
Quoted 2 lines
lib/vhost/virtio_net.c +2
-0+ + async_fill_desc(&tdes[nr_async_burst],&it_pool[it_idx],
Quoted 11 lines
lib/vhost/virtio_net.c +11
-0+ &it_pool[it_idx + 1]); + pkts_info[slot_idx].mbuf = pkt; + async_pkts_log[nr_async_pkts++].last_avail_idx = + vq->last_avail_idx; + nr_async_burst++; + iovec_idx += it_pool[it_idx].nr_segs; + it_idx +=2 ; + segs_await += it_pool[it_idx].nr_segs; + +/* keep used desc */ + vq->async_descs_split[to].id = head_idx;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ vq->async_descs_split[to].len =0 ; + vq->async_desc_idx_split++; + }else { +update_shadow_used_ring_split (vq, head_idx,0 ); + pkts[nr_done_pkts++] = pkt; + } + + vq->last_avail_idx++; + + if (unlikely((nr_async_burst >=
VHOST_ASYNC_BATCH_THRESHOLD) ||lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 8 lines
lib/vhost/virtio_net.c +8
-0+ ((VHOST_MAX_ASYNC_VEC >> 1) - + segs_await < BUF_VECTOR_MAX))) { +uint16_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, + queue_id, tdes,0 , nr_async_burst); + src_iovec = vec_pool; + dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >>1);
Quoted 57 lines
lib/vhost/virtio_net.c +57
-0+ it_idx =0 ; + segs_await =0 ; + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) { + pkt_err = nr_async_burst - nr_pkts; + nr_async_burst =0 ; +break ; + } + nr_async_burst =0 ; + } + } + +if (nr_async_burst) { +uint32_t nr_pkts; + + nr_pkts = vq->async_ops.transfer_data (dev->vid, queue_id, + tdes,0 , nr_async_burst); + vq->async_pkts_inflight_n += nr_pkts; + +if (unlikely (nr_pkts < nr_async_burst)) + pkt_err = nr_async_burst - nr_pkts; + } + +do_data_copy_dequeue (vq); + +if (unlikely (pkt_err)) { +uint16_t nr_err_dma = pkt_err; +uint16_t nr_err_sw; + + nr_async_pkts -= nr_err_dma; + +/** +* revert shadow used ring and free pktmbufs for +* CPU-copied pkts after the first DMA-error pkt. +*/ + nr_err_sw = vq->last_avail_idx - + async_pkts_log[nr_async_pkts].last_avail_idx - + nr_err_dma; + vq->shadow_used_idx -= nr_err_sw; +while (nr_err_sw-- >0 ) +rte_pktmbuf_free (pkts[--nr_done_pkts]); + +/** +* recover DMA-copy related structures and free pktmbufs +* for DMA-error pkts. +*/ + vq->async_desc_idx_split -= nr_err_dma; +while (nr_err_dma-- >0 ) { +rte_pktmbuf_free ( + pkts_info[slot_idx & (vq->size -1 )].mbuf); + slot_idx--; + } + +/* recover available ring */ + vq->last_avail_idx = + async_pkts_log[nr_async_pkts].last_avail_idx;lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
Quoted 10 lines
lib/vhost/virtio_net.c +10
-0+ } + + vq->async_pkts_idx += nr_async_pkts; + +if (likely (vq->shadow_used_idx)) +flush_shadow_used_ring_split (dev, vq); + +out: +if (nr_done_pkts < count && vq->async_pkts_inflight_n >0 ) { + nr_async_cmpl_pkts =async_poll_dequeue_completed_split(dev, vq,
Quoted 16 lines
lib/vhost/virtio_net.c +16
-0+ queue_id, &pkts[nr_done_pkts], + count - nr_done_pkts, + legacy_ol_flags); + nr_done_pkts += nr_async_cmpl_pkts; + } +if (likely (nr_done_pkts)) +vhost_vring_call_split (dev, vq); + +return nr_done_pkts; +} + +__rte_noinline +static uint16_t +virtio_dev_tx_async_split_legacy(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts,Quoted 8 lines
lib/vhost/virtio_net.c rte_vhost_dequeue_burst(int vid, uint16_t queue_id, · line 3621
Quoted 4 lines
lib/vhost/virtio_net.c +4
-0+ uint16_t count) +{ +return virtio_dev_tx_async_split (dev, vq, queue_id, mbuf_pool, + pkts, count, true);I think we don't need to support legacy offload.
It may be better to have the Vhost example to support the compliant way, what do you think?
Quoted 3 lines
The legacy offload is disabled by
RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS, and compliant mode is disabled by default. If we don't implement legacy mode in the async dequeue code, how to handle the case that users don't set the flag?
Ok, that's a valid point. We seem to have no choice than supporting it.
Thanks,
Maxime
Quoted 3 lines
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Hi, Maxime,
Quoted 83 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, July 15, 2021 9:18 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 26 lines · Jiayu
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 9 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 12 lines
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 101
Quoted 10 lines
struct
async_inflight_info{lib/vhost/rte_vhost_async.h +5
-2struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -}; +} __rte_cache_aligned;Does it really need to be cache aligned?
Quoted 1 line
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Or not forcing any alignment at all? Would there really be a performance regression?
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,(quoted diff) +10
-0struct rte_mbuf **pkts, uint16_t count); +/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets +are + * transfer completed, either by the CPU or the DMA engine, and +they are + * returned in "pkts". There may be other packets that are sent +from + * the guest but being transferred by the DMA engine, calledQuoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets only +after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Reordering packets is bad in my opinion. We cannot expect the user to know that he should set the threshold to zero to have packets ordered.
Quoted 8 lines
Maybe we should consider not having threshold, and so have every descriptors handled either by the CPU (sync datapath) or by the DMA (async datapath). Doing so would simplify a lot the code, and would make performance/latency more predictable.
I understand that we might not get the best performance for every packet size doing that, but that may be a tradeoff we would make to have the feature maintainable and easily useable by the user.
I understand and agree in some way. But before changing the existed design in async enqueue and dequeue, we need more careful tests, as current design is well validated and performance looks good. So I suggest to do it in 21.11.
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Hi,
Quoted 90 lines · Jiayu
Hi, Maxime,
Quoted 88 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, July 15, 2021 9:18 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 26 lines · Jiayu
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 9 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 12 lines
lib/vhost/rte_vhost_async.h struct rte_vhost_async_channel_ops { · line 101
Quoted 10 lines
struct
async_inflight_info{lib/vhost/rte_vhost_async.h +5
-2struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -}; +} __rte_cache_aligned;Does it really need to be cache aligned?
Quoted 1 line
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Or not forcing any alignment at all? Would there really be a performance regression?
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,(quoted diff) +10
-0struct rte_mbuf **pkts, uint16_t count); +/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets +are + * transfer completed, either by the CPU or the DMA engine, and +they are + * returned in "pkts". There may be other packets that are sent +from + * the guest but being transferred by the DMA engine, calledQuoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets only +after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Reordering packets is bad in my opinion. We cannot expect the user to know that he should set the threshold to zero to have packets ordered.
Maybe we should consider not having threshold, and so have every descriptors handled either by the CPU (sync datapath) or by the DMA (async datapath). Doing so would simplify a lot the code, and would make performance/latency more predictable.
Quoted 7 lines
Quoted 3 lines
I understand that we might not get the best performance for every packet size doing that, but that may be a tradeoff we would make to have the feature maintainable and easily useable by the user.
I understand and agree in some way. But before changing the existed design in async enqueue and dequeue, we need more careful tests, as current design is well validated and performance looks good. So I suggest to do it in 21.11.
My understanding was that for enqueue path packets were not reordered, thinking the used ring was written in order, but it seems I was wrong.
What kind of validation and performance testing has been done? I can imagine reordering to have a bad impact on L4+ benchmarks.
Let's first fix this for enqueue path, then submit new revision for dequeue path without packet reordering.
Regards,
Maxime
Quoted 3 lines
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 113 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, July 16, 2021 3:46 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringHi,
Quoted 6 lines · Jiayu
Hi, Maxime,
Quoted 4 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, July 15, 2021 9:18 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuXQuoted 85 lines
Quoted 85 lines
[email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 26 lines · Jiayu
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 9 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 12 lines
Quoted 10 lines
struct
async_inflight_info{lib/vhost/rte_vhost_async.h +4
-1struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ -};
+}__rte_cache_aligned;Does it really need to be cache aligned?
Quoted 1 line
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Or not forcing any alignment at all? Would there really be a performance regression?
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,(quoted diff) +10
-0struct rte_mbuf **pkts, uint16_t count); +/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets +are + * transfer completed, either by the CPU or the DMA engine, and +they are + * returned in "pkts". There may be other packets that are sent +from + * the guest but being transferred by the DMA engine, calledQuoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets +only after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Reordering packets is bad in my opinion. We cannot expect the user to know that he should set the threshold to zero to have packets ordered.
Maybe we should consider not having threshold, and so have every descriptors handled either by the CPU (sync datapath) or by the DMA (async datapath). Doing so would simplify a lot the code, and would make performance/latency more predictable.
Quoted 7 lines
Quoted 3 lines
I understand that we might not get the best performance for every packet size doing that, but that may be a tradeoff we would make to have the feature maintainable and easily useable by the user.
I understand and agree in some way. But before changing the existed design in async enqueue and dequeue, we need more careful tests, as current design is well validated and performance looks good. So I suggest
Quoted 7 lines
to do it in 21.11.
My understanding was that for enqueue path packets were not reordered, thinking the used ring was written in order, but it seems I was wrong.
What kind of validation and performance testing has been done? I can imagine reordering to have a bad impact on L4+ benchmarks.
Iperf and scp in V2V scenarios.
One thing to notice is that if we guarantee in-order, small packets will be blocked by large packets, especially for control packets in TCP, which significantly increases latency. In iperf tests, it will impact connection setup and increase latency. Current design doesn't show big impacts on iperf and scp tests, but I am not sure about more complex networking scenarios.
Quoted 3 lines
Let's first fix this for enqueue path, then submit new revision for dequeue path without packet reordering.
Sure. The way to fix it needs to be very careful, IMO. So I'd suggest more tests before any modification.
Thanks,
Jiayu
Quoted 7 lines
Regards,
MaximeQuoted 3 lines
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 121 lines · Jiayu
Quoted 113 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, July 16, 2021 3:46 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringHi,
Quoted 6 lines · Jiayu
Hi, Maxime,
Quoted 4 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, July 15, 2021 9:18 PM
To: Hu, Jiayu <[email protected]>; Ma, WenwuXQuoted 85 lines
Quoted 85 lines
[email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 26 lines · Jiayu
Hi Maxime,
Thanks for your comments. Applies are inline.
Quoted 9 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, July 13, 2021 10:30 PM
To: Ma, WenwuX <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 12 lines
Quoted 10 lines
struct
async_inflight_info{(quoted diff) +4
-1struct rte_mbuf *mbuf; - uint16_t descs; /* num of descs inflight */ + union { + uint16_t descs; /* num of descs in-flight */ + struct async_nethdr nethdr; + }; uint16_t nr_buffers; /* num of buffers inflight for packed ring*/ -};
+}__rte_cache_aligned;Does it really need to be cache aligned?
Quoted 1 line
How about changing to 32-byte align? So a cacheline can hold 2 objects.
Or not forcing any alignment at all? Would there really be a performance regression?
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
/**
* dma channel feature bit definition @@ -193,4 +201,34 @@__rte_experimentaluint16_trte_vhost_poll_enqueue_completed(int vid,uint16_tqueue_id,(quoted diff) +10
-0struct rte_mbuf **pkts, uint16_t count); +/** + * This function tries to receive packets from the guest with +offloading + * large copies to the DMA engine. Successfully dequeued packets +are + * transfer completed, either by the CPU or the DMA engine, and +they are + * returned in "pkts". There may be other packets that are sent +from + * the guest but being transferred by the DMA engine, calledQuoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+in-flight + * packets. The amount of in-flight packets by now is returned in + * "nr_inflight". This function will return in-flight packets +only after + * the DMA engine finishes transferring.I am not sure to understand that comment. Is it still "in-flight" if the DMA transfer is completed?
"in-flight" means packet copies are submitted to the DMA, but the DMA hasn't completed copies.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
Reordering packets is bad in my opinion. We cannot expect the user to know that he should set the threshold to zero to have packets ordered.
Maybe we should consider not having threshold, and so have every descriptors handled either by the CPU (sync datapath) or by the DMA (async datapath). Doing so would simplify a lot the code, and would make performance/latency more predictable.
Quoted 7 lines
Quoted 3 lines
I understand that we might not get the best performance for every packet size doing that, but that may be a tradeoff we would make to have the feature maintainable and easily useable by the user.
I understand and agree in some way. But before changing the existed design in async enqueue and dequeue, we need more careful tests, as current design is well validated and performance looks good. So I suggest
Quoted 7 lines
to do it in 21.11.
My understanding was that for enqueue path packets were not reordered, thinking the used ring was written in order, but it seems I was wrong.
What kind of validation and performance testing has been done? I can imagine reordering to have a bad impact on L4+ benchmarks.
Quoted 8 lines
Iperf and scp in V2V scenarios.
One thing to notice is that if we guarantee in-order, small packets will be blocked by large packets, especially for control packets in TCP, which significantly increases latency. In iperf tests, it will impact connection setup and increase latency. Current design doesn't show big impacts on iperf and scp tests, but I am not sure about more complex networking scenarios.
Ok, I see. I guess that depending on the payload size, one can see perf improvement if all the data segments are larger than the threshold. Or it could cause perf penalty if last segments arrives before the previous ones.
Quoted 17 lines
Quoted 3 lines
Let's first fix this for enqueue path, then submit new revision for dequeue path without packet reordering.
Sure. The way to fix it needs to be very careful, IMO. So I'd suggest more tests before any modification.
Thanks,
JiayuQuoted 7 lines
Regards,
MaximeQuoted 3 lines
Thanks,
Jiayu
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
In reply to Hu, JiayuQuoted 5 lines · Jiayu
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
- I find the rte_vhost_async_channel_register() signature with a bitfield quite ugly.
We are writing sw, this is not mapped to hw stuff... but ok this is a different topic.
- I don't like this threshold, this is too low level and most users will only see the shiny aspect "better performance" without understanding the consequences.
By default, it leaves the door open to a _bad_ behavior, that is packet reordering.
At a very minimum, strongly recommend to use 0 in the API.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 16 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, July 16, 2021 4:15 PM
To: Hu, Jiayu <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]; Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 2 lines · Jiayu
Quoted 1 line
Are we ensuring packets are not reordered with this way of working?
Quoted 8 lines
Quoted 3 lines
There is a threshold can be set by users. If set it to 0, which presents all packet copies assigned to the DMA, the packets sent from the guest will not be reordered.
- I find the
rte_vhost_async_channel_register()signature with a bitfield quite ugly.
We are writing sw, this is not mapped to hw stuff... but ok this is a different topic.
I have reworked the structure. Here is the link:
http://patches.dpdk.org/project/dpdk/patch/[email protected]/
Quoted 8 lines
- I don't like this threshold, this is too low level and most users will only see the shiny aspect "better performance" without understanding the consequences.
By default, it leaves the door open to a _bad_ behavior, that is packet reordering.
At a very minimum, strongly recommend to use 0 in the API.
That's a good point. But there are some reasons of open this value to users:
- large packets will block small packets, like control packets of TCP.
- dma efficiency. We usually see 20~30% drops because of offloading 64B copies to dma engine.
- the threshold is not only related to hardware, but also application. The value decides which copies are assigned to which worker, the CPU or the DMA. As async vhost works in an asynchronous way, the threshold value decides how many works can be done in parallel. It's not only about what DMA engine and what platform we use, but also what computation the CPU has been assigned. Different users will have different values.
I totally understand the worry about reordering. But simple iperf tests show positive results with setting threshold in our lab. We need more careful tests before modifying it, IMHO.
Thanks,
Jiayu
Quoted 5 lines
--
David Marchand
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 17 lines · Jiayu
Quoted 6 lines
- I don't like this threshold, this is too low level and most users will only see the shiny aspect "better performance" without understanding the consequences.
By default, it leaves the door open to a _bad_ behavior, that is packet reordering.
At a very minimum, strongly recommend to use 0 in the API.That's a good point. But there are some reasons of open this value to users:
- large packets will block small packets, like control packets of TCP.
- dma efficiency. We usually see 20~30% drops because of offloading 64B copies to dma engine.
- the threshold is not only related to hardware, but also application. The value decides which copies are assigned to which worker, the CPU or the DMA. As async vhost works in an asynchronous way, the threshold value decides how many works can be done in parallel. It's not only about what DMA engine and what platform we use, but also what computation the CPU has been assigned. Different users will have different values.
Quoted 3 lines
I totally understand the worry about reordering. But simple iperf tests show positive results with setting threshold in our lab. We need more careful tests before modifying it, IMHO.
If you need more time, then please take it.
The dma generic API could have an impact on this feature too.
Why the rush for merging this now?
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ring
Quoted 33 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, July 16, 2021 9:53 PM
To: Hu, Jiayu <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]; Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Wang, YuanX <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 3/4] vhost: support async dequeue for split ringQuoted 7 lines · Jiayu
Quoted 6 lines
- I don't like this threshold, this is too low level and most users will only see the shiny aspect "better performance" without understanding the consequences.
By default, it leaves the door open to a _bad_ behavior, that is packet reordering.
At a very minimum, strongly recommend to use 0 in the API.Quoted 9 lines
That's a good point. But there are some reasons of open this value to users:
- large packets will block small packets, like control packets of TCP.
- dma efficiency. We usually see 20~30% drops because of offloading 64B copies to dma engine.
- the threshold is not only related to hardware, but also application. The value decides which copies are assigned to which worker, the CPU or the DMA. As async vhost works in an asynchronous way, the threshold value decides how many works can be done in parallel. It's not only about what DMA engine and what platform we use, but also whatcomputation the CPU has been assigned. Different users will have different values.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
I totally understand the worry about reordering. But simple iperf tests show positive results with setting threshold in our lab. We need more careful tests before modifying it, IMHO.
If you need more time, then please take it.
The dma generic API could have an impact on this feature too.Why the rush for merging this now?
Changing threshold or not is under discussion. No data shows setting it to 0 is better than current design. On the contrary, our intensive lab data shows positive results with this design. Please don't mix it with this deq feature. Especially for now, app can set it to 0, if reordering really matters a lot.
Quoted 4 lines
--
David Marchand
PATCH v5 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +47 -14
134 lines not on this page · raw message
examples/vhost/ioat.h +25 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_RX_VHOST 1 +#define ASYNC_TX_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
@@ -36,6 +40,10 @@ uint32_t ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets); + +uint32_t get_async_flag_by_vid (int vid); +uint32_t get_async_flag_by_socketid (int socketid); +void init_vid2socketid_array (int vid,int socketid);#else static int open_ioat(const char *value __rte_unused) {
@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused, {return -1 ; } + +static uint32_t +get_async_flag_by_vid(int vid __rte_unused) +{ +return 0 ; +} + +static uint32_t +get_async_flag_by_socketid(int socketid __rte_unused) +{ +return 0 ; +} + +static void +init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused) +{ +}#endif #endif /* _IOAT_H_ */
examples/vhost/main.c +99 -41
201 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 4/4] examples/vhost: support vhost async dequeue data path
Quoted 2 lines · Wenwu Ma
This patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
"
This patch adds support for async dequeue path to Vhost example. "
Quoted 65 lines
Signed-off-by Wenwu Ma <[email protected]>--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)doc/guides/sample_app_ug/vhost.rst +6
-3@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------examples/vhost/ioat.c +5
-3@@ -21,6 +21,8 @@ struct packet_tracker {struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ]; +int vid2socketid[MAX_VHOST_DEVICE ]; +int open_ioat (const char *value) {@@ -29,7 +31,7 @@ open_ioat(const char *value)char *addrs = input;char *ptrs[2 ];char *start, *end, *substr; -int64_t vid, vring_id; +int64_t socketid, vring_id;struct rte_ioat_rawdev_config config;struct rte_rawdev_info info = { .dev_private = &config };char name[32 ];@@ -60,6 +62,8 @@ open_ioat(const char *value) goto out; }while (i < args_nr) { +char *txd, *rxd; +bool is_txd;char *arg_temp = dma_arg[i];uint8_t sub_nr; sub_nr =rte_strsplit (arg_temp,strlen (arg_temp), ptrs,2 ,'@' );@@ -68,27 +72,38 @@ open_ioat(const char *value) goto out; } - start =strstr (ptrs[0 ],"txd" ); -if (start ==NULL ) {
examples/vhost/ioat.c open_ioat(const char *value) · line 84
Quoted 10 lines
examples/vhost/ioat.c +8
-0+int async_flag; + txd =strstr (ptrs[0 ],"txd" ); + rxd =strstr (ptrs[0 ],"rxd" ); +if (txd ==NULL && rxd ==NULL ) { ret =-1 ; goto out; + }else if (txd) { + is_txd = true; + start = txd; + async_flag =ASYNC_RX_VHOST ;
That's confusing to set ASYNC_RX_VHOST flag when txd is present. IIUC, this is about the enqueue path, so TX from Vhost point of view. So either name the flag ASYNC_TX_VHOST or ASYNV_ENQUEUE_VHOST?
examples/vhost/ioat.c open_ioat(const char *value) · line 89
Quoted 5 lines
examples/vhost/ioat.c +4
-0+ }else { + is_txd = false; + start = rxd; + async_flag =ASYNC_TX_VHOST ; }
What if both are set by the user? you might want to add a check.
v6 cover support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v6:
- Allocate and free packets in bulk.
- struct async_inflight_info aligned to 32 bits.
- Change ASYNC_RX_VHOST to ASYNV_ENQUEUE_VHOST and ASYNC_TX_VHOST to ASYNV_DEQUEUE_VHOST.
v5:
- DMA address use IOVA instead of VA.
v4:
- Fix wrong packet index issue in async dequeue improve the performance of small packet copies.
v3:
- Fix compilation warning and error in arm platform.
- Restore the removed function virtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 9 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 39 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 586 ++++++++++++++++++++++++++++ 10 files changed, 904 insertions(+), 107 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
PATCH v6 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
PATCH v6 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the async channel, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 9 + lib/vhost/rte_vhost_async.h | 39 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 586 ++++++++++++++++++++++++++++ 4 files changed, 635 insertions(+), 2 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +9 -0
@@ -281,6 +281,15 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + This function tries to receive packets from the guest with offloading + large copies to the async channel. The packets that are transfer completed + are returned in ``pkts``. The other packets that their copies are submitted + to the async channel but not completed are called "in-flight packets". + This function will not return in-flight packets until their copies are + completed by the async channel. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +37 -2
@@ -83,12 +83,20 @@ struct rte_vhost_async_channel_ops { uint16_t max_packets); }; +struct async_nethdr { +struct virtio_net_hdr hdr; +bool valid; +}; +/** -* inflight async packet information +* in-flight async packet information */ struct async_inflight_info {struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ };
@@ -193,4 +201,31 @@ __rte_experimentaluint16_t rte_vhost_poll_enqueue_completed (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count); +/** +* This function tries to receive packets from the guest with offloading +* large copies to the async channel. The packets that are transfer completed +* are returned in "pkts". The other packets that their copies are submitted to +* the async channel but not completed are called "in-flight packets". +* This function will not return in-flight packets until their copies are +* completed by the async channel. +* +* @param vid +* id of vhost device to dequeue data +* @param queue_id +* queue id to dequeue data +* @param pkts +* blank array to keep successfully dequeued packets +* @param count +* size of the packet array +* @param nr_inflight +* the amount of in-flight packets. If error occurred, its value is set to -1. +* @return +* num of successfully dequeued packets +*/ +__rte_experimental +uint16_t +rte_vhost_async_try_dequeue_burst (int vid,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count, +int *nr_inflight); +#endif /* _RTE_VHOST_ASYNC_H_ */
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +586 -0
589 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +47 -14
134 lines not on this page · raw message
examples/vhost/ioat.h +25 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_ENQUEUE_VHOST 1 +#define ASYNC_DEQUEUE_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
@@ -36,6 +40,10 @@ uint32_t ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets); + +uint32_t get_async_flag_by_vid (int vid); +uint32_t get_async_flag_by_socketid (int socketid); +void init_vid2socketid_array (int vid,int socketid);#else static int open_ioat(const char *value __rte_unused) {
@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused, {return -1 ; } + +static uint32_t +get_async_flag_by_vid(int vid __rte_unused) +{ +return 0 ; +} + +static uint32_t +get_async_flag_by_socketid(int socketid __rte_unused) +{ +return 0 ; +} + +static void +init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused) +{ +}#endif #endif /* _IOAT_H_ */
examples/vhost/main.c +99 -41
201 lines not on this page · raw message
Signature · 1 line
2.25.1
v7 cover support async dequeue for split ring
In reply to Yuan WangThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v7:
- Add Reviewed-by to comments in examples/vhost.
v6:
- Allocate and free packets in bulk.
- struct async_inflight_info aligned to 32 bits.
- Change ASYNC_RX_VHOST to ASYNV_ENQUEUE_VHOST and ASYNC_TX_VHOST to ASYNV_DEQUEUE_VHOST.
v5:
- DMA address use IOVA instead of VA.
v4:
- Fix wrong packet index issue in async dequeue improve the performance of small packet copies.
v3:
- Fix compilation warning and error in arm platform.
- Restore the removed function virtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.
v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Check queue_id value before using it.
- Async dequeue performance enhancement. 160% performance improvement for v2 vs. v1.
- Async dequeue API name change from rte_vhost_try_dequeue_burst to rte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.
Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data path
Yuan Wang (1):
vhost: support async dequeue for split ring
doc/guides/prog_guide/vhost_lib.rst | 9 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 39 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 586 ++++++++++++++++++++++++++++ 10 files changed, 904 insertions(+), 107 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/4 examples/vhost: refactor vhost enqueue and dequeue datapaths
Previously, by judging the flag, we call different enqueue/dequeue functions in data path.
Now, we use an ops that was initialized when Vhost was created, so that we can call ops directly in Vhost data path without any more flag judgment.
--- examples/vhost/main.c | 112 ++++++++++++++++++++---------------- examples/vhost/main.h | 33 +++++++++-- examples/vhost/virtio_net.c | 16 +++++- 3 files changed, 105 insertions(+), 56 deletions(-)
examples/vhost/main.c +61 -51
@@ -106,6 +106,8 @@ static uint32_t burst_rx_retry_num = BURST_RX_RETRIES;static char *socket_files;static int nb_sockets; +static struct vhost_queue_ops vdev_queue_ops[MAX_VHOST_DEVICE ]; +/* empty vmdq configuration structure. Filled in programatically */ static struct rte_eth_conf vmdq_conf_default = { .rxmode = {
@@ -885,27 +887,8 @@ drain_vhost(struct vhost_dev *vdev)uint16_t nr_xmit = vhost_txbuff[buff_idx]->len;struct rte_mbuf **m = vhost_txbuff[buff_idx]->m_table; -if (builtin_net_driver) { - ret =vs_enqueue_pkts (vdev,VIRTIO_RXQ , m, nr_xmit); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[nr_xmit]; - -complete_async_pkts (vdev); - ret =rte_vhost_submit_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit, m_cpu_cpl, &cpu_cpl_nr); - -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = nr_xmit - ret; -if (enqueue_fail) -free_pkts (&m[ret], nr_xmit - ret); - }else { - ret =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - m, nr_xmit); - } + ret = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , m, nr_xmit);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, nr_xmit,
@@ -1184,6 +1167,36 @@ drain_mbuf_table(struct mbuf_table *tx_q) } } +uint16_t +async_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +uint16_t enqueue_count; +uint32_t cpu_cpl_nr =0 ; +uint16_t enqueue_fail =0 ; +struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; + +complete_async_pkts (vdev); + enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, + queue_id, pkts, rx_count, + m_cpu_cpl, &cpu_cpl_nr); +if (cpu_cpl_nr) +free_pkts (m_cpu_cpl, cpu_cpl_nr); + + enqueue_fail = rx_count - enqueue_count; +if (enqueue_fail) +free_pkts (&pkts[enqueue_count], enqueue_fail); + +return enqueue_count; +} + +uint16_t +sync_enqueue_pkts (struct vhost_dev *vdev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t rx_count) +{ +return rte_vhost_enqueue_burst (vdev->vid, queue_id, pkts, rx_count); +} + static __rte_always_inline voiddrain_eth_rx (struct vhost_dev *vdev) {
@@ -1214,29 +1227,8 @@ drain_eth_rx(struct vhost_dev *vdev) } } -if (builtin_net_driver) { - enqueue_count =vs_enqueue_pkts (vdev,VIRTIO_RXQ , - pkts, rx_count); - }else if (async_vhost_driver) { -uint32_t cpu_cpl_nr =0 ; -uint16_t enqueue_fail =0 ; -struct rte_mbuf *m_cpu_cpl[MAX_PKT_BURST ]; - -complete_async_pkts (vdev); - enqueue_count =rte_vhost_submit_enqueue_burst (vdev->vid, -VIRTIO_RXQ , pkts, rx_count, - m_cpu_cpl, &cpu_cpl_nr); -if (cpu_cpl_nr) -free_pkts (m_cpu_cpl, cpu_cpl_nr); - - enqueue_fail = rx_count - enqueue_count; -if (enqueue_fail) -free_pkts (&pkts[enqueue_count], enqueue_fail); - - }else { - enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , - pkts, rx_count); - } + enqueue_count = vdev_queue_ops[vdev->vid].enqueue_pkt_burst (vdev, +VIRTIO_RXQ , pkts, rx_count);if (enable_stats) { __atomic_add_fetch(&vdev->stats.rx_total_atomic, rx_count,
@@ -1249,6 +1241,14 @@ drain_eth_rx(struct vhost_dev *vdev)free_pkts (pkts, rx_count); } +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count) +{ +return rte_vhost_dequeue_burst (dev->vid, queue_id, + mbuf_pool, pkts, count); +} + static __rte_always_inline voiddrain_virtio_tx (struct vhost_dev *vdev) {
@@ -1256,13 +1256,8 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; -if (builtin_net_driver) { - count =vs_dequeue_pkts (vdev,VIRTIO_TXQ , mbuf_pool, - pkts,MAX_PKT_BURST ); - }else { - count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , - mbuf_pool, pkts,MAX_PKT_BURST ); - } + count = vdev_queue_ops[vdev->vid].dequeue_pkt_burst (vdev, +VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */ if (unlikely (vdev->ready ==DEVICE_MAC_LEARNING ) && count) {
@@ -1436,6 +1431,21 @@ new_device(int vid) } } +if (builtin_net_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts; + vdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts; + }else { +if (async_vhost_driver) { + vdev_queue_ops[vid].enqueue_pkt_burst = + async_enqueue_pkts; + }else { + vdev_queue_ops[vid].enqueue_pkt_burst = + sync_enqueue_pkts; + } + + vdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts; + } +if (builtin_net_driver)vs_vhost_net_setup (vdev);
examples/vhost/main.h +29 -4
@@ -60,6 +60,19 @@ struct vhost_dev {struct vhost_queue queues[MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned; +typedef uint16_t (*vhost_enqueue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mbuf **pkts, +uint32_t count); + +typedef uint16_t (*vhost_dequeue_burst_t )(struct vhost_dev *dev, +uint16_t queue_id,struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); + +struct vhost_queue_ops { +vhost_enqueue_burst_t enqueue_pkt_burst; +vhost_dequeue_burst_t dequeue_pkt_burst; +}; +TAILQ_HEAD (vhost_dev_tailq_list, vhost_dev);
@@ -84,9 +97,21 @@ struct lcore_info {void vs_vhost_net_setup (struct vhost_dev *dev);void vs_vhost_net_remove (struct vhost_dev *dev);uint16_t vs_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); + +uint16_t builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mbuf **pkts,uint32_t count); - -uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, -struct rte_mempool *mbuf_pool, -struct rte_mbuf **pkts,uint16_t count); +uint16_t sync_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count); +uint16_t async_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count); +uint16_t async_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool, +struct rte_mbuf **pkts,uint16_t count);#endif /* _MAIN_H_ */
examples/vhost/virtio_net.c +15 -1
@@ -238,6 +238,13 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,return count; } +uint16_t +builtin_enqueue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mbuf **pkts,uint32_t count) +{ +return vs_enqueue_pkts (dev, queue_id, pkts, count); +} + static __rte_always_inline int dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr, struct rte_mbuf *m, uint16_t desc_idx,
@@ -363,7 +370,7 @@ dequeue_pkt(struct vhost_dev *dev, struct rte_vhost_vring *vr,return 0 ; } -uint16_t +static uint16_t vs_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) {
@@ -440,3 +447,10 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,return i; } + +uint16_t +builtin_dequeue_pkts (struct vhost_dev *dev,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) +{ +return vs_dequeue_pkts (dev, queue_id, mbuf_pool, pkts, count); +}
Signature · 1 line
2.25.1
PATCH v7 2/4 examples/vhost: use a new API to query remaining ring space
In reply to Wenwu MaA new API for querying the remaining descriptor ring capacity is available, so we use the new one instead of the old one.
--- examples/vhost/ioat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
examples/vhost/ioat.c +1 -5
@@ -17,7 +17,6 @@ struct packet_tracker {unsigned short next_read;unsigned short next_write;unsigned short last_remain; -unsigned short ioat_space; };struct packet_tracker cb_tracker[MAX_VHOST_DEVICE ];
@@ -113,7 +112,6 @@ open_ioat(const char *value) goto out; }rte_rawdev_start (dev_id); - cb_tracker[dev_id].ioat_space =IOAT_RING_SIZE -1 ; dma_info->nr++; i++; }
@@ -140,7 +138,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, src = descs[i_desc].src; dst = descs[i_desc].dst; i_seg =0 ; -if (cb_tracker[dev_id].ioat_space < src->nr_segs) +if (rte_ioat_burst_capacity (dev_id) < src->nr_segs)break ;while (i_seg < src->nr_segs) { rte_ioat_enqueue_copy(dev_id,
@@ -155,7 +153,6 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, } write &= mask; cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; write++; } }else {
@@ -194,7 +191,6 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,if (n_seg ==0 )return 0 ; - cb_tracker[dev_id].ioat_space += n_seg; n_seg += cb_tracker[dev_id].last_remain; read = cb_tracker[dev_id].next_read;
Signature · 1 line
2.25.1
PATCH v7 3/4 vhost: support async dequeue for split ring
In reply to Wenwu MaFrom: Yuan Wang <[email protected]>
This patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the async channel, thus saving precious CPU cycles.
--- doc/guides/prog_guide/vhost_lib.rst | 9 + lib/vhost/rte_vhost_async.h | 39 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 586 ++++++++++++++++++++++++++++ 4 files changed, 635 insertions(+), 2 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +9 -0
@@ -281,6 +281,15 @@ The following is an overview of some key Vhost API functions: Poll enqueue completion status from async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)`` + + This function tries to receive packets from the guest with offloading + large copies to the async channel. The packets that are transfer completed + are returned in ``pkts``. The other packets that their copies are submitted + to the async channel but not completed are called "in-flight packets". + This function will not return in-flight packets until their copies are + completed by the async channel. + Vhost-user Implementations --------------------------
lib/vhost/rte_vhost_async.h +37 -2
@@ -83,12 +83,20 @@ struct rte_vhost_async_channel_ops { uint16_t max_packets); }; +struct async_nethdr { +struct virtio_net_hdr hdr; +bool valid; +}; +/** -* inflight async packet information +* in-flight async packet information */ struct async_inflight_info {struct rte_mbuf *mbuf; -uint16_t descs;/* num of descs inflight */ +union { +uint16_t descs;/* num of descs in-flight */ +struct async_nethdr nethdr; + };uint16_t nr_buffers;/* num of buffers inflight for packed ring */ };
@@ -193,4 +201,31 @@ __rte_experimentaluint16_t rte_vhost_poll_enqueue_completed (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count); +/** +* This function tries to receive packets from the guest with offloading +* large copies to the async channel. The packets that are transfer completed +* are returned in "pkts". The other packets that their copies are submitted to +* the async channel but not completed are called "in-flight packets". +* This function will not return in-flight packets until their copies are +* completed by the async channel. +* +* @param vid +* id of vhost device to dequeue data +* @param queue_id +* queue id to dequeue data +* @param pkts +* blank array to keep successfully dequeued packets +* @param count +* size of the packet array +* @param nr_inflight +* the amount of in-flight packets. If error occurred, its value is set to -1. +* @return +* num of successfully dequeued packets +*/ +__rte_experimental +uint16_t +rte_vhost_async_try_dequeue_burst (int vid,uint16_t queue_id, +struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count, +int *nr_inflight); +#endif /* _RTE_VHOST_ASYNC_H_ */
lib/vhost/version.map +3 -0
@@ -79,4 +79,7 @@ EXPERIMENTAL { # added in 21.05 rte_vhost_get_negotiated_protocol_features; + + # added in 21.08 + rte_vhost_async_try_dequeue_burst; };
lib/vhost/virtio_net.c +586 -0
589 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 4/4 examples/vhost: support vhost async dequeue data path
In reply to Wenwu MaThis patch is to add vhost async dequeue data-path in vhost sample. vswitch can leverage IOAT to accelerate vhost async dequeue data-path.
--- doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 61 ++++++++++--- examples/vhost/ioat.h | 25 ++++++ examples/vhost/main.c | 140 ++++++++++++++++++++--------- 4 files changed, 177 insertions(+), 58 deletions(-)
doc/guides/sample_app_ug/vhost.rst +6 -3
@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas **--dmas** This parameter is used to specify the assigned DMA device of a vhost device. Async vhost-user net driver will be used if --dmas is set. For example ---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost -device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1 -enqueue operation. +--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use +DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation +and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue +operation. The index of the device corresponds to the socket file in order, +that means vhost device 0 is created through the first socket file, vhost +device 1 is created through the second socket file, and so on. Common Issues -------------
examples/vhost/ioat.c +47 -14
134 lines not on this page · raw message
examples/vhost/ioat.h +25 -0
@@ -12,6 +12,9 @@#define MAX_VHOST_DEVICE 1024#define IOAT_RING_SIZE 4096#define MAX_ENQUEUED_SIZE 4096 +#define MAX_RING_COUNT 2 +#define ASYNC_ENQUEUE_VHOST 1 +#define ASYNC_DEQUEUE_VHOST 2struct dma_info {struct rte_pci_addr addr;
@@ -20,6 +23,7 @@ struct dma_info { };struct dma_for_vhost { +int async_flag;struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT *2 ];uint16_t nr; };
@@ -36,6 +40,10 @@ uint32_t ioat_check_completed_copies_cb(int vid, uint16_t queue_id, struct rte_vhost_async_status *opaque_data, uint16_t max_packets); + +uint32_t get_async_flag_by_vid (int vid); +uint32_t get_async_flag_by_socketid (int socketid); +void init_vid2socketid_array (int vid,int socketid);#else static int open_ioat(const char *value __rte_unused) {
@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused, {return -1 ; } + +static uint32_t +get_async_flag_by_vid(int vid __rte_unused) +{ +return 0 ; +} + +static uint32_t +get_async_flag_by_socketid(int socketid __rte_unused) +{ +return 0 ; +} + +static void +init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused) +{ +}#endif #endif /* _IOAT_H_ */
examples/vhost/main.c +99 -41
201 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v7 0/4] support async dequeue for split ring
In reply to Wenwu MaQuoted 69 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Wenwu Ma
Sent: 2021?7?21? 22:21
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Ma, WenwuX <[email protected]>
Subject: [dpdk-dev] [PATCH v7 0/4] support async dequeue for split ringThis patch implements asynchronous dequeue data path for split ring. A new asynchronous dequeue function is introduced. With this function, the application can try to receive packets from the guest with offloading large copies to the DMA engine, thus saving precious CPU cycles.
v7:
- Add Reviewed-by to comments in examples/vhost.v6:
- Allocate and free packets in bulk.
- structasync_inflight_infoaligned to 32 bits.
- ChangeASYNC_RX_VHOSTtoASYNV_ENQUEUE_VHOSTandASYNC_TX_VHOSTtoASYNV_DEQUEUE_VHOST.v5:
- DMA address use IOVA instead of VA.v4:
- Fix wrong packet index issue in async dequeue improve the performance of small packet copies.v3:
- Fix compilation warning and error in arm platform.
- Restore the removed functionvirtio_dev_pktmbuf_alloc, async dequeue allocate packets in separate.v2:
- Refactor vhost datapath as preliminary patch for this series.
- The change of using new API in examples/vhost is put into a dedicated patch.
- Checkqueue_idvalue before using it.
- Async dequeue performance enhancement. 160% performance improvement
for v2 vs. v1.
- Async dequeue API name change fromrte_vhost_try_dequeue_bursttorte_vhost_async_try_dequeue_burst.
- The completed package updates the used ring directly.Wenwu Ma (3):
examples/vhost: refactor vhost enqueue and dequeue datapaths examples/vhost: use a new API to query remaining ring space examples/vhost: support vhost async dequeue data pathYuan Wang (1):
vhost: support async dequeue for split ringdoc/guides/prog_guide/vhost_lib.rst | 9 + doc/guides/sample_app_ug/vhost.rst | 9 +- examples/vhost/ioat.c | 67 +++- examples/vhost/ioat.h | 25 ++ examples/vhost/main.c | 224 +++++++---- examples/vhost/main.h | 33 +- examples/vhost/virtio_net.c | 16 +- lib/vhost/rte_vhost_async.h | 39 +- lib/vhost/version.map | 3 + lib/vhost/virtio_net.c | 586 ++++++++++++++++++++++++++++ 10 files changed, 904 insertions(+), 107 deletions(-)--
2.25.1