virtio-blk: clean up around g_free() and inline a few functions
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
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
@@ -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
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_requestneeded an "if" as it accesses one field, since671ec3f05655("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on inf897bf751fbd("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were usingg_slice_free(), but it is the same.Now drop it.
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/block/virtio-blk.c +0
-0
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
Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()
In reply to Fam ZhengQuoted 9 lines · Fam Zheng
Laszlo spotted and studied this wasteful "if". He pointed out:
The original
virtio_blk_free_requestneeded an "if" as it accesses one field, since671ec3f05655("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on inf897bf751fbd("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were usingg_slice_free(), but it is the same.
Quoted 7 lines
Now drop it.
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Re: [Qemu-devel] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()
In reply to Fam ZhengQuoted 36 lines · Fam Zheng
Laszlo spotted and studied this wasteful "if". He pointed out:
The original
virtio_blk_free_requestneeded an "if" as it accesses one field, since671ec3f05655("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on inf897bf751fbd("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were usingg_slice_free(), but it is the same.Now drop it.
Reported-by Laszlo Ersek <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)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)Signature · 1 line
2.9.3
(Let's drop 2/2 and perhaps merge this via trivial)
Fam
Michael Tokarev
AppliedRe: [Qemu-devel] [PATCH 1/2] virtio-blk: Remove useless condition around g_free()
In reply to Fam ZhengQuoted 10 lines · Fam Zheng
Laszlo spotted and studied this wasteful "if". He pointed out:
The original
virtio_blk_free_requestneeded an "if" as it accesses one field, since671ec3f05655("virtio-blk: Convert VirtIOBlockReq.elem to pointer", 2014-06-11); later on inf897bf751fbd("virtio-blk: embed VirtQueueElement in VirtIOBlockReq", 2014-07-09) the field became embedded, so the "if" became unnecessary (at which point we were usingg_slice_free(), but it is the same.Now drop it.
Applied to -trivial, thanks!
/mjt
PATCH 2/2 virtio-blk: Inline request init, complete and free functions
In reply to Fam ZhengThese 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
@@ -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
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.
Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +3
-3@@ -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
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.
Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +3
-3@@ -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
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.
Signed-off-by Fam Zheng <[email protected]>--- hw/block/virtio-blk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +3
-3@@ -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