lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat,  9 Jul 2022 10:27:45 +0800
From:   Guo Zhi <qtxuning1999@...u.edu.cn>
To:     jasowang@...hat.com, mst@...hat.com
Cc:     eperezma@...hat.com, virtualization@...ts.linux-foundation.org,
        linux-kernel@...r.kernel.org, sgarzare@...hat.com,
        Guo Zhi <qtxuning1999@...u.edu.cn>
Subject: [PATCH v3 4/4] virtio_test: pregenerate random numbers

random numbers on data path is expensive, using a rand pool to
pregenerate them before tests start

Signed-off-by: Guo Zhi <qtxuning1999@...u.edu.cn>
---
 tools/virtio/virtio_test.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 8f3ef3a78..7cc43e5bf 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -23,6 +23,7 @@
 #define MAX_SG_FRAGS 8UL
 #define RINGSIZE   256
 #define INDIRECT_TABLE_SIZE   (RINGSIZE * sizeof(struct vring_desc) * 8)
+#define RAND_POOL_SIZE 4096
 
 void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
 
@@ -199,6 +200,8 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
 {
 	struct scatterlist sg[MAX_SG_FRAGS];
 	int sg_size = 0;
+	int rand_pool[RAND_POOL_SIZE];
+	unsigned int rand_idx;
 	long started = 0, completed = 0, next_reset = reset_n;
 	long completed_before, started_before;
 	int r, test = 1;
@@ -213,6 +216,10 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
 		next_reset = INT_MAX;
 	}
 
+	/* Init rand pool */
+	for (rand_idx = 0; rand_idx < RAND_POOL_SIZE; ++rand_idx)
+		rand_pool[rand_idx] = random();
+
 	/* Don't kfree indirect_table. */
 	__kfree_ignore_start = dev->indirect_table;
 	__kfree_ignore_end = dev->indirect_table + dev->indirect_table_size;
@@ -225,11 +232,13 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
 		do {
 			const bool reset = completed > next_reset;
 			if (random_batch)
-				batch = (random() % vq->vring.num) + 1;
+				batch = (rand_pool[rand_idx++ % RAND_POOL_SIZE]
+						% vq->vring.num) + 1;
 
 			while (started < bufs &&
 			       (started - completed) < batch) {
-				sg_size = random() % (MAX_SG_FRAGS - 1) + 1;
+				sg_size = (rand_pool[rand_idx++ % RAND_POOL_SIZE]
+						% (MAX_SG_FRAGS - 1)) + 1;
 				sg_init_table(sg, sg_size);
 				for (int i = 0; i < sg_size; ++i)
 					sg_set_buf(&sg[i], dev->buf + i, 0x1);
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ