From: Xuan Ding Date: Mon, 16 May 2022 11:10:39 +0000 (+0000) Subject: vhost: merge sync and async descriptor to mbuf filling X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=844e113a051d64e24886d3bf61cb6687ac16ef00;p=dpdk.git vhost: merge sync and async descriptor to mbuf filling This patch refactors copy_desc_to_mbuf() used by the sync path to support both sync and async descriptor to mbuf filling. Signed-off-by: Xuan Ding Tested-by: Yvonne Yang Reviewed-by: Maxime Coquelin --- diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 1573d0afe9..14235aaf81 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -199,6 +199,7 @@ struct async_inflight_info { struct rte_mbuf *mbuf; uint16_t descs; /* num of descs inflight */ uint16_t nr_buffers; /* num of buffers inflight for packed ring */ + struct virtio_net_hdr nethdr; }; struct vhost_async { diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 6c38d3cbf9..c540435c34 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -2551,10 +2551,10 @@ copy_vnet_hdr_from_desc(struct virtio_net_hdr *hdr, } static __rte_always_inline int -copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, +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, - bool legacy_ol_flags) + bool legacy_ol_flags, uint16_t slot_idx, bool is_async) { uint32_t buf_avail, buf_offset, buf_len; uint64_t buf_addr, buf_iova; @@ -2565,6 +2565,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, struct virtio_net_hdr *hdr = NULL; /* A counter to avoid desc dead loop chain */ uint16_t vec_idx = 0; + struct vhost_async *async = vq->async; + struct async_inflight_info *pkts_info; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; @@ -2602,6 +2604,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, if (unlikely(++vec_idx >= nr_vec)) goto error; buf_addr = buf_vec[vec_idx].buf_addr; + buf_iova = buf_vec[vec_idx].buf_iova; buf_len = buf_vec[vec_idx].buf_len; buf_offset = 0; @@ -2617,12 +2620,25 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, mbuf_offset = 0; mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM; + + if (is_async) { + pkts_info = async->pkts_info; + if (async_iter_initialize(dev, async)) + return -1; + } + while (1) { cpy_len = RTE_MIN(buf_avail, mbuf_avail); - sync_fill_seg(dev, vq, cur, mbuf_offset, - buf_addr + buf_offset, - buf_iova + buf_offset, cpy_len, false); + if (is_async) { + if (async_fill_seg(dev, vq, cur, mbuf_offset, + buf_iova + buf_offset, cpy_len, false) < 0) + goto error; + } else { + sync_fill_seg(dev, vq, cur, mbuf_offset, + buf_addr + buf_offset, + buf_iova + buf_offset, cpy_len, false); + } mbuf_avail -= cpy_len; mbuf_offset += cpy_len; @@ -2671,11 +2687,20 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, prev->data_len = mbuf_offset; m->pkt_len += mbuf_offset; - if (hdr) - vhost_dequeue_offload(dev, hdr, m, legacy_ol_flags); + if (is_async) { + async_iter_finalize(async); + if (hdr) + pkts_info[slot_idx].nethdr = *hdr; + } else { + if (hdr) + vhost_dequeue_offload(dev, hdr, m, legacy_ol_flags); + } return 0; error: + if (is_async) + async_iter_cancel(async); + return -1; } @@ -2807,8 +2832,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, break; } - err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i], - mbuf_pool, legacy_ol_flags); + err = desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i], + mbuf_pool, legacy_ol_flags, 0, false); if (unlikely(err)) { if (!allocerr_warned) { VHOST_LOG_DATA(ERR, "(%s) failed to copy desc to mbuf.\n", @@ -2819,6 +2844,7 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, i++; break; } + } if (dropped) @@ -3000,8 +3026,8 @@ vhost_dequeue_single_packed(struct virtio_net *dev, return -1; } - err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts, - mbuf_pool, legacy_ol_flags); + err = desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts, + mbuf_pool, legacy_ol_flags, 0, false); if (unlikely(err)) { if (!allocerr_warned) { VHOST_LOG_DATA(ERR, "(%s) failed to copy desc to mbuf.\n",