[dpdk-dev,11/17] vhost: add helpers for packed virtqueues

Message ID 20180316152120.13199-12-jfreimann@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers

Checks

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

Commit Message

Jens Freimann March 16, 2018, 3:21 p.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 | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
  

Comments

Tiwei Bie March 19, 2018, 10:39 a.m. UTC | #1
On Fri, Mar 16, 2018 at 04:21:14PM +0100, 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>
[...]
>  
> +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 (unlikely(!vq))
> +		return -1;

Maybe it's better to let the caller make sure the vq
won't be NULL.

> +
> +	if (vq->used_wrap_counter == 1)
> +		if ((desc->flags & DESC_AVAIL) && !(desc->flags & DESC_USED))
> +			return 1;
> +	if (vq->used_wrap_counter == 0)

Maybe it's better to use '} else {' here.

Thanks

> +		if (!(desc->flags & DESC_AVAIL) && (desc->flags & DESC_USED))
> +			return 1;
> +	return 0;
> +}
  
Jens Freimann March 21, 2018, 9:17 a.m. UTC | #2
On Mon, Mar 19, 2018 at 06:39:56PM +0800, Tiwei Bie wrote:
>On Fri, Mar 16, 2018 at 04:21:14PM +0100, 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>
>[...]
>>
>> +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 (unlikely(!vq))
>> +		return -1;
>
>Maybe it's better to let the caller make sure the vq
>won't be NULL.
>
>> +
>> +	if (vq->used_wrap_counter == 1)
>> +		if ((desc->flags & DESC_AVAIL) && !(desc->flags & DESC_USED))
>> +			return 1;
>> +	if (vq->used_wrap_counter == 0)
>
>Maybe it's better to use '} else {' here.

Agree with both, thanks for the review!

regards,
Jens
  

Patch

diff --git a/lib/librte_vhost/virtio-1.1.h b/lib/librte_vhost/virtio-1.1.h
index b37d621..7b37d26 100644
--- a/lib/librte_vhost/virtio-1.1.h
+++ b/lib/librte_vhost/virtio-1.1.h
@@ -17,4 +17,47 @@  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 (unlikely(!vq))
+		return -1;
+
+	if (vq->used_wrap_counter == 1)
+		if ((desc->flags & DESC_AVAIL) && !(desc->flags & DESC_USED))
+			return 1;
+	if (vq->used_wrap_counter == 0)
+		if (!(desc->flags & DESC_AVAIL) && (desc->flags & DESC_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 |= DESC_USED;
+		flags |= DESC_AVAIL;
+	} else {
+		flags &= ~DESC_USED;
+		flags &= ~DESC_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 */