[dpdk-dev,v3,13/21] vhost: add helpers for packed virtqueues

Message ID 20180405101031.26468-14-jfreimann@redhat.com (mailing list archive)
State Changes Requested, archived
Delegated to: Maxime Coquelin
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jens Freimann April 5, 2018, 10:10 a.m. UTC
  Add some helper functions to set/check descriptor flags
and toggle the used wrap counter.

Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
 lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
  

Comments

Maxime Coquelin April 6, 2018, 9:20 a.m. UTC | #1
On 04/05/2018 12:10 PM, Jens Freimann wrote:
> Add some helper functions to set/check descriptor flags
> and toggle the used wrap counter.
> 
> Signed-off-by: Jens Freimann <jfreimann@redhat.com>
> ---
>   lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 44 insertions(+)
> 
> diff --git a/lib/librte_vhost/virtio-1.1.h b/lib/librte_vhost/virtio-1.1.h
> index 7b48caed7..e77d7aa6c 100644
> --- a/lib/librte_vhost/virtio-1.1.h
> +++ b/lib/librte_vhost/virtio-1.1.h
Shouldn't the file be named virtio-packed.h?

> @@ -15,4 +15,48 @@ struct vring_desc_packed {
>   	uint16_t flags;
>   };
>   
> +static inline void
> +toggle_wrap_counter(struct vhost_virtqueue *vq)
> +{
> +	vq->used_wrap_counter ^= 1;
> +}
> +
> +static inline int
> +desc_is_avail(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
> +{
> +	if (vq->used_wrap_counter == 1) {
> +		if ((desc->flags & VRING_DESC_F_AVAIL) &&
> +				!(desc->flags & VRING_DESC_F_USED))
> +			return 1;
> +	}
> +	if (vq->used_wrap_counter == 0) {
> +		if (!(desc->flags & VRING_DESC_F_AVAIL) &&
> +				(desc->flags & VRING_DESC_F_USED))
> +			return 1;
> +	}
> +	return 0;
> +}
> +
> +static inline void
> +_set_desc_used(struct vring_desc_packed *desc, int wrap_counter)
> +{
> +	uint16_t flags = desc->flags;
> +
> +	if (wrap_counter == 1) {
> +		flags |= VRING_DESC_F_USED;
> +		flags |= VRING_DESC_F_AVAIL;
> +	} else {
> +		flags &= ~VRING_DESC_F_USED;
> +		flags &= ~VRING_DESC_F_AVAIL;
> +	}
> +
> +	desc->flags = flags;
> +}
> +
> +static inline void
> +set_desc_used(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
> +{
> +	_set_desc_used(desc, vq->used_wrap_counter);
> +}
> +

Maybe prefix all with vring_
>   #endif /* __VIRTIO_PACKED_H */
>
  
Jens Freimann April 6, 2018, 9:21 a.m. UTC | #2
On Fri, Apr 06, 2018 at 11:20:10AM +0200, Maxime Coquelin wrote:
>
>
>On 04/05/2018 12:10 PM, Jens Freimann wrote:
>>Add some helper functions to set/check descriptor flags
>>and toggle the used wrap counter.
>>
>>Signed-off-by: Jens Freimann <jfreimann@redhat.com>
>>---
>>  lib/librte_vhost/virtio-1.1.h | 44 +++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 44 insertions(+)
>>
>>diff --git a/lib/librte_vhost/virtio-1.1.h b/lib/librte_vhost/virtio-1.1.h
>>index 7b48caed7..e77d7aa6c 100644
>>--- a/lib/librte_vhost/virtio-1.1.h
>>+++ b/lib/librte_vhost/virtio-1.1.h
>Shouldn't the file be named virtio-packed.h?

yes, will rename it. 

>>@@ -15,4 +15,48 @@ struct vring_desc_packed {
>>  	uint16_t flags;
>>  };
>>+static inline void
>>+toggle_wrap_counter(struct vhost_virtqueue *vq)
>>+{
>>+	vq->used_wrap_counter ^= 1;
>>+}
>>+
>>+static inline int
>>+desc_is_avail(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
>>+{
>>+	if (vq->used_wrap_counter == 1) {
>>+		if ((desc->flags & VRING_DESC_F_AVAIL) &&
>>+				!(desc->flags & VRING_DESC_F_USED))
>>+			return 1;
>>+	}
>>+	if (vq->used_wrap_counter == 0) {
>>+		if (!(desc->flags & VRING_DESC_F_AVAIL) &&
>>+				(desc->flags & VRING_DESC_F_USED))
>>+			return 1;
>>+	}
>>+	return 0;
>>+}
>>+
>>+static inline void
>>+_set_desc_used(struct vring_desc_packed *desc, int wrap_counter)
>>+{
>>+	uint16_t flags = desc->flags;
>>+
>>+	if (wrap_counter == 1) {
>>+		flags |= VRING_DESC_F_USED;
>>+		flags |= VRING_DESC_F_AVAIL;
>>+	} else {
>>+		flags &= ~VRING_DESC_F_USED;
>>+		flags &= ~VRING_DESC_F_AVAIL;
>>+	}
>>+
>>+	desc->flags = flags;
>>+}
>>+
>>+static inline void
>>+set_desc_used(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
>>+{
>>+	_set_desc_used(desc, vq->used_wrap_counter);
>>+}
>>+
>
>Maybe prefix all with vring_
>>  #endif /* __VIRTIO_PACKED_H */

ok

Thanks!

regards,
Jens 
>>
  

Patch

diff --git a/lib/librte_vhost/virtio-1.1.h b/lib/librte_vhost/virtio-1.1.h
index 7b48caed7..e77d7aa6c 100644
--- a/lib/librte_vhost/virtio-1.1.h
+++ b/lib/librte_vhost/virtio-1.1.h
@@ -15,4 +15,48 @@  struct vring_desc_packed {
 	uint16_t flags;
 };
 
+static inline void
+toggle_wrap_counter(struct vhost_virtqueue *vq)
+{
+	vq->used_wrap_counter ^= 1;
+}
+
+static inline int
+desc_is_avail(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
+{
+	if (vq->used_wrap_counter == 1) {
+		if ((desc->flags & VRING_DESC_F_AVAIL) &&
+				!(desc->flags & VRING_DESC_F_USED))
+			return 1;
+	}
+	if (vq->used_wrap_counter == 0) {
+		if (!(desc->flags & VRING_DESC_F_AVAIL) &&
+				(desc->flags & VRING_DESC_F_USED))
+			return 1;
+	}
+	return 0;
+}
+
+static inline void
+_set_desc_used(struct vring_desc_packed *desc, int wrap_counter)
+{
+	uint16_t flags = desc->flags;
+
+	if (wrap_counter == 1) {
+		flags |= VRING_DESC_F_USED;
+		flags |= VRING_DESC_F_AVAIL;
+	} else {
+		flags &= ~VRING_DESC_F_USED;
+		flags &= ~VRING_DESC_F_AVAIL;
+	}
+
+	desc->flags = flags;
+}
+
+static inline void
+set_desc_used(struct vhost_virtqueue *vq, struct vring_desc_packed *desc)
+{
+	_set_desc_used(desc, vq->used_wrap_counter);
+}
+
 #endif /* __VIRTIO_PACKED_H */