zcrx: Get the page size at runtime
PATCH v3 1/1 zcrx: Get the page size at runtime
Use the API sysconf() to query page size at runtime, instead of using hard code number 4096.
Signed-off-by Haiyue Wang <[email protected]>
---
v3:
- Fix the whitespace damage for line 'parse_opts'
v2:
- Use 'sysconf(_SC_PAGESIZE)' to get page size at runtime
--- examples/zcrx.c | 18 ++++++++++++------ test/zcrx.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-)
examples/zcrx.c +12 -6
@@ -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,6 +329,12 @@ static void parse_opts(int argc, char **argv)int main (int argc,char **argv) { + page_size =sysconf (_SC_PAGESIZE); +if (page_size <0 ) { +perror ("sysconf(_SC_PAGESIZE)" ); +return 1 ; + } +parse_opts (argc, argv);run_server ();return 0 ;
test/zcrx.c +9 -2
@@ -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 ) {
Signature · 1 line
2.49.0
Quoted 4 lines · Haiyue Wang
Use the API
sysconf()to query page size at runtime, instead of using hard code number 4096.
Applied, thanks!
[1/1] zcrx: Get the page size at runtime
commit: 4b1102ba64e29db81a9481bdb4ed2b8ecfd77264
Best regards,
Signature · 1 line
Jens Axboe