public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Wei <dw@davidwei.uk>
Subject: [PATCH liburing v2 2/4] examples/zcrx: rework size limiting
Date: Mon, 21 Apr 2025 08:25:30 +0100	[thread overview]
Message-ID: <236d055a6864ba1dc57f62727be36ca985da9e4e.1745220124.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1745220124.git.asml.silence@gmail.com>

zcrx doesn't work in a single shot mode, we can limit the number of
bytes it processes but not the number of cqes. Replace cfg_oneshot with
total byte size limiting.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/zcrx.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/examples/zcrx.c b/examples/zcrx.c
index 727943c4..5b06bb4c 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -46,9 +46,8 @@ static long page_size;
 static int cfg_port = 8000;
 static const char *cfg_ifname;
 static int cfg_queue_id = -1;
-static bool cfg_oneshot;
-static int cfg_oneshot_recvs;
 static bool cfg_verify_data = false;
+static size_t cfg_size = 0;
 static struct sockaddr_in6 cfg_addr;
 
 static void *area_ptr;
@@ -158,7 +157,7 @@ static void process_accept(struct io_uring *ring, struct io_uring_cqe *cqe)
 		t_error(1, 0, "Unexpected second connection");
 
 	connfd = cqe->res;
-	add_recvzc(ring, connfd, cfg_oneshot ? page_size : 0);
+	add_recvzc(ring, connfd, cfg_size);
 }
 
 static void verify_data(char *data, size_t size, unsigned long seq)
@@ -176,7 +175,8 @@ static void verify_data(char *data, size_t size, unsigned long seq)
 	}
 }
 
-static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe)
+static void process_recvzc(struct io_uring __attribute__((unused)) *ring,
+			   struct io_uring_cqe *cqe)
 {
 	unsigned rq_mask = rq_ring.ring_entries - 1;
 	struct io_uring_zcrx_cqe *rcqe;
@@ -184,22 +184,16 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe)
 	uint64_t mask;
 	char *data;
 
-	if (cqe->res < 0)
-		t_error(1, 0, "recvzc(): %d", cqe->res);
-
-	if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs == 0) {
+	if (!(cqe->flags & IORING_CQE_F_MORE)) {
+		if (!cfg_size || cqe->res != 0)
+			t_error(1, 0, "invalid final recvzc ret %i", cqe->res);
+		if (received != cfg_size)
+			t_error(1, 0, "total receive size mismatch %lu / %lu",
+				received, cfg_size);
 		stop = true;
-		return;
-	}
-
-	if (cfg_oneshot) {
-		if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) {
-			add_recvzc(ring, connfd, page_size);
-			cfg_oneshot_recvs--;
-		}
-	} else if (!(cqe->flags & IORING_CQE_F_MORE)) {
-		add_recvzc(ring, connfd, 0);
 	}
+	if (cqe->res < 0)
+		t_error(1, 0, "recvzc(): %d", cqe->res);
 
 	rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1);
 	mask = (1ULL << IORING_ZCRX_AREA_SHIFT) - 1;
@@ -286,7 +280,7 @@ static void parse_opts(int argc, char **argv)
 	if (argc <= 1)
 		usage(argv[0]);
 
-	while ((c = getopt(argc, argv, "vp:i:q:o:")) != -1) {
+	while ((c = getopt(argc, argv, "vp:i:q:s:")) != -1) {
 		switch (c) {
 		case 'p':
 			cfg_port = strtoul(optarg, NULL, 0);
@@ -294,11 +288,9 @@ static void parse_opts(int argc, char **argv)
 		case 'i':
 			cfg_ifname = optarg;
 			break;
-		case 'o': {
-			cfg_oneshot = true;
-			cfg_oneshot_recvs = strtoul(optarg, NULL, 0);
+		case 's':
+			cfg_size = strtoul(optarg, NULL, 0);
 			break;
-		}
 		case 'q':
 			cfg_queue_id = strtoul(optarg, NULL, 0);
 			break;
-- 
2.48.1


  parent reply	other threads:[~2025-04-21  7:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-21  7:25 [PATCH liburing v2 0/4] zcrx refill queue allocation modes Pavel Begunkov
2025-04-21  7:25 ` [PATCH liburing v2 1/4] examples/zcrx: consolidate add_recvzc variants Pavel Begunkov
2025-04-21  7:25 ` Pavel Begunkov [this message]
2025-04-21  7:25 ` [PATCH liburing v2 3/4] examples/zcrx: constants for request types Pavel Begunkov
2025-04-21  7:25 ` [PATCH liburing v2 4/4] examples/zcrx: add refill queue allocation modes Pavel Begunkov
2025-04-21 15:26 ` [PATCH liburing v2 0/4] zcrx " Jens Axboe

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 \
    --in-reply-to=236d055a6864ba1dc57f62727be36ca985da9e4e.1745220124.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=dw@davidwei.uk \
    --cc=io-uring@vger.kernel.org \
    /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