Message ID | 20201120185105.279030-19-eperezma@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vDPA software assisted live migration | expand |
On Fri, Nov 20, 2020 at 07:50:56PM +0100, Eugenio Pérez wrote: > @@ -83,6 +89,18 @@ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable) > smp_mb(); > } > > +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq) A name like "more_used" is clearer than "poll".
On Tue, Dec 8, 2020 at 9:42 AM Stefan Hajnoczi <stefanha@gmail.com> wrote: > > On Fri, Nov 20, 2020 at 07:50:56PM +0100, Eugenio Pérez wrote: > > @@ -83,6 +89,18 @@ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable) > > smp_mb(); > > } > > > > +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq) > > A name like "more_used" is clearer than "poll". I agree, I will rename. Thanks!
diff --git a/hw/virtio/vhost-sw-lm-ring.h b/hw/virtio/vhost-sw-lm-ring.h index c537500d9e..03257d60c1 100644 --- a/hw/virtio/vhost-sw-lm-ring.h +++ b/hw/virtio/vhost-sw-lm-ring.h @@ -22,6 +22,8 @@ int vhost_vring_add(VhostShadowVirtqueue *vq, VirtQueueElement *elem); /* Called within rcu_read_lock(). */ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable); +/* Called within rcu_read_lock(). */ +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq); void vhost_vring_write_addr(const VhostShadowVirtqueue *vq, struct vhost_vring_addr *addr); diff --git a/hw/virtio/vhost-sw-lm-ring.c b/hw/virtio/vhost-sw-lm-ring.c index c3244c550e..3652889d8e 100644 --- a/hw/virtio/vhost-sw-lm-ring.c +++ b/hw/virtio/vhost-sw-lm-ring.c @@ -34,6 +34,12 @@ typedef struct VhostShadowVirtqueue { /* Next free descriptor */ uint16_t free_head; + /* Last seen used idx */ + uint16_t shadow_used_idx; + + /* Next head to consume from device */ + uint16_t used_idx; + /* Cache for exposed notification flag */ bool notification; @@ -83,6 +89,18 @@ void vhost_vring_set_notification_rcu(VhostShadowVirtqueue *vq, bool enable) smp_mb(); } +bool vhost_vring_poll_rcu(VhostShadowVirtqueue *vq) +{ + if (vq->used_idx != vq->shadow_used_idx) { + return true; + } + + smp_rmb(); + vq->shadow_used_idx = virtio_tswap16(vq->vdev, vq->vring.used->idx); + + return vq->used_idx != vq->shadow_used_idx; +} + static void vhost_vring_write_descs(VhostShadowVirtqueue *vq, const struct iovec *iovec, size_t num, bool more_descs, bool write)
Signed-off-by: Eugenio Pérez <eperezma@redhat.com> --- hw/virtio/vhost-sw-lm-ring.h | 2 ++ hw/virtio/vhost-sw-lm-ring.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+)