polyphony 0.85 → 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 +4 -0
- data/Gemfile.lock +1 -1
- data/ext/polyphony/io_extensions.c +2 -3
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- 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 +223 -2
@@ -0,0 +1,228 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test io_uring poll cancel handling
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <inttypes.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/wait.h>
|
14
|
+
#include <signal.h>
|
15
|
+
|
16
|
+
#include "liburing.h"
|
17
|
+
|
18
|
+
struct poll_data {
|
19
|
+
unsigned is_poll;
|
20
|
+
unsigned is_cancel;
|
21
|
+
};
|
22
|
+
|
23
|
+
static void sig_alrm(int sig)
|
24
|
+
{
|
25
|
+
fprintf(stderr, "Timed out!\n");
|
26
|
+
exit(1);
|
27
|
+
}
|
28
|
+
|
29
|
+
static int test_poll_cancel(void)
|
30
|
+
{
|
31
|
+
struct io_uring ring;
|
32
|
+
int pipe1[2];
|
33
|
+
struct io_uring_cqe *cqe;
|
34
|
+
struct io_uring_sqe *sqe;
|
35
|
+
struct poll_data *pd, pds[2];
|
36
|
+
struct sigaction act;
|
37
|
+
int ret;
|
38
|
+
|
39
|
+
if (pipe(pipe1) != 0) {
|
40
|
+
perror("pipe");
|
41
|
+
return 1;
|
42
|
+
}
|
43
|
+
|
44
|
+
ret = io_uring_queue_init(2, &ring, 0);
|
45
|
+
if (ret) {
|
46
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
47
|
+
return 1;
|
48
|
+
}
|
49
|
+
|
50
|
+
memset(&act, 0, sizeof(act));
|
51
|
+
act.sa_handler = sig_alrm;
|
52
|
+
act.sa_flags = SA_RESTART;
|
53
|
+
sigaction(SIGALRM, &act, NULL);
|
54
|
+
alarm(1);
|
55
|
+
|
56
|
+
sqe = io_uring_get_sqe(&ring);
|
57
|
+
if (!sqe) {
|
58
|
+
fprintf(stderr, "get sqe failed\n");
|
59
|
+
return 1;
|
60
|
+
}
|
61
|
+
|
62
|
+
io_uring_prep_poll_add(sqe, pipe1[0], POLLIN);
|
63
|
+
|
64
|
+
pds[0].is_poll = 1;
|
65
|
+
pds[0].is_cancel = 0;
|
66
|
+
io_uring_sqe_set_data(sqe, &pds[0]);
|
67
|
+
|
68
|
+
ret = io_uring_submit(&ring);
|
69
|
+
if (ret <= 0) {
|
70
|
+
fprintf(stderr, "sqe submit failed\n");
|
71
|
+
return 1;
|
72
|
+
}
|
73
|
+
|
74
|
+
sqe = io_uring_get_sqe(&ring);
|
75
|
+
if (!sqe) {
|
76
|
+
fprintf(stderr, "get sqe failed\n");
|
77
|
+
return 1;
|
78
|
+
}
|
79
|
+
|
80
|
+
pds[1].is_poll = 0;
|
81
|
+
pds[1].is_cancel = 1;
|
82
|
+
io_uring_prep_poll_remove(sqe, (__u64)(uintptr_t)&pds[0]);
|
83
|
+
io_uring_sqe_set_data(sqe, &pds[1]);
|
84
|
+
|
85
|
+
ret = io_uring_submit(&ring);
|
86
|
+
if (ret <= 0) {
|
87
|
+
fprintf(stderr, "sqe submit failed: %d\n", ret);
|
88
|
+
return 1;
|
89
|
+
}
|
90
|
+
|
91
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
92
|
+
if (ret < 0) {
|
93
|
+
fprintf(stderr, "wait cqe failed: %d\n", ret);
|
94
|
+
return 1;
|
95
|
+
}
|
96
|
+
|
97
|
+
pd = io_uring_cqe_get_data(cqe);
|
98
|
+
if (pd->is_poll && cqe->res != -ECANCELED) {
|
99
|
+
fprintf(stderr ,"sqe (add=%d/remove=%d) failed with %ld\n",
|
100
|
+
pd->is_poll, pd->is_cancel,
|
101
|
+
(long) cqe->res);
|
102
|
+
return 1;
|
103
|
+
} else if (pd->is_cancel && cqe->res) {
|
104
|
+
fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
|
105
|
+
pd->is_poll, pd->is_cancel,
|
106
|
+
(long) cqe->res);
|
107
|
+
return 1;
|
108
|
+
}
|
109
|
+
io_uring_cqe_seen(&ring, cqe);
|
110
|
+
|
111
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
112
|
+
if (ret < 0) {
|
113
|
+
fprintf(stderr, "wait_cqe: %d\n", ret);
|
114
|
+
return 1;
|
115
|
+
}
|
116
|
+
|
117
|
+
pd = io_uring_cqe_get_data(cqe);
|
118
|
+
if (pd->is_poll && cqe->res != -ECANCELED) {
|
119
|
+
fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
|
120
|
+
pd->is_poll, pd->is_cancel,
|
121
|
+
(long) cqe->res);
|
122
|
+
return 1;
|
123
|
+
} else if (pd->is_cancel && cqe->res) {
|
124
|
+
fprintf(stderr, "sqe (add=%d/remove=%d) failed with %ld\n",
|
125
|
+
pd->is_poll, pd->is_cancel,
|
126
|
+
(long) cqe->res);
|
127
|
+
return 1;
|
128
|
+
}
|
129
|
+
|
130
|
+
close(pipe1[0]);
|
131
|
+
close(pipe1[1]);
|
132
|
+
io_uring_cqe_seen(&ring, cqe);
|
133
|
+
io_uring_queue_exit(&ring);
|
134
|
+
return 0;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
static int __test_poll_cancel_with_timeouts(void)
|
139
|
+
{
|
140
|
+
struct __kernel_timespec ts = { .tv_sec = 10, };
|
141
|
+
struct io_uring ring, ring2;
|
142
|
+
struct io_uring_sqe *sqe;
|
143
|
+
int ret, off_nr = 1000;
|
144
|
+
|
145
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
146
|
+
if (ret) {
|
147
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
148
|
+
return 1;
|
149
|
+
}
|
150
|
+
|
151
|
+
ret = io_uring_queue_init(1, &ring2, 0);
|
152
|
+
if (ret) {
|
153
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
154
|
+
return 1;
|
155
|
+
}
|
156
|
+
|
157
|
+
/* test timeout-offset triggering path during cancellation */
|
158
|
+
sqe = io_uring_get_sqe(&ring);
|
159
|
+
io_uring_prep_timeout(sqe, &ts, off_nr, 0);
|
160
|
+
|
161
|
+
/* poll ring2 to trigger cancellation on exit() */
|
162
|
+
sqe = io_uring_get_sqe(&ring);
|
163
|
+
io_uring_prep_poll_add(sqe, ring2.ring_fd, POLLIN);
|
164
|
+
sqe->flags |= IOSQE_IO_LINK;
|
165
|
+
|
166
|
+
sqe = io_uring_get_sqe(&ring);
|
167
|
+
io_uring_prep_link_timeout(sqe, &ts, 0);
|
168
|
+
|
169
|
+
ret = io_uring_submit(&ring);
|
170
|
+
if (ret != 3) {
|
171
|
+
fprintf(stderr, "sqe submit failed\n");
|
172
|
+
return 1;
|
173
|
+
}
|
174
|
+
|
175
|
+
/* just drop all rings/etc. intact, exit() will clean them up */
|
176
|
+
return 0;
|
177
|
+
}
|
178
|
+
|
179
|
+
static int test_poll_cancel_with_timeouts(void)
|
180
|
+
{
|
181
|
+
int ret;
|
182
|
+
pid_t p;
|
183
|
+
|
184
|
+
p = fork();
|
185
|
+
if (p == -1) {
|
186
|
+
fprintf(stderr, "fork() failed\n");
|
187
|
+
return 1;
|
188
|
+
}
|
189
|
+
|
190
|
+
if (p == 0) {
|
191
|
+
ret = __test_poll_cancel_with_timeouts();
|
192
|
+
exit(ret);
|
193
|
+
} else {
|
194
|
+
int wstatus;
|
195
|
+
|
196
|
+
if (waitpid(p, &wstatus, 0) == (pid_t)-1) {
|
197
|
+
perror("waitpid()");
|
198
|
+
return 1;
|
199
|
+
}
|
200
|
+
if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {
|
201
|
+
fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
|
202
|
+
return 1;
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return 0;
|
206
|
+
}
|
207
|
+
|
208
|
+
int main(int argc, char *argv[])
|
209
|
+
{
|
210
|
+
int ret;
|
211
|
+
|
212
|
+
if (argc > 1)
|
213
|
+
return 0;
|
214
|
+
|
215
|
+
ret = test_poll_cancel();
|
216
|
+
if (ret) {
|
217
|
+
fprintf(stderr, "test_poll_cancel failed\n");
|
218
|
+
return -1;
|
219
|
+
}
|
220
|
+
|
221
|
+
ret = test_poll_cancel_with_timeouts();
|
222
|
+
if (ret) {
|
223
|
+
fprintf(stderr, "test_poll_cancel_with_timeouts failed\n");
|
224
|
+
return -1;
|
225
|
+
}
|
226
|
+
|
227
|
+
return 0;
|
228
|
+
}
|
@@ -0,0 +1,230 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#include <errno.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <fcntl.h>
|
8
|
+
#include <assert.h>
|
9
|
+
#include <pthread.h>
|
10
|
+
#include <sys/socket.h>
|
11
|
+
#include <netinet/tcp.h>
|
12
|
+
#include <netinet/in.h>
|
13
|
+
#include <poll.h>
|
14
|
+
#include <arpa/inet.h>
|
15
|
+
|
16
|
+
#include "liburing.h"
|
17
|
+
|
18
|
+
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
19
|
+
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
20
|
+
|
21
|
+
static int recv_thread_ready = 0;
|
22
|
+
static int recv_thread_done = 0;
|
23
|
+
|
24
|
+
static void signal_var(int *var)
|
25
|
+
{
|
26
|
+
pthread_mutex_lock(&mutex);
|
27
|
+
*var = 1;
|
28
|
+
pthread_cond_signal(&cond);
|
29
|
+
pthread_mutex_unlock(&mutex);
|
30
|
+
}
|
31
|
+
|
32
|
+
static void wait_for_var(int *var)
|
33
|
+
{
|
34
|
+
pthread_mutex_lock(&mutex);
|
35
|
+
|
36
|
+
while (!*var)
|
37
|
+
pthread_cond_wait(&cond, &mutex);
|
38
|
+
|
39
|
+
pthread_mutex_unlock(&mutex);
|
40
|
+
}
|
41
|
+
|
42
|
+
struct data {
|
43
|
+
unsigned expected[2];
|
44
|
+
unsigned is_mask[2];
|
45
|
+
unsigned long timeout;
|
46
|
+
unsigned short port;
|
47
|
+
unsigned int addr;
|
48
|
+
int stop;
|
49
|
+
};
|
50
|
+
|
51
|
+
static void *send_thread(void *arg)
|
52
|
+
{
|
53
|
+
struct data *data = arg;
|
54
|
+
|
55
|
+
wait_for_var(&recv_thread_ready);
|
56
|
+
|
57
|
+
int s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
58
|
+
assert(s0 != -1);
|
59
|
+
|
60
|
+
struct sockaddr_in addr;
|
61
|
+
|
62
|
+
addr.sin_family = AF_INET;
|
63
|
+
addr.sin_port = data->port;
|
64
|
+
addr.sin_addr.s_addr = data->addr;
|
65
|
+
|
66
|
+
if (connect(s0, (struct sockaddr*)&addr, sizeof(addr)) != -1)
|
67
|
+
wait_for_var(&recv_thread_done);
|
68
|
+
|
69
|
+
close(s0);
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
void *recv_thread(void *arg)
|
74
|
+
{
|
75
|
+
struct data *data = arg;
|
76
|
+
struct io_uring_sqe *sqe;
|
77
|
+
struct io_uring ring;
|
78
|
+
int i, ret;
|
79
|
+
|
80
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
81
|
+
assert(ret == 0);
|
82
|
+
|
83
|
+
int s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
84
|
+
assert(s0 != -1);
|
85
|
+
|
86
|
+
int32_t val = 1;
|
87
|
+
ret = setsockopt(s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
|
88
|
+
assert(ret != -1);
|
89
|
+
ret = setsockopt(s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
90
|
+
assert(ret != -1);
|
91
|
+
|
92
|
+
struct sockaddr_in addr;
|
93
|
+
|
94
|
+
addr.sin_family = AF_INET;
|
95
|
+
data->addr = inet_addr("127.0.0.1");
|
96
|
+
addr.sin_addr.s_addr = data->addr;
|
97
|
+
|
98
|
+
i = 0;
|
99
|
+
do {
|
100
|
+
data->port = htons(1025 + (rand() % 64510));
|
101
|
+
addr.sin_port = data->port;
|
102
|
+
|
103
|
+
if (bind(s0, (struct sockaddr*)&addr, sizeof(addr)) != -1)
|
104
|
+
break;
|
105
|
+
} while (++i < 100);
|
106
|
+
|
107
|
+
if (i >= 100) {
|
108
|
+
fprintf(stderr, "Can't find good port, skipped\n");
|
109
|
+
data->stop = 1;
|
110
|
+
signal_var(&recv_thread_ready);
|
111
|
+
goto out;
|
112
|
+
}
|
113
|
+
|
114
|
+
ret = listen(s0, 128);
|
115
|
+
assert(ret != -1);
|
116
|
+
|
117
|
+
signal_var(&recv_thread_ready);
|
118
|
+
|
119
|
+
sqe = io_uring_get_sqe(&ring);
|
120
|
+
assert(sqe != NULL);
|
121
|
+
|
122
|
+
io_uring_prep_poll_add(sqe, s0, POLLIN | POLLHUP | POLLERR);
|
123
|
+
sqe->flags |= IOSQE_IO_LINK;
|
124
|
+
sqe->user_data = 1;
|
125
|
+
|
126
|
+
sqe = io_uring_get_sqe(&ring);
|
127
|
+
assert(sqe != NULL);
|
128
|
+
|
129
|
+
struct __kernel_timespec ts;
|
130
|
+
ts.tv_sec = data->timeout / 1000000000;
|
131
|
+
ts.tv_nsec = data->timeout % 1000000000;
|
132
|
+
io_uring_prep_link_timeout(sqe, &ts, 0);
|
133
|
+
sqe->user_data = 2;
|
134
|
+
|
135
|
+
ret = io_uring_submit(&ring);
|
136
|
+
assert(ret == 2);
|
137
|
+
|
138
|
+
for (i = 0; i < 2; i++) {
|
139
|
+
struct io_uring_cqe *cqe;
|
140
|
+
int idx;
|
141
|
+
|
142
|
+
if (io_uring_wait_cqe(&ring, &cqe)) {
|
143
|
+
fprintf(stderr, "wait cqe failed\n");
|
144
|
+
goto err;
|
145
|
+
}
|
146
|
+
idx = cqe->user_data - 1;
|
147
|
+
if (data->is_mask[idx] && !(data->expected[idx] & cqe->res)) {
|
148
|
+
fprintf(stderr, "cqe %" PRIu64 " got %x, wanted mask %x\n",
|
149
|
+
(uint64_t) cqe->user_data, cqe->res,
|
150
|
+
data->expected[idx]);
|
151
|
+
goto err;
|
152
|
+
} else if (!data->is_mask[idx] && cqe->res != data->expected[idx]) {
|
153
|
+
fprintf(stderr, "cqe %" PRIu64 " got %d, wanted %d\n",
|
154
|
+
(uint64_t) cqe->user_data, cqe->res,
|
155
|
+
data->expected[idx]);
|
156
|
+
goto err;
|
157
|
+
}
|
158
|
+
io_uring_cqe_seen(&ring, cqe);
|
159
|
+
}
|
160
|
+
|
161
|
+
out:
|
162
|
+
signal_var(&recv_thread_done);
|
163
|
+
close(s0);
|
164
|
+
io_uring_queue_exit(&ring);
|
165
|
+
return NULL;
|
166
|
+
err:
|
167
|
+
signal_var(&recv_thread_done);
|
168
|
+
close(s0);
|
169
|
+
io_uring_queue_exit(&ring);
|
170
|
+
return (void *) 1;
|
171
|
+
}
|
172
|
+
|
173
|
+
static int test_poll_timeout(int do_connect, unsigned long timeout)
|
174
|
+
{
|
175
|
+
pthread_t t1, t2;
|
176
|
+
struct data d;
|
177
|
+
void *tret;
|
178
|
+
int ret = 0;
|
179
|
+
|
180
|
+
recv_thread_ready = 0;
|
181
|
+
recv_thread_done = 0;
|
182
|
+
|
183
|
+
memset(&d, 0, sizeof(d));
|
184
|
+
d.timeout = timeout;
|
185
|
+
if (!do_connect) {
|
186
|
+
d.expected[0] = -ECANCELED;
|
187
|
+
d.expected[1] = -ETIME;
|
188
|
+
} else {
|
189
|
+
d.expected[0] = POLLIN;
|
190
|
+
d.is_mask[0] = 1;
|
191
|
+
d.expected[1] = -ECANCELED;
|
192
|
+
}
|
193
|
+
|
194
|
+
pthread_create(&t1, NULL, recv_thread, &d);
|
195
|
+
|
196
|
+
if (do_connect)
|
197
|
+
pthread_create(&t2, NULL, send_thread, &d);
|
198
|
+
|
199
|
+
pthread_join(t1, &tret);
|
200
|
+
if (tret)
|
201
|
+
ret++;
|
202
|
+
|
203
|
+
if (do_connect) {
|
204
|
+
pthread_join(t2, &tret);
|
205
|
+
if (tret)
|
206
|
+
ret++;
|
207
|
+
}
|
208
|
+
|
209
|
+
return ret;
|
210
|
+
}
|
211
|
+
|
212
|
+
int main(int argc, char *argv[])
|
213
|
+
{
|
214
|
+
if (argc > 1)
|
215
|
+
return 0;
|
216
|
+
|
217
|
+
srand(getpid());
|
218
|
+
|
219
|
+
if (test_poll_timeout(0, 200000000)) {
|
220
|
+
fprintf(stderr, "poll timeout 0 failed\n");
|
221
|
+
return 1;
|
222
|
+
}
|
223
|
+
|
224
|
+
if (test_poll_timeout(1, 1000000000)) {
|
225
|
+
fprintf(stderr, "poll timeout 1 failed\n");
|
226
|
+
return 1;
|
227
|
+
}
|
228
|
+
|
229
|
+
return 0;
|
230
|
+
}
|
@@ -0,0 +1,208 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test many files being polled for
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <signal.h>
|
12
|
+
#include <poll.h>
|
13
|
+
#include <sys/resource.h>
|
14
|
+
#include <fcntl.h>
|
15
|
+
|
16
|
+
#include "liburing.h"
|
17
|
+
|
18
|
+
#define NFILES 5000
|
19
|
+
#define BATCH 500
|
20
|
+
#define NLOOPS 1000
|
21
|
+
|
22
|
+
#define RING_SIZE 512
|
23
|
+
|
24
|
+
struct p {
|
25
|
+
int fd[2];
|
26
|
+
int triggered;
|
27
|
+
};
|
28
|
+
|
29
|
+
static struct p p[NFILES];
|
30
|
+
|
31
|
+
static int arm_poll(struct io_uring *ring, int off)
|
32
|
+
{
|
33
|
+
struct io_uring_sqe *sqe;
|
34
|
+
|
35
|
+
sqe = io_uring_get_sqe(ring);
|
36
|
+
if (!sqe) {
|
37
|
+
fprintf(stderr, "failed getting sqe\n");
|
38
|
+
return 1;
|
39
|
+
}
|
40
|
+
|
41
|
+
io_uring_prep_poll_add(sqe, p[off].fd[0], POLLIN);
|
42
|
+
sqe->user_data = off;
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
static int reap_polls(struct io_uring *ring)
|
47
|
+
{
|
48
|
+
struct io_uring_cqe *cqe;
|
49
|
+
int i, ret, off;
|
50
|
+
char c;
|
51
|
+
|
52
|
+
for (i = 0; i < BATCH; i++) {
|
53
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
54
|
+
if (ret) {
|
55
|
+
fprintf(stderr, "wait cqe %d\n", ret);
|
56
|
+
return ret;
|
57
|
+
}
|
58
|
+
off = cqe->user_data;
|
59
|
+
p[off].triggered = 0;
|
60
|
+
ret = read(p[off].fd[0], &c, 1);
|
61
|
+
if (ret != 1) {
|
62
|
+
fprintf(stderr, "read got %d/%d\n", ret, errno);
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
if (arm_poll(ring, off))
|
66
|
+
break;
|
67
|
+
io_uring_cqe_seen(ring, cqe);
|
68
|
+
}
|
69
|
+
|
70
|
+
if (i != BATCH) {
|
71
|
+
fprintf(stderr, "gave up at %d\n", i);
|
72
|
+
return 1;
|
73
|
+
}
|
74
|
+
|
75
|
+
ret = io_uring_submit(ring);
|
76
|
+
if (ret != BATCH) {
|
77
|
+
fprintf(stderr, "submitted %d, %d\n", ret, BATCH);
|
78
|
+
return 1;
|
79
|
+
}
|
80
|
+
|
81
|
+
return 0;
|
82
|
+
}
|
83
|
+
|
84
|
+
static int trigger_polls(void)
|
85
|
+
{
|
86
|
+
char c = 89;
|
87
|
+
int i, ret;
|
88
|
+
|
89
|
+
for (i = 0; i < BATCH; i++) {
|
90
|
+
int off;
|
91
|
+
|
92
|
+
do {
|
93
|
+
off = rand() % NFILES;
|
94
|
+
if (!p[off].triggered)
|
95
|
+
break;
|
96
|
+
} while (1);
|
97
|
+
|
98
|
+
p[off].triggered = 1;
|
99
|
+
ret = write(p[off].fd[1], &c, 1);
|
100
|
+
if (ret != 1) {
|
101
|
+
fprintf(stderr, "write got %d/%d\n", ret, errno);
|
102
|
+
return 1;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
return 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
static int arm_polls(struct io_uring *ring)
|
110
|
+
{
|
111
|
+
int ret, to_arm = NFILES, i, off;
|
112
|
+
|
113
|
+
off = 0;
|
114
|
+
while (to_arm) {
|
115
|
+
int this_arm;
|
116
|
+
|
117
|
+
this_arm = to_arm;
|
118
|
+
if (this_arm > RING_SIZE)
|
119
|
+
this_arm = RING_SIZE;
|
120
|
+
|
121
|
+
for (i = 0; i < this_arm; i++) {
|
122
|
+
if (arm_poll(ring, off)) {
|
123
|
+
fprintf(stderr, "arm failed at %d\n", off);
|
124
|
+
return 1;
|
125
|
+
}
|
126
|
+
off++;
|
127
|
+
}
|
128
|
+
|
129
|
+
ret = io_uring_submit(ring);
|
130
|
+
if (ret != this_arm) {
|
131
|
+
fprintf(stderr, "submitted %d, %d\n", ret, this_arm);
|
132
|
+
return 1;
|
133
|
+
}
|
134
|
+
to_arm -= this_arm;
|
135
|
+
}
|
136
|
+
|
137
|
+
return 0;
|
138
|
+
}
|
139
|
+
|
140
|
+
int main(int argc, char *argv[])
|
141
|
+
{
|
142
|
+
struct io_uring ring;
|
143
|
+
struct io_uring_params params = { };
|
144
|
+
struct rlimit rlim;
|
145
|
+
int i, ret;
|
146
|
+
|
147
|
+
if (argc > 1)
|
148
|
+
return 0;
|
149
|
+
|
150
|
+
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
|
151
|
+
perror("getrlimit");
|
152
|
+
goto err_noring;
|
153
|
+
}
|
154
|
+
|
155
|
+
if (rlim.rlim_cur < (2 * NFILES + 5)) {
|
156
|
+
rlim.rlim_cur = (2 * NFILES + 5);
|
157
|
+
rlim.rlim_max = rlim.rlim_cur;
|
158
|
+
if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
|
159
|
+
if (errno == EPERM)
|
160
|
+
goto err_nofail;
|
161
|
+
perror("setrlimit");
|
162
|
+
goto err_noring;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
for (i = 0; i < NFILES; i++) {
|
167
|
+
if (pipe(p[i].fd) < 0) {
|
168
|
+
perror("pipe");
|
169
|
+
goto err_noring;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
params.flags = IORING_SETUP_CQSIZE;
|
174
|
+
params.cq_entries = 4096;
|
175
|
+
ret = io_uring_queue_init_params(RING_SIZE, &ring, ¶ms);
|
176
|
+
if (ret) {
|
177
|
+
if (ret == -EINVAL) {
|
178
|
+
fprintf(stdout, "No CQSIZE, trying without\n");
|
179
|
+
ret = io_uring_queue_init(RING_SIZE, &ring, 0);
|
180
|
+
if (ret) {
|
181
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
182
|
+
return 1;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
if (arm_polls(&ring))
|
188
|
+
goto err;
|
189
|
+
|
190
|
+
for (i = 0; i < NLOOPS; i++) {
|
191
|
+
trigger_polls();
|
192
|
+
ret = reap_polls(&ring);
|
193
|
+
if (ret)
|
194
|
+
goto err;
|
195
|
+
}
|
196
|
+
|
197
|
+
io_uring_queue_exit(&ring);
|
198
|
+
return 0;
|
199
|
+
err:
|
200
|
+
io_uring_queue_exit(&ring);
|
201
|
+
err_noring:
|
202
|
+
fprintf(stderr, "poll-many failed\n");
|
203
|
+
return 1;
|
204
|
+
err_nofail:
|
205
|
+
fprintf(stderr, "poll-many: not enough files available (and not root), "
|
206
|
+
"skipped\n");
|
207
|
+
return 0;
|
208
|
+
}
|