From patchwork Wed Sep 21 11:21:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12983614 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 26A9EC6FA8E for ; Wed, 21 Sep 2022 11:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbiIULYg (ORCPT ); Wed, 21 Sep 2022 07:24:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiIULYf (ORCPT ); Wed, 21 Sep 2022 07:24:35 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2404F10A8 for ; Wed, 21 Sep 2022 04:24:34 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id n15so2418207wrq.5 for ; Wed, 21 Sep 2022 04:24:34 -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=1A/AF2O0KnZf8BC1p2lMQccLfFnZcq73/1o1rWc+TI0=; b=qKrdiONCoCqclcrGFpNgMT1hdgp75LDcuftI0IhAY3k6mjOV5k0ivvDNzaVyzDuVes JWsBgzQyVf0BU1n/98qqK99jN1U8Ev1dLcc2NO9aPOplCCCn0WKASm/NxQK4fwjw6zxJ yo7CCHhfNn09F2tPJ7wuv/1ITGrPCHfaOA+1/JUP+jiWJCPIuYI5r6mRp/xw1dSzH2ix /H4klwlm6v2DypQTu12zACXukLJ84TO4qH6MiKb6bepQNg6CeWUgMoo2ISbAyjbpCcHR VkhiiphTyXjcRCb9cZlA+h5jP6fFC0hWiaHXWhLnZmBdFA/OYzzH0O3WqAhYNrPPhLvm TwOg== 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=1A/AF2O0KnZf8BC1p2lMQccLfFnZcq73/1o1rWc+TI0=; b=NKYn3b+xC9mm963Gbz1gOBdleBkYv0HYEiiUDkhlDJWb7BrWk/0kjviDLY+snh88Vf Bbwt/DA4q2a76XgcRYgo3uj3zIKbAKNTsi7YE87BEek8TjA0DwKnZ3PnvTrO2IGtf5G7 tfG3BPMp5S4DAR/THtkWmd/7zrPww+ESogIga1ZUfTIsFjUJ4NKWYS8zLGRFDKxvOUxH p3CsXPSxSeNuy/yzm1BEBJ6gSVU7WrzyE/snfO/+VTeEDLeUjTJeHjqWrcGhVQaPhuxb LuBeCWEmsuGw44YtrpR8I6T2EQYA/WFptCnV6qIu0EjZnhFf35bO39KP1HF/CUagh0h9 +uhA== X-Gm-Message-State: ACrzQf3LKH9jRfdL7XDlgU48S1HVpczaMfhindcY4MKTRgsTptD6ZKBa vKt+N977Onnbkm8Uf0UK36KgelJugzs= X-Google-Smtp-Source: AMsMyM7h2jU0wAY1u8vj0dhhit70/6zsJMt5JxN+IrdeQDXxN3lZZc/lbXE6repONg9z5z+QiuoC4g== X-Received: by 2002:a5d:47c5:0:b0:22a:6c7a:10f3 with SMTP id o5-20020a5d47c5000000b0022a6c7a10f3mr16278734wrc.523.1663759472401; Wed, 21 Sep 2022 04:24:32 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.205.62.threembb.co.uk. [188.28.205.62]) by smtp.gmail.com with ESMTPSA id bw25-20020a0560001f9900b0022ac1be009esm2467539wrb.16.2022.09.21.04.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 04:24:32 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 1/4] examples: fix sendzc notif handling Date: Wed, 21 Sep 2022 12:21:55 +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 --- examples/send-zerocopy.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c index 4ed0f67..7f5f2b1 100644 --- a/examples/send-zerocopy.c +++ b/examples/send-zerocopy.c @@ -190,8 +190,6 @@ static void do_tx(int domain, int type, int protocol) sqe->flags |= IOSQE_FIXED_FILE; } } - if (cfg_zc) - compl_cqes += cfg_nr_reqs; ret = io_uring_submit(&ring); if (ret != cfg_nr_reqs) @@ -205,19 +203,20 @@ static void do_tx(int domain, int type, int protocol) error(1, -EINVAL, "F_MORE notif"); compl_cqes--; i--; - } else if (cqe->res >= 0) { - if (!(cqe->flags & IORING_CQE_F_MORE) && cfg_zc) - error(1, -EINVAL, "no F_MORE"); + io_uring_cqe_seen(&ring, cqe); + continue; + } + if (cqe->flags & IORING_CQE_F_MORE) + compl_cqes++; + + if (cqe->res >= 0) { packets++; bytes += cqe->res; - } else if (cqe->res == -EAGAIN) { - if (cfg_zc) - compl_cqes--; } else if (cqe->res == -ECONNREFUSED || cqe->res == -EPIPE || cqe->res == -ECONNRESET) { fprintf(stderr, "Connection failure"); goto out_fail; - } else { + } else if (cqe->res != -EAGAIN) { error(1, cqe->res, "send failed"); } io_uring_cqe_seen(&ring, cqe); From patchwork Wed Sep 21 11:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12983615 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 F3426ECAAD8 for ; Wed, 21 Sep 2022 11:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229566AbiIULYi (ORCPT ); Wed, 21 Sep 2022 07:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiIULYh (ORCPT ); Wed, 21 Sep 2022 07:24:37 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4DA855B1 for ; Wed, 21 Sep 2022 04:24:35 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id bq9so9364101wrb.4 for ; Wed, 21 Sep 2022 04:24:35 -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=d87InZRix5/dcCxIK4j++OlFEw67hTdpxdg2YxzrBds=; b=lKFw42IxDvTDmxaaCBQWMtXTgnT0XVnn/H6j1zFtcamuKgRzDsuajHBVTCHN0+STc7 faJaw/vU6eqQPJa2wlIACcQ2LjlSxIAUBO3e4KNjnvQUEv94GTgDJqEcafimeWlN+Hbi hvke14blmlEWyj3Z4KpiZcxYckbNW5lAAeaYCvL9P0o10bs/RZC1ZH/Bo6YKbgOfvLvw 1wv1kGfNsG0lKfbE3dNFz+SC5Dewpkvuu8xw/18ohCoDXPH40DEnzr7HPipo/a7/AWHD OQ4+vFN2+C3fNPhnzTuvw/kmH3yUfbM2mwGbKJZJTcqIv3407XXxH+gLMnYHpryQwycP DXiA== 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=d87InZRix5/dcCxIK4j++OlFEw67hTdpxdg2YxzrBds=; b=oVryuGOUUXnVWI9cd6ZK3X9Ite0aZ/zjwune7K9EhZL3klCX0cejZq0sWv5osiAwFJ oIpufBGWJYEh6b3Fs3hqkqF5l+739E2e/T46xjn6LVCoLHDZa98TUFyBTosxlvAABwsK paFwnXehF44yw9cy+claD4LFush5BD5WmIQUN3eDb40WbVIU0SdMT6UCvGReYJp1nR2I R3PvuXfGdEINtvhgdJZM8mssI4BcJpWgdXRSkRxuLRBO6UWr+6XsVtC09QaSvNZ544Wr jt93nebNkR+XY3qewOIJxTULx1xVmFhteEH4HSOAxBp8qQuMvX16R2l6iNFj3NohIRi/ lgYg== X-Gm-Message-State: ACrzQf3lHgPo0VVPqGp4AWo8d4uaZS2y6OQE8BgOWHNdXf9qZfJMr0Bq T2AvS3rsov558+2Ki/LHTajROy+8hfU= X-Google-Smtp-Source: AMsMyM5QtHmB68vVVBqy0U4NT68RnJn3eJgJpysnQgf3r/gLF7HT/Tl7VlnRdHedEgDI2ryzSdztkg== X-Received: by 2002:a05:6000:696:b0:22a:f497:3c45 with SMTP id bo22-20020a056000069600b0022af4973c45mr12226298wrb.24.1663759473705; Wed, 21 Sep 2022 04:24:33 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.205.62.threembb.co.uk. [188.28.205.62]) by smtp.gmail.com with ESMTPSA id bw25-20020a0560001f9900b0022ac1be009esm2467539wrb.16.2022.09.21.04.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 04:24:33 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 2/4] test: fix zc tests Date: Wed, 21 Sep 2022 12:21:56 +0100 Message-Id: <1529ac2cc55de274f3cf96aa150f56b5d550a19c.1663759148.git.asml.silence@gmail.com> 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 Decouple result from F_NOTIF/F_MORE, even failed requests may produce a notification. Signed-off-by: Pavel Begunkov --- test/send-zerocopy.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index 39c5c5d..e34e0c1 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -117,7 +117,7 @@ static int test_send_faults(struct io_uring *ring, int sock_tx, int sock_rx) int msg_flags = 0; unsigned zc_flags = 0; int payload_size = 100; - int ret, i; + int ret, i, nr_cqes = 2; sqe = io_uring_get_sqe(ring); io_uring_prep_send_zc(sqe, sock_tx, (void *)1UL, payload_size, @@ -125,7 +125,7 @@ static int test_send_faults(struct io_uring *ring, int sock_tx, int sock_rx) sqe->user_data = 1; sqe = io_uring_get_sqe(ring); - io_uring_prep_send_zc(sqe, sock_tx, (void *)1UL, payload_size, + io_uring_prep_send_zc(sqe, sock_tx, tx_buffer, payload_size, msg_flags, zc_flags); sqe->user_data = 2; io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)1UL, @@ -134,12 +134,18 @@ static int test_send_faults(struct io_uring *ring, int sock_tx, int sock_rx) ret = io_uring_submit(ring); assert(ret == 2); - for (i = 0; i < 2; i++) { + for (i = 0; i < nr_cqes; i++) { ret = io_uring_wait_cqe(ring, &cqe); assert(!ret); assert(cqe->user_data <= 2); - assert(cqe->res == -EFAULT); - assert(!(cqe->flags & IORING_CQE_F_MORE)); + + if (cqe->flags & IORING_CQE_F_NOTIF) { + assert(ret > 0); + } else { + assert(cqe->res == -EFAULT); + if (cqe->flags & IORING_CQE_F_MORE) + nr_cqes++; + } io_uring_cqe_seen(ring, cqe); } assert(check_cq_empty(ring)); From patchwork Wed Sep 21 11:21:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12983616 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 BA84CC6FA8E for ; Wed, 21 Sep 2022 11:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbiIULYk (ORCPT ); Wed, 21 Sep 2022 07:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiIULYj (ORCPT ); Wed, 21 Sep 2022 07:24:39 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F4E99FD9 for ; Wed, 21 Sep 2022 04:24:36 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id t7so9292368wrm.10 for ; Wed, 21 Sep 2022 04:24:36 -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=GAf4t+ngaW1C8kXmw2/v4leVYroVSMso1wp1/IttN7Q=; b=hu6wDVlNKZysVGR7FxO746WOvHIDCaEwPZMgdPoAtppcIHb6EOPjpOkkwt09wcP/0Q yj4agQ/y8H5DE/Kpz3jygZMX3k5rpmFR+AFShjmRqO/IbpZXwgeuJ51TNLG8FP/ArUeW ZbYEYmB/OM829xvwGz/eCgI28giqXPWSmAb6x115wsxqslwZgjd5lAMsjuTl7GlEx6MF UrK6QVQlFiCh/Pjnb9Czk8mhE3xOceXhl/xoET1vuMdq0ov0e54eaci6Il4K5eix2td9 8tYYnePb3j7umwoYGCxo3WfLIm7IXD/yiLCwnqo3vd4Na5h24v/MMvIBUjYYkUSd7esW rPgA== 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=GAf4t+ngaW1C8kXmw2/v4leVYroVSMso1wp1/IttN7Q=; b=as7b6SyqWhq8XBZGD74aDlgofB4uyqv0D4+3fDn/w7mwzjIPuor+rtHKcu5qKS/1Yf MeJ9469DsaXcBMG5nArRMh9v6LmP6gRilQctqO/cIYwbhGXFPwsL4DKE14CEUgasObef /t2tnqWe8u90gJSd0pgN6WUX0sjJniZCsiPAdVzD2ilyet+vuf0L/vGwbJiRJBPWEbBO RUe30dadMceAHQOWEZJZD1NOMLGS7b/QdQtrS2m/si9X304ojUFAoZm9nfL916vF2nIs iAmfv7wAynGahko9nSzbFpD+CJ6gI89uBBWz+9ezN++dUyvH5cu86CJCYs8xkme3dAxL xvUw== X-Gm-Message-State: ACrzQf1hsscnKWjxvuSeFX+//i4K+IQNAJGa8n7XXd6mHigIYHx5kImc jDTNWxfbqocVbM+jqKZez4u/HdFDN58= X-Google-Smtp-Source: AMsMyM7aXZpr3qZYopL9GZpcMC2iKsg/n1YX2nqujqdJmvNEun1fVOxlIB2bvhuGi2CyY4nlELmipQ== X-Received: by 2002:a5d:6c6e:0:b0:22a:c36d:e411 with SMTP id r14-20020a5d6c6e000000b0022ac36de411mr16392864wrz.183.1663759474829; Wed, 21 Sep 2022 04:24:34 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.205.62.threembb.co.uk. [188.28.205.62]) by smtp.gmail.com with ESMTPSA id bw25-20020a0560001f9900b0022ac1be009esm2467539wrb.16.2022.09.21.04.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 04:24:34 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 3/4] man: note about notification generation Date: Wed, 21 Sep 2022 12:21:57 +0100 Message-Id: <4ae18336994f973d2e5e111479844c79547d7922.1663759148.git.asml.silence@gmail.com> 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 Add a small note to clarify expectations on when to expect a notification. Signed-off-by: Pavel Begunkov --- man/io_uring_enter.2 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/man/io_uring_enter.2 b/man/io_uring_enter.2 index d87f254..e0ce051 100644 --- a/man/io_uring_enter.2 +++ b/man/io_uring_enter.2 @@ -1091,7 +1091,10 @@ long time, e.g. waiting for a TCP ACK, and having a separate cqe for request completions allows userspace to push more data without extra delays. Note, notifications are only responsible for controlling the lifetime of the buffers, and as such don't mean anything about whether the data has atually been sent -out or received by the other end. +out or received by the other end. Even errored requests may generate a +notification, and the user must check for +.B IORING_CQE_F_MORE +rather than relying on the result. .I fd must be set to the socket file descriptor, From patchwork Wed Sep 21 11:21:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12983617 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 69879C32771 for ; Wed, 21 Sep 2022 11:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbiIULYl (ORCPT ); Wed, 21 Sep 2022 07:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiIULYk (ORCPT ); Wed, 21 Sep 2022 07:24:40 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0881055B1 for ; Wed, 21 Sep 2022 04:24:37 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id n10so9280405wrw.12 for ; Wed, 21 Sep 2022 04:24:37 -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=pKbMXg8Ue1DsGmilQ1piyQRsNo5PG/HHHa0idiyGZpw=; b=WGdMq5JkoKj/zpUqGvHldK3OqDYIFk6TQ4jITJDwTj65F2JdedFL6H+ppXsmI3wdWw q1SsUVD4MfRJ41DvFV+W/KHCUxuaLvGs0Yo6qGqrnOg3jHve3uEAJU5PAXr+ONRte+p5 RdoNVx0R4WpZJgMR2D8LV+1BCyBz+YYFPWLQyIJRx24VIIs5dBdc04imEVjAdsqH12Ef r4S0wPcUOmDql2CXwKvesVWFISWft02tMtBfsMcM4o2QaMOFl9q+7eEvVbgEeJhSYYO5 dqhTyXZixzxIpCPCX3ciqGJ6Y2CjsrqvDTlXL+bb63hNTxOuHueHuCToyJ0SJ2nVjuq9 Ih3g== 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=pKbMXg8Ue1DsGmilQ1piyQRsNo5PG/HHHa0idiyGZpw=; b=0R91XFtu4XMCOiUM4X2S14JZLCJgPI3mKS2jlksIb+ncgq/mrJ2VObecsgPEO6Ljm5 598Zt2ULKmmxGghETZ+d236WT0L2mopw6SUemXOl0ttJVLAJreZ3FspYGAo7cqWJzcIN gh8ObyxPTJXzX2AvZYqMsIr5MEt8YZ0lQsoiONLQ9YbATcGSK4VXX4BnN6vBqoAq6ThM uGPsKLlQUnBRhm9X66tMsPbg3DZgpeCq5AXPxAt9PaeSur6xIeekEXLXi4EJcLMMB+O8 FIS0kNEGf9gr4igshsYIGbR9RoTGCeXyLxA0Dlu9RB354ZEzgKcreBHozoN4/qIn0pRi Q+fw== X-Gm-Message-State: ACrzQf30cOPjUOkei/C56cUIH35bUH7isbGWHc2kDQ0c5COcA4m8Wi7i PgTXOXWGm8Xr/nYrkzZDobvKjVwwRws= X-Google-Smtp-Source: AMsMyM50exdMmRVmoHx1Jam4obuf8yX/keN+rFxgcUxwwF1n6utss2DiGv1z//KwyCC7kzrXzRG93w== X-Received: by 2002:a5d:4c4c:0:b0:22a:35bd:84a9 with SMTP id n12-20020a5d4c4c000000b0022a35bd84a9mr15981892wrt.103.1663759476000; Wed, 21 Sep 2022 04:24:36 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.205.62.threembb.co.uk. [188.28.205.62]) by smtp.gmail.com with ESMTPSA id bw25-20020a0560001f9900b0022ac1be009esm2467539wrb.16.2022.09.21.04.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 04:24:35 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 4/4] tests: add sendmsg_zc tests Date: Wed, 21 Sep 2022 12:21:58 +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 --- src/include/liburing/io_uring.h | 1 + test/send-zerocopy.c | 85 +++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 972b179..92f29d9 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -213,6 +213,7 @@ enum io_uring_op { IORING_OP_SOCKET, IORING_OP_URING_CMD, IORING_OP_SEND_ZC, + IORING_OP_SENDMSG_ZC, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c index e34e0c1..80723de 100644 --- a/test/send-zerocopy.c +++ b/test/send-zerocopy.c @@ -44,6 +44,7 @@ #define HOST "127.0.0.1" #define HOSTV6 "::1" +#define CORK_REQS 5 #define RX_TAG 10000 #define BUFFER_OFFSET 41 @@ -60,6 +61,7 @@ enum { static char *tx_buffer, *rx_buffer; static struct iovec buffers_iov[4]; +static bool has_sendmsg; static bool check_cq_empty(struct io_uring *ring) { @@ -252,18 +254,27 @@ 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 cork, bool mix_register, - int buf_idx, bool force_async) + int buf_idx, bool force_async, bool use_sendmsg) { + struct iovec iov[CORK_REQS]; + struct msghdr msghdr[CORK_REQS]; const unsigned zc_flags = 0; struct io_uring_sqe *sqe; struct io_uring_cqe *cqe; - int nr_reqs = cork ? 5 : 1; - int i, ret, nr_cqes; + int nr_reqs = cork ? CORK_REQS : 1; + int i, ret, nr_cqes, addr_len = 0; 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; + if (addr) { + sa_family_t fam = ((struct sockaddr_in *)addr)->sin_family; + + addr_len = (fam == AF_INET) ? sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6); + } + memset(rx_buffer, 0, send_size); for (i = 0; i < nr_reqs; i++) { @@ -280,25 +291,35 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se cur_size = chunk_size_last; sqe = io_uring_get_sqe(ring); - io_uring_prep_send_zc(sqe, sock_client, buf + i * chunk_size, - cur_size, msg_flags, zc_flags); - sqe->user_data = i; - - if (real_fixed_buf) { - sqe->ioprio |= IORING_RECVSEND_FIXED_BUF; - sqe->buf_index = buf_idx; - } - if (addr) { - sa_family_t fam = ((struct sockaddr_in *)addr)->sin_family; - int addr_len = fam == AF_INET ? sizeof(struct sockaddr_in) : - sizeof(struct sockaddr_in6); - io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)addr, - addr_len); + if (!use_sendmsg) { + io_uring_prep_send_zc(sqe, sock_client, buf + i * chunk_size, + cur_size, msg_flags, zc_flags); + if (real_fixed_buf) { + sqe->ioprio |= IORING_RECVSEND_FIXED_BUF; + sqe->buf_index = buf_idx; + } + if (addr) + io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)addr, + addr_len); + } else { + io_uring_prep_sendmsg(sqe, sock_client, &msghdr[i], msg_flags); + sqe->opcode = IORING_OP_SENDMSG_ZC; + + memset(&msghdr[i], 0, sizeof(msghdr[i])); + iov[i].iov_len = cur_size; + iov[i].iov_base = buf + i * chunk_size; + msghdr[i].msg_iov = &iov[i]; + msghdr[i].msg_iovlen = 1; + if (addr) { + msghdr[i].msg_name = addr; + msghdr[i].msg_namelen = addr_len; + } } + sqe->user_data = i; if (force_async) sqe->flags |= IOSQE_ASYNC; - if (cork && i != nr_reqs - 1) + if (i != nr_reqs - 1) sqe->flags |= IOSQE_IO_LINK; } @@ -346,7 +367,8 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se } if ((cqe->flags & IORING_CQE_F_MORE) == (cqe->flags & IORING_CQE_F_NOTIF)) { - fprintf(stderr, "unexpected cflags %i\n", cqe->flags); + fprintf(stderr, "unexpected cflags %i res %i\n", + cqe->flags, cqe->res); return 1; } io_uring_cqe_seen(ring, cqe); @@ -384,13 +406,14 @@ static int test_inet_send(struct io_uring *ring) return 1; } - for (i = 0; i < 128; i++) { + for (i = 0; i < 256; 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; + bool use_sendmsg = i & 128; if (buf_flavour == BUF_T_LARGE && !tcp) continue; @@ -402,10 +425,12 @@ static int test_inet_send(struct io_uring *ring) continue; if (!client_connect && addr_arg == NULL) continue; + if (use_sendmsg && (mix_register || fixed_buf || !has_sendmsg)) + continue; ret = do_test_inet_send(ring, sock_client, sock_server, fixed_buf, addr_arg, cork, mix_register, - buf_flavour, force_async); + buf_flavour, force_async, use_sendmsg); if (ret) { fprintf(stderr, "send failed fixed buf %i, conn %i, addr %i, " "cork %i\n", @@ -492,6 +517,22 @@ static int test_async_addr(struct io_uring *ring) return 0; } +static bool io_check_zc_sendmsg(struct io_uring *ring) +{ + struct io_uring_probe *p; + int ret; + + p = t_calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op)); + if (!p) { + fprintf(stderr, "probe allocation failed\n"); + return false; + } + ret = io_uring_register_probe(ring, p, 256); + if (ret) + return false; + return p->ops_len > IORING_OP_SENDMSG_ZC; +} + int main(int argc, char *argv[]) { struct io_uring ring; @@ -550,6 +591,8 @@ int main(int argc, char *argv[]) return T_EXIT_FAIL; } + has_sendmsg = io_check_zc_sendmsg(&ring); + ret = test_send_faults(&ring, sp[0], sp[1]); if (ret) { fprintf(stderr, "test_send_faults() failed\n");