polyphony 0.84 → 0.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -1
- data/examples/core/multi_suspend.rb +39 -0
- data/examples/core/shutdown_all_children.rb +41 -0
- data/examples/io/gzip.rb +8 -0
- data/examples/io/splice_echo_server.rb +15 -0
- data/ext/polyphony/backend_io_uring.c +57 -31
- data/ext/polyphony/io_extensions.c +137 -26
- data/lib/polyphony/extensions/fiber.rb +3 -1
- data/lib/polyphony/extensions/io.rb +4 -0
- data/lib/polyphony/extensions/pipe.rb +4 -0
- data/lib/polyphony/extensions/socket.rb +4 -0
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- data/test/test_fiber.rb +5 -2
- data/test/test_signal.rb +3 -3
- data/vendor/liburing/.github/pull_request_template.md +86 -0
- data/vendor/liburing/.github/workflows/build.yml +85 -0
- data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
- data/vendor/liburing/.gitignore +149 -0
- data/vendor/liburing/COPYING +502 -0
- data/vendor/liburing/COPYING.GPL +339 -0
- data/vendor/liburing/LICENSE +7 -0
- data/vendor/liburing/Makefile +82 -0
- data/vendor/liburing/Makefile.common +5 -0
- data/vendor/liburing/Makefile.quiet +11 -0
- data/vendor/liburing/README +46 -0
- data/vendor/liburing/configure +486 -0
- data/vendor/liburing/debian/README.Debian +7 -0
- data/vendor/liburing/debian/changelog +27 -0
- data/vendor/liburing/debian/compat +1 -0
- data/vendor/liburing/debian/control +48 -0
- data/vendor/liburing/debian/copyright +49 -0
- data/vendor/liburing/debian/liburing-dev.install +4 -0
- data/vendor/liburing/debian/liburing-dev.manpages +6 -0
- data/vendor/liburing/debian/liburing1-udeb.install +1 -0
- data/vendor/liburing/debian/liburing1.install +1 -0
- data/vendor/liburing/debian/liburing1.symbols +32 -0
- data/vendor/liburing/debian/patches/series +1 -0
- data/vendor/liburing/debian/rules +81 -0
- data/vendor/liburing/debian/source/format +1 -0
- data/vendor/liburing/debian/source/local-options +2 -0
- data/vendor/liburing/debian/source/options +1 -0
- data/vendor/liburing/debian/watch +3 -0
- data/vendor/liburing/examples/Makefile +38 -0
- data/vendor/liburing/examples/io_uring-cp.c +282 -0
- data/vendor/liburing/examples/io_uring-test.c +112 -0
- data/vendor/liburing/examples/link-cp.c +193 -0
- data/vendor/liburing/examples/ucontext-cp.c +273 -0
- data/vendor/liburing/liburing.pc.in +12 -0
- data/vendor/liburing/liburing.spec +66 -0
- data/vendor/liburing/make-debs.sh +53 -0
- data/vendor/liburing/man/io_uring.7 +754 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
- data/vendor/liburing/man/io_uring_enter.2 +1483 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
- data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
- data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
- data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
- data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
- data/vendor/liburing/man/io_uring_register.2 +688 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
- data/vendor/liburing/man/io_uring_register_files.3 +35 -0
- data/vendor/liburing/man/io_uring_setup.2 +534 -0
- data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
- data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
- data/vendor/liburing/man/io_uring_submit.3 +29 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
- data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
- data/vendor/liburing/src/Makefile +89 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
- data/vendor/liburing/src/arch/generic/lib.h +21 -0
- data/vendor/liburing/src/arch/generic/syscall.h +87 -0
- data/vendor/liburing/src/arch/syscall-defs.h +67 -0
- data/vendor/liburing/src/arch/x86/lib.h +32 -0
- data/vendor/liburing/src/arch/x86/syscall.h +160 -0
- data/vendor/liburing/src/include/liburing/barrier.h +81 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
- data/vendor/liburing/src/include/liburing.h +921 -0
- data/vendor/liburing/src/int_flags.h +8 -0
- data/vendor/liburing/src/lib.h +57 -0
- data/vendor/liburing/src/liburing.map +53 -0
- data/vendor/liburing/src/nolibc.c +48 -0
- data/vendor/liburing/src/queue.c +403 -0
- data/vendor/liburing/src/register.c +293 -0
- data/vendor/liburing/src/setup.c +332 -0
- data/vendor/liburing/src/syscall.c +47 -0
- data/vendor/liburing/src/syscall.h +103 -0
- data/vendor/liburing/test/232c93d07b74-test.c +306 -0
- data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
- data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
- data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
- data/vendor/liburing/test/8a9973408177-test.c +106 -0
- data/vendor/liburing/test/917257daa0fe-test.c +53 -0
- data/vendor/liburing/test/Makefile +244 -0
- data/vendor/liburing/test/a0908ae19763-test.c +58 -0
- data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
- data/vendor/liburing/test/accept-link.c +254 -0
- data/vendor/liburing/test/accept-reuse.c +164 -0
- data/vendor/liburing/test/accept-test.c +79 -0
- data/vendor/liburing/test/accept.c +477 -0
- data/vendor/liburing/test/across-fork.c +283 -0
- data/vendor/liburing/test/b19062a56726-test.c +53 -0
- data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
- data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
- data/vendor/liburing/test/close-opath.c +122 -0
- data/vendor/liburing/test/config +10 -0
- data/vendor/liburing/test/connect.c +398 -0
- data/vendor/liburing/test/cq-full.c +96 -0
- data/vendor/liburing/test/cq-overflow.c +294 -0
- data/vendor/liburing/test/cq-peek-batch.c +102 -0
- data/vendor/liburing/test/cq-ready.c +94 -0
- data/vendor/liburing/test/cq-size.c +64 -0
- data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
- data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
- data/vendor/liburing/test/defer.c +307 -0
- data/vendor/liburing/test/double-poll-crash.c +185 -0
- data/vendor/liburing/test/drop-submit.c +92 -0
- data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
- data/vendor/liburing/test/empty-eownerdead.c +45 -0
- data/vendor/liburing/test/eventfd-disable.c +151 -0
- data/vendor/liburing/test/eventfd-reg.c +76 -0
- data/vendor/liburing/test/eventfd-ring.c +97 -0
- data/vendor/liburing/test/eventfd.c +112 -0
- data/vendor/liburing/test/exec-target.c +6 -0
- data/vendor/liburing/test/exit-no-cleanup.c +117 -0
- data/vendor/liburing/test/fadvise.c +202 -0
- data/vendor/liburing/test/fallocate.c +249 -0
- data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
- data/vendor/liburing/test/file-register.c +858 -0
- data/vendor/liburing/test/file-update.c +173 -0
- data/vendor/liburing/test/file-verify.c +629 -0
- data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
- data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
- data/vendor/liburing/test/fixed-link.c +90 -0
- data/vendor/liburing/test/fpos.c +252 -0
- data/vendor/liburing/test/fsync.c +224 -0
- data/vendor/liburing/test/hardlink.c +136 -0
- data/vendor/liburing/test/helpers.c +135 -0
- data/vendor/liburing/test/helpers.h +67 -0
- data/vendor/liburing/test/io-cancel.c +550 -0
- data/vendor/liburing/test/io_uring_enter.c +296 -0
- data/vendor/liburing/test/io_uring_register.c +676 -0
- data/vendor/liburing/test/io_uring_setup.c +192 -0
- data/vendor/liburing/test/iopoll.c +372 -0
- data/vendor/liburing/test/lfs-openat-write.c +119 -0
- data/vendor/liburing/test/lfs-openat.c +275 -0
- data/vendor/liburing/test/link-timeout.c +1107 -0
- data/vendor/liburing/test/link.c +496 -0
- data/vendor/liburing/test/link_drain.c +229 -0
- data/vendor/liburing/test/madvise.c +195 -0
- data/vendor/liburing/test/mkdir.c +108 -0
- data/vendor/liburing/test/msg-ring.c +234 -0
- data/vendor/liburing/test/multicqes_drain.c +387 -0
- data/vendor/liburing/test/nop-all-sizes.c +99 -0
- data/vendor/liburing/test/nop.c +115 -0
- data/vendor/liburing/test/open-close.c +261 -0
- data/vendor/liburing/test/openat2.c +308 -0
- data/vendor/liburing/test/personality.c +204 -0
- data/vendor/liburing/test/pipe-eof.c +83 -0
- data/vendor/liburing/test/pipe-reuse.c +105 -0
- data/vendor/liburing/test/poll-cancel-ton.c +135 -0
- data/vendor/liburing/test/poll-cancel.c +228 -0
- data/vendor/liburing/test/poll-link.c +230 -0
- data/vendor/liburing/test/poll-many.c +208 -0
- data/vendor/liburing/test/poll-mshot-update.c +273 -0
- data/vendor/liburing/test/poll-ring.c +48 -0
- data/vendor/liburing/test/poll-v-poll.c +353 -0
- data/vendor/liburing/test/poll.c +109 -0
- data/vendor/liburing/test/pollfree.c +426 -0
- data/vendor/liburing/test/probe.c +135 -0
- data/vendor/liburing/test/read-write.c +876 -0
- data/vendor/liburing/test/register-restrictions.c +633 -0
- data/vendor/liburing/test/rename.c +135 -0
- data/vendor/liburing/test/ring-leak.c +173 -0
- data/vendor/liburing/test/ring-leak2.c +249 -0
- data/vendor/liburing/test/rsrc_tags.c +449 -0
- data/vendor/liburing/test/runtests-loop.sh +16 -0
- data/vendor/liburing/test/runtests.sh +170 -0
- data/vendor/liburing/test/rw_merge_test.c +97 -0
- data/vendor/liburing/test/self.c +91 -0
- data/vendor/liburing/test/send_recv.c +286 -0
- data/vendor/liburing/test/send_recvmsg.c +345 -0
- data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
- data/vendor/liburing/test/shared-wq.c +84 -0
- data/vendor/liburing/test/short-read.c +75 -0
- data/vendor/liburing/test/shutdown.c +165 -0
- data/vendor/liburing/test/sigfd-deadlock.c +74 -0
- data/vendor/liburing/test/skip-cqe.c +429 -0
- data/vendor/liburing/test/socket-rw-eagain.c +158 -0
- data/vendor/liburing/test/socket-rw-offset.c +157 -0
- data/vendor/liburing/test/socket-rw.c +145 -0
- data/vendor/liburing/test/splice.c +512 -0
- data/vendor/liburing/test/sq-full-cpp.cc +45 -0
- data/vendor/liburing/test/sq-full.c +45 -0
- data/vendor/liburing/test/sq-poll-dup.c +204 -0
- data/vendor/liburing/test/sq-poll-kthread.c +169 -0
- data/vendor/liburing/test/sq-poll-share.c +137 -0
- data/vendor/liburing/test/sq-space_left.c +159 -0
- data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
- data/vendor/liburing/test/sqpoll-sleep.c +69 -0
- data/vendor/liburing/test/statx.c +172 -0
- data/vendor/liburing/test/stdout.c +232 -0
- data/vendor/liburing/test/submit-link-fail.c +154 -0
- data/vendor/liburing/test/submit-reuse.c +239 -0
- data/vendor/liburing/test/symlink.c +116 -0
- data/vendor/liburing/test/teardowns.c +58 -0
- data/vendor/liburing/test/thread-exit.c +143 -0
- data/vendor/liburing/test/timeout-new.c +252 -0
- data/vendor/liburing/test/timeout-overflow.c +204 -0
- data/vendor/liburing/test/timeout.c +1523 -0
- data/vendor/liburing/test/unlink.c +112 -0
- data/vendor/liburing/test/wakeup-hang.c +162 -0
- metadata +227 -2
@@ -0,0 +1,45 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Test if entering with nothing to submit/wait for SQPOLL returns an error.
|
4
|
+
*/
|
5
|
+
#include <stdio.h>
|
6
|
+
#include <errno.h>
|
7
|
+
#include <string.h>
|
8
|
+
|
9
|
+
#include "liburing.h"
|
10
|
+
#include "helpers.h"
|
11
|
+
#include "../src/syscall.h"
|
12
|
+
|
13
|
+
int main(int argc, char *argv[])
|
14
|
+
{
|
15
|
+
struct io_uring_params p = {};
|
16
|
+
struct io_uring ring;
|
17
|
+
int ret;
|
18
|
+
|
19
|
+
if (argc > 1)
|
20
|
+
return 0;
|
21
|
+
|
22
|
+
p.flags = IORING_SETUP_SQPOLL;
|
23
|
+
p.sq_thread_idle = 100;
|
24
|
+
|
25
|
+
ret = t_create_ring_params(1, &ring, &p);
|
26
|
+
if (ret == T_SETUP_SKIP)
|
27
|
+
return 0;
|
28
|
+
else if (ret < 0)
|
29
|
+
goto err;
|
30
|
+
|
31
|
+
ret = __sys_io_uring_enter(ring.ring_fd, 0, 0, 0, NULL);
|
32
|
+
if (ret < 0) {
|
33
|
+
int __e = errno;
|
34
|
+
|
35
|
+
if (__e == EOWNERDEAD)
|
36
|
+
fprintf(stderr, "sqe submit unexpected failure due old kernel bug: %s\n", strerror(__e));
|
37
|
+
else
|
38
|
+
fprintf(stderr, "sqe submit unexpected failure: %s\n", strerror(__e));
|
39
|
+
goto err;
|
40
|
+
}
|
41
|
+
|
42
|
+
return 0;
|
43
|
+
err:
|
44
|
+
return 1;
|
45
|
+
}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test disable/enable notifications through eventfd
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/eventfd.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
int main(int argc, char *argv[])
|
18
|
+
{
|
19
|
+
struct io_uring_params p = {};
|
20
|
+
struct io_uring_sqe *sqe;
|
21
|
+
struct io_uring_cqe *cqe;
|
22
|
+
struct io_uring ring;
|
23
|
+
uint64_t ptr;
|
24
|
+
struct iovec vec = {
|
25
|
+
.iov_base = &ptr,
|
26
|
+
.iov_len = sizeof(ptr)
|
27
|
+
};
|
28
|
+
int ret, evfd, i;
|
29
|
+
|
30
|
+
if (argc > 1)
|
31
|
+
return 0;
|
32
|
+
|
33
|
+
ret = io_uring_queue_init_params(64, &ring, &p);
|
34
|
+
if (ret) {
|
35
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
36
|
+
return 1;
|
37
|
+
}
|
38
|
+
|
39
|
+
evfd = eventfd(0, EFD_CLOEXEC);
|
40
|
+
if (evfd < 0) {
|
41
|
+
perror("eventfd");
|
42
|
+
return 1;
|
43
|
+
}
|
44
|
+
|
45
|
+
ret = io_uring_register_eventfd(&ring, evfd);
|
46
|
+
if (ret) {
|
47
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
48
|
+
return 1;
|
49
|
+
}
|
50
|
+
|
51
|
+
if (!io_uring_cq_eventfd_enabled(&ring)) {
|
52
|
+
fprintf(stderr, "eventfd disabled\n");
|
53
|
+
return 1;
|
54
|
+
}
|
55
|
+
|
56
|
+
ret = io_uring_cq_eventfd_toggle(&ring, false);
|
57
|
+
if (ret) {
|
58
|
+
fprintf(stdout, "Skipping, CQ flags not available!\n");
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
sqe = io_uring_get_sqe(&ring);
|
63
|
+
io_uring_prep_readv(sqe, evfd, &vec, 1, 0);
|
64
|
+
sqe->user_data = 1;
|
65
|
+
|
66
|
+
ret = io_uring_submit(&ring);
|
67
|
+
if (ret != 1) {
|
68
|
+
fprintf(stderr, "submit: %d\n", ret);
|
69
|
+
return 1;
|
70
|
+
}
|
71
|
+
|
72
|
+
for (i = 0; i < 63; i++) {
|
73
|
+
sqe = io_uring_get_sqe(&ring);
|
74
|
+
io_uring_prep_nop(sqe);
|
75
|
+
sqe->user_data = 2;
|
76
|
+
}
|
77
|
+
|
78
|
+
ret = io_uring_submit(&ring);
|
79
|
+
if (ret != 63) {
|
80
|
+
fprintf(stderr, "submit: %d\n", ret);
|
81
|
+
return 1;
|
82
|
+
}
|
83
|
+
|
84
|
+
for (i = 0; i < 63; i++) {
|
85
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
86
|
+
if (ret) {
|
87
|
+
fprintf(stderr, "wait: %d\n", ret);
|
88
|
+
return 1;
|
89
|
+
}
|
90
|
+
|
91
|
+
switch (cqe->user_data) {
|
92
|
+
case 1: /* eventfd */
|
93
|
+
fprintf(stderr, "eventfd unexpected: %d\n", (int)ptr);
|
94
|
+
return 1;
|
95
|
+
case 2:
|
96
|
+
if (cqe->res) {
|
97
|
+
fprintf(stderr, "nop: %d\n", cqe->res);
|
98
|
+
return 1;
|
99
|
+
}
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
io_uring_cqe_seen(&ring, cqe);
|
103
|
+
}
|
104
|
+
|
105
|
+
ret = io_uring_cq_eventfd_toggle(&ring, true);
|
106
|
+
if (ret) {
|
107
|
+
fprintf(stderr, "io_uring_cq_eventfd_toggle: %d\n", ret);
|
108
|
+
return 1;
|
109
|
+
}
|
110
|
+
|
111
|
+
sqe = io_uring_get_sqe(&ring);
|
112
|
+
io_uring_prep_nop(sqe);
|
113
|
+
sqe->user_data = 2;
|
114
|
+
|
115
|
+
ret = io_uring_submit(&ring);
|
116
|
+
if (ret != 1) {
|
117
|
+
fprintf(stderr, "submit: %d\n", ret);
|
118
|
+
return 1;
|
119
|
+
}
|
120
|
+
|
121
|
+
for (i = 0; i < 2; i++) {
|
122
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
123
|
+
if (ret) {
|
124
|
+
fprintf(stderr, "wait: %d\n", ret);
|
125
|
+
return 1;
|
126
|
+
}
|
127
|
+
|
128
|
+
switch (cqe->user_data) {
|
129
|
+
case 1: /* eventfd */
|
130
|
+
if (cqe->res != sizeof(ptr)) {
|
131
|
+
fprintf(stderr, "read res: %d\n", cqe->res);
|
132
|
+
return 1;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (ptr != 1) {
|
136
|
+
fprintf(stderr, "eventfd: %d\n", (int)ptr);
|
137
|
+
return 1;
|
138
|
+
}
|
139
|
+
break;
|
140
|
+
case 2:
|
141
|
+
if (cqe->res) {
|
142
|
+
fprintf(stderr, "nop: %d\n", cqe->res);
|
143
|
+
return 1;
|
144
|
+
}
|
145
|
+
break;
|
146
|
+
}
|
147
|
+
io_uring_cqe_seen(&ring, cqe);
|
148
|
+
}
|
149
|
+
|
150
|
+
return 0;
|
151
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test eventfd registration+unregistration
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/eventfd.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
int main(int argc, char *argv[])
|
18
|
+
{
|
19
|
+
struct io_uring_params p = {};
|
20
|
+
struct io_uring ring;
|
21
|
+
int ret, evfd[2], i;
|
22
|
+
|
23
|
+
if (argc > 1)
|
24
|
+
return 0;
|
25
|
+
|
26
|
+
ret = io_uring_queue_init_params(8, &ring, &p);
|
27
|
+
if (ret) {
|
28
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
29
|
+
return 1;
|
30
|
+
}
|
31
|
+
|
32
|
+
evfd[0] = eventfd(0, EFD_CLOEXEC);
|
33
|
+
evfd[1] = eventfd(0, EFD_CLOEXEC);
|
34
|
+
if (evfd[0] < 0 || evfd[1] < 0) {
|
35
|
+
perror("eventfd");
|
36
|
+
return 1;
|
37
|
+
}
|
38
|
+
|
39
|
+
ret = io_uring_register_eventfd(&ring, evfd[0]);
|
40
|
+
if (ret) {
|
41
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
42
|
+
return 1;
|
43
|
+
}
|
44
|
+
|
45
|
+
/* Check that registrering again will get -EBUSY */
|
46
|
+
ret = io_uring_register_eventfd(&ring, evfd[1]);
|
47
|
+
if (ret != -EBUSY) {
|
48
|
+
fprintf(stderr, "unexpected 2nd register: %d\n", ret);
|
49
|
+
return 1;
|
50
|
+
}
|
51
|
+
close(evfd[1]);
|
52
|
+
|
53
|
+
ret = io_uring_unregister_eventfd(&ring);
|
54
|
+
if (ret) {
|
55
|
+
fprintf(stderr, "unexpected unregister: %d\n", ret);
|
56
|
+
return 1;
|
57
|
+
}
|
58
|
+
|
59
|
+
/* loop 100 registers/unregister */
|
60
|
+
for (i = 0; i < 100; i++) {
|
61
|
+
ret = io_uring_register_eventfd(&ring, evfd[0]);
|
62
|
+
if (ret) {
|
63
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
64
|
+
return 1;
|
65
|
+
}
|
66
|
+
|
67
|
+
ret = io_uring_unregister_eventfd(&ring);
|
68
|
+
if (ret) {
|
69
|
+
fprintf(stderr, "unexpected unregister: %d\n", ret);
|
70
|
+
return 1;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
close(evfd[0]);
|
75
|
+
return 0;
|
76
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: run various nop tests
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/eventfd.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
int main(int argc, char *argv[])
|
18
|
+
{
|
19
|
+
struct io_uring_params p = {};
|
20
|
+
struct io_uring ring1, ring2;
|
21
|
+
struct io_uring_sqe *sqe;
|
22
|
+
int ret, evfd1, evfd2;
|
23
|
+
|
24
|
+
if (argc > 1)
|
25
|
+
return 0;
|
26
|
+
|
27
|
+
ret = io_uring_queue_init_params(8, &ring1, &p);
|
28
|
+
if (ret) {
|
29
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
30
|
+
return 1;
|
31
|
+
}
|
32
|
+
if (!(p.features & IORING_FEAT_CUR_PERSONALITY)) {
|
33
|
+
fprintf(stdout, "Skipping\n");
|
34
|
+
return 0;
|
35
|
+
}
|
36
|
+
ret = io_uring_queue_init(8, &ring2, 0);
|
37
|
+
if (ret) {
|
38
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
39
|
+
return 1;
|
40
|
+
}
|
41
|
+
|
42
|
+
evfd1 = eventfd(0, EFD_CLOEXEC);
|
43
|
+
if (evfd1 < 0) {
|
44
|
+
perror("eventfd");
|
45
|
+
return 1;
|
46
|
+
}
|
47
|
+
|
48
|
+
evfd2 = eventfd(0, EFD_CLOEXEC);
|
49
|
+
if (evfd2 < 0) {
|
50
|
+
perror("eventfd");
|
51
|
+
return 1;
|
52
|
+
}
|
53
|
+
|
54
|
+
ret = io_uring_register_eventfd(&ring1, evfd1);
|
55
|
+
if (ret) {
|
56
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
57
|
+
return 1;
|
58
|
+
}
|
59
|
+
|
60
|
+
ret = io_uring_register_eventfd(&ring2, evfd2);
|
61
|
+
if (ret) {
|
62
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
63
|
+
return 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
sqe = io_uring_get_sqe(&ring1);
|
67
|
+
io_uring_prep_poll_add(sqe, evfd2, POLLIN);
|
68
|
+
sqe->user_data = 1;
|
69
|
+
|
70
|
+
sqe = io_uring_get_sqe(&ring2);
|
71
|
+
io_uring_prep_poll_add(sqe, evfd1, POLLIN);
|
72
|
+
sqe->user_data = 1;
|
73
|
+
|
74
|
+
ret = io_uring_submit(&ring1);
|
75
|
+
if (ret != 1) {
|
76
|
+
fprintf(stderr, "submit: %d\n", ret);
|
77
|
+
return 1;
|
78
|
+
}
|
79
|
+
|
80
|
+
ret = io_uring_submit(&ring2);
|
81
|
+
if (ret != 1) {
|
82
|
+
fprintf(stderr, "submit: %d\n", ret);
|
83
|
+
return 1;
|
84
|
+
}
|
85
|
+
|
86
|
+
sqe = io_uring_get_sqe(&ring1);
|
87
|
+
io_uring_prep_nop(sqe);
|
88
|
+
sqe->user_data = 3;
|
89
|
+
|
90
|
+
ret = io_uring_submit(&ring1);
|
91
|
+
if (ret != 1) {
|
92
|
+
fprintf(stderr, "submit: %d\n", ret);
|
93
|
+
return 1;
|
94
|
+
}
|
95
|
+
|
96
|
+
return 0;
|
97
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: run various nop tests
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/eventfd.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
int main(int argc, char *argv[])
|
18
|
+
{
|
19
|
+
struct io_uring_params p = {};
|
20
|
+
struct io_uring_sqe *sqe;
|
21
|
+
struct io_uring_cqe *cqe;
|
22
|
+
struct io_uring ring;
|
23
|
+
uint64_t ptr;
|
24
|
+
struct iovec vec = {
|
25
|
+
.iov_base = &ptr,
|
26
|
+
.iov_len = sizeof(ptr)
|
27
|
+
};
|
28
|
+
int ret, evfd, i;
|
29
|
+
|
30
|
+
if (argc > 1)
|
31
|
+
return 0;
|
32
|
+
|
33
|
+
ret = io_uring_queue_init_params(8, &ring, &p);
|
34
|
+
if (ret) {
|
35
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
36
|
+
return 1;
|
37
|
+
}
|
38
|
+
if (!(p.features & IORING_FEAT_CUR_PERSONALITY)) {
|
39
|
+
fprintf(stdout, "Skipping\n");
|
40
|
+
return 0;
|
41
|
+
}
|
42
|
+
|
43
|
+
evfd = eventfd(0, EFD_CLOEXEC);
|
44
|
+
if (evfd < 0) {
|
45
|
+
perror("eventfd");
|
46
|
+
return 1;
|
47
|
+
}
|
48
|
+
|
49
|
+
ret = io_uring_register_eventfd(&ring, evfd);
|
50
|
+
if (ret) {
|
51
|
+
fprintf(stderr, "failed to register evfd: %d\n", ret);
|
52
|
+
return 1;
|
53
|
+
}
|
54
|
+
|
55
|
+
sqe = io_uring_get_sqe(&ring);
|
56
|
+
io_uring_prep_poll_add(sqe, evfd, POLLIN);
|
57
|
+
sqe->flags |= IOSQE_IO_LINK;
|
58
|
+
sqe->user_data = 1;
|
59
|
+
|
60
|
+
sqe = io_uring_get_sqe(&ring);
|
61
|
+
io_uring_prep_readv(sqe, evfd, &vec, 1, 0);
|
62
|
+
sqe->flags |= IOSQE_IO_LINK;
|
63
|
+
sqe->user_data = 2;
|
64
|
+
|
65
|
+
ret = io_uring_submit(&ring);
|
66
|
+
if (ret != 2) {
|
67
|
+
fprintf(stderr, "submit: %d\n", ret);
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
sqe = io_uring_get_sqe(&ring);
|
72
|
+
io_uring_prep_nop(sqe);
|
73
|
+
sqe->user_data = 3;
|
74
|
+
|
75
|
+
ret = io_uring_submit(&ring);
|
76
|
+
if (ret != 1) {
|
77
|
+
fprintf(stderr, "submit: %d\n", ret);
|
78
|
+
return 1;
|
79
|
+
}
|
80
|
+
|
81
|
+
for (i = 0; i < 3; i++) {
|
82
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
83
|
+
if (ret) {
|
84
|
+
fprintf(stderr, "wait: %d\n", ret);
|
85
|
+
return 1;
|
86
|
+
}
|
87
|
+
switch (cqe->user_data) {
|
88
|
+
case 1:
|
89
|
+
/* POLLIN */
|
90
|
+
if (cqe->res != 1) {
|
91
|
+
fprintf(stderr, "poll: %d\n", cqe->res);
|
92
|
+
return 1;
|
93
|
+
}
|
94
|
+
break;
|
95
|
+
case 2:
|
96
|
+
if (cqe->res != sizeof(ptr)) {
|
97
|
+
fprintf(stderr, "read: %d\n", cqe->res);
|
98
|
+
return 1;
|
99
|
+
}
|
100
|
+
break;
|
101
|
+
case 3:
|
102
|
+
if (cqe->res) {
|
103
|
+
fprintf(stderr, "nop: %d\n", cqe->res);
|
104
|
+
return 1;
|
105
|
+
}
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
io_uring_cqe_seen(&ring, cqe);
|
109
|
+
}
|
110
|
+
|
111
|
+
return 0;
|
112
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Test case testing exit without cleanup and io-wq work pending or queued.
|
4
|
+
*
|
5
|
+
* From Florian Fischer <florian.fl.fischer@fau.de>
|
6
|
+
* Link: https://lore.kernel.org/io-uring/20211202165606.mqryio4yzubl7ms5@pasture/
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
#include <assert.h>
|
10
|
+
#include <err.h>
|
11
|
+
#include <errno.h>
|
12
|
+
#include <pthread.h>
|
13
|
+
#include <semaphore.h>
|
14
|
+
#include <stdio.h>
|
15
|
+
#include <stdlib.h>
|
16
|
+
#include <sys/sysinfo.h>
|
17
|
+
#include <unistd.h>
|
18
|
+
|
19
|
+
#include "liburing.h"
|
20
|
+
#include "helpers.h"
|
21
|
+
|
22
|
+
#define IORING_ENTRIES 8
|
23
|
+
|
24
|
+
static pthread_t *threads;
|
25
|
+
static pthread_barrier_t init_barrier;
|
26
|
+
static int sleep_fd, notify_fd;
|
27
|
+
static sem_t sem;
|
28
|
+
|
29
|
+
void *thread_func(void *arg)
|
30
|
+
{
|
31
|
+
struct io_uring ring;
|
32
|
+
int res;
|
33
|
+
|
34
|
+
res = io_uring_queue_init(IORING_ENTRIES, &ring, 0);
|
35
|
+
if (res)
|
36
|
+
err(EXIT_FAILURE, "io_uring_queue_init failed");
|
37
|
+
|
38
|
+
pthread_barrier_wait(&init_barrier);
|
39
|
+
|
40
|
+
for(;;) {
|
41
|
+
struct io_uring_cqe *cqe;
|
42
|
+
struct io_uring_sqe *sqe;
|
43
|
+
uint64_t buf;
|
44
|
+
int res;
|
45
|
+
|
46
|
+
sqe = io_uring_get_sqe(&ring);
|
47
|
+
assert(sqe);
|
48
|
+
|
49
|
+
io_uring_prep_read(sqe, sleep_fd, &buf, sizeof(buf), 0);
|
50
|
+
|
51
|
+
res = io_uring_submit_and_wait(&ring, 1);
|
52
|
+
if (res < 0)
|
53
|
+
err(EXIT_FAILURE, "io_uring_submit_and_wait failed");
|
54
|
+
|
55
|
+
res = io_uring_peek_cqe(&ring, &cqe);
|
56
|
+
assert(!res);
|
57
|
+
if (cqe->res < 0) {
|
58
|
+
errno = -cqe->res;
|
59
|
+
err(EXIT_FAILURE, "read failed");
|
60
|
+
}
|
61
|
+
assert(cqe->res == sizeof(buf));
|
62
|
+
|
63
|
+
sem_post(&sem);
|
64
|
+
|
65
|
+
io_uring_cqe_seen(&ring, cqe);
|
66
|
+
}
|
67
|
+
|
68
|
+
return NULL;
|
69
|
+
}
|
70
|
+
|
71
|
+
int main(int argc, char *argv[])
|
72
|
+
{
|
73
|
+
int res, fds[2], i, cpus;
|
74
|
+
const uint64_t n = 0x42;
|
75
|
+
|
76
|
+
if (argc > 1)
|
77
|
+
return 0;
|
78
|
+
|
79
|
+
cpus = get_nprocs();
|
80
|
+
res = pthread_barrier_init(&init_barrier, NULL, cpus);
|
81
|
+
if (res)
|
82
|
+
err(EXIT_FAILURE, "pthread_barrier_init failed");
|
83
|
+
|
84
|
+
res = sem_init(&sem, 0, 0);
|
85
|
+
if (res)
|
86
|
+
err(EXIT_FAILURE, "sem_init failed");
|
87
|
+
|
88
|
+
threads = t_malloc(sizeof(pthread_t) * cpus);
|
89
|
+
|
90
|
+
res = pipe(fds);
|
91
|
+
if (res)
|
92
|
+
err(EXIT_FAILURE, "pipe failed");
|
93
|
+
|
94
|
+
sleep_fd = fds[0];
|
95
|
+
notify_fd = fds[1];
|
96
|
+
|
97
|
+
for (i = 0; i < cpus; i++) {
|
98
|
+
errno = pthread_create(&threads[i], NULL, thread_func, NULL);
|
99
|
+
if (errno)
|
100
|
+
err(EXIT_FAILURE, "pthread_create failed");
|
101
|
+
}
|
102
|
+
|
103
|
+
// Write #cpus notifications
|
104
|
+
for (i = 0; i < cpus; i++) {
|
105
|
+
res = write(notify_fd, &n, sizeof(n));
|
106
|
+
if (res < 0)
|
107
|
+
err(EXIT_FAILURE, "write failed");
|
108
|
+
assert(res == sizeof(n));
|
109
|
+
}
|
110
|
+
|
111
|
+
// Await that all notifications were received
|
112
|
+
for (i = 0; i < cpus; i++)
|
113
|
+
sem_wait(&sem);
|
114
|
+
|
115
|
+
// Exit without resource cleanup
|
116
|
+
exit(EXIT_SUCCESS);
|
117
|
+
}
|