public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 3/6] test/zc: allocate buffers dynamically
Date: Thu,  4 Aug 2022 15:20:22 +0100	[thread overview]
Message-ID: <55d91cebef205ca8bf9c004980f36eca06dae966.1659622771.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

A prep patch, allocate receive and transfer buffers dynamically.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/send-zerocopy.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index 7999f46..a572407 100644
--- a/test/send-zerocopy.c
+++ b/test/send-zerocopy.c
@@ -46,7 +46,6 @@
 
 #define NR_SLOTS 5
 #define ZC_TAG 10000
-#define MAX_PAYLOAD 8195
 #define BUFFER_OFFSET 41
 
 #ifndef ARRAY_SIZE
@@ -54,14 +53,8 @@
 #endif
 
 static int seqs[NR_SLOTS];
-static char tx_buffer[MAX_PAYLOAD] __attribute__((aligned(4096)));
-static char rx_buffer[MAX_PAYLOAD] __attribute__((aligned(4096)));
-static struct iovec buffers_iov[] = {
-	{ .iov_base = tx_buffer,
-	  .iov_len = sizeof(tx_buffer), },
-	{ .iov_base = tx_buffer + BUFFER_OFFSET,
-	  .iov_len = sizeof(tx_buffer) - BUFFER_OFFSET - 13, },
-};
+static char *tx_buffer, *rx_buffer;
+static struct iovec buffers_iov[2];
 
 static inline bool tag_userdata(__u64 user_data)
 {
@@ -662,7 +655,7 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se
 	char *buf = buffers_iov[buf_idx].iov_base;
 
 	assert(send_size <= buffers_iov[buf_idx].iov_len);
-	memset(rx_buffer, 0, sizeof(rx_buffer));
+	memset(rx_buffer, 0, send_size);
 
 	for (i = 0; i < nr_reqs; i++) {
 		bool cur_fixed_buf = fixed_buf;
@@ -804,10 +797,23 @@ int main(int argc, char *argv[])
 {
 	struct io_uring ring;
 	int i, ret, sp[2];
+	size_t len = 8096;
 
 	if (argc > 1)
 		return T_EXIT_SKIP;
 
+	tx_buffer = aligned_alloc(4096, len);
+	rx_buffer = aligned_alloc(4096, len);
+	if (!tx_buffer || !rx_buffer) {
+		fprintf(stderr, "can't allocate buffers\n");
+		return T_EXIT_FAIL;
+	}
+
+	buffers_iov[0].iov_base = tx_buffer;
+	buffers_iov[0].iov_len = len;
+	buffers_iov[1].iov_base = tx_buffer + BUFFER_OFFSET;
+	buffers_iov[1].iov_len = len - BUFFER_OFFSET - 13;
+
 	ret = io_uring_queue_init(32, &ring, 0);
 	if (ret) {
 		fprintf(stderr, "queue init failed: %d\n", ret);
@@ -824,8 +830,9 @@ int main(int argc, char *argv[])
 	}
 
 	srand((unsigned)time(NULL));
-	for (i = 0; i < sizeof(tx_buffer); i++)
+	for (i = 0; i < len; i++)
 		tx_buffer[i] = i;
+	memset(rx_buffer, 0, len);
 
 	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
 		perror("Failed to create Unix-domain socket pair\n");
-- 
2.37.0


  parent reply	other threads:[~2022-08-04 14:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 14:20 [PATCH liburing 0/6] improve zeoropy testing Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 1/6] test/zc: improve error messages Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 2/6] tests/zc: test tcp Pavel Begunkov
2022-08-04 14:20 ` Pavel Begunkov [this message]
2022-08-04 14:20 ` [PATCH liburing 4/6] test/zc: handle short rx Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 5/6] test/zc: recv asynchronously Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 6/6] test/zc: test short zc send Pavel Begunkov
2022-08-04 22:22 ` [PATCH liburing 0/6] improve zeoropy testing Jens Axboe

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=55d91cebef205ca8bf9c004980f36eca06dae966.1659622771.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /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