Skip to contentSkip to conversation

virtio: replace constant parameter '1' with num

PATCH In review liush 2 participants 3 messages Dec 8, 2020 – Dec 9, 2020 virtio core

lore
Share & tools
lore

liush

author
#0 lore raw

PATCH 1/1 virtio: replace constant parameter '1' with num

'num' can represent the value of out_sgs(in_sags), no need to pass in constant parameters in 'virtqueue_add'.

---
 drivers/virtio/virtio_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +2 -2
index becc776..7583f8b 100644
@@ -1760,7 +1760,7 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
 			 void *data,
 			 gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, gfp);
+	return virtqueue_add(vq, &sg, num, num, 0, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
@@ -1782,7 +1782,7 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, gfp);
+	return virtqueue_add(vq, &sg, num, 0, num, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · liush

'num' can represent the value of out_sgs(in_sags), no need to pass in constant parameters in 'virtqueue_add'.

Point being?
A constant is likely easier for the compiler to optimize ...

Quoted 28 lines
---
 drivers/virtio/virtio_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +2 -2
index becc776..7583f8b 100644
@@ -1760,7 +1760,7 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
 			 void *data,
 			 gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, gfp);
+	return virtqueue_add(vq, &sg, num, num, 0, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
@@ -1782,7 +1782,7 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, gfp);
+	return virtqueue_add(vq, &sg, num, 0, num, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
 
Signature · 1 line
2.7.4

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw

Hi Michael,

Quoted 7 lines
Quoted 4 lines

'num' can represent the value of out_sgs(in_sags), no need to pass in constant parameters in 'virtqueue_add'.

Point being?
A constant is likely easier for the compiler to optimize ...

Thanks.
I was unaware that a constant was for compiler optimization.
It seems that 'num' is more readable compared to a constant. And 'virtqueue_add_*' does not specify that only one buf is added, but ‘1’ is passed in ‘virtqueue_add’, which limits the function of 'virtqueue_add_*'. Besides compilation optimization, are there any other considerations.

Quoted 27 lines
Quoted 27 lines
---
 drivers/virtio/virtio_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +2 -3
index becc776..7583f8b 100644
@@ -1760,7 +1760,7 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
     void *data,
     gfp_t gfp)
 {
- return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, gfp);
+ return virtqueue_add(vq, &sg, num, num, 0, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
@@ -1782,7 +1782,7 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
    void *data,
    gfp_t gfp)
 {
- return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, gfp);
+ return virtqueue_add(vq, &sg, num, 0, num, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
 
--