public inbox for [email protected]
 help / color / mirror / Atom feed
From: Bob Liu <[email protected]>
To: [email protected]
Cc: [email protected], Bob Liu <[email protected]>
Subject: [PATCH] example/io_uring-test.c: change to use real readv
Date: Mon, 17 Feb 2020 21:37:07 +0800	[thread overview]
Message-ID: <[email protected]> (raw)

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


                 reply	other threads:[~2020-02-17 13:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox