From patchwork Fri Jul 22 10:37: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: 12926336 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 E9C4FC433EF for ; Fri, 22 Jul 2022 10:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbiGVKiP (ORCPT ); Fri, 22 Jul 2022 06:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbiGVKiO (ORCPT ); Fri, 22 Jul 2022 06:38:14 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EDE4BA251 for ; Fri, 22 Jul 2022 03:38:13 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id b21-20020a05600c4e1500b003a32bc8612fso2248210wmq.3 for ; Fri, 22 Jul 2022 03:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rvf+Q4PeWgNXaBLrQizpS669Y3a54Lxw5uCTpfz0k5o=; b=nXqO/I8IVkPkqLqa/Y8rl+OGVZDi54L++7GfWpI/Y8zPQN6EDjabUfxdqDZvDU9lFp vx9hK2vMnTjM0SXnAT7O7N9zmLNSHnCY9Dr6FxyQ4jAQ3xZv2nSs4gcnRen1Vc1bMTXo Y9V1+CS2L08C2OsWH2OZVykqmqEHXw+uSsVe9OSFZLzI01VXW+XtdIYDWjlJ7URQUnCX Rp904Gc9CcaNqDQ2BiM0js/lC6BdLzoA3A1S1ZCqTOQnZP1g68sWDRzjWRWzICHCmwLe 7D57HRXeo57ERuOUBJo4m4angYPxW8xk+n3ullF6viyCALiZYh0PT00SaLwpbvzBHSiH RDFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rvf+Q4PeWgNXaBLrQizpS669Y3a54Lxw5uCTpfz0k5o=; b=WoG+CyLdF8xP4eWba5jAozWwoChiLBysDpAPuVSYIVPDSO3sglGkWfc9ALhpUCXekm +fn0A7rKiEpVYhgikfqGWlkb3e37nC+JxuGbXv4D0BiBFAiAL1oRFMGrtVINYxAvd5il f77NXo0112j2KRLheLpU2TARfz0rqKwBjKeGF1YiK02xM1a7Ohje5FWN6aM/lxGqQRfi IckEmmo/gxj5eiQX7B5FpDI22FONRZC8rBtpVG3Y3jYiVPOugFyCbCBOECRbimcHbQID h79mPYllES6Ifah26I4V7PF/yiYMTnproPMKMDoRnDWmLWV6Z3eH/41Q76+gEEQS9mI9 g4Vg== X-Gm-Message-State: AJIora8OnaJi3EhrLM2fII64y1yOHuNV/gWIJF0ze93dqFR3amBH763x vTyQ4zS2A8th3RT4FLIggEGsugcojitdeg== X-Google-Smtp-Source: AGRyM1uwEmzi2MbVJ1SJ5S4YGI3MJqCl7dJo/tPTgNrZFFWJx859bmKrRqi/SkgSsBgeCPHX1x2/4w== X-Received: by 2002:a05:600c:4e01:b0:3a3:342:5f55 with SMTP id b1-20020a05600c4e0100b003a303425f55mr2141654wmq.150.1658486291518; Fri, 22 Jul 2022 03:38:11 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a3d]) by smtp.gmail.com with ESMTPSA id p21-20020a05600c205500b003a2eacc8179sm4572832wmg.27.2022.07.22.03.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 03:38:10 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing v2 1/2] examples: add a simple single-shot poll benchmark Date: Fri, 22 Jul 2022 11:37:05 +0100 Message-Id: <20a5afbb4f8aeb586b6ce04a623264f18c4fe467.1658484803.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.0 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/Makefile | 3 +- examples/poll-bench.c | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 examples/poll-bench.c diff --git a/examples/Makefile b/examples/Makefile index 95a45f9..8e7067f 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,7 +13,8 @@ endif example_srcs := \ io_uring-cp.c \ io_uring-test.c \ - link-cp.c + link-cp.c \ + poll-bench.c all_targets := diff --git a/examples/poll-bench.c b/examples/poll-bench.c new file mode 100644 index 0000000..e3c0052 --- /dev/null +++ b/examples/poll-bench.c @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: MIT */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "liburing.h" + +static char buf[4096]; +static unsigned long runtime_ms = 10000; + +static unsigned long gettimeofday_ms(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +int main(void) +{ + unsigned long tstop; + unsigned long nr_reqs = 0; + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + struct io_uring ring; + int pipe1[2]; + int ret, i, qd = 32; + + if (pipe(pipe1) != 0) { + perror("pipe"); + return 1; + } + + ret = io_uring_queue_init(1024, &ring, IORING_SETUP_SINGLE_ISSUER); + if (ret == -EINVAL) { + fprintf(stderr, "can't single\n"); + ret = io_uring_queue_init(1024, &ring, 0); + } + if (ret) { + fprintf(stderr, "child: ring setup failed: %d\n", ret); + return 1; + } + + ret = io_uring_register_files(&ring, pipe1, 2); + if (ret < 0) { + fprintf(stderr, "io_uring_register_files failed\n"); + return 1; + } + + ret = io_uring_register_ring_fd(&ring); + if (ret < 0) { + fprintf(stderr, "io_uring_register_ring_fd failed\n"); + return 1; + } + + tstop = gettimeofday_ms() + runtime_ms; + do { + for (i = 0; i < qd; i++) { + sqe = io_uring_get_sqe(&ring); + io_uring_prep_poll_add(sqe, 0, POLLIN); + sqe->flags |= IOSQE_FIXED_FILE; + sqe->user_data = 1; + } + + ret = io_uring_submit(&ring); + if (ret != qd) { + fprintf(stderr, "child: sqe submit failed: %d\n", ret); + return 1; + } + + ret = write(pipe1[1], buf, 1); + if (ret != 1) { + fprintf(stderr, "write failed %i\n", errno); + return 1; + } + ret = read(pipe1[0], buf, 1); + if (ret != 1) { + fprintf(stderr, "read failed %i\n", errno); + return 1; + } + + for (i = 0; i < qd; i++) { + ret = io_uring_wait_cqe(&ring, &cqe); + if (ret < 0) { + fprintf(stderr, "child: wait completion %d\n", ret); + break; + } + io_uring_cqe_seen(&ring, cqe); + nr_reqs++; + } + } while (gettimeofday_ms() < tstop); + + fprintf(stderr, "requests/s: %lu\n", nr_reqs * 1000UL / runtime_ms); + return 0; +} From patchwork Fri Jul 22 10:37: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: 12926337 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 1EAD3C43334 for ; Fri, 22 Jul 2022 10:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbiGVKiQ (ORCPT ); Fri, 22 Jul 2022 06:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234249AbiGVKiP (ORCPT ); Fri, 22 Jul 2022 06:38:15 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACC6BA24E for ; Fri, 22 Jul 2022 03:38:14 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d16so5910062wrv.10 for ; Fri, 22 Jul 2022 03:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uL+YcL1uM1wr+XEYcgTjSTJRq0qdYlELKmNXfoDNo1Y=; b=ZN/xMS4QEFVQgYPoiPXRA8JBHyh4gCD9ikCmFzx4HKwlf0gtiSt5yQ2MB7EYgeivhn ZqSJ+IWeCNQrBEn6nTDEMDnEw1WDsr2w5TxPnqSIRPGoFjIsuGkyzSzAOUezVmY+mH9r oRuI8oFzgiTbYlWj2c4l3rY3z79iHl9ph5iRepJxIetMVor7yEbwPHRe6jxf7ia9BbCz FZIRSwEYb9zrEfQQbY3No96hx+xjvQ6nAfs7YFjL1QlbN4HYv1Q1mzUsddUddeYOweSe 8y/+aXun4pECNI3rfjv597F5aB2HH1c5Th68jUeWGrYAnmKEW+p8jIM17N1Spn1j1qwX Wnew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uL+YcL1uM1wr+XEYcgTjSTJRq0qdYlELKmNXfoDNo1Y=; b=Hr7m3qjHGzZZLMi1ihnKydYie8Q1Ox0rO8hiVZ9BqmNLMvqVmac4ApYtU1lgAL4Phj 718ikm3CAsqDXfu6ML++U4MbII1ez3wu9yG8WBec7gtrCPvACH1BqYCyhWRKBjFjOFgQ AnvxqLCyA1AfG4OhtjsrAvfoFfO6qhdgidhIouDwUVG6WpRGHB0lx1nXuo0CDUVGzUT5 abkG7UyHa1xD/uHU0gDW8JQ0mHliwxafLYVH/8DmG0k1MDfzc5orU++phScabadXUOhh bHfIWwBN+/SaNaVNR+WOuKtgqoiQrF13NrI2DQKUtgmMV7xUSH+c5BdDq5L6dQdpM+bP yjlg== X-Gm-Message-State: AJIora8e5QdJD7PwK6TajZqkWtvLWJPPf0tEBLGJTix0Ouhlh/iQC8pB qLnpM75l437THRsx9TVzkpNF+Ic4cgc0Lg== X-Google-Smtp-Source: AGRyM1uZM7R+Qgst6uFpakuTZNT38jtOp7hJwc/bNuRu+FpIomKlXa705M+IO9WPJogAegKum6BuCA== X-Received: by 2002:a5d:5a98:0:b0:21e:203f:2897 with SMTP id bp24-20020a5d5a98000000b0021e203f2897mr2005398wrb.707.1658486292507; Fri, 22 Jul 2022 03:38:12 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:a3d]) by smtp.gmail.com with ESMTPSA id p21-20020a05600c205500b003a2eacc8179sm4572832wmg.27.2022.07.22.03.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 03:38:12 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing v2 2/2] tests: test IORING_SETUP_SINGLE_ISSUER Date: Fri, 22 Jul 2022 11:37:06 +0100 Message-Id: <54af31b0b34fea289dc82ac228ec0cabed408cb6.1658484803.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.0 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/Makefile | 1 + test/single-issuer.c | 153 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 test/single-issuer.c diff --git a/test/Makefile b/test/Makefile index e958a35..8945368 100644 --- a/test/Makefile +++ b/test/Makefile @@ -174,6 +174,7 @@ test_srcs := \ wakeup-hang.c \ xattr.c \ skip-cqe.c \ + single-issuer.c \ # EOL all_targets := diff --git a/test/single-issuer.c b/test/single-issuer.c new file mode 100644 index 0000000..3bbc6c4 --- /dev/null +++ b/test/single-issuer.c @@ -0,0 +1,153 @@ +/* SPDX-License-Identifier: MIT */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "liburing.h" +#include "test.h" +#include "helpers.h" + +static pid_t pid; + +static pid_t fork_t(void) +{ + pid = fork(); + if (pid == -1) { + fprintf(stderr, "fork failed\n"); + exit(T_EXIT_FAIL); + } + return pid; +} + +static void wait_child_t(void) +{ + int wstatus; + + if (waitpid(pid, &wstatus, 0) == (pid_t)-1) { + perror("waitpid()"); + exit(T_EXIT_FAIL); + } + if (!WIFEXITED(wstatus)) { + fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus)); + exit(T_EXIT_FAIL); + } + if (WEXITSTATUS(wstatus)) + exit(T_EXIT_FAIL); +} + +static int try_submit(struct io_uring *ring) +{ + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + int ret; + + sqe = io_uring_get_sqe(ring); + io_uring_prep_nop(sqe); + sqe->user_data = 42; + + ret = io_uring_submit(ring); + if (ret < 0) + return ret; + + if (ret != 1) + error(1, ret, "submit %i", ret); + ret = io_uring_wait_cqe(ring, &cqe); + if (ret) + error(1, ret, "wait fail %i", ret); + + if (cqe->res || cqe->user_data != 42) + error(1, ret, "invalid cqe"); + + io_uring_cqe_seen(ring, cqe); + return 0; +} + +int main(int argc, char *argv[]) +{ + struct io_uring ring; + int ret; + + if (argc > 1) + return T_EXIT_SKIP; + + ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER); + if (ret == -EINVAL) { + fprintf(stderr, "SETUP_SINGLE_ISSUER is not supported, skip\n"); + return T_EXIT_SKIP; + } else if (ret) { + fprintf(stderr, "io_uring_queue_init() failed %i\n", ret); + return T_EXIT_FAIL; + } + + /* test that the creator iw allowed to submit */ + ret = try_submit(&ring); + if (ret) { + fprintf(stderr, "the creater can't submit %i\n", ret); + return T_EXIT_FAIL; + } + + /* test that a second submitter doesn't succeed */ + if (!fork_t()) { + ret = try_submit(&ring); + if (ret != -EEXIST) + fprintf(stderr, "not owner child could submit %i\n", ret); + return ret != -EEXIST; + } + wait_child_t(); + io_uring_queue_exit(&ring); + + /* test that the first submitter but not creator can submit */ + ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER); + if (ret) + error(1, ret, "ring init (2) %i", ret); + + if (!fork_t()) { + ret = try_submit(&ring); + if (ret) + fprintf(stderr, "not owner child could submit %i\n", ret); + return !!ret; + } + wait_child_t(); + io_uring_queue_exit(&ring); + + /* test that anyone can submit to a SQPOLL|SINGLE_ISSUER ring */ + ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER|IORING_SETUP_SQPOLL); + if (ret) + error(1, ret, "ring init (3) %i", ret); + + ret = try_submit(&ring); + if (ret) { + fprintf(stderr, "SQPOLL submit failed (creator) %i\n", ret); + return T_EXIT_FAIL; + } + + if (!fork_t()) { + ret = try_submit(&ring); + if (ret) + fprintf(stderr, "SQPOLL submit failed (child) %i\n", ret); + return !!ret; + } + wait_child_t(); + io_uring_queue_exit(&ring); + + /* test that IORING_ENTER_REGISTERED_RING doesn't break anything */ + ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER); + if (ret) + error(1, ret, "ring init (4) %i", ret); + + if (!fork_t()) { + ret = try_submit(&ring); + if (ret) + fprintf(stderr, "not owner child could submit %i\n", ret); + return !!ret; + } + wait_child_t(); + io_uring_queue_exit(&ring); + return T_EXIT_PASS; +}