uringmachine 0.10 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/examples/bm_http_parse.rb +108 -35
- data/examples/bm_side_running.rb +83 -0
- data/examples/bm_sqlite.rb +1 -1
- data/ext/um/um.c +17 -1
- data/ext/um/um.h +30 -0
- data/ext/um/um_ext.c +2 -0
- data/ext/um/um_stream.c +372 -0
- data/ext/um/um_stream_class.c +121 -0
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +20 -16
- data/test/test_stream.rb +133 -0
- data/test/test_um.rb +63 -0
- data/uringmachine.gemspec +1 -0
- data/vendor/liburing/.github/workflows/{build.yml → ci.yml} +107 -42
- data/vendor/liburing/.gitignore +1 -0
- data/vendor/liburing/CHANGELOG +10 -0
- data/vendor/liburing/README +5 -0
- data/vendor/liburing/configure +1 -1
- data/vendor/liburing/examples/Makefile +1 -0
- data/vendor/liburing/examples/helpers.c +25 -0
- data/vendor/liburing/examples/helpers.h +13 -0
- data/vendor/liburing/examples/io_uring-test.c +3 -0
- data/vendor/liburing/examples/proxy.c +1 -1
- data/vendor/liburing/examples/reg-wait.c +41 -6
- data/vendor/liburing/examples/send-zerocopy.c +79 -32
- data/vendor/liburing/examples/zcrx.c +436 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/Makefile +0 -1
- data/vendor/liburing/src/arch/generic/syscall.h +2 -2
- data/vendor/liburing/src/arch/syscall-defs.h +2 -2
- data/vendor/liburing/src/include/liburing/io_uring.h +101 -17
- data/vendor/liburing/src/include/liburing.h +179 -59
- data/vendor/liburing/src/int_flags.h +4 -1
- data/vendor/liburing/src/liburing-ffi.map +14 -2
- data/vendor/liburing/src/liburing.map +9 -2
- data/vendor/liburing/src/queue.c +35 -30
- data/vendor/liburing/src/register.c +46 -15
- data/vendor/liburing/src/sanitize.c +6 -9
- data/vendor/liburing/src/setup.c +37 -71
- data/vendor/liburing/src/syscall.c +2 -2
- data/vendor/liburing/test/232c93d07b74.c +1 -0
- data/vendor/liburing/test/Makefile +9 -0
- data/vendor/liburing/test/accept-test.c +1 -0
- data/vendor/liburing/test/cmd-discard.c +16 -8
- data/vendor/liburing/test/connect.c +11 -7
- data/vendor/liburing/test/epwait.c +420 -0
- data/vendor/liburing/test/eventfd-ring.c +30 -5
- data/vendor/liburing/test/fallocate.c +1 -1
- data/vendor/liburing/test/fixed-hugepage.c +10 -7
- data/vendor/liburing/test/fixed-seg.c +187 -0
- data/vendor/liburing/test/helpers.c +121 -0
- data/vendor/liburing/test/helpers.h +13 -0
- data/vendor/liburing/test/init-mem.c +2 -0
- data/vendor/liburing/test/io_uring_passthrough.c +78 -62
- data/vendor/liburing/test/iopoll-overflow.c +5 -4
- data/vendor/liburing/test/iopoll.c +20 -10
- data/vendor/liburing/test/iowait.c +141 -0
- data/vendor/liburing/test/nvme.h +2 -0
- data/vendor/liburing/test/pipe-bug.c +11 -5
- data/vendor/liburing/test/pipe-eof.c +11 -1
- data/vendor/liburing/test/read-inc-file.c +150 -0
- data/vendor/liburing/test/read-write.c +21 -14
- data/vendor/liburing/test/recv-bundle-short-ooo.c +435 -0
- data/vendor/liburing/test/recv-multishot.c +2 -2
- data/vendor/liburing/test/reg-wait.c +449 -120
- data/vendor/liburing/test/regbuf-clone.c +53 -0
- data/vendor/liburing/test/resize-rings.c +25 -2
- data/vendor/liburing/test/rsrc_tags.c +67 -14
- data/vendor/liburing/test/send-zerocopy.c +52 -130
- data/vendor/liburing/test/sendmsg_iov_clean.c +216 -0
- data/vendor/liburing/test/socket-nb.c +158 -0
- data/vendor/liburing/test/sqwait.c +9 -11
- data/vendor/liburing/test/timeout.c +198 -0
- data/vendor/liburing/test/vec-regbuf.c +609 -0
- data/vendor/liburing/test/wait-timeout.c +1 -1
- data/vendor/liburing/test/wq-aff.c +5 -1
- data/vendor/liburing/test/zcrx.c +928 -0
- metadata +30 -4
- data/vendor/liburing/.github/workflows/codespell.yml +0 -25
- data/vendor/liburing/.github/workflows/shellcheck.yml +0 -20
@@ -0,0 +1,609 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#include <sys/mman.h>
|
3
|
+
#include <linux/mman.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <unistd.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include <fcntl.h>
|
9
|
+
#include <sys/types.h>
|
10
|
+
#include <poll.h>
|
11
|
+
#include <pthread.h>
|
12
|
+
#include <errno.h>
|
13
|
+
|
14
|
+
#include "helpers.h"
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
static bool has_regvec;
|
18
|
+
|
19
|
+
struct buf_desc {
|
20
|
+
char *buf_wr;
|
21
|
+
char *buf_rd;
|
22
|
+
size_t size;
|
23
|
+
|
24
|
+
struct io_uring ring;
|
25
|
+
bool ring_init;
|
26
|
+
bool fixed;
|
27
|
+
int buf_idx;
|
28
|
+
bool rw;
|
29
|
+
};
|
30
|
+
|
31
|
+
#define BUF_BASE_IDX 1
|
32
|
+
static int page_sz;
|
33
|
+
|
34
|
+
static void probe_support(void)
|
35
|
+
{
|
36
|
+
struct io_uring_probe *p;
|
37
|
+
struct io_uring ring;
|
38
|
+
int ret = 0;
|
39
|
+
|
40
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
41
|
+
if (ret) {
|
42
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
43
|
+
exit(ret);
|
44
|
+
}
|
45
|
+
|
46
|
+
p = t_calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
|
47
|
+
ret = io_uring_register_probe(&ring, p, 256);
|
48
|
+
|
49
|
+
/* if we don't have PROBE_REGISTER, we don't have OP_READ/WRITE */
|
50
|
+
if (ret == -EINVAL)
|
51
|
+
goto out;
|
52
|
+
if (ret) {
|
53
|
+
fprintf(stderr, "register_probe: %d\n", ret);
|
54
|
+
goto out;
|
55
|
+
}
|
56
|
+
|
57
|
+
has_regvec = p->ops_len > IORING_OP_READV_FIXED &&
|
58
|
+
(p->ops[IORING_OP_READV_FIXED].flags & IO_URING_OP_SUPPORTED);
|
59
|
+
out:
|
60
|
+
io_uring_queue_exit(&ring);
|
61
|
+
if (p)
|
62
|
+
free(p);
|
63
|
+
}
|
64
|
+
|
65
|
+
static void bind_ring(struct buf_desc *bd, struct io_uring *ring, unsigned buf_idx)
|
66
|
+
{
|
67
|
+
size_t size = bd->size;
|
68
|
+
struct iovec iov;
|
69
|
+
int ret;
|
70
|
+
|
71
|
+
iov.iov_len = size;
|
72
|
+
iov.iov_base = bd->buf_wr;
|
73
|
+
|
74
|
+
ret = io_uring_register_buffers_update_tag(ring, buf_idx, &iov, NULL, 1);
|
75
|
+
if (ret != 1) {
|
76
|
+
if (geteuid()) {
|
77
|
+
fprintf(stderr, "Not root, skipping\n");
|
78
|
+
exit(T_EXIT_SKIP);
|
79
|
+
}
|
80
|
+
fprintf(stderr, "buf reg failed %i\n", ret);
|
81
|
+
exit(1);
|
82
|
+
}
|
83
|
+
bd->buf_idx = buf_idx;
|
84
|
+
}
|
85
|
+
|
86
|
+
static void reinit_ring(struct buf_desc *bd)
|
87
|
+
{
|
88
|
+
struct io_uring *ring = &bd->ring;
|
89
|
+
int ret;
|
90
|
+
|
91
|
+
if (bd->ring_init) {
|
92
|
+
io_uring_queue_exit(ring);
|
93
|
+
bd->ring_init = false;
|
94
|
+
}
|
95
|
+
|
96
|
+
ret = io_uring_queue_init(32, ring, 0);
|
97
|
+
if (ret) {
|
98
|
+
fprintf(stderr, "ring init error %i\n", ret);
|
99
|
+
exit(1);
|
100
|
+
}
|
101
|
+
|
102
|
+
ret = io_uring_register_buffers_sparse(ring, 128);
|
103
|
+
if (ret) {
|
104
|
+
fprintf(stderr, "table reg error %i\n", ret);
|
105
|
+
exit(1);
|
106
|
+
}
|
107
|
+
|
108
|
+
bind_ring(bd, &bd->ring, BUF_BASE_IDX);
|
109
|
+
bd->ring_init = true;
|
110
|
+
}
|
111
|
+
|
112
|
+
static void init_buffers(struct buf_desc *bd, size_t size)
|
113
|
+
{
|
114
|
+
void *start;
|
115
|
+
void *mem;
|
116
|
+
|
117
|
+
start = mmap(NULL, size + page_sz * 2, PROT_NONE,
|
118
|
+
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
|
119
|
+
if (start == MAP_FAILED) {
|
120
|
+
fprintf(stderr, "Unable to preserve the page mixture memory.\n");
|
121
|
+
exit(1);
|
122
|
+
}
|
123
|
+
|
124
|
+
mem = mmap(start + page_sz, size, PROT_READ | PROT_WRITE,
|
125
|
+
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
126
|
+
if (mem == MAP_FAILED) {
|
127
|
+
fprintf(stderr, "mmap fail\n");
|
128
|
+
exit(1);
|
129
|
+
}
|
130
|
+
|
131
|
+
memset(bd, 0, sizeof(*bd));
|
132
|
+
bd->size = size;
|
133
|
+
bd->buf_wr = mem;
|
134
|
+
bd->buf_rd = malloc(size);
|
135
|
+
if (!bd->buf_rd) {
|
136
|
+
fprintf(stderr, "malloc fail\n");
|
137
|
+
exit(1);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
static int verify_data(struct buf_desc *bd, struct iovec *wr_vecs, int nr_iovec,
|
142
|
+
int fd)
|
143
|
+
{
|
144
|
+
int iov_idx, ret;
|
145
|
+
|
146
|
+
for (iov_idx = 0; iov_idx < nr_iovec; iov_idx++) {
|
147
|
+
struct iovec *vec = &wr_vecs[iov_idx];
|
148
|
+
size_t seg_size = vec->iov_len;
|
149
|
+
size_t read_bytes = 0;
|
150
|
+
|
151
|
+
while (1) {
|
152
|
+
ret = read(fd, bd->buf_rd + read_bytes, seg_size - read_bytes);
|
153
|
+
if (ret < 0) {
|
154
|
+
fprintf(stderr, "read error %i", ret);
|
155
|
+
return 1;
|
156
|
+
}
|
157
|
+
read_bytes += ret;
|
158
|
+
if (read_bytes == seg_size)
|
159
|
+
break;
|
160
|
+
if (ret == 0) {
|
161
|
+
fprintf(stderr, "can't read %i", ret);
|
162
|
+
return 2;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
ret = memcmp(bd->buf_rd, vec->iov_base, seg_size);
|
167
|
+
if (ret != 0) {
|
168
|
+
fprintf(stderr, "data mismatch %i\n", ret);
|
169
|
+
return 3;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return 0;
|
173
|
+
}
|
174
|
+
|
175
|
+
struct verify_data {
|
176
|
+
struct buf_desc *bd;
|
177
|
+
struct iovec *vecs;
|
178
|
+
int nr_vec;
|
179
|
+
int fd;
|
180
|
+
};
|
181
|
+
|
182
|
+
static void *verify_thread_cb(void *data)
|
183
|
+
{
|
184
|
+
struct verify_data *vd = data;
|
185
|
+
int ret;
|
186
|
+
|
187
|
+
ret = verify_data(vd->bd, vd->vecs, vd->nr_vec, vd->fd);
|
188
|
+
return (void *)(unsigned long)ret;
|
189
|
+
}
|
190
|
+
|
191
|
+
static int test_rw(struct buf_desc *bd, struct iovec *vecs, int nr_vec, int fd_wr)
|
192
|
+
{
|
193
|
+
unsigned buf_idx = bd->buf_idx;
|
194
|
+
struct io_uring *ring = &bd->ring;
|
195
|
+
struct io_uring_sqe *sqe;
|
196
|
+
struct io_uring_cqe *cqe;
|
197
|
+
int ret;
|
198
|
+
|
199
|
+
sqe = io_uring_get_sqe(ring);
|
200
|
+
if (bd->fixed)
|
201
|
+
io_uring_prep_writev_fixed(sqe, fd_wr, vecs, nr_vec, 0, 0, buf_idx);
|
202
|
+
else
|
203
|
+
io_uring_prep_writev(sqe, fd_wr, vecs, nr_vec, 0);
|
204
|
+
|
205
|
+
ret = io_uring_submit(ring);
|
206
|
+
if (ret != 1) {
|
207
|
+
fprintf(stderr, "submit failed %i\n", ret);
|
208
|
+
exit(1);
|
209
|
+
}
|
210
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
211
|
+
if (ret) {
|
212
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
213
|
+
exit(1);
|
214
|
+
}
|
215
|
+
|
216
|
+
ret = cqe->res;
|
217
|
+
io_uring_cqe_seen(ring, cqe);
|
218
|
+
return ret;
|
219
|
+
}
|
220
|
+
|
221
|
+
static int test_sendzc(struct buf_desc *bd, struct iovec *vecs, int nr_vec, int fd_wr)
|
222
|
+
{
|
223
|
+
unsigned buf_idx = bd->buf_idx;
|
224
|
+
struct io_uring *ring = &bd->ring;
|
225
|
+
struct io_uring_sqe *sqe;
|
226
|
+
struct io_uring_cqe *cqe;
|
227
|
+
int ret, cqe_ret, more;
|
228
|
+
struct msghdr msghdr;
|
229
|
+
|
230
|
+
memset(&msghdr, 0, sizeof(msghdr));
|
231
|
+
msghdr.msg_iov = vecs;
|
232
|
+
msghdr.msg_iovlen = nr_vec;
|
233
|
+
|
234
|
+
sqe = io_uring_get_sqe(ring);
|
235
|
+
if (bd->fixed)
|
236
|
+
io_uring_prep_sendmsg_zc_fixed(sqe, fd_wr, &msghdr, 0, buf_idx);
|
237
|
+
else
|
238
|
+
io_uring_prep_sendmsg_zc(sqe, fd_wr, &msghdr, 0);
|
239
|
+
|
240
|
+
ret = io_uring_submit(ring);
|
241
|
+
if (ret != 1) {
|
242
|
+
fprintf(stderr, "submit failed %i\n", ret);
|
243
|
+
exit(1);
|
244
|
+
}
|
245
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
246
|
+
if (ret) {
|
247
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
248
|
+
exit(1);
|
249
|
+
}
|
250
|
+
|
251
|
+
cqe_ret = cqe->res;
|
252
|
+
more = cqe->flags & IORING_CQE_F_MORE;
|
253
|
+
io_uring_cqe_seen(ring, cqe);
|
254
|
+
|
255
|
+
if (more) {
|
256
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
257
|
+
if (ret) {
|
258
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
259
|
+
exit(1);
|
260
|
+
}
|
261
|
+
io_uring_cqe_seen(ring, cqe);
|
262
|
+
}
|
263
|
+
return cqe_ret;
|
264
|
+
}
|
265
|
+
|
266
|
+
static int test_vec(struct buf_desc *bd, struct iovec *vecs, int nr_vec,
|
267
|
+
bool expect_fail, int *cqe_ret)
|
268
|
+
{
|
269
|
+
struct sockaddr_storage addr;
|
270
|
+
int sock_server, sock_client;
|
271
|
+
struct verify_data vd;
|
272
|
+
size_t total_len = 0;
|
273
|
+
int i, ret;
|
274
|
+
void *verify_res;
|
275
|
+
pthread_t th;
|
276
|
+
|
277
|
+
ret = t_create_socketpair_ip(&addr, &sock_client, &sock_server,
|
278
|
+
true, true, false, true, "::1");
|
279
|
+
if (ret) {
|
280
|
+
fprintf(stderr, "sock prep failed %d\n", ret);
|
281
|
+
return 1;
|
282
|
+
}
|
283
|
+
|
284
|
+
for (i = 0; i < bd->size; i++)
|
285
|
+
bd->buf_wr[i] = i;
|
286
|
+
memset(bd->buf_rd, 0, bd->size);
|
287
|
+
|
288
|
+
for (i = 0; i < nr_vec; i++)
|
289
|
+
total_len += vecs[i].iov_len;
|
290
|
+
|
291
|
+
vd.bd = bd;
|
292
|
+
vd.vecs = vecs;
|
293
|
+
vd.nr_vec = nr_vec;
|
294
|
+
vd.fd = sock_server;
|
295
|
+
|
296
|
+
if (!expect_fail) {
|
297
|
+
ret = pthread_create(&th, NULL, verify_thread_cb, &vd);
|
298
|
+
if (ret) {
|
299
|
+
fprintf(stderr, "pthread_create failed %i\n", ret);
|
300
|
+
return ret;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
if (bd->rw)
|
305
|
+
ret = test_rw(bd, vecs, nr_vec, sock_client);
|
306
|
+
else
|
307
|
+
ret = test_sendzc(bd, vecs, nr_vec, sock_client);
|
308
|
+
|
309
|
+
*cqe_ret = ret;
|
310
|
+
|
311
|
+
if (!expect_fail && ret != total_len) {
|
312
|
+
fprintf(stderr, "invalid cqe %i, expected %lu\n",
|
313
|
+
ret, (unsigned long)total_len);
|
314
|
+
return 1;
|
315
|
+
}
|
316
|
+
|
317
|
+
if (!expect_fail) {
|
318
|
+
pthread_join(th, &verify_res);
|
319
|
+
ret = (int)(unsigned long)verify_res;
|
320
|
+
if (ret) {
|
321
|
+
fprintf(stderr, "verify failed %i\n", ret);
|
322
|
+
return 1;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
close(sock_client);
|
326
|
+
close(sock_server);
|
327
|
+
return 0;
|
328
|
+
}
|
329
|
+
|
330
|
+
struct work {
|
331
|
+
struct iovec *vecs;
|
332
|
+
unsigned nr_vecs;
|
333
|
+
};
|
334
|
+
|
335
|
+
static int test_sequence(struct buf_desc *bd, unsigned nr, struct work *ws)
|
336
|
+
{
|
337
|
+
int i, ret;
|
338
|
+
int cqe_ret;
|
339
|
+
|
340
|
+
reinit_ring(bd);
|
341
|
+
|
342
|
+
for (i = 0; i < nr; i++) {
|
343
|
+
ret = test_vec(bd, ws[i].vecs, ws[i].nr_vecs, false, &cqe_ret);
|
344
|
+
if (ret) {
|
345
|
+
fprintf(stderr, "sequence failed, idx %i/%i\n", i, nr);
|
346
|
+
return ret;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
return 0;
|
350
|
+
}
|
351
|
+
|
352
|
+
static void test_basic(struct buf_desc *bd)
|
353
|
+
{
|
354
|
+
void *p = bd->buf_wr;
|
355
|
+
int ret;
|
356
|
+
struct iovec iov_page = { .iov_base = p,
|
357
|
+
.iov_len = page_sz, };
|
358
|
+
struct iovec iov_inner = { .iov_base = p + 1,
|
359
|
+
.iov_len = 3, };
|
360
|
+
struct iovec iov_maxbvec = { .iov_base = p + page_sz - 1,
|
361
|
+
.iov_len = page_sz + 2, };
|
362
|
+
struct iovec iov_big = { .iov_base = p,
|
363
|
+
.iov_len = page_sz * 12 + 33, };
|
364
|
+
struct iovec iov_big_unalign = { .iov_base = p + 10,
|
365
|
+
.iov_len = page_sz * 7 + 41, };
|
366
|
+
struct iovec iov_full = { .iov_base = p,
|
367
|
+
.iov_len = bd->size, };
|
368
|
+
struct iovec iov_right1 = { .iov_base = p + bd->size - page_sz + 5,
|
369
|
+
.iov_len = page_sz - 5 };
|
370
|
+
struct iovec iov_right2 = { .iov_base = p + bd->size - page_sz - 5,
|
371
|
+
.iov_len = page_sz + 5 };
|
372
|
+
struct iovec iov_full_unalign = { .iov_base = p + 1,
|
373
|
+
.iov_len = bd->size - 1, };
|
374
|
+
struct iovec vecs[] = {
|
375
|
+
iov_page,
|
376
|
+
iov_big,
|
377
|
+
iov_inner,
|
378
|
+
iov_big_unalign,
|
379
|
+
iov_big_unalign,
|
380
|
+
};
|
381
|
+
struct iovec vecs_basic[] = { iov_page, iov_page, iov_page };
|
382
|
+
struct iovec vecs_full[] = { iov_full, iov_full, iov_full };
|
383
|
+
struct iovec vecs_full_unalign[] = { iov_full_unalign, iov_full_unalign,
|
384
|
+
iov_full_unalign };
|
385
|
+
struct iovec vecs_maxsegs[] = { iov_maxbvec, iov_maxbvec, iov_maxbvec,
|
386
|
+
iov_maxbvec, iov_maxbvec, iov_maxbvec};
|
387
|
+
|
388
|
+
ret = test_sequence(bd, 1, (struct work[]) {
|
389
|
+
{ &iov_page, 1 },
|
390
|
+
{ vecs, 1 }});
|
391
|
+
if (ret) {
|
392
|
+
fprintf(stderr, "seq failure: basic aligned, %i\n", ret);
|
393
|
+
exit(1);
|
394
|
+
}
|
395
|
+
|
396
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
397
|
+
{ vecs, 1 },
|
398
|
+
{ vecs, 1 }});
|
399
|
+
if (ret) {
|
400
|
+
fprintf(stderr, "seq failure: basic aligned, %i\n", ret);
|
401
|
+
exit(1);
|
402
|
+
}
|
403
|
+
|
404
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
405
|
+
{ vecs + 1, 1 },
|
406
|
+
{ vecs + 1, 1 }});
|
407
|
+
if (ret) {
|
408
|
+
fprintf(stderr, "seq failure: multi page buffer, %i\n", ret);
|
409
|
+
exit(1);
|
410
|
+
}
|
411
|
+
|
412
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
413
|
+
{ vecs + 2, 1 },
|
414
|
+
{ vecs + 2, 1 }});
|
415
|
+
if (ret) {
|
416
|
+
fprintf(stderr, "seq failure: misaligned buffer, %i\n", ret);
|
417
|
+
exit(1);
|
418
|
+
}
|
419
|
+
|
420
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
421
|
+
{ vecs + 3, 1 },
|
422
|
+
{ vecs + 3, 1 }});
|
423
|
+
if (ret) {
|
424
|
+
fprintf(stderr, "seq failure: misaligned multipage buffer, %i\n", ret);
|
425
|
+
exit(1);
|
426
|
+
}
|
427
|
+
|
428
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
429
|
+
{ vecs, 1 },
|
430
|
+
{ vecs + 3, 1 }});
|
431
|
+
if (ret) {
|
432
|
+
fprintf(stderr, "seq failure: realloc + increase bvec, %i\n", ret);
|
433
|
+
exit(1);
|
434
|
+
}
|
435
|
+
|
436
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
437
|
+
{ vecs + 3, 1 },
|
438
|
+
{ vecs + 0, 1 }});
|
439
|
+
if (ret) {
|
440
|
+
fprintf(stderr, "seq failure: realloc + decrease bvec, %i\n", ret);
|
441
|
+
exit(1);
|
442
|
+
}
|
443
|
+
|
444
|
+
ret = test_sequence(bd, 2, (struct work[]) {
|
445
|
+
{ vecs, 4 },
|
446
|
+
{ vecs, 4 }});
|
447
|
+
if (ret) {
|
448
|
+
fprintf(stderr, "seq failure: multisegment, %i\n", ret);
|
449
|
+
exit(1);
|
450
|
+
}
|
451
|
+
|
452
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
453
|
+
{ vecs, 2 },
|
454
|
+
{ vecs, 3 },
|
455
|
+
{ vecs, 4 }});
|
456
|
+
if (ret) {
|
457
|
+
fprintf(stderr, "seq failure: multisegment 2, %i\n", ret);
|
458
|
+
exit(1);
|
459
|
+
}
|
460
|
+
|
461
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
462
|
+
{ vecs_basic, 1 },
|
463
|
+
{ vecs_basic, 2 },
|
464
|
+
{ vecs_basic, 3 }});
|
465
|
+
if (ret) {
|
466
|
+
fprintf(stderr, "seq failure: increase iovec, %i\n", ret);
|
467
|
+
exit(1);
|
468
|
+
}
|
469
|
+
|
470
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
471
|
+
{ vecs_basic, 3 },
|
472
|
+
{ vecs_basic, 2 },
|
473
|
+
{ vecs_basic, 1 }});
|
474
|
+
if (ret) {
|
475
|
+
fprintf(stderr, "seq failure: decrease iovec, %i\n", ret);
|
476
|
+
exit(1);
|
477
|
+
}
|
478
|
+
|
479
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
480
|
+
{ &iov_right1, 1 },
|
481
|
+
{ &iov_right2, 1 },
|
482
|
+
{ &iov_right1, 1 }});
|
483
|
+
if (ret) {
|
484
|
+
fprintf(stderr, "seq failure: right aligned, %i\n", ret);
|
485
|
+
exit(1);
|
486
|
+
}
|
487
|
+
|
488
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
489
|
+
{ vecs_full, 1 },
|
490
|
+
{ vecs_full, 1 },
|
491
|
+
{ vecs_full, 3 }});
|
492
|
+
if (ret) {
|
493
|
+
fprintf(stderr, "seq failure: full size, %i\n", ret);
|
494
|
+
exit(1);
|
495
|
+
}
|
496
|
+
|
497
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
498
|
+
{ vecs_full_unalign, 1 },
|
499
|
+
{ vecs_full_unalign, 1 },
|
500
|
+
{ vecs_full_unalign, 3 }});
|
501
|
+
if (ret) {
|
502
|
+
fprintf(stderr, "seq failure: full size unsigned, %i\n", ret);
|
503
|
+
exit(1);
|
504
|
+
}
|
505
|
+
|
506
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
507
|
+
{ vecs_maxsegs, 1 },
|
508
|
+
{ vecs_maxsegs, 2 },
|
509
|
+
{ vecs_maxsegs, 3 }});
|
510
|
+
if (ret) {
|
511
|
+
fprintf(stderr, "seq failure: overestimated segments, %i\n", ret);
|
512
|
+
exit(1);
|
513
|
+
}
|
514
|
+
|
515
|
+
ret = test_sequence(bd, 3, (struct work[]) {
|
516
|
+
{ vecs_maxsegs, 6 },
|
517
|
+
{ vecs_maxsegs, 6 },
|
518
|
+
{ vecs_maxsegs, 6 }});
|
519
|
+
if (ret) {
|
520
|
+
fprintf(stderr, "seq failure: overestimated segments 2, %i\n", ret);
|
521
|
+
exit(1);
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
static void test_fail(struct buf_desc *bd)
|
526
|
+
{
|
527
|
+
int ret, cqe_ret;
|
528
|
+
void *p = bd->buf_wr;
|
529
|
+
struct iovec iov_0len = { .iov_base = p, .iov_len = 0 };
|
530
|
+
struct iovec iov_0buf = { .iov_base = 0, .iov_len = 1 };
|
531
|
+
struct iovec iov_inv = { .iov_base = (void *)-1U, .iov_len = 1 };
|
532
|
+
struct iovec iov_under = { .iov_base = p - 1, .iov_len = 1 };
|
533
|
+
struct iovec iov_over = { .iov_base = p + bd->size, .iov_len = 1 };
|
534
|
+
struct iovec vecs_0[] = { iov_0len, iov_0len, iov_0len, iov_0len,
|
535
|
+
iov_0len, iov_0len, iov_0len, iov_0len };
|
536
|
+
|
537
|
+
reinit_ring(bd);
|
538
|
+
ret = test_vec(bd, vecs_0, 8, true, &cqe_ret);
|
539
|
+
if (ret || cqe_ret > 0) {
|
540
|
+
fprintf(stderr, "0 length test failed %i, cqe %i\n",
|
541
|
+
ret, cqe_ret);
|
542
|
+
exit(1);
|
543
|
+
}
|
544
|
+
|
545
|
+
reinit_ring(bd);
|
546
|
+
ret = test_vec(bd, &iov_0buf, 1, true, &cqe_ret);
|
547
|
+
if (ret || cqe_ret >= 0) {
|
548
|
+
fprintf(stderr, "0 buf test failed %i, cqe %i\n",
|
549
|
+
ret, cqe_ret);
|
550
|
+
exit(1);
|
551
|
+
}
|
552
|
+
|
553
|
+
reinit_ring(bd);
|
554
|
+
ret = test_vec(bd, &iov_inv, 1, true, &cqe_ret);
|
555
|
+
if (ret || cqe_ret >= 0) {
|
556
|
+
fprintf(stderr, "inv buf test failed %i, cqe %i\n",
|
557
|
+
ret, cqe_ret);
|
558
|
+
exit(1);
|
559
|
+
}
|
560
|
+
|
561
|
+
reinit_ring(bd);
|
562
|
+
ret = test_vec(bd, &iov_under, 1, true, &cqe_ret);
|
563
|
+
if (ret || cqe_ret >= 0) {
|
564
|
+
fprintf(stderr, "inv buf underflow failed %i, cqe %i\n",
|
565
|
+
ret, cqe_ret);
|
566
|
+
exit(1);
|
567
|
+
}
|
568
|
+
|
569
|
+
reinit_ring(bd);
|
570
|
+
ret = test_vec(bd, &iov_over, 1, true, &cqe_ret);
|
571
|
+
if (ret || cqe_ret >= 0) {
|
572
|
+
fprintf(stderr, "inv buf overflow failed %i, cqe %i\n",
|
573
|
+
ret, cqe_ret);
|
574
|
+
exit(1);
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
int main(int argc, char *argv[])
|
579
|
+
{
|
580
|
+
struct buf_desc bd = {};
|
581
|
+
int i = 0;
|
582
|
+
|
583
|
+
if (argc > 1)
|
584
|
+
return T_EXIT_SKIP;
|
585
|
+
|
586
|
+
page_sz = sysconf(_SC_PAGESIZE);
|
587
|
+
|
588
|
+
probe_support();
|
589
|
+
if (!has_regvec) {
|
590
|
+
printf("doesn't support registered vector ops, skip\n");
|
591
|
+
return T_EXIT_SKIP;
|
592
|
+
}
|
593
|
+
|
594
|
+
init_buffers(&bd, page_sz * 32);
|
595
|
+
bd.fixed = true;
|
596
|
+
|
597
|
+
for (i = 0; i < 2; i++) {
|
598
|
+
bool rw = i & 1;
|
599
|
+
|
600
|
+
bd.rw = rw;
|
601
|
+
|
602
|
+
test_basic(&bd);
|
603
|
+
test_fail(&bd);
|
604
|
+
}
|
605
|
+
|
606
|
+
free(bd.buf_rd);
|
607
|
+
io_uring_queue_exit(&bd.ring);
|
608
|
+
return 0;
|
609
|
+
}
|
@@ -68,7 +68,7 @@ static int t_io_uring_wait(struct io_uring *ring, int nr, unsigned enter_flags,
|
|
68
68
|
|
69
69
|
enter_flags |= IORING_ENTER_GETEVENTS | IORING_ENTER_EXT_ARG;
|
70
70
|
ret = io_uring_enter2(ring->ring_fd, 0, nr, enter_flags,
|
71
|
-
|
71
|
+
&arg, sizeof(arg));
|
72
72
|
return ret;
|
73
73
|
}
|
74
74
|
|
@@ -98,7 +98,11 @@ static int test(int sqpoll)
|
|
98
98
|
p.sq_thread_cpu = SQPOLL_CPU;
|
99
99
|
}
|
100
100
|
|
101
|
-
io_uring_queue_init_params(8, &ring, &p);
|
101
|
+
ret = io_uring_queue_init_params(8, &ring, &p);
|
102
|
+
if (ret) {
|
103
|
+
fprintf(stderr, "Queue init: %d\n", ret);
|
104
|
+
return T_EXIT_FAIL;
|
105
|
+
}
|
102
106
|
|
103
107
|
CPU_ZERO(&set);
|
104
108
|
CPU_SET(IOWQ_CPU, &set);
|