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 3/4] examples/zcrx: constants for request types
Date: Mon, 21 Apr 2025 08:25:31 +0100 [thread overview]
Message-ID: <c562d397d5983909de8c6c5685d1471a73b00256.1745220124.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1745220124.git.asml.silence@gmail.com>
Instead of hard coding user_data, name request types we need and use
them.
Reviewed-by: David Wei <dw@davidwei.uk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
examples/zcrx.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/examples/zcrx.c b/examples/zcrx.c
index 5b06bb4c..e5c3c6ec 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -43,6 +43,14 @@ static long page_size;
#define AREA_SIZE (8192 * page_size)
#define SEND_SIZE (512 * 4096)
+#define REQ_TYPE_SHIFT 3
+#define REQ_TYPE_MASK ((1UL << REQ_TYPE_SHIFT) - 1)
+
+enum request_type {
+ REQ_TYPE_ACCEPT = 1,
+ REQ_TYPE_RX = 2,
+};
+
static int cfg_port = 8000;
static const char *cfg_ifname;
static int cfg_queue_id = -1;
@@ -136,7 +144,7 @@ static void add_accept(struct io_uring *ring, int sockfd)
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
io_uring_prep_accept(sqe, sockfd, NULL, NULL, 0);
- sqe->user_data = 1;
+ sqe->user_data = REQ_TYPE_ACCEPT;
}
static void add_recvzc(struct io_uring *ring, int sockfd, size_t len)
@@ -146,7 +154,7 @@ static void add_recvzc(struct io_uring *ring, int sockfd, size_t len)
io_uring_prep_rw(IORING_OP_RECV_ZC, sqe, sockfd, NULL, len, 0);
sqe->ioprio |= IORING_RECV_MULTISHOT;
sqe->zcrx_ifq_idx = zcrx_id;
- sqe->user_data = 2;
+ sqe->user_data = REQ_TYPE_RX;
}
static void process_accept(struct io_uring *ring, struct io_uring_cqe *cqe)
@@ -217,12 +225,16 @@ static void server_loop(struct io_uring *ring)
io_uring_submit_and_wait(ring, 1);
io_uring_for_each_cqe(ring, head, cqe) {
- if (cqe->user_data == 1)
+ switch (cqe->user_data & REQ_TYPE_MASK) {
+ case REQ_TYPE_ACCEPT:
process_accept(ring, cqe);
- else if (cqe->user_data == 2)
+ break;
+ case REQ_TYPE_RX:
process_recvzc(ring, cqe);
- else
+ break;
+ default:
t_error(1, 0, "unknown cqe");
+ }
count++;
}
io_uring_cq_advance(ring, count);
--
2.48.1
next prev 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 ` [PATCH liburing v2 2/4] examples/zcrx: rework size limiting Pavel Begunkov
2025-04-21 7:25 ` Pavel Begunkov [this message]
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=c562d397d5983909de8c6c5685d1471a73b00256.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