[PATCH] example/io_uring-test.c: change to use real readv

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Readv can read vecs in one sqe instead of multi sqe.

Signed-off-by: Bob Liu <bob.liu@xxxxxxxxxx>
---
 examples/io_uring-test.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/examples/io_uring-test.c b/examples/io_uring-test.c
index 4f5ebf6..96fa4d1 100644
--- a/examples/io_uring-test.c
+++ b/examples/io_uring-test.c
@@ -20,7 +20,6 @@ int main(int argc, char *argv[])
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	struct iovec *iovecs;
-	off_t offset;
 	void *buf;
 
 	if (argc < 2) {
@@ -28,7 +27,7 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
-	ret = io_uring_queue_init(QD, &ring, 0);
+	ret = io_uring_queue_init(1, &ring, 0);
 	if (ret < 0) {
 		fprintf(stderr, "queue_init: %s\n", strerror(-ret));
 		return 1;
@@ -48,16 +47,10 @@ int main(int argc, char *argv[])
 		iovecs[i].iov_len = 4096;
 	}
 
-	offset = 0;
-	i = 0;
-	do {
-		sqe = io_uring_get_sqe(&ring);
-		if (!sqe)
-			break;
-		io_uring_prep_readv(sqe, fd, &iovecs[i], 1, offset);
-		offset += iovecs[i].iov_len;
-		i++;
-	} while (1);
+	sqe = io_uring_get_sqe(&ring);
+	if (!sqe)
+		return 1;
+	io_uring_prep_readv(sqe, fd, iovecs, QD, 0);
 
 	ret = io_uring_submit(&ring);
 	if (ret < 0) {
@@ -76,8 +69,8 @@ int main(int argc, char *argv[])
 
 		done++;
 		ret = 0;
-		if (cqe->res != 4096) {
-			fprintf(stderr, "ret=%d, wanted 4096\n", cqe->res);
+		if (cqe->res != 4096 * QD) {
+			fprintf(stderr, "ret=%d, wanted=%d\n", cqe->res, 4096*QD);
 			ret = 1;
 		}
 		io_uring_cqe_seen(&ring, cqe);
-- 
2.17.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux