Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: iou-zcrx: Get the page size at runtime

Use the API `sysconf()` to query page size at runtime, instead of using
hard code number 4096.

And use `posix_memalign` to allocate the page size aligned momory.

Signed-off-by: Haiyue Wang <haiyuewa@163.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: David Wei <dw@davidwei.uk>
Link: https://patch.msgid.link/20250419141044.10304-1-haiyuewa@163.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Haiyue Wang and committed by
Jakub Kicinski
df8cf324 5565acd1

+15 -8
+15 -8
tools/testing/selftests/drivers/net/hw/iou-zcrx.c
··· 37 37 38 38 #include <liburing.h> 39 39 40 - #define PAGE_SIZE (4096) 41 - #define AREA_SIZE (8192 * PAGE_SIZE) 40 + static long page_size; 41 + #define AREA_SIZE (8192 * page_size) 42 42 #define SEND_SIZE (512 * 4096) 43 43 #define min(a, b) \ 44 44 ({ \ ··· 66 66 static int cfg_send_size = SEND_SIZE; 67 67 static struct sockaddr_in6 cfg_addr; 68 68 69 - static char payload[SEND_SIZE] __attribute__((aligned(PAGE_SIZE))); 69 + static char *payload; 70 70 static void *area_ptr; 71 71 static void *ring_ptr; 72 72 static size_t ring_size; ··· 114 114 115 115 ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe); 116 116 /* add space for the header (head/tail/etc.) */ 117 - ring_size += PAGE_SIZE; 118 - return ALIGN_UP(ring_size, 4096); 117 + ring_size += page_size; 118 + return ALIGN_UP(ring_size, page_size); 119 119 } 120 120 121 121 static void setup_zcrx(struct io_uring *ring) ··· 219 219 220 220 connfd = cqe->res; 221 221 if (cfg_oneshot) 222 - add_recvzc_oneshot(ring, connfd, PAGE_SIZE); 222 + add_recvzc_oneshot(ring, connfd, page_size); 223 223 else 224 224 add_recvzc(ring, connfd); 225 225 } ··· 245 245 246 246 if (cfg_oneshot) { 247 247 if (cqe->res == 0 && cqe->flags == 0 && cfg_oneshot_recvs) { 248 - add_recvzc_oneshot(ring, connfd, PAGE_SIZE); 248 + add_recvzc_oneshot(ring, connfd, page_size); 249 249 cfg_oneshot_recvs--; 250 250 } 251 251 } else if (!(cqe->flags & IORING_CQE_F_MORE)) { ··· 370 370 371 371 static void parse_opts(int argc, char **argv) 372 372 { 373 - const int max_payload_len = sizeof(payload) - 373 + const int max_payload_len = SEND_SIZE - 374 374 sizeof(struct ipv6hdr) - 375 375 sizeof(struct tcphdr) - 376 376 40 /* max tcp options */; ··· 442 442 { 443 443 const char *cfg_test = argv[argc - 1]; 444 444 int i; 445 + 446 + page_size = sysconf(_SC_PAGESIZE); 447 + if (page_size < 0) 448 + return 1; 449 + 450 + if (posix_memalign((void **)&payload, page_size, SEND_SIZE)) 451 + return 1; 445 452 446 453 parse_opts(argc, argv); 447 454