From patchwork Mon Sep 5 14:21:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12966185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87B00ECAAD5 for ; Mon, 5 Sep 2022 14:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbiIEOXf (ORCPT ); Mon, 5 Sep 2022 10:23:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236801AbiIEOX3 (ORCPT ); Mon, 5 Sep 2022 10:23:29 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D5654D17D for ; Mon, 5 Sep 2022 07:23:28 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id qh18so17414598ejb.7 for ; Mon, 05 Sep 2022 07:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=+6GKmuMBvxvZ7P18wLcMpxJrZ6oY37ClDCfrGbE2Lhw=; b=nitVqB7/lmXkA+TJUD65MfrR/09V90JB6Dsw6k6tUbDAMHhE2clan9N/fTte8mtjW+ Qmif1CJKAgGZrPpzJ3jn/CGolQZ5P8plz5vMDshq08vgl1Uilwr8P8kUCKkYm0e7QjHe gxxyJCsjNdXnYeum0x3HXc2RViPWXmxp3BTp1/oMuccygdHaoJrXBnc799LOkeHNaFei JY0AT+BNVmhEMVuKH2D+rD8rMvVy5E2rC0TxlOcelkjWBNcPMCWIAaeO8Ujr/lZaDJEz c89gW0ZMD2bAcNMWLlaTNfP1QTS8I+jozOo9uwLf7FBzBTYeevbfmwzkRG8sJJRm4uKB r0Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=+6GKmuMBvxvZ7P18wLcMpxJrZ6oY37ClDCfrGbE2Lhw=; b=tzCcdlbBnp6x/jxeAwp+YEFxd+vZ6i4bevJ9vVfuyt8f5Yj+wAp77zOzJzvSaHZ5KP 6u1w9LKJOhMjhrnXOmuhs5KYatNHG+BPjyztK8/TMbbg/LLnp7OwQwDGCPKSffzL+qjl OgUYMqM8h8qH5NEMbXU4CAOKdSooYGmVQYtItIOpFZqmRZxy89fRKGLeGWy0+siFfx74 mSND6LVE18XSCF12/mM7QsAtEcwCqKdwTCEbF/1nBEFV/BxdXTz1MeWvqvkS7T3GV1OB fG/uywXuOWoq1P/PNKyBhpX1x+qzkYY0a2vS6OxJfeDDxaBuYsGQyni4H1xNFWM4jI44 /xvA== X-Gm-Message-State: ACgBeo0l62WOesGrjHRdhZ/81QSsc7/OO0Ao3rp7kgThu2vViMXKK3+d SqB3ocvtTQfptt4Tl9MTZVAZEO2Cbug= X-Google-Smtp-Source: AA6agR6gUrX0NSJ3IZToa/Adpk2VYfUIK4fLHkI7pmmd2R6pyzW8oQOW5BOUWQI0N8YzPYqFZp9vzw== X-Received: by 2002:a17:907:a0c6:b0:741:d9a1:e2b6 with SMTP id hw6-20020a170907a0c600b00741d9a1e2b6mr21610869ejc.99.1662387806580; Mon, 05 Sep 2022 07:23:26 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a118]) by smtp.gmail.com with ESMTPSA id x10-20020a1709064bca00b0074182109623sm5168799ejv.39.2022.09.05.07.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 07:23:26 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 1/4] tests/zc: move send size calc into do_test_inet_send Date: Mon, 5 Sep 2022 15:21:03 +0100 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index 8714b6f..0a8531e 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -238,7 +238,7 @@ static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_server, bool fixed_buf, struct sockaddr_storage *addr, - size_t send_size, bool cork, bool mix_register, + bool small_send, bool cork, bool mix_register, int buf_idx, bool force_async) { const unsigned zc_flags = 0; @@ -246,13 +246,13 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se struct io_uring_cqe *cqe; int nr_reqs = cork ? 5 : 1; int i, ret, nr_cqes; + size_t send_size = small_send ? 137 : buffers_iov[buf_idx].iov_len; size_t chunk_size = send_size / nr_reqs; size_t chunk_size_last = send_size - chunk_size * (nr_reqs - 1); char *buf = buffers_iov[buf_idx].iov_base; pid_t p; int wstatus; - assert(send_size <= buffers_iov[buf_idx].iov_len); memset(rx_buffer, 0, send_size); for (i = 0; i < nr_reqs; i++) { @@ -394,7 +394,7 @@ static int test_inet_send(struct io_uring *ring) for (i = 0; i < 256; i++) { bool fixed_buf = i & 1; struct sockaddr_storage *addr_arg = (i & 2) ? &addr : NULL; - size_t size = (i & 4) ? 137 : 4096; + bool small_send = i & 4; bool cork = i & 8; bool mix_register = i & 16; bool aligned = i & 32; @@ -406,8 +406,7 @@ static int test_inet_send(struct io_uring *ring) continue; if (large_buf) { buf_idx = 2; - size = buffers_iov[buf_idx].iov_len; - if (!aligned || !tcp) + if (!aligned || !tcp || small_send) continue; } if (!buffers_iov[buf_idx].iov_base) @@ -420,7 +419,7 @@ static int test_inet_send(struct io_uring *ring) continue; ret = do_test_inet_send(ring, sock_client, sock_server, fixed_buf, - addr_arg, size, cork, mix_register, + addr_arg, small_send, cork, mix_register, buf_idx, force_async); if (ret) { fprintf(stderr, "send failed fixed buf %i, conn %i, addr %i, " @@ -535,8 +534,8 @@ int main(int argc, char *argv[]) return T_EXIT_FAIL; } - buffers_iov[0].iov_base = tx_buffer; - buffers_iov[0].iov_len = 8192; + buffers_iov[0].iov_base = tx_buffer + 4096; + buffers_iov[0].iov_len = 4096; buffers_iov[1].iov_base = tx_buffer + BUFFER_OFFSET; buffers_iov[1].iov_len = 8192 - BUFFER_OFFSET - 13; From patchwork Mon Sep 5 14:21:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12966186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49F36C54EE9 for ; Mon, 5 Sep 2022 14:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbiIEOXg (ORCPT ); Mon, 5 Sep 2022 10:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237051AbiIEOXa (ORCPT ); Mon, 5 Sep 2022 10:23:30 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3F73B958 for ; Mon, 5 Sep 2022 07:23:29 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id b16so11581274edd.4 for ; Mon, 05 Sep 2022 07:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=hIx/uQLZr8G/oqBxR1JafNpk64QXFQUgFBNLn+IqcbQ=; b=lzz1RFQ9AZR42XudEozXp0RbZ7IjwuK8NAJYsQtsGZ1fwIKxreMhm+/YT7ixPxKk/U GZo1i/jzQ/V5KLiDUGxijuCouV2iDS8T0vC5BlzWKUivxjnoIGB7IT9n/Qsgumzfl7tg 0Hzj6jkr37SvqaO/Ng4i4DKSHBJnlRoiSndUD34bwyYrYOCaFeL0J/3XAqUKwoN4uvyF OuSwC/bFOHCkJUGgZcS42g4Y0btGuDybav66znAD5V05+mife/1cT0vAwYKEJb3y/nm8 RpA1kKfULhqCpTMHP8SRBNRO9p1Z8HdG3f2zj+gegob0vcIrdOwkWoUw0tPtEkMdHBe7 DOog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=hIx/uQLZr8G/oqBxR1JafNpk64QXFQUgFBNLn+IqcbQ=; b=MFyG4m/xg9GvNuyONi6xY+GXRob8ek7t5YKBOQrflISMqfNk90ZOznWzm7/6Jhnh6v NZasR0Omd5fxeG56e8CqFD6e/MzOr1zrowbYZVdZjwesrb1D0ziR5SuiPog5cDDzuFad mb1gUR5Os+37sR0LJ9tqxYMvjld56XQa5zIknKoqrzqHgQyjQhABkdgFmXTjEY5e8QFh 3mgylvB3GJxU97VVGckMiREjFXVEndJP4RubVBMMPoNM2eqOlAPg5INcrZ8oJ6hmVDfy SdipgEYUEZEP7g4bZwrkP95qtT+HM3oYa0kH8Yo9rbIO6GpxHGhX7Xf8qqvDGWrhWJss o06w== X-Gm-Message-State: ACgBeo3N83SwDNvBaF9RwKZbWCWfC56o8mPUm8XuY9fkhaIWpVVxIJDx kYbf7Kr1VTWmTmSYDEp3Ue2EKPlKSo0= X-Google-Smtp-Source: AA6agR5mq9IGSlttpWvWItpiptqVfoYoWblNGdyWLFraI0wrBAoJlAGFnzwHWFmO6FzffpLS+pmAsA== X-Received: by 2002:a05:6402:1f01:b0:445:fbe8:4b2e with SMTP id b1-20020a0564021f0100b00445fbe84b2emr43561862edb.192.1662387807350; Mon, 05 Sep 2022 07:23:27 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a118]) by smtp.gmail.com with ESMTPSA id x10-20020a1709064bca00b0074182109623sm5168799ejv.39.2022.09.05.07.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 07:23:26 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 2/4] tests/zc: use io_uring for rx Date: Mon, 5 Sep 2022 15:21:04 +0100 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Recieve via io_uring, this simplifies code by removing forking. Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 70 +++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index 0a8531e..f80a5cd 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -44,7 +44,7 @@ #define HOST "127.0.0.1" #define HOSTV6 "::1" -#define ZC_TAG 10000 +#define RX_TAG 10000 #define BUFFER_OFFSET 41 #ifndef ARRAY_SIZE @@ -250,8 +250,6 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se size_t chunk_size = send_size / nr_reqs; size_t chunk_size_last = send_size - chunk_size * (nr_reqs - 1); char *buf = buffers_iov[buf_idx].iov_base; - pid_t p; - int wstatus; memset(rx_buffer, 0, send_size); @@ -289,42 +287,17 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se sqe->flags |= IOSQE_ASYNC; } + sqe = io_uring_get_sqe(ring); + io_uring_prep_recv(sqe, sock_server, rx_buffer, send_size, MSG_WAITALL); + sqe->user_data = RX_TAG; + ret = io_uring_submit(ring); - if (ret != nr_reqs) { + if (ret != nr_reqs + 1) { fprintf(stderr, "submit failed, got %i expected %i\n", ret, nr_reqs); return 1; } - p = fork(); - if (p == -1) { - fprintf(stderr, "fork() failed\n"); - return 1; - } else if (p == 0) { - size_t bytes_received = 0; - - while (bytes_received != send_size) { - ret = recv(sock_server, - rx_buffer + bytes_received, - send_size - bytes_received, 0); - if (ret <= 0) { - fprintf(stderr, "recv failed, got %i, errno %i\n", - ret, errno); - exit(1); - } - bytes_received += ret; - } - - for (i = 0; i < send_size; i++) { - if (buf[i] != rx_buffer[i]) { - fprintf(stderr, "botched data, first mismated byte %i, " - "%u vs %u\n", i, buf[i], rx_buffer[i]); - exit(1); - } - } - exit(0); - } - - nr_cqes = 2 * nr_reqs; + nr_cqes = 2 * nr_reqs + 1; for (i = 0; i < nr_cqes; i++) { int expected = chunk_size; @@ -333,8 +306,18 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se fprintf(stderr, "io_uring_wait_cqe failed %i\n", ret); return 1; } + if (cqe->user_data == RX_TAG) { + if (cqe->res != send_size) { + fprintf(stderr, "rx failed %i\n", cqe->res); + return 1; + } + io_uring_cqe_seen(ring, cqe); + continue; + } + if (cqe->user_data >= nr_reqs) { - fprintf(stderr, "invalid user_data\n"); + fprintf(stderr, "invalid user_data %lu\n", + (unsigned long)cqe->user_data); return 1; } if (!(cqe->flags & IORING_CQE_F_NOTIF)) { @@ -354,17 +337,12 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se io_uring_cqe_seen(ring, cqe); } - if (waitpid(p, &wstatus, 0) == (pid_t)-1) { - perror("waitpid()"); - return 1; - } - if (!WIFEXITED(wstatus)) { - fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus)); - return 1; - } - if (WEXITSTATUS(wstatus)) { - fprintf(stderr, "child failed\n"); - return 1; + for (i = 0; i < send_size; i++) { + if (buf[i] != rx_buffer[i]) { + fprintf(stderr, "botched data, first mismated byte %i, " + "%u vs %u\n", i, buf[i], rx_buffer[i]); + return 1; + } } return 0; } From patchwork Mon Sep 5 14:21:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12966188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAD5CC6FA83 for ; Mon, 5 Sep 2022 14:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237051AbiIEOXg (ORCPT ); Mon, 5 Sep 2022 10:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237361AbiIEOXa (ORCPT ); Mon, 5 Sep 2022 10:23:30 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC51853014 for ; Mon, 5 Sep 2022 07:23:29 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id s11so11539124edd.13 for ; Mon, 05 Sep 2022 07:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=AKrZ1urcngCqlh4eeSJunnwPCrMDBRenolGBDYtEd20=; b=N0/Hw04jRYvVKGfLhfXvYMDa7hV33/Oyc4qfWe2CNLNZXgEKFrT+a1li/D3GSpxP9v sZE7YCniJg7MCZ2oBR0S5ff2h+4PNOm7wEcXPNTk8+jc67Cs2g/7DVjbO5GWPtAmFxqs sQRAelbOnti5BM2XlZL1EZgmkgDW7U3dMPvp0pXIEiEgAUdtDCzj32efVrEtfudfHuLo h5JIho46qgXtq131fKVGasM+xqT5bCb/ZMIMeqtqMG44mlU2hQew1FJvwSVyKa37qksg Xywia1INNqmIkP02104WOUsOaj96Vt0zTT1blaoJFXbYFVVyZ8ad/+FbPX7djbuZoDlE NN4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=AKrZ1urcngCqlh4eeSJunnwPCrMDBRenolGBDYtEd20=; b=CdzhfeTD5U3KK3eciH0WiYL1JXjxes4NoYTdn3TgeX4mB+gAVwD852pUpbIZsHXUqS 20lU81OMEJcfNiT0EN2YKxkxSYp3RdmkHox8lzpio8balEaPQy9gSoBfTPHwIJFWqAt8 MqxFy2K5XKAIGlNClGJe1QZrt/ehuVWEnNCLZMaL5vZNwNQtTRjYaau+cSMFSeeLqEJD NmhiEKTwobKUdZf7mYZms4pp1L3wvMBmF/TpFjnEIm5/oq41kqOHk6yNtJvDX/eWRGUF SeH/pCtEAbB30KWRmPC399wcpvKQ0q8K7K9APP92cF3gxGKNk7tmAE0LXPJITmlyupOz RTtg== X-Gm-Message-State: ACgBeo2rxSiKMXaBBjil5dd87ud0ZwUw2i0X3Hp7CPHvr9RtumjSv+iT OlrOcRIs4W6fsv7PtPhrhYl3/8jHbjc= X-Google-Smtp-Source: AA6agR789VbcnyO21Woh+Aiq7a0FpNeBEyu3VUd4VWsezstwCbS6hwGmdkOjYNKAIcp0VU5zEh0xag== X-Received: by 2002:aa7:dc13:0:b0:443:3f15:8440 with SMTP id b19-20020aa7dc13000000b004433f158440mr42264890edu.274.1662387808237; Mon, 05 Sep 2022 07:23:28 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a118]) by smtp.gmail.com with ESMTPSA id x10-20020a1709064bca00b0074182109623sm5168799ejv.39.2022.09.05.07.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 07:23:27 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 3/4] tests/zc: fix udp testing Date: Mon, 5 Sep 2022 15:21:05 +0100 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The tcp vs large_buf skip condition is not what we want and it skips udp testing, fix it and also make sure we serialise cork requests with IOSQE_IO_LINK as they might get executed OOO. Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index f80a5cd..bfe4cf7 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -285,6 +285,8 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se } if (force_async) sqe->flags |= IOSQE_ASYNC; + if (cork && i != nr_reqs - 1) + sqe->flags |= IOSQE_IO_LINK; } sqe = io_uring_get_sqe(ring); @@ -380,11 +382,9 @@ static int test_inet_send(struct io_uring *ring) int buf_idx = aligned ? 0 : 1; bool force_async = i & 128; - if (!tcp || !large_buf) - continue; if (large_buf) { buf_idx = 2; - if (!aligned || !tcp || small_send) + if (!aligned || !tcp || small_send || cork) continue; } if (!buffers_iov[buf_idx].iov_base) From patchwork Mon Sep 5 14:21:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12966187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E786C6FA8B for ; Mon, 5 Sep 2022 14:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236801AbiIEOXh (ORCPT ); Mon, 5 Sep 2022 10:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237673AbiIEOXb (ORCPT ); Mon, 5 Sep 2022 10:23:31 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B89513B958 for ; Mon, 5 Sep 2022 07:23:30 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id x73so4593261ede.10 for ; Mon, 05 Sep 2022 07:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=KkamG207Zpuat8/NcFbS1peIilUkfg9ZIppCPTBY7PM=; b=M8abwmP3Yl6ZlPlzN4PM5KSDFNw2Uwtc0k+6+FQhZC+K/Q/aZkMxA9cHR9o3y7gCtt Ah8IPbtjhklFoMwVEX+FwRp508hnH6WCkWwFDWFlaWuXrx7bklccf31WR2OZqYWbcw+9 BTn5/+m62FCyX4QRwSkCfOKgW7r4qCxuadGluDZhUDYYYEVkr4rTOPi5/pvYRdRavHGZ k4Yjh2XFQVn3tAhnGl2t+T96m5vY3OGLbltmYXpjqWhOU8CC9ffVm/HFxMAkjsncIrwR BFaEnkXUDUatOlWVCNoZlIsreZvyqeR5ZzOHp94sdf3OzVp2F+C+PBQH52r3KD9RmQ5K Ufog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=KkamG207Zpuat8/NcFbS1peIilUkfg9ZIppCPTBY7PM=; b=bdw5DPYUVL6kxpeV8WJisuEwQZlf8NNBzcga4yLLlZh6kFaDHCAhdBOQe9IkSgfN9O TuW8QSQRB6EEE/Gq6ZmX47379PYo/WbXKmUjJCPUrKfQsOUd0VAIqBkNqRwDnTujSHKS 3E8CvJ4SdCXUehhrlUcLYKU/r9hoCjSkpeg6dVXNoa1a9KFhvw/yg6XLRiym9LDimoO7 X1w8gvCt6r40tqYMaorLeg+oydEduRoMFdGWDDoA94p4DTpbPfnWSlYkWXhmAd9YrJKc FcLQwGfnb2Mtpskhrf7mUSIots8HbCX0ckyse56ivmFZetqaVrNly/xSDsca3YyjHO8C albw== X-Gm-Message-State: ACgBeo2y8Umq6qGn7/8S3LKDoIrP1kqdHCCcFFuBQPMyB5QdEpDtfEIS uxP8tf5ExsxuwyIo+P8xhH/GsCTgU/U= X-Google-Smtp-Source: AA6agR5nSTftqjNsqlXnOspb5cMK+7vrasOsFlLXb9v/HZg/NGX+ReMGxRCPy0XH3UOJjKXkTwcLmQ== X-Received: by 2002:a05:6402:50ca:b0:447:3355:76e3 with SMTP id h10-20020a05640250ca00b00447335576e3mr43335482edb.72.1662387809036; Mon, 05 Sep 2022 07:23:29 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a118]) by smtp.gmail.com with ESMTPSA id x10-20020a1709064bca00b0074182109623sm5168799ejv.39.2022.09.05.07.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 07:23:28 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 4/4] tests/zc: name buffer flavours Date: Mon, 5 Sep 2022 15:21:06 +0100 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Remove duplicating tests and pass a buf index instead of dozens of flags to specify the buffer we want to use. Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index bfe4cf7..2efbcf9 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -51,8 +51,16 @@ #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) #endif +enum { + BUF_T_NORMAL, + BUF_T_SMALL, + BUF_T_NONALIGNED, + BUF_T_LARGE, + __BUT_T_MAX, +}; + static char *tx_buffer, *rx_buffer; -static struct iovec buffers_iov[3]; +static struct iovec buffers_iov[__BUT_T_MAX]; static bool check_cq_empty(struct io_uring *ring) { @@ -238,7 +246,7 @@ static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_server, bool fixed_buf, struct sockaddr_storage *addr, - bool small_send, bool cork, bool mix_register, + bool cork, bool mix_register, int buf_idx, bool force_async) { const unsigned zc_flags = 0; @@ -246,7 +254,7 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se struct io_uring_cqe *cqe; int nr_reqs = cork ? 5 : 1; int i, ret, nr_cqes; - size_t send_size = small_send ? 137 : buffers_iov[buf_idx].iov_len; + size_t send_size = buffers_iov[buf_idx].iov_len; size_t chunk_size = send_size / nr_reqs; size_t chunk_size_last = send_size - chunk_size * (nr_reqs - 1); char *buf = buffers_iov[buf_idx].iov_base; @@ -371,23 +379,17 @@ static int test_inet_send(struct io_uring *ring) return 1; } - for (i = 0; i < 256; i++) { - bool fixed_buf = i & 1; - struct sockaddr_storage *addr_arg = (i & 2) ? &addr : NULL; - bool small_send = i & 4; - bool cork = i & 8; - bool mix_register = i & 16; - bool aligned = i & 32; - bool large_buf = i & 64; - int buf_idx = aligned ? 0 : 1; - bool force_async = i & 128; - - if (large_buf) { - buf_idx = 2; - if (!aligned || !tcp || small_send || cork) - continue; - } - if (!buffers_iov[buf_idx].iov_base) + for (i = 0; i < 128; i++) { + int buf_flavour = i & 3; + bool fixed_buf = i & 4; + struct sockaddr_storage *addr_arg = (i & 8) ? &addr : NULL; + bool cork = i & 16; + bool mix_register = i & 32; + bool force_async = i & 64; + + if (buf_flavour == BUF_T_LARGE && !tcp) + continue; + if (!buffers_iov[buf_flavour].iov_base) continue; if (tcp && cork) continue; @@ -397,8 +399,8 @@ static int test_inet_send(struct io_uring *ring) continue; ret = do_test_inet_send(ring, sock_client, sock_server, fixed_buf, - addr_arg, small_send, cork, mix_register, - buf_idx, force_async); + addr_arg, cork, mix_register, + buf_flavour, force_async); if (ret) { fprintf(stderr, "send failed fixed buf %i, conn %i, addr %i, " "cork %i\n", @@ -498,8 +500,8 @@ int main(int argc, char *argv[]) tx_buffer = aligned_alloc(4096, len); rx_buffer = aligned_alloc(4096, len); if (tx_buffer && rx_buffer) { - buffers_iov[2].iov_base = tx_buffer; - buffers_iov[2].iov_len = len; + buffers_iov[BUF_T_LARGE].iov_base = tx_buffer; + buffers_iov[BUF_T_LARGE].iov_len = len; } else { printf("skip large buffer tests, can't alloc\n"); @@ -512,10 +514,12 @@ int main(int argc, char *argv[]) return T_EXIT_FAIL; } - buffers_iov[0].iov_base = tx_buffer + 4096; - buffers_iov[0].iov_len = 4096; - buffers_iov[1].iov_base = tx_buffer + BUFFER_OFFSET; - buffers_iov[1].iov_len = 8192 - BUFFER_OFFSET - 13; + buffers_iov[BUF_T_NORMAL].iov_base = tx_buffer + 4096; + buffers_iov[BUF_T_NORMAL].iov_len = 4096; + buffers_iov[BUF_T_SMALL].iov_base = tx_buffer; + buffers_iov[BUF_T_SMALL].iov_len = 137; + buffers_iov[BUF_T_NONALIGNED].iov_base = tx_buffer + BUFFER_OFFSET; + buffers_iov[BUF_T_NONALIGNED].iov_len = 8192 - BUFFER_OFFSET - 13; ret = io_uring_queue_init(32, &ring, 0); if (ret) {