public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] example/io_uring-test.c: change to use real readv
@ 2020-02-17 13:37 Bob Liu
  0 siblings, 0 replies; only message in thread
From: Bob Liu @ 2020-02-17 13:37 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Bob Liu

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

Signed-off-by: Bob Liu <[email protected]>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-17 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-17 13:37 [PATCH] example/io_uring-test.c: change to use real readv Bob Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox