diff mbox

[2/2] virtio-blk: Inline request init, complete and free functions

Message ID 20170207132723.13934-3-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Feb. 7, 2017, 1:27 p.m. UTC
These are used in each request handling, inline them.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 hw/block/virtio-blk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Laszlo Ersek Feb. 7, 2017, 1:52 p.m. UTC | #1
On 02/07/17 14:27, Fam Zheng wrote:
> These are used in each request handling, inline them.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  hw/block/virtio-blk.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 2858c31..1da9570 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -29,8 +29,8 @@
>  #include "hw/virtio/virtio-bus.h"
>  #include "hw/virtio/virtio-access.h"
>  
> -static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> -                                    VirtIOBlockReq *req)
> +static inline void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> +                                           VirtIOBlockReq *req)
>  {
>      req->dev = s;
>      req->vq = vq;
> @@ -40,12 +40,13 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
>      req->mr_next = NULL;
>  }
>  
> -static void virtio_blk_free_request(VirtIOBlockReq *req)
> +static inline void virtio_blk_free_request(VirtIOBlockReq *req)
>  {
>      g_free(req);
>  }
>  
> -static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
> +static inline void virtio_blk_req_complete(VirtIOBlockReq *req,
> +                                           unsigned char status)
>  {
>      VirtIOBlock *s = req->dev;
>      VirtIODevice *vdev = VIRTIO_DEVICE(s);
> 

Hm, virtio_blk_req_complete() looks a bit too "meaty" and seems to be
called from a little too many places for me to feel convenient about
inlining it. I guess I'd leave it to the compiler to optimize the
function call. Does the explicit hint offer a noticeable perf improvement?

Inlining virtio_blk_free_request() looks reasonable.

virtio_blk_init_request() looks okay too.

Other reviewers should feel free to override my concerns :) My view on
this is distant.

Thanks
Laszlo
Stefan Hajnoczi Feb. 13, 2017, 2:28 p.m. UTC | #2
On Tue, Feb 07, 2017 at 02:52:38PM +0100, Laszlo Ersek wrote:
> On 02/07/17 14:27, Fam Zheng wrote:
> > These are used in each request handling, inline them.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  hw/block/virtio-blk.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> > index 2858c31..1da9570 100644
> > --- a/hw/block/virtio-blk.c
> > +++ b/hw/block/virtio-blk.c
> > @@ -29,8 +29,8 @@
> >  #include "hw/virtio/virtio-bus.h"
> >  #include "hw/virtio/virtio-access.h"
> >  
> > -static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> > -                                    VirtIOBlockReq *req)
> > +static inline void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> > +                                           VirtIOBlockReq *req)
> >  {
> >      req->dev = s;
> >      req->vq = vq;
> > @@ -40,12 +40,13 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> >      req->mr_next = NULL;
> >  }
> >  
> > -static void virtio_blk_free_request(VirtIOBlockReq *req)
> > +static inline void virtio_blk_free_request(VirtIOBlockReq *req)
> >  {
> >      g_free(req);
> >  }
> >  
> > -static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
> > +static inline void virtio_blk_req_complete(VirtIOBlockReq *req,
> > +                                           unsigned char status)
> >  {
> >      VirtIOBlock *s = req->dev;
> >      VirtIODevice *vdev = VIRTIO_DEVICE(s);
> > 
> 
> Hm, virtio_blk_req_complete() looks a bit too "meaty" and seems to be
> called from a little too many places for me to feel convenient about
> inlining it. I guess I'd leave it to the compiler to optimize the
> function call. Does the explicit hint offer a noticeable perf improvement?
> 
> Inlining virtio_blk_free_request() looks reasonable.
> 
> virtio_blk_init_request() looks okay too.
> 
> Other reviewers should feel free to override my concerns :) My view on
> this is distant.

I'm not a big fan of manually inlining functions.  Let the compiler
decide whether these static functions should be inlined.

Stefan
Fam Zheng Feb. 14, 2017, 12:54 a.m. UTC | #3
On Mon, 02/13 14:28, Stefan Hajnoczi wrote:
> On Tue, Feb 07, 2017 at 02:52:38PM +0100, Laszlo Ersek wrote:
> > On 02/07/17 14:27, Fam Zheng wrote:
> > > These are used in each request handling, inline them.
> > > 
> > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > ---
> > >  hw/block/virtio-blk.c | 9 +++++----
> > >  1 file changed, 5 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> > > index 2858c31..1da9570 100644
> > > --- a/hw/block/virtio-blk.c
> > > +++ b/hw/block/virtio-blk.c
> > > @@ -29,8 +29,8 @@
> > >  #include "hw/virtio/virtio-bus.h"
> > >  #include "hw/virtio/virtio-access.h"
> > >  
> > > -static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> > > -                                    VirtIOBlockReq *req)
> > > +static inline void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> > > +                                           VirtIOBlockReq *req)
> > >  {
> > >      req->dev = s;
> > >      req->vq = vq;
> > > @@ -40,12 +40,13 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
> > >      req->mr_next = NULL;
> > >  }
> > >  
> > > -static void virtio_blk_free_request(VirtIOBlockReq *req)
> > > +static inline void virtio_blk_free_request(VirtIOBlockReq *req)
> > >  {
> > >      g_free(req);
> > >  }
> > >  
> > > -static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
> > > +static inline void virtio_blk_req_complete(VirtIOBlockReq *req,
> > > +                                           unsigned char status)
> > >  {
> > >      VirtIOBlock *s = req->dev;
> > >      VirtIODevice *vdev = VIRTIO_DEVICE(s);
> > > 
> > 
> > Hm, virtio_blk_req_complete() looks a bit too "meaty" and seems to be
> > called from a little too many places for me to feel convenient about
> > inlining it. I guess I'd leave it to the compiler to optimize the
> > function call. Does the explicit hint offer a noticeable perf improvement?
> > 
> > Inlining virtio_blk_free_request() looks reasonable.
> > 
> > virtio_blk_init_request() looks okay too.
> > 
> > Other reviewers should feel free to override my concerns :) My view on
> > this is distant.
> 
> I'm not a big fan of manually inlining functions.  Let the compiler
> decide whether these static functions should be inlined.
> 

Fair enough, let's drop this one.

Fam
diff mbox

Patch

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 2858c31..1da9570 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -29,8 +29,8 @@ 
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 
-static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
-                                    VirtIOBlockReq *req)
+static inline void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
+                                           VirtIOBlockReq *req)
 {
     req->dev = s;
     req->vq = vq;
@@ -40,12 +40,13 @@  static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
     req->mr_next = NULL;
 }
 
-static void virtio_blk_free_request(VirtIOBlockReq *req)
+static inline void virtio_blk_free_request(VirtIOBlockReq *req)
 {
     g_free(req);
 }
 
-static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
+static inline void virtio_blk_req_complete(VirtIOBlockReq *req,
+                                           unsigned char status)
 {
     VirtIOBlock *s = req->dev;
     VirtIODevice *vdev = VIRTIO_DEVICE(s);