[dpdk-dev] lib/librte_vhost: remove redundant logic judgement

Message ID 20171225091617.60387-1-zhiyong.yang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Yang, Zhiyong Dec. 25, 2017, 9:16 a.m. UTC
  At the beginning of vring_translate, the code
if(!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) already judges
if IOMMU_PLATFORM is supported. The function vhost_iova_to_vva always
repeats the logic, __vhost_iova_to_vva can be used directly to avoid it
here.

Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
---
 lib/librte_vhost/vhost.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Yuanhan Liu Dec. 27, 2017, 2:29 p.m. UTC | #1
On Mon, Dec 25, 2017 at 05:16:17PM +0800, Zhiyong Yang wrote:
> At the beginning of vring_translate, the code
> if(!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) already judges
> if IOMMU_PLATFORM is supported. The function vhost_iova_to_vva always
> repeats the logic, __vhost_iova_to_vva can be used directly to avoid it
> here.
> 
> Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
> ---
>  lib/librte_vhost/vhost.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index 4f8b73a09..bb615fd2a 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -157,7 +157,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
>  		goto out;
>  
>  	size = sizeof(struct vring_desc) * vq->size;
> -	vq->desc = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, vq,
> +	vq->desc = (struct vring_desc *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
>  						vq->ring_addrs.desc_user_addr,
>  						size, VHOST_ACCESS_RW);


I don't see strong reason to bother doing the change. It's not in the
datapath after all. I'd like to keep the code as it is, to keep it simpler:
user just has to call vhost_iova_to_vva() and let it to handle the details.

	--yliu


>  	if (!vq->desc)
> @@ -165,7 +165,8 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
>  
>  	size = sizeof(struct vring_avail);
>  	size += sizeof(uint16_t) * vq->size;
> -	vq->avail = (struct vring_avail *)(uintptr_t)vhost_iova_to_vva(dev, vq,
> +	vq->avail = (struct vring_avail *)(uintptr_t)__vhost_iova_to_vva(dev,
> +						vq,
>  						vq->ring_addrs.avail_user_addr,
>  						size, VHOST_ACCESS_RW);
>  	if (!vq->avail)
> @@ -173,7 +174,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
>  
>  	size = sizeof(struct vring_used);
>  	size += sizeof(struct vring_used_elem) * vq->size;
> -	vq->used = (struct vring_used *)(uintptr_t)vhost_iova_to_vva(dev, vq,
> +	vq->used = (struct vring_used *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
>  						vq->ring_addrs.used_user_addr,
>  						size, VHOST_ACCESS_RW);
>  	if (!vq->used)
> -- 
> 2.13.3
  
Yang, Zhiyong Jan. 3, 2018, 10:21 a.m. UTC | #2
> -----Original Message-----
> From: Yuanhan Liu [mailto:yliu@fridaylinux.org]
> Sent: Wednesday, December 27, 2017 10:29 PM
> To: Yang, Zhiyong <zhiyong.yang@intel.com>
> Cc: dev@dpdk.org; maxime.coquelin@redhat.com
> Subject: Re: [PATCH] lib/librte_vhost: remove redundant logic judgement
> 
> On Mon, Dec 25, 2017 at 05:16:17PM +0800, Zhiyong Yang wrote:
> > At the beginning of vring_translate, the code if(!(dev->features &
> > (1ULL << VIRTIO_F_IOMMU_PLATFORM))) already judges if
> IOMMU_PLATFORM
> > is supported. The function vhost_iova_to_vva always repeats the logic,
> > __vhost_iova_to_vva can be used directly to avoid it here.
> >
> > Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
> > ---
> >  lib/librte_vhost/vhost.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index
> > 4f8b73a09..bb615fd2a 100644
> > --- a/lib/librte_vhost/vhost.c
> > +++ b/lib/librte_vhost/vhost.c
> > @@ -157,7 +157,7 @@ vring_translate(struct virtio_net *dev, struct
> vhost_virtqueue *vq)
> >  		goto out;
> >
> >  	size = sizeof(struct vring_desc) * vq->size;
> > -	vq->desc = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, vq,
> > +	vq->desc = (struct vring_desc *)(uintptr_t)__vhost_iova_to_vva(dev,
> > +vq,
> >  						vq-
> >ring_addrs.desc_user_addr,
> >  						size, VHOST_ACCESS_RW);
> 
> 
> I don't see strong reason to bother doing the change. It's not in the datapath
> after all. I'd like to keep the code as it is, to keep it simpler:
> user just has to call vhost_iova_to_vva() and let it to handle the details.
> 
> 	--yliu
> 

Ok, drop it. 

Thanks
Zhiyong
  

Patch

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 4f8b73a09..bb615fd2a 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -157,7 +157,7 @@  vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		goto out;
 
 	size = sizeof(struct vring_desc) * vq->size;
-	vq->desc = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+	vq->desc = (struct vring_desc *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
 						vq->ring_addrs.desc_user_addr,
 						size, VHOST_ACCESS_RW);
 	if (!vq->desc)
@@ -165,7 +165,8 @@  vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
 
 	size = sizeof(struct vring_avail);
 	size += sizeof(uint16_t) * vq->size;
-	vq->avail = (struct vring_avail *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+	vq->avail = (struct vring_avail *)(uintptr_t)__vhost_iova_to_vva(dev,
+						vq,
 						vq->ring_addrs.avail_user_addr,
 						size, VHOST_ACCESS_RW);
 	if (!vq->avail)
@@ -173,7 +174,7 @@  vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
 
 	size = sizeof(struct vring_used);
 	size += sizeof(struct vring_used_elem) * vq->size;
-	vq->used = (struct vring_used *)(uintptr_t)vhost_iova_to_vva(dev, vq,
+	vq->used = (struct vring_used *)(uintptr_t)__vhost_iova_to_vva(dev, vq,
 						vq->ring_addrs.used_user_addr,
 						size, VHOST_ACCESS_RW);
 	if (!vq->used)