public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing v1] zcrx: Get the page size at runtime
@ 2025-04-19 13:38 Haiyue Wang
  2025-04-19 15:12 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Haiyue Wang @ 2025-04-19 13:38 UTC (permalink / raw)
  To: io-uring; +Cc: Haiyue Wang

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-19 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-19 13:38 [PATCH liburing v1] zcrx: Get the page size at runtime Haiyue Wang
2025-04-19 15:12 ` Jens Axboe
2025-04-19 16:51   ` Haiyue Wang

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