From c5c63432f61179f2e003b16d452a8e5b0e5a7b5e Mon Sep 17 00:00:00 2001 From: ZiyangZhang Date: Wed, 7 Dec 2022 17:56:17 +0800 Subject: [PATCH] Update anolis customized patches (1) revert io_uring ioctl support (2) update uapi for IORING_ENTER_SQ_SUBMIT_ON_IDLE (3) add a test for sqpoll sq_thread_idle_us mode Reviewed-by: Joseph Qi Signed-off-by: ZiyangZhang --- ...olis-support-async-ioctl-in-liburing.patch | 46 ---- ...timeout-new-test-for-timeout-feature.patch | 0 ...to-define-test-files-devices-we-need.patch | 0 ...-overflow-don-t-run-on-newer-kernels.patch | 0 ...-us-granularity-of-io_sq_thread_idle.patch | 0 ...-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch | 0 ...-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch | 33 +++ ...st-for-sqpoll-sq_thread_idle_us-mode.patch | 227 ++++++------------ liburing.spec | 21 +- 9 files changed, 119 insertions(+), 208 deletions(-) delete mode 100644 1013-liburing-anolis-support-async-ioctl-in-liburing.patch rename 1014-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch => 1013-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch (100%) rename 1015-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch => 1014-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch (100%) rename 1017-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch => 1015-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch (100%) rename 1018-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch => 1016-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch (100%) rename 1019-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch => 1017-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch (100%) create mode 100644 1018-liburing-anolis-adjust-value-for-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch rename 1016-liburing-anolis-test-add-ioctl-test.patch => 1019-liburing-anolis-Add-a-test-for-sqpoll-sq_thread_idle_us-mode.patch (31%) diff --git a/1013-liburing-anolis-support-async-ioctl-in-liburing.patch b/1013-liburing-anolis-support-async-ioctl-in-liburing.patch deleted file mode 100644 index 74594b5..0000000 --- a/1013-liburing-anolis-support-async-ioctl-in-liburing.patch +++ /dev/null @@ -1,46 +0,0 @@ -From e8dbd563b3a355b8885f2bf5ae96be83a1624432 Mon Sep 17 00:00:00 2001 -From: Hao Xu -Date: Thu, 26 Nov 2020 14:56:58 +0800 -Subject: [PATCH] support async ioctl in liburing - -Async ioctl is now supported in io_uring kernel part. Add the -counterpart in liburing. Currently we just support BLKDISCARD. - -Signed-off-by: Hao Xu ---- - src/include/liburing.h | 6 ++++++ - src/include/liburing/io_uring.h | 1 + - 2 files changed, 7 insertions(+) - -diff --git a/src/include/liburing.h b/src/include/liburing.h -index ac2d4a1cbeba..9fa5bc92986d 100644 ---- a/src/include/liburing.h -+++ b/src/include/liburing.h -@@ -438,6 +438,12 @@ static inline void io_uring_prep_remove_buffers(struct io_uring_sqe *sqe, - sqe->buf_group = bgid; - } - -+static inline void io_uring_prep_ioctl(struct io_uring_sqe *sqe, int fd, -+ unsigned len, void *buf) -+{ -+ io_uring_prep_rw(IORING_OP_IOCTL, sqe, fd, buf, len, 0); -+} -+ - static inline unsigned io_uring_sq_ready(struct io_uring *ring) - { - /* always use real head, to avoid losing sync for short submit */ -diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h -index e8393b87e7bd..05d58cebcfcc 100644 ---- a/src/include/liburing/io_uring.h -+++ b/src/include/liburing/io_uring.h -@@ -133,6 +133,7 @@ enum { - IORING_OP_PROVIDE_BUFFERS, - IORING_OP_REMOVE_BUFFERS, - IORING_OP_TEE, -+ IORING_OP_IOCTL, - - /* this goes last, obviously */ - IORING_OP_LAST, --- -1.8.3.1 - diff --git a/1014-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch b/1013-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch similarity index 100% rename from 1014-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch rename to 1013-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch diff --git a/1015-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch b/1014-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch similarity index 100% rename from 1015-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch rename to 1014-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch diff --git a/1017-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch b/1015-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch similarity index 100% rename from 1017-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch rename to 1015-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch diff --git a/1018-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch b/1016-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch similarity index 100% rename from 1018-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch rename to 1016-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch diff --git a/1019-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch b/1017-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch similarity index 100% rename from 1019-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch rename to 1017-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch diff --git a/1018-liburing-anolis-adjust-value-for-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch b/1018-liburing-anolis-adjust-value-for-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch new file mode 100644 index 0000000..b7aab1e --- /dev/null +++ b/1018-liburing-anolis-adjust-value-for-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch @@ -0,0 +1,33 @@ +From 24fa4be977ba0232d6b1abcb8c95a9f65de3a686 Mon Sep 17 00:00:00 2001 +From: Ziyang Zhang +Date: Wed, 30 Nov 2022 15:13:15 +0800 +Subject: [PATCH 1/2] adjust value for IORING_ENTER_SQ_SUBMIT_ON_IDLE to sync + with kernel uapi + +Current value of IORING_ENTER_SQ_SUBMIT_ON_IDLE is too small and it is +in conflict with the upstream IORING_ENTER_REGISTERED_RING. + +Let's adjust value of IORING_ENTER_SQ_SUBMIT_ON_IDLE and prepare for +new io_uring features. + +Signed-off-by: Ziyang Zhang +--- + src/include/liburing/io_uring.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h +index cacc210..64df61b 100644 +--- a/src/include/liburing/io_uring.h ++++ b/src/include/liburing/io_uring.h +@@ -228,7 +228,7 @@ struct io_cqring_offsets { + #define IORING_ENTER_GETEVENTS (1U << 0) + #define IORING_ENTER_SQ_WAKEUP (1U << 1) + #define IORING_ENTER_EXT_ARG (1U << 3) +-#define IORING_ENTER_SQ_SUBMIT_ON_IDLE (1U << 4) ++#define IORING_ENTER_SQ_SUBMIT_ON_IDLE (1U << 31) + + /* + * Passed in for io_uring_setup(2). Copied back with updated info on success +-- +2.31.1 + diff --git a/1016-liburing-anolis-test-add-ioctl-test.patch b/1019-liburing-anolis-Add-a-test-for-sqpoll-sq_thread_idle_us-mode.patch similarity index 31% rename from 1016-liburing-anolis-test-add-ioctl-test.patch rename to 1019-liburing-anolis-Add-a-test-for-sqpoll-sq_thread_idle_us-mode.patch index 3b35ace..48ac945 100644 --- a/1016-liburing-anolis-test-add-ioctl-test.patch +++ b/1019-liburing-anolis-Add-a-test-for-sqpoll-sq_thread_idle_us-mode.patch @@ -1,21 +1,18 @@ -From c838127df8046c4b2ab83a8b75125f91ff4d03c2 Mon Sep 17 00:00:00 2001 +From de26d9e8009058afef94d46b6a7c1751fadae894 Mon Sep 17 00:00:00 2001 From: Hao Xu -Date: Thu, 25 Feb 2021 17:26:59 +0800 -Subject: [PATCH] test: add ioctl test - -add a test for ioctl, make sure there is a device for this test in the -TEST_FILES in conifg.local. -eg. declare -A TEST_FILES=(["ioctl"]="/dev/nvme0n1") +Date: Thu, 18 Nov 2021 15:51:54 +0800 +Subject: [PATCH 2/2] Add a test for sqpoll sq_thread_idle_us mode +Reviewed-by: Xiaoguang Wang Signed-off-by: Hao Xu --- - test/Makefile | 4 +- - test/ioctl.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 178 insertions(+), 2 deletions(-) - create mode 100644 test/ioctl.c + test/Makefile | 4 +- + test/sqpoll-idle-us.c | 98 +++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 100 insertions(+), 2 deletions(-) + create mode 100644 test/sqpoll-idle-us.c diff --git a/test/Makefile b/test/Makefile -index 0720dcd39950..9e911e6a596a 100644 +index 0720dcd..b58858b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -26,7 +26,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register @@ -23,7 +20,7 @@ index 0720dcd39950..9e911e6a596a 100644 lfs-openat lfs-openat-write iopoll d4ae271dfaae-test \ eventfd-disable close-opath ce593a6c480a-test cq-overflow-peek \ - timeout-new -+ timeout-new ioctl ++ timeout-new sqpoll-idle-us include ../Makefile.quiet @@ -32,192 +29,114 @@ index 0720dcd39950..9e911e6a596a 100644 splice.c lfs-openat.c lfs-openat-write.c iopoll.c d4ae271dfaae-test.c \ eventfd-disable.c close-opath.c ce593a6c480a-test.c cq-overflow-peek.c \ - timeout-new.c -+ timeout-new.c ioctl.c ++ timeout-new.c sqpoll-idle-us.c ifdef CONFIG_HAVE_STATX test_srcs += statx.c -diff --git a/test/ioctl.c b/test/ioctl.c +diff --git a/test/sqpoll-idle-us.c b/test/sqpoll-idle-us.c new file mode 100644 -index 000000000000..33077fb5ffc7 +index 0000000..957ea7c --- /dev/null -+++ b/test/ioctl.c -@@ -0,0 +1,176 @@ -+/* SPDX-License-Identifier: MIT */ ++++ b/test/sqpoll-idle-us.c +@@ -0,0 +1,98 @@ +/* -+ * Description: test io_uring ioctl -+ * ++ * Test sqpoll sq_thread_idle in us mode + */ ++#include +#include +#include -+#include -+#include -+#include +#include -+#include -+ +#include "liburing.h" + -+#ifndef BLKDISCARD -+#define BLKDISCARD _IO(0x12,119) -+#endif -+ -+typedef unsigned long long ull; -+char *dev_path; -+ -+static int init_params(int cmd, int *fd, int *len, void **buf) -+{ -+ *len = cmd; -+ switch (cmd) { -+ case BLKDISCARD: -+ *fd = open(dev_path, O_RDWR); -+ ull *range = (ull *)malloc(sizeof(ull) * 2); -+ range[0] = 0; -+ range[1] = 1024; -+ *buf = range; -+ break; -+ default: -+ return -1; -+ } -+ -+ return 0; -+} ++#define DEFAULT_IDLE_US 50 + -+int ioctl_clean(int cmd, int fd, void *buf) ++static int submit_single_nop(struct io_uring *ring, bool submit_on_idle) +{ -+ int ret; -+ if (fd > 0) { -+ ret = close(fd); -+ if (ret) -+ return ret; -+ } -+ -+ switch (cmd) { -+ case BLKDISCARD: -+ if (buf) -+ free(buf); -+ break; -+ } -+ -+ return 0; -+} -+static int ioctl_extra_check(int cmd, void *buf) -+{ -+ switch (cmd) { -+ case BLKDISCARD: -+ break; -+ } -+ return 0; -+} -+ -+static int test_ioctl(struct io_uring *ring, int cmd) -+{ -+ struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; -+ int fd = 0, len, ret, ret2; -+ void *buf = NULL; -+ -+ ret = init_params(cmd, &fd, &len, &buf); -+ if (ret == -1) { -+ perror("invalid command"); -+ goto err; -+ } -+ if (fd < 0) { -+ perror("open"); -+ goto err; -+ } ++ int ret; + + sqe = io_uring_get_sqe(ring); + if (!sqe) { + fprintf(stderr, "get sqe failed\n"); + goto err; + } -+ io_uring_prep_ioctl(sqe, fd, len, buf); + -+ ret = io_uring_submit(ring); ++ io_uring_prep_nop(sqe); ++ ++ if (submit_on_idle) ++ ret = io_uring_submit_on_idle(ring); ++ else ++ ret = io_uring_submit(ring); + if (ret <= 0) { + fprintf(stderr, "sqe submit failed: %d\n", ret); + goto err; + } + -+ ret = io_uring_wait_cqe(ring, &cqe); -+ if (ret < 0) { -+ fprintf(stderr, "wait completion %d\n", ret); -+ goto err; -+ } ++ return 0; ++err: ++ return 1; ++} + -+ ret = 1; -+ switch (cqe->res) { -+ /* -+ * Two cases return -EINVAL: -+ * - sys_ioctl() itself returns it -+ * - IORING_OP_IOCTL isn't supported in io_uring -+ * -+ * To distinguish them, one solution is to return other stuff other -+ * than -EINVAL when sys_ioctl() logic returns -EINVAL. But this -+ * change the logic of the original sys_ioctl() syscall. -+ * Leave it as it is for now. -+ */ -+ case -EINVAL: -+ fprintf(stderr, "cqe->res is -EINVAL\n"); -+ break; -+ case -EFAULT: -+ fprintf(stderr, "cqe->res is -EFAULT\n"); -+ break; -+ case -EBADF: -+ fprintf(stderr, "cqe->res is -EBADF\n"); -+ break; -+ case -ENOTTY: -+ fprintf(stderr, "cqe->res is -ENOTTY\n"); -+ break; -+ default: -+ if (cqe->res) { -+ fprintf(stderr, "cqe->res is %d\n", cqe->res); -+ } else if (ioctl_extra_check(cmd, buf)) { -+ fprintf(stderr, "ioctl cmd:%d failed\n", cmd); -+ } else { -+ ret = 0; ++static int reap_cqes(struct io_uring *ring, int count) ++{ ++ int ret; ++ struct io_uring_cqe *cqe; ++ ++ while(count--) { ++ ret = io_uring_wait_cqe(ring, &cqe); ++ if (ret < 0) { ++ fprintf(stderr, "wait completion %d\n", ret); ++ return 1; + } ++ io_uring_cqe_seen(ring, cqe); + } ++ return 0; ++} + -+ io_uring_cqe_seen(ring, cqe); -+err: -+ ret2 = ioctl_clean(cmd, fd, buf); -+ /* -+ * it's not a test error, just print warning, still return 0 -+ */ -+ if (ret2) -+ fprintf(stderr, "close test file failure\n"); ++static int test_sqpoll_idle_us(int nr) ++{ ++ struct io_uring_params p = {}; ++ struct io_uring ring; ++ int ret, count = nr; ++ ++ srand((unsigned)time(NULL)); ++ p.flags = (IORING_SETUP_SQPOLL | IORING_SETUP_SQPOLL_PERCPU | IORING_SETUP_IDLE_US); ++ p.sq_thread_idle = DEFAULT_IDLE_US; + -+ return ret; ++ ret = io_uring_queue_init_params(nr + 10, &ring, &p); ++ if (ret) { ++ fprintf(stderr, "queue_init=%d\n", ret); ++ return 1; ++ } ++ while (nr--) { ++ unsigned x = p.sq_thread_idle; ++ /* ++ * sleep some time to make sure sqthread often sleeps. ++ * [(1 / 2) * sq_thread_idle, (2 + 1 / 2) * sq_thread_idle) ++ */ ++ usleep((x >> 1) + rand() % (x << 1)); ++ ret = submit_single_nop(&ring, nr % 2); ++ if (ret) ++ return ret; ++ } ++ return reap_cqes(&ring, count); +} + +int main(int argc, char *argv[]) +{ -+ struct io_uring ring; + int ret; + -+ if (argc < 2) { -+ fprintf(stderr, "no ssd device indicated, skip.\n"); ++ if (argc > 1) + return 0; -+ } + -+ dev_path = argv[1]; -+ -+ ret = io_uring_queue_init(8, &ring, 0); ++ ret = test_sqpoll_idle_us(10000); + if (ret) { -+ fprintf(stderr, "ring setup failed\n"); ++ fprintf(stderr, "test failed: %d\n", ret); + return 1; + } + -+ ret = test_ioctl(&ring, BLKDISCARD); -+ if (ret) { -+ fprintf(stderr, "test_ioctl BLKDISCARD failed\n"); -+ return ret; -+ } -+ + return 0; +} -+ -- -1.8.3.1 +2.31.1 diff --git a/liburing.spec b/liburing.spec index cf65dd8..7a74e37 100644 --- a/liburing.spec +++ b/liburing.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 Name: liburing Version: 1.0.7 @@ -22,13 +22,13 @@ Patch1009: 1009-liburing-anolis-Add-wrapper-for-__io_uring_get_cqe.patch Patch1010: 1010-liburing-anolis-Use-IORING_ENTER_GETEVENTS_TIMEOUT-if-available.patch Patch1011: 1011-liburing-anolis-Update-SIG_IS_DATA-to-modified-kernel-API.patch Patch1012: 1012-liburing-anolis-Rename-SIG_IS_DATA-EXT_ARG.patch -Patch1013: 1013-liburing-anolis-support-async-ioctl-in-liburing.patch -Patch1014: 1014-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch -Patch1015: 1015-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch -Patch1016: 1016-liburing-anolis-test-add-ioctl-test.patch -Patch1017: 1017-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch -Patch1018: 1018-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch -Patch1019: 1019-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch +Patch1013: 1013-liburing-anolis-test-timeout-new-test-for-timeout-feature.patch +Patch1014: 1014-liburing-anolis-test-use-a-map-to-define-test-files-devices-we-need.patch +Patch1015: 1015-liburing-anolis-test-timeout-overflow-don-t-run-on-newer-kernels.patch +Patch1016: 1016-liburing-anolis-support-us-granularity-of-io_sq_thread_idle.patch +Patch1017: 1017-liburing-anolis-add-IORING_ENTER_SQ_SUBMIT_ON_IDLE-flag.patch +Patch1018: 1018-liburing-anolis-adjust-value-for-IORING_ENTER_SQ_SUBMIT_ON_IDLE-to-s.patch +Patch1019: 1019-liburing-anolis-Add-a-test-for-sqpoll-sq_thread_idle_us-mode.patch # End: Anolis customized patches %description @@ -68,6 +68,11 @@ for the Linux-native io_uring. %{_mandir}/man2/* %changelog +* Tue Dec 6 2022 Ziyang Zhang - 1.0.7-3.0.2 +- revert io_uring ioctl support +- update uapi for IORING_ENTER_SQ_SUBMIT_ON_IDLE +- add a test for sqpoll sq_thread_idle_us mode + * Mon Nov 29 2021 Hao Xu - 1.0.7-3.0.1 - add anolis customized patches to support features in Anolis OS Kernel -- Gitee