Skip to contentSkip to conversation

virtio-blk: clean up around g_free() and inline a few functions

PATCH Applied Fam Zheng 4 participants 10 messages Feb 7, 2017 – Apr 23, 2017

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover virtio-blk: clean up around g_free() and inline a few functions

Fam Zheng (2):
virtio-blk: Remove useless condition around g_free()
virtio-blk: Inline request init, complete and free functions

 hw/block/virtio-blk.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/2 virtio-blk: Remove useless condition around g_free()

Laszlo spotted and studied this wasteful "if". He pointed out:

The original virtio_blk_free_request needed an "if" as it accesses one field, since 671ec3f05655 ("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on in f897bf751fbd ("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were using g_slice_free(), but it is the same.

Now drop it.

---
 hw/block/virtio-blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/block/virtio-blk.c +1 -3
index 702eda8..2858c31 100644
@@ -42,9 +42,7 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
 
 static void virtio_blk_free_request(VirtIOBlockReq *req)
 {
-    if (req) {
-        g_free(req);
-    }
+    g_free(req);
 }
 
 static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
Signature · 1 line
2.9.3
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()

Quoted 23 lines · Fam Zheng

Laszlo spotted and studied this wasteful "if". He pointed out:

The original virtio_blk_free_request needed an "if" as it accesses one field, since 671ec3f05655 ("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on in f897bf751fbd ("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were using g_slice_free(), but it is the same.

Now drop it.

---
 hw/block/virtio-blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/block/virtio-blk.c +0 -0
index 702eda8..2858c31 100644

hw/block/virtio-blk.c static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, · line 48

Quoted 10 lines
hw/block/virtio-blk.c +1 -3
@@ -42,9 +42,7 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
 
 static void virtio_blk_free_request(VirtIOBlockReq *req)
 {
-    if (req) {
-        g_free(req);
-    }
+    g_free(req);
 }
 
 static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)

Thanks!
Laszlo

Reviewed-by on v1 1/2
#3 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()

In reply to Fam Zheng
Quoted 9 lines · Fam Zheng

Laszlo spotted and studied this wasteful "if". He pointed out:

The original virtio_blk_free_request needed an "if" as it accesses one field, since 671ec3f05655 ("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on in f897bf751fbd ("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were using g_slice_free(), but it is the same.

Quoted 7 lines

Now drop it.

---
 hw/block/virtio-blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
author
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()

In reply to Fam Zheng
Quoted 36 lines · Fam Zheng

Laszlo spotted and studied this wasteful "if". He pointed out:

The original virtio_blk_free_request needed an "if" as it accesses one field, since 671ec3f05655 ("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on in f897bf751fbd ("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were using g_slice_free(), but it is the same.

Now drop it.

---
 hw/block/virtio-blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/block/virtio-blk.c +1 -3
index 702eda8..2858c31 100644
@@ -42,9 +42,7 @@ static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
 
 static void virtio_blk_free_request(VirtIOBlockReq *req)
 {
-    if (req) {
-        g_free(req);
-    }
+    g_free(req);
 }
 
 static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
Signature · 1 line
2.9.3

(Let's drop 2/2 and perhaps merge this via trivial)

Fam

#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()

In reply to Fam Zheng
Quoted 10 lines · Fam Zheng

Laszlo spotted and studied this wasteful "if". He pointed out:

The original virtio_blk_free_request needed an "if" as it accesses one field, since 671ec3f05655 ("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on in f897bf751fbd ("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were using g_slice_free(), but it is the same.

Now drop it.

Applied to -trivial, thanks!

/mjt

author
#6 lore raw

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

In reply to Fam Zheng

These are used in each request handling, inline them.

---
 hw/block/virtio-blk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +5 -4
index 2858c31..1da9570 100644
@@ -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);
Signature · 1 line
2.9.3
#7 lore raw

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

Quoted 29 lines · Fam Zheng

These are used in each request handling, inline them.

---
 hw/block/virtio-blk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +3 -3
index 2858c31..1da9570 100644
@@ -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)

hw/block/virtio-blk.c static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, · line 52

Quoted 10 lines
hw/block/virtio-blk.c +2 -1
 {
     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

#8 lore raw

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

Quoted 46 lines · Laszlo Ersek
Quoted 29 lines · Fam Zheng

These are used in each request handling, inline them.

---
 hw/block/virtio-blk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +3 -3
index 2858c31..1da9570 100644
@@ -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)

hw/block/virtio-blk.c static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, · line 52

Quoted 10 lines
hw/block/virtio-blk.c +2 -1
 {
     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?

Quoted 6 lines

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

author
#9 lore raw

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

Quoted 49 lines · Stefan Hajnoczi
Quoted 48 lines · Laszlo Ersek
Quoted 29 lines · Fam Zheng

These are used in each request handling, inline them.

---
 hw/block/virtio-blk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +3 -3
index 2858c31..1da9570 100644
@@ -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)

hw/block/virtio-blk.c static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq, · line 52

Quoted 10 lines
hw/block/virtio-blk.c +2 -1
 {
     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.

Quoted 8 lines
Quoted 4 lines

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