Commit df8cf324 authored by Haiyue Wang's avatar Haiyue Wang Committed by Jakub Kicinski
Browse files

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: default avatarHaiyue Wang <haiyuewa@163.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarDavid Wei <dw@davidwei.uk>
Link: https://patch.msgid.link/20250419141044.10304-1-haiyuewa@163.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 5565acd1
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@

#include <liburing.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)
#define min(a, b) \
	({ \
@@ -66,7 +66,7 @@ static int cfg_oneshot_recvs;
static int cfg_send_size = SEND_SIZE;
static struct sockaddr_in6 cfg_addr;

static char payload[SEND_SIZE] __attribute__((aligned(PAGE_SIZE)));
static char *payload;
static void *area_ptr;
static void *ring_ptr;
static size_t ring_size;
@@ -114,8 +114,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 ALIGN_UP(ring_size, 4096);
	ring_size += page_size;
	return ALIGN_UP(ring_size, page_size);
}

static void setup_zcrx(struct io_uring *ring)
@@ -219,7 +219,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);
}
@@ -245,7 +245,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)) {
@@ -370,7 +370,7 @@ static void usage(const char *filepath)

static void parse_opts(int argc, char **argv)
{
	const int max_payload_len = sizeof(payload) -
	const int max_payload_len = SEND_SIZE -
				    sizeof(struct ipv6hdr) -
				    sizeof(struct tcphdr) -
				    40 /* max tcp options */;
@@ -443,6 +443,13 @@ int main(int argc, char **argv)
	const char *cfg_test = argv[argc - 1];
	int i;

	page_size = sysconf(_SC_PAGESIZE);
	if (page_size < 0)
		return 1;

	if (posix_memalign((void **)&payload, page_size, SEND_SIZE))
		return 1;

	parse_opts(argc, argv);

	for (i = 0; i < SEND_SIZE; i++)