virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs()
@ 2014-01-25 19:59 Leandro Dorileo
  0 siblings, 0 replies; 4+ messages in thread
From: Leandro Dorileo @ 2014-01-25 19:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: virtio-dev, mst, virtualization

Cchange init_vqs() to avoid calling twice the virtio_has_feature()
- attempting to find out if VIRTIO_BALLOON_F_STATS_VQ feature was negotiated -
consequently we prevent unnecessarily running the drivers' feature_table more
than needed.

Signed-off-by: Leandro Dorileo <l@dorileo.org>
---
 drivers/virtio/virtio_balloon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 34bdaba..41771c1 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -320,19 +320,21 @@ static int init_vqs(struct virtio_balloon *vb)
 	vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
 	const char *names[] = { "inflate", "deflate", "stats" };
 	int err, nvqs;
+	bool stats;
 
 	/*
 	 * We expect two virtqueues: inflate and deflate, and
 	 * optionally stat.
 	 */
-	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
+	stats = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ);
+	nvqs = stats ? 3 : 2;
 	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names);
 	if (err)
 		return err;
 
 	vb->inflate_vq = vqs[0];
 	vb->deflate_vq = vqs[1];
-	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
+	if (stats) {
 		struct scatterlist sg;
 		vb->stats_vq = vqs[2];
 
-- 
1.8.5.3

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

* Re: [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs()
       [not found] <1390679972-1406-1-git-send-email-l@dorileo.org>
@ 2014-01-28  0:18 ` Rusty Russell
  2014-01-28  1:27   ` Leandro Dorileo
  2014-01-28  2:06   ` Leandro Dorileo
  0 siblings, 2 replies; 4+ messages in thread
From: Rusty Russell @ 2014-01-28  0:18 UTC (permalink / raw)
  To: Leandro Dorileo, linux-kernel; +Cc: virtio-dev, mst, virtualization

Leandro Dorileo <l@dorileo.org> writes:
> Cchange init_vqs() to avoid calling twice the virtio_has_feature()
> - attempting to find out if VIRTIO_BALLOON_F_STATS_VQ feature was negotiated -
> consequently we prevent unnecessarily running the drivers' feature_table more
> than needed.
>
> Signed-off-by: Leandro Dorileo <l@dorileo.org>

Hi Leandro,

        This seems like a premature optimization.  The current code is
fairly clear, and there's no performance issue with init_vqs.

Am I missing something?
Rusty.

> ---
>  drivers/virtio/virtio_balloon.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34bdaba..41771c1 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -320,19 +320,21 @@ static int init_vqs(struct virtio_balloon *vb)
>  	vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
>  	const char *names[] = { "inflate", "deflate", "stats" };
>  	int err, nvqs;
> +	bool stats;
>  
>  	/*
>  	 * We expect two virtqueues: inflate and deflate, and
>  	 * optionally stat.
>  	 */
> -	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
> +	stats = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ);
> +	nvqs = stats ? 3 : 2;
>  	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names);
>  	if (err)
>  		return err;
>  
>  	vb->inflate_vq = vqs[0];
>  	vb->deflate_vq = vqs[1];
> -	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
> +	if (stats) {
>  		struct scatterlist sg;
>  		vb->stats_vq = vqs[2];
>  
> -- 
> 1.8.5.3

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

* Re: [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs()
  2014-01-28  0:18 ` [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs() Rusty Russell
@ 2014-01-28  1:27   ` Leandro Dorileo
  2014-01-28  2:06   ` Leandro Dorileo
  1 sibling, 0 replies; 4+ messages in thread
From: Leandro Dorileo @ 2014-01-28  1:27 UTC (permalink / raw)
  To: Rusty Russell; +Cc: virtio-dev, mst, linux-kernel, virtualization


[-- Attachment #1.1: Type: text/plain, Size: 2395 bytes --]

Hi Rusty,

On Mon, Jan 27, 2014 at 10:18 PM, Rusty Russell <rusty@rustcorp.com.au>wrote:

> Leandro Dorileo <l@dorileo.org> writes:
> > Cchange init_vqs() to avoid calling twice the virtio_has_feature()
> > - attempting to find out if VIRTIO_BALLOON_F_STATS_VQ feature was
> negotiated -
> > consequently we prevent unnecessarily running the drivers' feature_table
> more
> > than needed.
> >
> > Signed-off-by: Leandro Dorileo <l@dorileo.org>
>
> Hi Leandro,
>
>         This seems like a premature optimization.  The current code is
> fairly clear, and there's no performance issue with init_vqs.
>
>

Indeed, rethinking the patch and reviewing the code path it seems to be no
gain,
It's just called on probe and restore operations. As you said a premature
optimization.

Thanks...



> Am I missing something?
> Rusty.
>
> > ---
> >  drivers/virtio/virtio_balloon.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_balloon.c
> b/drivers/virtio/virtio_balloon.c
> > index 34bdaba..41771c1 100644
> > --- a/drivers/virtio/virtio_balloon.c
> > +++ b/drivers/virtio/virtio_balloon.c
> > @@ -320,19 +320,21 @@ static int init_vqs(struct virtio_balloon *vb)
> >       vq_callback_t *callbacks[] = { balloon_ack, balloon_ack,
> stats_request };
> >       const char *names[] = { "inflate", "deflate", "stats" };
> >       int err, nvqs;
> > +     bool stats;
> >
> >       /*
> >        * We expect two virtqueues: inflate and deflate, and
> >        * optionally stat.
> >        */
> > -     nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3
> : 2;
> > +     stats = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ);
> > +     nvqs = stats ? 3 : 2;
> >       err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks,
> names);
> >       if (err)
> >               return err;
> >
> >       vb->inflate_vq = vqs[0];
> >       vb->deflate_vq = vqs[1];
> > -     if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
> > +     if (stats) {
> >               struct scatterlist sg;
> >               vb->stats_vq = vqs[2];
> >
> > --
> > 1.8.5.3
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

[-- Attachment #1.2: Type: text/html, Size: 3586 bytes --]

[-- Attachment #2: Type: text/plain, Size: 183 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs()
  2014-01-28  0:18 ` [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs() Rusty Russell
  2014-01-28  1:27   ` Leandro Dorileo
@ 2014-01-28  2:06   ` Leandro Dorileo
  1 sibling, 0 replies; 4+ messages in thread
From: Leandro Dorileo @ 2014-01-28  2:06 UTC (permalink / raw)
  To: Rusty Russell; +Cc: virtio-dev, mst, linux-kernel, virtualization

Hi Rusty,

On Tue, Jan 28, 2014 at 10:48:31AM +1030, Rusty Russell wrote:
> Leandro Dorileo <l@dorileo.org> writes:
> > Cchange init_vqs() to avoid calling twice the virtio_has_feature()
> > - attempting to find out if VIRTIO_BALLOON_F_STATS_VQ feature was negotiated -
> > consequently we prevent unnecessarily running the drivers' feature_table more
> > than needed.
> >
> > Signed-off-by: Leandro Dorileo <l@dorileo.org>
> 
> Hi Leandro,
> 
>         This seems like a premature optimization.  The current code is
> fairly clear, and there's no performance issue with init_vqs.
> 

Indeed, rethinking the patch and reviewing the code path it seems to be no gain,
It's just called on probe and restore operations. As you said a premature optimization.

Thanks...


> Am I missing something?
> Rusty.
> 
> > ---
> >  drivers/virtio/virtio_balloon.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> > index 34bdaba..41771c1 100644
> > --- a/drivers/virtio/virtio_balloon.c
> > +++ b/drivers/virtio/virtio_balloon.c
> > @@ -320,19 +320,21 @@ static int init_vqs(struct virtio_balloon *vb)
> >  	vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
> >  	const char *names[] = { "inflate", "deflate", "stats" };
> >  	int err, nvqs;
> > +	bool stats;
> >  
> >  	/*
> >  	 * We expect two virtqueues: inflate and deflate, and
> >  	 * optionally stat.
> >  	 */
> > -	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
> > +	stats = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ);
> > +	nvqs = stats ? 3 : 2;
> >  	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names);
> >  	if (err)
> >  		return err;
> >  
> >  	vb->inflate_vq = vqs[0];
> >  	vb->deflate_vq = vqs[1];
> > -	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
> > +	if (stats) {
> >  		struct scatterlist sg;
> >  		vb->stats_vq = vqs[2];
> >  
> > -- 
> > 1.8.5.3
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Leandro Dorileo

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

end of thread, other threads:[~2014-01-28  2:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1390679972-1406-1-git-send-email-l@dorileo.org>
2014-01-28  0:18 ` [PATCH] virtio_balloon: don't call virtio_has_feature() twice on init_vqs() Rusty Russell
2014-01-28  1:27   ` Leandro Dorileo
2014-01-28  2:06   ` Leandro Dorileo
2014-01-25 19:59 Leandro Dorileo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).