From: Haiyue Wang <haiyuewa@163.com>
To: io-uring@vger.kernel.org
Cc: Haiyue Wang <haiyuewa@163.com>
Subject: [PATCH liburing v1] zcrx: Get the page size at runtime
Date: Sat, 19 Apr 2025 21:38:06 +0800 [thread overview]
Message-ID: <20250419133819.7633-1-haiyuewa@163.com> (raw)
Use the API `sysconf()` to query page size at runtime, instead of using
hard code number 4096.
Signed-off-by: Haiyue Wang <haiyuewa@163.com>
---
examples/zcrx.c | 20 +++++++++++++-------
test/zcrx.c | 11 +++++++++--
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/examples/zcrx.c b/examples/zcrx.c
index 8393cfe..9a9b8b9 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -39,8 +39,8 @@
#include "liburing.h"
#include "helpers.h"
-#define PAGE_SIZE (4096)
-#define AREA_SIZE (8192 * PAGE_SIZE)
+static long page_size;
+#define AREA_SIZE (8192 * page_size)
#define SEND_SIZE (512 * 4096)
static int cfg_port = 8000;
@@ -65,8 +65,8 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries)
{
ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe);
/* add space for the header (head/tail/etc.) */
- ring_size += PAGE_SIZE;
- return T_ALIGN_UP(ring_size, 4096);
+ ring_size += page_size;
+ return T_ALIGN_UP(ring_size, page_size);
}
static void setup_zcrx(struct io_uring *ring)
@@ -169,7 +169,7 @@ static void process_accept(struct io_uring *ring, struct io_uring_cqe *cqe)
connfd = cqe->res;
if (cfg_oneshot)
- add_recvzc_oneshot(ring, connfd, PAGE_SIZE);
+ add_recvzc_oneshot(ring, connfd, page_size);
else
add_recvzc(ring, connfd);
}
@@ -207,7 +207,7 @@ static void process_recvzc(struct io_uring *ring, struct io_uring_cqe *cqe)
if (cfg_oneshot) {
if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) {
- add_recvzc_oneshot(ring, connfd, PAGE_SIZE);
+ add_recvzc_oneshot(ring, connfd, page_size);
cfg_oneshot_recvs--;
}
} else if (!(cqe->flags & IORING_CQE_F_MORE)) {
@@ -329,7 +329,13 @@ static void parse_opts(int argc, char **argv)
int main(int argc, char **argv)
{
- parse_opts(argc, argv);
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ perror("sysconf(_SC_PAGESIZE)");
+ return 1;
+ }
+
+ parse_opts(argc, argv);
run_server();
return 0;
}
diff --git a/test/zcrx.c b/test/zcrx.c
index b60462a..61c984d 100644
--- a/test/zcrx.c
+++ b/test/zcrx.c
@@ -19,10 +19,11 @@
static unsigned int ifidx, rxq;
+static long page_size;
+
/* the hw rxq must consume 128 of these pages, leaving 4 left */
#define AREA_PAGES 132
-#define PAGE_SIZE 4096
-#define AREA_SZ AREA_PAGES * PAGE_SIZE
+#define AREA_SZ (AREA_PAGES * page_size)
#define RQ_ENTRIES 128
/* this is one more than the # of free pages after filling hw rxq */
#define LOOP_COUNT 5
@@ -822,6 +823,12 @@ int main(int argc, char *argv[])
if (argc > 1)
return T_EXIT_SKIP;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ perror("sysconf(_SC_PAGESIZE)");
+ return T_EXIT_FAIL;
+ }
+
area_outer = mmap(NULL, AREA_SZ + 8192, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
if (area_outer == MAP_FAILED) {
--
2.49.0
next reply other threads:[~2025-04-19 13:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-19 13:38 Haiyue Wang [this message]
2025-04-19 15:12 ` [PATCH liburing v1] zcrx: Get the page size at runtime Jens Axboe
2025-04-19 16:51 ` Haiyue Wang
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=20250419133819.7633-1-haiyuewa@163.com \
--to=haiyuewa@163.com \
--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