Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3195187imw; Wed, 6 Jul 2022 19:57:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1Yw3awweESIm9U5fuutB3zk3SfyYTgztR9BHu01wa+/MtZsuW45u+bRANv03NVFu1/RsL X-Received: by 2002:a17:902:a502:b0:151:8289:b19 with SMTP id s2-20020a170902a50200b0015182890b19mr49601446plq.149.1657162631164; Wed, 06 Jul 2022 19:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657162631; cv=none; d=google.com; s=arc-20160816; b=DSDUv5B9cdy2ajB8UfixK7bEUhpl1TJt43uz5ZzZdaWHW5Cl+zRdLFDmx4XFlYEOwT 9lt3pKV5Mmg92yWsZ9mjvhsGy/rKvasBItq3K6x4a6T6lYmF4eTvbkjMnmT0mSvZs8U6 drCvbaN8riTKMiktxGK7Yl1bAuo9tlyYdVwjSladWyKmIYUBrEvM3cFnjTTZUxYEcba7 iZJ0HyqDQxfMqIafk0i2vhqMyya4/0qA3FPC/90ZpwoMmAJtrogZrshkdsT/yqN7c8HK pa39E/sQcfIGa8fKJCg6rLocEPV2fmGP3ktVhmVMm/zj7JEmZfxhd4Sui3/EoCmYfiF/ EIlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=2W1RyO3k5Sf0842oipiQKpnTL9mgQfqFGfW3S9H0txk=; b=HRkvnPtwE28dTRGzxlrek815hFeNJla4x3Xn0dnGqhNVKo4xkfzPdtcNj/pqoUE1VP wK81Loen9J9XLTi+h8J8xYuFwV5B/CK6fipMeYpKMIhjA1x+0/oiKRFF5uViGpHGkLey /O9pcTylhTWusrpHdGSIQD/br2giolVH16FUgrtgMwhU+GjD8iBSIUfRNcioVLTChnjD WIotk8hLxSmYA4V+ZLLmq7Gdky7ZcY3A67yYzVG3UUdP5PTjBci8JGfPcGe5ofVXpMRV iNM0X1r5E1Bx1TvIK8Blm952+ASAKQdja52O5AqEdsegJAmswgOQo/VMb7ewhmhNw6/H kpPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a17090301c500b0016bf2bf7c2dsi3076635plh.237.2022.07.06.19.56.56; Wed, 06 Jul 2022 19:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234810AbiGGCzc (ORCPT + 99 others); Wed, 6 Jul 2022 22:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234177AbiGGCzb (ORCPT ); Wed, 6 Jul 2022 22:55:31 -0400 Received: from smtp236.sjtu.edu.cn (smtp236.sjtu.edu.cn [202.120.2.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 036612E9FE for ; Wed, 6 Jul 2022 19:55:30 -0700 (PDT) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 8A4131008B388; Thu, 7 Jul 2022 10:44:39 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 6F06F200A5BFF; Thu, 7 Jul 2022 10:44:39 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id e5TwBO-loqPR; Thu, 7 Jul 2022 10:44:39 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 464792009BEA0; Thu, 7 Jul 2022 10:44:30 +0800 (CST) From: Guo Zhi To: jasowang@redhat.com, mst@redhat.com Cc: eperezma@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, sgarzare@redhat.com, Guo Zhi Subject: [PATCH v2 2/4] virtio_test: move magic number in code as defined constant Date: Thu, 7 Jul 2022 10:44:07 +0800 Message-Id: <20220707024409.1869-3-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> References: <20220707024409.1869-1-qtxuning1999@sjtu.edu.cn> X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,RCVD_IN_SORBS_WEB, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We should avoid using magic numbers directly. Signed-off-by: Guo Zhi --- 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); @@ -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; 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; } -- 2.17.1