[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
General comment after reading this page: http://dpdk.org/dev/patchwork/patch/6905/ Please remove useless context when replying to make answers shorter and easier to read. Thanks
[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
On Sun, 6 Sep 2015 08:40:44 + "Ouyang, Changchun" wrote: > > @@ -220,11 +221,26 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, > > struct rte_mbuf *cookie) > > dxp = >vq_descx[idx]; > > dxp->cookie = (void *)cookie; > > dxp->ndescs = needed; > > - > > start_dp = txvq->vq_ring.desc; > > - start_dp[idx].addr = > > - txvq->virtio_net_hdr_mem + idx * head_size; > > - start_dp[idx].len = (uint32_t)head_size; > > + > > + if (use_indirect) { > > + offs = offsetof(struct virtio_tx_region, tx_indir) > > + + idx * sizeof(struct virtio_tx_region); > > + > > + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; > > + start_dp[idx].len = sizeof(struct vring_desc); > > Should the length be N * sizeof(struct vring_desc)? Yes.
[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
On Sun, 6 Sep 2015 08:36:10 + "Ouyang, Changchun" wrote: > > -Original Message- > > From: Stephen Hemminger [mailto:stephen at networkplumber.org] > > Sent: Saturday, September 5, 2015 4:58 AM > > To: Xie, Huawei; Ouyang, Changchun > > Cc: dev at dpdk.org; Stephen Hemminger > > Subject: [PATCH 3/4] virtio: use indirect ring elements > > > > The virtio ring in QEMU/KVM is usually limited to 256 entries and the normal > > way that virtio driver was queuing mbufs required nsegs + 1 ring elements. > > By using the indirect ring element feature if available, each packet will > > take > > only one ring slot even for multi-segment packets. > > > > Signed-off-by: Stephen Hemminger > > --- > > drivers/net/virtio/virtio_ethdev.c | 11 +--- > > drivers/net/virtio/virtio_ethdev.h | 3 ++- > > drivers/net/virtio/virtio_rxtx.c | 51 ++- > > --- > > drivers/net/virtio/virtqueue.h | 8 ++ > > 4 files changed, 57 insertions(+), 16 deletions(-) > > > > diff --git a/drivers/net/virtio/virtio_ethdev.c > > b/drivers/net/virtio/virtio_ethdev.c > > index 465d3cd..bcfb87b 100644 > > --- a/drivers/net/virtio/virtio_ethdev.c > > +++ b/drivers/net/virtio/virtio_ethdev.c > > @@ -359,12 +359,15 @@ int virtio_dev_queue_setup(struct rte_eth_dev > > *dev, > > if (queue_type == VTNET_TQ) { > > Do we also need implement indirect ring elements for RX path? No. Look at Linux driver, indirect elements are never passed to RX driver.
[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
> -Original Message- > From: Stephen Hemminger [mailto:stephen at networkplumber.org] > Sent: Saturday, September 5, 2015 4:58 AM > To: Xie, Huawei; Ouyang, Changchun > Cc: dev at dpdk.org; Stephen Hemminger > Subject: [PATCH 3/4] virtio: use indirect ring elements > > The virtio ring in QEMU/KVM is usually limited to 256 entries and the normal > way that virtio driver was queuing mbufs required nsegs + 1 ring elements. > By using the indirect ring element feature if available, each packet will take > only one ring slot even for multi-segment packets. > > Signed-off-by: Stephen Hemminger > --- > drivers/net/virtio/virtio_ethdev.c | 11 +--- > drivers/net/virtio/virtio_ethdev.h | 3 ++- > drivers/net/virtio/virtio_rxtx.c | 51 ++- > --- > drivers/net/virtio/virtqueue.h | 8 ++ > 4 files changed, 57 insertions(+), 16 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c > b/drivers/net/virtio/virtio_ethdev.c > index 465d3cd..bcfb87b 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -359,12 +359,15 @@ int virtio_dev_queue_setup(struct rte_eth_dev > *dev, > if (queue_type == VTNET_TQ) { > /* >* For each xmit packet, allocate a virtio_net_hdr > + * and indirect ring elements >*/ > snprintf(vq_name, sizeof(vq_name), > "port%d_tvq%d_hdrzone", > - dev->data->port_id, queue_idx); > - vq->virtio_net_hdr_mz = > rte_memzone_reserve_aligned(vq_name, > - vq_size * hw->vtnet_hdr_size, > - socket_id, 0, RTE_CACHE_LINE_SIZE); > + dev->data->port_id, queue_idx); > + > + vq->virtio_net_hdr_mz = > + rte_memzone_reserve_aligned(vq_name, > + vq_size * sizeof(struct > virtio_tx_region), > + socket_id, 0, > RTE_CACHE_LINE_SIZE); > if (vq->virtio_net_hdr_mz == NULL) { > if (rte_errno == EEXIST) > vq->virtio_net_hdr_mz = > diff --git a/drivers/net/virtio/virtio_ethdev.h > b/drivers/net/virtio/virtio_ethdev.h > index 9026d42..07a9265 100644 > --- a/drivers/net/virtio/virtio_ethdev.h > +++ b/drivers/net/virtio/virtio_ethdev.h > @@ -64,7 +64,8 @@ >1u << VIRTIO_NET_F_CTRL_VQ | \ >1u << VIRTIO_NET_F_CTRL_RX | \ >1u << VIRTIO_NET_F_CTRL_VLAN | \ > - 1u << VIRTIO_NET_F_MRG_RXBUF) > + 1u << VIRTIO_NET_F_MRG_RXBUF | \ > + 1u << VIRTIO_RING_F_INDIRECT_DESC) > > /* > * CQ function prototype > diff --git a/drivers/net/virtio/virtio_rxtx.c > b/drivers/net/virtio/virtio_rxtx.c > index dbe6665..8979695 100644 > --- a/drivers/net/virtio/virtio_rxtx.c > +++ b/drivers/net/virtio/virtio_rxtx.c > @@ -199,14 +199,15 @@ virtqueue_enqueue_recv_refill(struct virtqueue > *vq, struct rte_mbuf *cookie) } > > static int > -virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie) > +virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie, > +int use_indirect) > { > struct vq_desc_extra *dxp; > struct vring_desc *start_dp; > uint16_t seg_num = cookie->nb_segs; > - uint16_t needed = 1 + seg_num; > + uint16_t needed = use_indirect ? 1 : 1 + seg_num; > uint16_t head_idx, idx; > - uint16_t head_size = txvq->hw->vtnet_hdr_size; > + unsigned long offs; > > if (unlikely(txvq->vq_free_cnt == 0)) > return -ENOSPC; > @@ -220,11 +221,26 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, > struct rte_mbuf *cookie) > dxp = >vq_descx[idx]; > dxp->cookie = (void *)cookie; > dxp->ndescs = needed; > - > start_dp = txvq->vq_ring.desc; > - start_dp[idx].addr = > - txvq->virtio_net_hdr_mem + idx * head_size; > - start_dp[idx].len = (uint32_t)head_size; > + > + if (use_indirect) { > + offs = offsetof(struct virtio_tx_region, tx_indir) > + + idx * sizeof(struct virtio_tx_region); > + > + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; > + start_dp[idx].len = sizeof(struct vring_desc); Should the length be N * sizeof(struct vring_desc)? > + start_dp[idx].flags = VRING_DESC_F_INDIRECT; > + > + start_dp = (struct vring_desc *) > + ((char *)txvq->virtio_net_hdr_mz->addr + offs); > + idx = 0; > + } > + > + offs = offsetof(struct virtio_tx_region, tx_hdr) > + + idx * sizeof(struct virtio_tx_region); > + > + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; > + start_dp[idx].len = txvq->hw->vtnet_hdr_size; > start_dp[idx].flags = VRING_DESC_F_NEXT; > > for (; ((seg_num > 0) && (cookie != NULL)); seg_num--) { @@
[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
> -Original Message- > From: Stephen Hemminger [mailto:stephen at networkplumber.org] > Sent: Saturday, September 5, 2015 4:58 AM > To: Xie, Huawei; Ouyang, Changchun > Cc: dev at dpdk.org; Stephen Hemminger > Subject: [PATCH 3/4] virtio: use indirect ring elements > > The virtio ring in QEMU/KVM is usually limited to 256 entries and the normal > way that virtio driver was queuing mbufs required nsegs + 1 ring elements. > By using the indirect ring element feature if available, each packet will take > only one ring slot even for multi-segment packets. > > Signed-off-by: Stephen Hemminger > --- > drivers/net/virtio/virtio_ethdev.c | 11 +--- > drivers/net/virtio/virtio_ethdev.h | 3 ++- > drivers/net/virtio/virtio_rxtx.c | 51 ++- > --- > drivers/net/virtio/virtqueue.h | 8 ++ > 4 files changed, 57 insertions(+), 16 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c > b/drivers/net/virtio/virtio_ethdev.c > index 465d3cd..bcfb87b 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -359,12 +359,15 @@ int virtio_dev_queue_setup(struct rte_eth_dev > *dev, > if (queue_type == VTNET_TQ) { Do we also need implement indirect ring elements for RX path? > /* >* For each xmit packet, allocate a virtio_net_hdr > + * and indirect ring elements >*/ > snprintf(vq_name, sizeof(vq_name), > "port%d_tvq%d_hdrzone", > - dev->data->port_id, queue_idx); > - vq->virtio_net_hdr_mz = > rte_memzone_reserve_aligned(vq_name, > - vq_size * hw->vtnet_hdr_size, > - socket_id, 0, RTE_CACHE_LINE_SIZE); > + dev->data->port_id, queue_idx); > + > + vq->virtio_net_hdr_mz = > + rte_memzone_reserve_aligned(vq_name, > + vq_size * sizeof(struct > virtio_tx_region), > + socket_id, 0, > RTE_CACHE_LINE_SIZE); > if (vq->virtio_net_hdr_mz == NULL) { > if (rte_errno == EEXIST) > vq->virtio_net_hdr_mz = > diff --git a/drivers/net/virtio/virtio_ethdev.h > b/drivers/net/virtio/virtio_ethdev.h > index 9026d42..07a9265 100644 > --- a/drivers/net/virtio/virtio_ethdev.h > +++ b/drivers/net/virtio/virtio_ethdev.h > @@ -64,7 +64,8 @@ >1u << VIRTIO_NET_F_CTRL_VQ | \ >1u << VIRTIO_NET_F_CTRL_RX | \ >1u << VIRTIO_NET_F_CTRL_VLAN | \ > - 1u << VIRTIO_NET_F_MRG_RXBUF) > + 1u << VIRTIO_NET_F_MRG_RXBUF | \ > + 1u << VIRTIO_RING_F_INDIRECT_DESC) > > /* > * CQ function prototype > diff --git a/drivers/net/virtio/virtio_rxtx.c > b/drivers/net/virtio/virtio_rxtx.c > index dbe6665..8979695 100644 > --- a/drivers/net/virtio/virtio_rxtx.c > +++ b/drivers/net/virtio/virtio_rxtx.c > @@ -199,14 +199,15 @@ virtqueue_enqueue_recv_refill(struct virtqueue > *vq, struct rte_mbuf *cookie) } > > static int > -virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie) > +virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie, > +int use_indirect) > { > struct vq_desc_extra *dxp; > struct vring_desc *start_dp; > uint16_t seg_num = cookie->nb_segs; > - uint16_t needed = 1 + seg_num; > + uint16_t needed = use_indirect ? 1 : 1 + seg_num; Do we need check if seg_num > VIRTIO_MAX_TX_INDIRECT? That mean one slot is not enough for the whole big packet even it is indirect ring. > uint16_t head_idx, idx; > - uint16_t head_size = txvq->hw->vtnet_hdr_size; > + unsigned long offs; > > if (unlikely(txvq->vq_free_cnt == 0)) > return -ENOSPC; > @@ -220,11 +221,26 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, > struct rte_mbuf *cookie) > dxp = >vq_descx[idx]; > dxp->cookie = (void *)cookie; > dxp->ndescs = needed; > - > start_dp = txvq->vq_ring.desc; > - start_dp[idx].addr = > - txvq->virtio_net_hdr_mem + idx * head_size; > - start_dp[idx].len = (uint32_t)head_size; > + > + if (use_indirect) { > + offs = offsetof(struct virtio_tx_region, tx_indir) > + + idx * sizeof(struct virtio_tx_region); > + > + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; > + start_dp[idx].len = sizeof(struct vring_desc); > + start_dp[idx].flags = VRING_DESC_F_INDIRECT; > + > + start_dp = (struct vring_desc *) > + ((char *)txvq->virtio_net_hdr_mz->addr + offs); > + idx = 0; > + } > + > + offs = offsetof(struct virtio_tx_region, tx_hdr) > + + idx * sizeof(struct virtio_tx_region); > + > + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; > +
[dpdk-dev] [PATCH 3/4] virtio: use indirect ring elements
The virtio ring in QEMU/KVM is usually limited to 256 entries and the normal way that virtio driver was queuing mbufs required nsegs + 1 ring elements. By using the indirect ring element feature if available, each packet will take only one ring slot even for multi-segment packets. Signed-off-by: Stephen Hemminger --- drivers/net/virtio/virtio_ethdev.c | 11 +--- drivers/net/virtio/virtio_ethdev.h | 3 ++- drivers/net/virtio/virtio_rxtx.c | 51 ++ drivers/net/virtio/virtqueue.h | 8 ++ 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 465d3cd..bcfb87b 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -359,12 +359,15 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, if (queue_type == VTNET_TQ) { /* * For each xmit packet, allocate a virtio_net_hdr +* and indirect ring elements */ snprintf(vq_name, sizeof(vq_name), "port%d_tvq%d_hdrzone", - dev->data->port_id, queue_idx); - vq->virtio_net_hdr_mz = rte_memzone_reserve_aligned(vq_name, - vq_size * hw->vtnet_hdr_size, - socket_id, 0, RTE_CACHE_LINE_SIZE); +dev->data->port_id, queue_idx); + + vq->virtio_net_hdr_mz = + rte_memzone_reserve_aligned(vq_name, + vq_size * sizeof(struct virtio_tx_region), + socket_id, 0, RTE_CACHE_LINE_SIZE); if (vq->virtio_net_hdr_mz == NULL) { if (rte_errno == EEXIST) vq->virtio_net_hdr_mz = diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h index 9026d42..07a9265 100644 --- a/drivers/net/virtio/virtio_ethdev.h +++ b/drivers/net/virtio/virtio_ethdev.h @@ -64,7 +64,8 @@ 1u << VIRTIO_NET_F_CTRL_VQ | \ 1u << VIRTIO_NET_F_CTRL_RX | \ 1u << VIRTIO_NET_F_CTRL_VLAN | \ -1u << VIRTIO_NET_F_MRG_RXBUF) +1u << VIRTIO_NET_F_MRG_RXBUF | \ +1u << VIRTIO_RING_F_INDIRECT_DESC) /* * CQ function prototype diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index dbe6665..8979695 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -199,14 +199,15 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie) } static int -virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie) +virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie, + int use_indirect) { struct vq_desc_extra *dxp; struct vring_desc *start_dp; uint16_t seg_num = cookie->nb_segs; - uint16_t needed = 1 + seg_num; + uint16_t needed = use_indirect ? 1 : 1 + seg_num; uint16_t head_idx, idx; - uint16_t head_size = txvq->hw->vtnet_hdr_size; + unsigned long offs; if (unlikely(txvq->vq_free_cnt == 0)) return -ENOSPC; @@ -220,11 +221,26 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie) dxp = >vq_descx[idx]; dxp->cookie = (void *)cookie; dxp->ndescs = needed; - start_dp = txvq->vq_ring.desc; - start_dp[idx].addr = - txvq->virtio_net_hdr_mem + idx * head_size; - start_dp[idx].len = (uint32_t)head_size; + + if (use_indirect) { + offs = offsetof(struct virtio_tx_region, tx_indir) + + idx * sizeof(struct virtio_tx_region); + + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; + start_dp[idx].len = sizeof(struct vring_desc); + start_dp[idx].flags = VRING_DESC_F_INDIRECT; + + start_dp = (struct vring_desc *) + ((char *)txvq->virtio_net_hdr_mz->addr + offs); + idx = 0; + } + + offs = offsetof(struct virtio_tx_region, tx_hdr) + + idx * sizeof(struct virtio_tx_region); + + start_dp[idx].addr = txvq->virtio_net_hdr_mem + offs; + start_dp[idx].len = txvq->hw->vtnet_hdr_size; start_dp[idx].flags = VRING_DESC_F_NEXT; for (; ((seg_num > 0) && (cookie != NULL)); seg_num--) { @@ -236,7 +252,12 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie) } start_dp[idx].flags &= ~VRING_DESC_F_NEXT; - idx = start_dp[idx].next; + + if (use_indirect) + idx = txvq->vq_ring.desc[head_idx].next; + else + idx = start_dp[idx].next; + txvq->vq_desc_head_idx = idx; if (txvq->vq_desc_head_idx == VQ_RING_DESC_CHAIN_END)