diff mbox series

[RFC,v4,17/20] vhost: Use VRING_AVAIL_F_NO_INTERRUPT at device call on shadow virtqueue

Message ID 20211001070603.307037-18-eperezma@redhat.com
State New
Headers show
Series vDPA shadow virtqueue | expand

Commit Message

Eugenio Perez Martin Oct. 1, 2021, 7:06 a.m. UTC
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Jason Wang Oct. 13, 2021, 4:36 a.m. UTC | #1
在 2021/10/1 下午3:06, Eugenio Pérez 写道:
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>


Commit log please.

Thanks


> ---
>   hw/virtio/vhost-shadow-virtqueue.c | 24 +++++++++++++++++++++++-
>   1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
> index 775f8d36a0..2fd0bab75d 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.c
> +++ b/hw/virtio/vhost-shadow-virtqueue.c
> @@ -60,6 +60,9 @@ typedef struct VhostShadowVirtqueue {
>   
>       /* Next head to consume from device */
>       uint16_t used_idx;
> +
> +    /* Cache for the exposed notification flag */
> +    bool notification;
>   } VhostShadowVirtqueue;
>   
>   /* If the device is using some of these, SVQ cannot communicate */
> @@ -105,6 +108,24 @@ bool vhost_svq_valid_device_features(uint64_t *dev_features)
>       return r;
>   }
>   
> +static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable)
> +{
> +    uint16_t notification_flag;
> +
> +    if (svq->notification == enable) {
> +        return;
> +    }
> +
> +    notification_flag = cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT);
> +
> +    svq->notification = enable;
> +    if (enable) {
> +        svq->vring.avail->flags &= ~notification_flag;
> +    } else {
> +        svq->vring.avail->flags |= notification_flag;
> +    }
> +}
> +
>   static void vhost_vring_write_descs(VhostShadowVirtqueue *svq,
>                                       const struct iovec *iovec,
>                                       size_t num, bool more_descs, bool write)
> @@ -273,7 +294,7 @@ static void vhost_svq_handle_call_no_test(EventNotifier *n)
>       do {
>           unsigned i = 0;
>   
> -        /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */
> +        vhost_svq_set_notification(svq, false);
>           while (true) {
>               g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq);
>               if (!elem) {
> @@ -286,6 +307,7 @@ static void vhost_svq_handle_call_no_test(EventNotifier *n)
>   
>           virtqueue_flush(vq, i);
>           event_notifier_set(&svq->guest_call_notifier);
> +        vhost_svq_set_notification(svq, true);
>       } while (vhost_svq_more_used(svq));
>   }
>
Eugenio Perez Martin Oct. 15, 2021, 6:22 a.m. UTC | #2
On Wed, Oct 13, 2021 at 6:36 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> 在 2021/10/1 下午3:06, Eugenio Pérez 写道:
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
>
>
> Commit log please.
>
> Thanks
>

Sorry, this was another commit that was intended to be squashed.

I think I squashed two other (previous) commits by mistake in the
rebase editor, that's why you detected unrelated changes and mixed SVQ
& vhost-vdpa changes. I will take more care for the next series I
send.

Thanks!

>
> > ---
> >   hw/virtio/vhost-shadow-virtqueue.c | 24 +++++++++++++++++++++++-
> >   1 file changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
> > index 775f8d36a0..2fd0bab75d 100644
> > --- a/hw/virtio/vhost-shadow-virtqueue.c
> > +++ b/hw/virtio/vhost-shadow-virtqueue.c
> > @@ -60,6 +60,9 @@ typedef struct VhostShadowVirtqueue {
> >
> >       /* Next head to consume from device */
> >       uint16_t used_idx;
> > +
> > +    /* Cache for the exposed notification flag */
> > +    bool notification;
> >   } VhostShadowVirtqueue;
> >
> >   /* If the device is using some of these, SVQ cannot communicate */
> > @@ -105,6 +108,24 @@ bool vhost_svq_valid_device_features(uint64_t *dev_features)
> >       return r;
> >   }
> >
> > +static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable)
> > +{
> > +    uint16_t notification_flag;
> > +
> > +    if (svq->notification == enable) {
> > +        return;
> > +    }
> > +
> > +    notification_flag = cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT);
> > +
> > +    svq->notification = enable;
> > +    if (enable) {
> > +        svq->vring.avail->flags &= ~notification_flag;
> > +    } else {
> > +        svq->vring.avail->flags |= notification_flag;
> > +    }
> > +}
> > +
> >   static void vhost_vring_write_descs(VhostShadowVirtqueue *svq,
> >                                       const struct iovec *iovec,
> >                                       size_t num, bool more_descs, bool write)
> > @@ -273,7 +294,7 @@ static void vhost_svq_handle_call_no_test(EventNotifier *n)
> >       do {
> >           unsigned i = 0;
> >
> > -        /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */
> > +        vhost_svq_set_notification(svq, false);
> >           while (true) {
> >               g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq);
> >               if (!elem) {
> > @@ -286,6 +307,7 @@ static void vhost_svq_handle_call_no_test(EventNotifier *n)
> >
> >           virtqueue_flush(vq, i);
> >           event_notifier_set(&svq->guest_call_notifier);
> > +        vhost_svq_set_notification(svq, true);
> >       } while (vhost_svq_more_used(svq));
> >   }
> >
>
diff mbox series

Patch

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 775f8d36a0..2fd0bab75d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -60,6 +60,9 @@  typedef struct VhostShadowVirtqueue {
 
     /* Next head to consume from device */
     uint16_t used_idx;
+
+    /* Cache for the exposed notification flag */
+    bool notification;
 } VhostShadowVirtqueue;
 
 /* If the device is using some of these, SVQ cannot communicate */
@@ -105,6 +108,24 @@  bool vhost_svq_valid_device_features(uint64_t *dev_features)
     return r;
 }
 
+static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable)
+{
+    uint16_t notification_flag;
+
+    if (svq->notification == enable) {
+        return;
+    }
+
+    notification_flag = cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT);
+
+    svq->notification = enable;
+    if (enable) {
+        svq->vring.avail->flags &= ~notification_flag;
+    } else {
+        svq->vring.avail->flags |= notification_flag;
+    }
+}
+
 static void vhost_vring_write_descs(VhostShadowVirtqueue *svq,
                                     const struct iovec *iovec,
                                     size_t num, bool more_descs, bool write)
@@ -273,7 +294,7 @@  static void vhost_svq_handle_call_no_test(EventNotifier *n)
     do {
         unsigned i = 0;
 
-        /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */
+        vhost_svq_set_notification(svq, false);
         while (true) {
             g_autofree VirtQueueElement *elem = vhost_svq_get_buf(svq);
             if (!elem) {
@@ -286,6 +307,7 @@  static void vhost_svq_handle_call_no_test(EventNotifier *n)
 
         virtqueue_flush(vq, i);
         event_notifier_set(&svq->guest_call_notifier);
+        vhost_svq_set_notification(svq, true);
     } while (vhost_svq_more_used(svq));
 }