From: "Michael S. Tsirkin" <mst@redhat.com>
To: Guo Zhi <qtxuning1999@sjtu.edu.cn>
Cc: eperezma@redhat.com, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v2 2/4] virtio_test: move magic number in code as defined constant
Date: Thu, 7 Jul 2022 01:09:55 -0400 [thread overview]
Message-ID: <20220707010036-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220707024409.1869-3-qtxuning1999@sjtu.edu.cn>
On Thu, Jul 07, 2022 at 10:44:07AM +0800, Guo Zhi wrote:
> We should avoid using magic numbers directly.
Not necessarily. For repeated values - I guess.
But this kind of thing:
#define BUF_SIZE 1024
int buf_size = BUF_SIZE;
brings no benefit IMHO.
And this has cost - values are now removed from code.
> Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
> ---
> tools/virtio/virtio_test.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
> index 95f78b311..1ecd64271 100644
> --- a/tools/virtio/virtio_test.c
> +++ b/tools/virtio/virtio_test.c
> @@ -20,7 +20,10 @@
> #include "../../drivers/vhost/test.h"
>
> #define RANDOM_BATCH -1
> -
> +#define ALIGN 4096
> +#define RINGSIZE 256
> +#define TEST_BUF_NUM 0x100000
> +#define BUF_SIZE 1024
> /* Unused */
> void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
>
> @@ -100,8 +103,8 @@ static void vq_reset(struct vq_info *info, int num, struct virtio_device *vdev)
> if (info->vq)
> vring_del_virtqueue(info->vq);
>
> - memset(info->ring, 0, vring_size(num, 4096));
> - vring_init(&info->vring, num, info->ring, 4096);
> + memset(info->ring, 0, vring_size(num, ALIGN));
> + vring_init(&info->vring, num, info->ring, ALIGN);
> info->vq = __vring_new_virtqueue(info->idx, info->vring, vdev, true,
> false, vq_notify, vq_callback, "test");
> assert(info->vq);
> @@ -115,7 +118,7 @@ static void vq_info_add(struct vdev_info *dev, int num)
> info->idx = dev->nvqs;
> info->kick = eventfd(0, EFD_NONBLOCK);
> info->call = eventfd(0, EFD_NONBLOCK);
> - r = posix_memalign(&info->ring, 4096, vring_size(num, 4096));
> + r = posix_memalign(&info->ring, PAGE_SIZE, vring_size(num, ALIGN));
> assert(r >= 0);
> vq_reset(info, num, &dev->vdev);
> vhost_vq_setup(dev, info);
This is actually doing more than what commit log says.
> @@ -131,7 +134,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
> dev->vdev.features = features;
> INIT_LIST_HEAD(&dev->vdev.vqs);
> spin_lock_init(&dev->vdev.vqs_list_lock);
> - dev->buf_size = 1024;
> + dev->buf_size = BUF_SIZE;
This seems to have zero added value.
> dev->buf = malloc(dev->buf_size);
> assert(dev->buf);
> dev->control = open("/dev/vhost-test", O_RDWR);
> @@ -396,7 +399,8 @@ int main(int argc, char **argv)
>
> done:
> vdev_info_init(&dev, features);
> - vq_info_add(&dev, 256);
> - run_test(&dev, &dev.vqs[0], delayed, batch, reset, 0x100000);
> + vq_info_add(&dev, RINGSIZE);
> +
> + run_test(&dev, &dev.vqs[0], delayed, batch, reset, TEST_BUF_NUM);
> return 0;
This replacement does not buy us anything either.
> }
> --
> 2.17.1
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Guo Zhi <qtxuning1999@sjtu.edu.cn>
Cc: jasowang@redhat.com, eperezma@redhat.com,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, sgarzare@redhat.com
Subject: Re: [PATCH v2 2/4] virtio_test: move magic number in code as defined constant
Date: Thu, 7 Jul 2022 01:09:55 -0400 [thread overview]
Message-ID: <20220707010036-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220707024409.1869-3-qtxuning1999@sjtu.edu.cn>
On Thu, Jul 07, 2022 at 10:44:07AM +0800, Guo Zhi wrote:
> We should avoid using magic numbers directly.
Not necessarily. For repeated values - I guess.
But this kind of thing:
#define BUF_SIZE 1024
int buf_size = BUF_SIZE;
brings no benefit IMHO.
And this has cost - values are now removed from code.
> Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
> ---
> tools/virtio/virtio_test.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
> index 95f78b311..1ecd64271 100644
> --- a/tools/virtio/virtio_test.c
> +++ b/tools/virtio/virtio_test.c
> @@ -20,7 +20,10 @@
> #include "../../drivers/vhost/test.h"
>
> #define RANDOM_BATCH -1
> -
> +#define ALIGN 4096
> +#define RINGSIZE 256
> +#define TEST_BUF_NUM 0x100000
> +#define BUF_SIZE 1024
> /* Unused */
> void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
>
> @@ -100,8 +103,8 @@ static void vq_reset(struct vq_info *info, int num, struct virtio_device *vdev)
> if (info->vq)
> vring_del_virtqueue(info->vq);
>
> - memset(info->ring, 0, vring_size(num, 4096));
> - vring_init(&info->vring, num, info->ring, 4096);
> + memset(info->ring, 0, vring_size(num, ALIGN));
> + vring_init(&info->vring, num, info->ring, ALIGN);
> info->vq = __vring_new_virtqueue(info->idx, info->vring, vdev, true,
> false, vq_notify, vq_callback, "test");
> assert(info->vq);
> @@ -115,7 +118,7 @@ static void vq_info_add(struct vdev_info *dev, int num)
> info->idx = dev->nvqs;
> info->kick = eventfd(0, EFD_NONBLOCK);
> info->call = eventfd(0, EFD_NONBLOCK);
> - r = posix_memalign(&info->ring, 4096, vring_size(num, 4096));
> + r = posix_memalign(&info->ring, PAGE_SIZE, vring_size(num, ALIGN));
> assert(r >= 0);
> vq_reset(info, num, &dev->vdev);
> vhost_vq_setup(dev, info);
This is actually doing more than what commit log says.
> @@ -131,7 +134,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
> dev->vdev.features = features;
> INIT_LIST_HEAD(&dev->vdev.vqs);
> spin_lock_init(&dev->vdev.vqs_list_lock);
> - dev->buf_size = 1024;
> + dev->buf_size = BUF_SIZE;
This seems to have zero added value.
> dev->buf = malloc(dev->buf_size);
> assert(dev->buf);
> dev->control = open("/dev/vhost-test", O_RDWR);
> @@ -396,7 +399,8 @@ int main(int argc, char **argv)
>
> done:
> vdev_info_init(&dev, features);
> - vq_info_add(&dev, 256);
> - run_test(&dev, &dev.vqs[0], delayed, batch, reset, 0x100000);
> + vq_info_add(&dev, RINGSIZE);
> +
> + run_test(&dev, &dev.vqs[0], delayed, batch, reset, TEST_BUF_NUM);
> return 0;
This replacement does not buy us anything either.
> }
> --
> 2.17.1
next prev parent reply other threads:[~2022-07-07 5:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 2:44 [PATCH v2 0/4] virtio/virtio_test Guo Zhi
2022-07-07 2:44 ` [PATCH v2 1/4] virtio_test: kick vhost for a batch of descriptors Guo Zhi
2022-07-07 2:44 ` [PATCH v2 2/4] virtio_test: move magic number in code as defined constant Guo Zhi
2022-07-07 5:09 ` Michael S. Tsirkin [this message]
2022-07-07 5:09 ` Michael S. Tsirkin
2022-07-07 6:17 ` Guo Zhi
2022-07-07 7:36 ` Michael S. Tsirkin
2022-07-07 7:36 ` Michael S. Tsirkin
2022-07-07 12:15 ` Guo Zhi
2022-07-07 12:19 ` Guo Zhi
2022-07-07 2:44 ` [PATCH v2 3/4] virtio_test: use random length scatterlists to test descriptor chain Guo Zhi
2022-07-07 5:16 ` Michael S. Tsirkin
2022-07-07 5:16 ` Michael S. Tsirkin
2022-07-07 6:24 ` Guo Zhi
2022-07-07 2:44 ` [PATCH v2 4/4] virtio_test: enable indirection feature Guo Zhi
2022-07-07 4:59 ` Michael S. Tsirkin
2022-07-07 4:59 ` Michael S. Tsirkin
2022-07-07 5:56 ` Guo Zhi
2022-07-07 5:59 ` Michael S. Tsirkin
2022-07-07 5:59 ` Michael S. Tsirkin
2022-07-07 6:05 ` Guo Zhi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220707010036-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=eperezma@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=qtxuning1999@sjtu.edu.cn \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.