public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed
@ 2011-11-25 15:47 Asias He
  2011-11-26 12:40 ` Pekka Enberg
  0 siblings, 1 reply; 4+ messages in thread
From: Asias He @ 2011-11-25 15:47 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, kvm, Asias He

This patch also fixes fio seq-read hang problem.

   root@guest-kvm:~# cat seq-read.fio
   [seq-read]
   rw=read
   bs=4096
   size=512m
   direct=1
   filename=/dev/vdb

   root@guest-kvm:~# fio seq-read.fio
   random-read: (g=0): rw=read, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
   Starting 1 process
   Jobs: 1 (f=1): [R] [50.0% done] [0K/0K /s] [0/0 iops] [eta 00m:27s]

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/include/kvm/virtio.h |    6 ++----
 tools/kvm/virtio/core.c        |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index cd24285..d117bfc 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -22,6 +22,7 @@ struct virt_queue {
 	/* The last_avail_idx field is an index to ->ring of struct vring_avail.
 	   It's where we assume the next request index is at.  */
 	u16		last_avail_idx;
+	u16		last_used_signalled;
 };
 
 static inline u16 virt_queue__pop(struct virt_queue *queue)
@@ -53,13 +54,10 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
 	return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
 }
 
-static inline int virtio_queue__should_signal(struct virt_queue *vq)
-{
-	return vring_used_event(&vq->vring) <= vq->vring.used->idx;
-}
 
 struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
 
+bool virtio_queue__should_signal(struct virt_queue *vq);
 u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
 u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue,
 			      struct iovec in_iov[], struct iovec out_iov[],
diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c
index 0466e07..8032d7a 100644
--- a/tools/kvm/virtio/core.c
+++ b/tools/kvm/virtio/core.c
@@ -109,3 +109,19 @@ int virtio__get_dev_specific_field(int offset, bool msix, bool features_hi, u32
 
 	return VIRTIO_PCI_O_CONFIG;
 }
+
+bool virtio_queue__should_signal(struct virt_queue *vq)
+{
+	u16 old_idx, new_idx, event_idx;
+
+	old_idx		= vq->last_used_signalled;
+	new_idx		= vq->vring.used->idx;
+	event_idx	= vring_used_event(&vq->vring);
+
+	if (vring_need_event(event_idx, new_idx, old_idx)) {
+		vq->last_used_signalled = new_idx;
+		return true;
+	}
+
+	return false;
+}
-- 
1.7.7.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed
  2011-11-25 15:47 [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed Asias He
@ 2011-11-26 12:40 ` Pekka Enberg
  2011-11-26 13:27   ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Pekka Enberg @ 2011-11-26 12:40 UTC (permalink / raw)
  To: Asias He; +Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, kvm

On Fri, Nov 25, 2011 at 5:47 PM, Asias He <asias.hejun@gmail.com> wrote:
> This patch also fixes fio seq-read hang problem.
>
>   root@guest-kvm:~# cat seq-read.fio
>   [seq-read]
>   rw=read
>   bs=4096
>   size=512m
>   direct=1
>   filename=/dev/vdb
>
>   root@guest-kvm:~# fio seq-read.fio
>   random-read: (g=0): rw=read, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
>   Starting 1 process
>   Jobs: 1 (f=1): [R] [50.0% done] [0K/0K /s] [0/0 iops] [eta 00m:27s]
>
> Signed-off-by: Asias He <asias.hejun@gmail.com>

Sasha, does this look good to you?

> ---
>  tools/kvm/include/kvm/virtio.h |    6 ++----
>  tools/kvm/virtio/core.c        |   16 ++++++++++++++++
>  2 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
> index cd24285..d117bfc 100644
> --- a/tools/kvm/include/kvm/virtio.h
> +++ b/tools/kvm/include/kvm/virtio.h
> @@ -22,6 +22,7 @@ struct virt_queue {
>        /* The last_avail_idx field is an index to ->ring of struct vring_avail.
>           It's where we assume the next request index is at.  */
>        u16             last_avail_idx;
> +       u16             last_used_signalled;
>  };
>
>  static inline u16 virt_queue__pop(struct virt_queue *queue)
> @@ -53,13 +54,10 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
>        return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
>  }
>
> -static inline int virtio_queue__should_signal(struct virt_queue *vq)
> -{
> -       return vring_used_event(&vq->vring) <= vq->vring.used->idx;
> -}
>
>  struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
>
> +bool virtio_queue__should_signal(struct virt_queue *vq);
>  u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
>  u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue,
>                              struct iovec in_iov[], struct iovec out_iov[],
> diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c
> index 0466e07..8032d7a 100644
> --- a/tools/kvm/virtio/core.c
> +++ b/tools/kvm/virtio/core.c
> @@ -109,3 +109,19 @@ int virtio__get_dev_specific_field(int offset, bool msix, bool features_hi, u32
>
>        return VIRTIO_PCI_O_CONFIG;
>  }
> +
> +bool virtio_queue__should_signal(struct virt_queue *vq)
> +{
> +       u16 old_idx, new_idx, event_idx;
> +
> +       old_idx         = vq->last_used_signalled;
> +       new_idx         = vq->vring.used->idx;
> +       event_idx       = vring_used_event(&vq->vring);
> +
> +       if (vring_need_event(event_idx, new_idx, old_idx)) {
> +               vq->last_used_signalled = new_idx;
> +               return true;
> +       }
> +
> +       return false;
> +}
> --
> 1.7.7.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed
  2011-11-26 12:40 ` Pekka Enberg
@ 2011-11-26 13:27   ` Sasha Levin
  2011-11-26 20:41     ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2011-11-26 13:27 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Asias He, Cyrill Gorcunov, Ingo Molnar, kvm

On Sat, 2011-11-26 at 14:40 +0200, Pekka Enberg wrote:
> On Fri, Nov 25, 2011 at 5:47 PM, Asias He <asias.hejun@gmail.com> wrote:
> > This patch also fixes fio seq-read hang problem.
> >
> >   root@guest-kvm:~# cat seq-read.fio
> >   [seq-read]
> >   rw=read
> >   bs=4096
> >   size=512m
> >   direct=1
> >   filename=/dev/vdb
> >
> >   root@guest-kvm:~# fio seq-read.fio
> >   random-read: (g=0): rw=read, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
> >   Starting 1 process
> >   Jobs: 1 (f=1): [R] [50.0% done] [0K/0K /s] [0/0 iops] [eta 00m:27s]
> >
> > Signed-off-by: Asias He <asias.hejun@gmail.com>
> 
> Sasha, does this look good to you?

I'm trying to see if it solved the hang problem I've mentioned on IRC.
Will update.
> 
> > ---
> >  tools/kvm/include/kvm/virtio.h |    6 ++----
> >  tools/kvm/virtio/core.c        |   16 ++++++++++++++++
> >  2 files changed, 18 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
> > index cd24285..d117bfc 100644
> > --- a/tools/kvm/include/kvm/virtio.h
> > +++ b/tools/kvm/include/kvm/virtio.h
> > @@ -22,6 +22,7 @@ struct virt_queue {
> >        /* The last_avail_idx field is an index to ->ring of struct vring_avail.
> >           It's where we assume the next request index is at.  */
> >        u16             last_avail_idx;
> > +       u16             last_used_signalled;
> >  };
> >
> >  static inline u16 virt_queue__pop(struct virt_queue *queue)
> > @@ -53,13 +54,10 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
> >        return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
> >  }
> >
> > -static inline int virtio_queue__should_signal(struct virt_queue *vq)
> > -{
> > -       return vring_used_event(&vq->vring) <= vq->vring.used->idx;
> > -}
> >
> >  struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
> >
> > +bool virtio_queue__should_signal(struct virt_queue *vq);
> >  u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
> >  u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue,
> >                              struct iovec in_iov[], struct iovec out_iov[],
> > diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c
> > index 0466e07..8032d7a 100644
> > --- a/tools/kvm/virtio/core.c
> > +++ b/tools/kvm/virtio/core.c
> > @@ -109,3 +109,19 @@ int virtio__get_dev_specific_field(int offset, bool msix, bool features_hi, u32
> >
> >        return VIRTIO_PCI_O_CONFIG;
> >  }
> > +
> > +bool virtio_queue__should_signal(struct virt_queue *vq)
> > +{
> > +       u16 old_idx, new_idx, event_idx;
> > +
> > +       old_idx         = vq->last_used_signalled;
> > +       new_idx         = vq->vring.used->idx;
> > +       event_idx       = vring_used_event(&vq->vring);
> > +
> > +       if (vring_need_event(event_idx, new_idx, old_idx)) {
> > +               vq->last_used_signalled = new_idx;
> > +               return true;
> > +       }
> > +
> > +       return false;
> > +}
> > --
> > 1.7.7.3
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >

-- 

Sasha.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed
  2011-11-26 13:27   ` Sasha Levin
@ 2011-11-26 20:41     ` Sasha Levin
  0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2011-11-26 20:41 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Asias He, Cyrill Gorcunov, Ingo Molnar, kvm

On Sat, 2011-11-26 at 15:27 +0200, Sasha Levin wrote:
> On Sat, 2011-11-26 at 14:40 +0200, Pekka Enberg wrote:
> > On Fri, Nov 25, 2011 at 5:47 PM, Asias He <asias.hejun@gmail.com> wrote:
> > > This patch also fixes fio seq-read hang problem.
> > >
> > >   root@guest-kvm:~# cat seq-read.fio
> > >   [seq-read]
> > >   rw=read
> > >   bs=4096
> > >   size=512m
> > >   direct=1
> > >   filename=/dev/vdb
> > >
> > >   root@guest-kvm:~# fio seq-read.fio
> > >   random-read: (g=0): rw=read, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
> > >   Starting 1 process
> > >   Jobs: 1 (f=1): [R] [50.0% done] [0K/0K /s] [0/0 iops] [eta 00m:27s]
> > >
> > > Signed-off-by: Asias He <asias.hejun@gmail.com>
> > 
> > Sasha, does this look good to you?
> 
> I'm trying to see if it solved the hang problem I've mentioned on IRC.
> Will update.

Yup, fixed it for me.

	Acked-by: Sasha Levin <levinsasha928@gmail.com>

-- 

Sasha.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-26 20:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-25 15:47 [PATCH] kvm tools: Use vring_need_event() to determine if interrupt is needed Asias He
2011-11-26 12:40 ` Pekka Enberg
2011-11-26 13:27   ` Sasha Levin
2011-11-26 20:41     ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox