engines/io_uring: use non-vectored read/write if available
[fio.git] / t / io_uring.c
CommitLineData
c9fb4c5b
JA
1#include <stdio.h>
2#include <errno.h>
3#include <assert.h>
4#include <stdlib.h>
5#include <stddef.h>
6#include <signal.h>
7#include <inttypes.h>
8
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/ioctl.h>
12#include <sys/syscall.h>
13#include <sys/resource.h>
c3e2fc25 14#include <sys/mman.h>
e31b8288 15#include <sys/uio.h>
c9fb4c5b
JA
16#include <linux/fs.h>
17#include <fcntl.h>
18#include <unistd.h>
c9fb4c5b
JA
19#include <string.h>
20#include <pthread.h>
21#include <sched.h>
22
74efb029 23#include "../arch/arch.h"
57fa61f0 24#include "../lib/types.h"
f3e769a4 25#include "../os/linux/io_uring.h"
ac122fea 26
e31b8288 27#define min(a, b) ((a < b) ? (a) : (b))
c3e2fc25 28
e31b8288 29struct io_sq_ring {
e2239016
JA
30 unsigned *head;
31 unsigned *tail;
32 unsigned *ring_mask;
33 unsigned *ring_entries;
ce1705de 34 unsigned *flags;
e2239016 35 unsigned *array;
c9fb4c5b
JA
36};
37
e31b8288 38struct io_cq_ring {
e2239016
JA
39 unsigned *head;
40 unsigned *tail;
41 unsigned *ring_mask;
42 unsigned *ring_entries;
f0403f94 43 struct io_uring_cqe *cqes;
c9fb4c5b
JA
44};
45
701d1277 46#define DEPTH 128
2e7888ef
JA
47#define BATCH_SUBMIT 32
48#define BATCH_COMPLETE 32
c9fb4c5b
JA
49#define BS 4096
50
a7086591
JA
51#define MAX_FDS 16
52
c3e2fc25 53static unsigned sq_ring_mask, cq_ring_mask;
e39c34dc 54
a7086591
JA
55struct file {
56 unsigned long max_blocks;
701d1277 57 unsigned pending_ios;
48e698fa
JA
58 int real_fd;
59 int fixed_fd;
a7086591
JA
60};
61
c9fb4c5b
JA
62struct submitter {
63 pthread_t thread;
f310970e 64 int ring_fd;
e31b8288 65 struct io_sq_ring sq_ring;
f0403f94 66 struct io_uring_sqe *sqes;
e31b8288 67 struct io_cq_ring cq_ring;
c9fb4c5b
JA
68 int inflight;
69 unsigned long reaps;
70 unsigned long done;
71 unsigned long calls;
72 volatile int finish;
701d1277 73
48e698fa
JA
74 __s32 *fds;
75
a7086591
JA
76 struct file files[MAX_FDS];
77 unsigned nr_files;
78 unsigned cur_file;
e39863e3 79 struct iovec iovecs[];
c9fb4c5b
JA
80};
81
e39863e3 82static struct submitter *submitter;
c9fb4c5b
JA
83static volatile int finish;
84
e39863e3
KB
85static int depth = DEPTH;
86static int batch_submit = BATCH_SUBMIT;
87static int batch_complete = BATCH_COMPLETE;
5bd526f2 88static int bs = BS;
f0403f94 89static int polled = 1; /* use IO polling */
701d1277 90static int fixedbufs = 1; /* use fixed user buffers */
8c5fa755 91static int register_files = 1; /* use fixed files */
f0403f94 92static int buffered = 0; /* use buffered IO, not O_DIRECT */
3d7d00a3
JA
93static int sq_thread_poll = 0; /* use kernel submission/poller thread */
94static int sq_thread_cpu = -1; /* pin above thread to this CPU */
8025517d 95static int do_nop = 0; /* no-op SQ ring commands */
c9fb4c5b 96
2ea53ca3 97static int io_uring_register_buffers(struct submitter *s)
c9fb4c5b 98{
8025517d
JA
99 if (do_nop)
100 return 0;
101
bfed648c 102 return syscall(__NR_io_uring_register, s->ring_fd,
e39863e3 103 IORING_REGISTER_BUFFERS, s->iovecs, depth);
2ea53ca3
JA
104}
105
a7abc9fb
JA
106static int io_uring_register_files(struct submitter *s)
107{
48e698fa 108 int i;
a7abc9fb 109
8025517d
JA
110 if (do_nop)
111 return 0;
112
48e698fa
JA
113 s->fds = calloc(s->nr_files, sizeof(__s32));
114 for (i = 0; i < s->nr_files; i++) {
115 s->fds[i] = s->files[i].real_fd;
116 s->files[i].fixed_fd = i;
117 }
a7abc9fb 118
bfed648c 119 return syscall(__NR_io_uring_register, s->ring_fd,
919850d2 120 IORING_REGISTER_FILES, s->fds, s->nr_files);
a7abc9fb
JA
121}
122
2ea53ca3
JA
123static int io_uring_setup(unsigned entries, struct io_uring_params *p)
124{
bfed648c 125 return syscall(__NR_io_uring_setup, entries, p);
c9fb4c5b
JA
126}
127
c3e2fc25
JA
128static int io_uring_enter(struct submitter *s, unsigned int to_submit,
129 unsigned int min_complete, unsigned int flags)
c9fb4c5b 130{
bfed648c
JA
131 return syscall(__NR_io_uring_enter, s->ring_fd, to_submit, min_complete,
132 flags, NULL, 0);
c9fb4c5b
JA
133}
134
77d814a1 135#ifndef CONFIG_HAVE_GETTID
c9fb4c5b
JA
136static int gettid(void)
137{
138 return syscall(__NR_gettid);
139}
77d814a1 140#endif
c9fb4c5b 141
701d1277
JA
142static unsigned file_depth(struct submitter *s)
143{
e39863e3 144 return (depth + s->nr_files - 1) / s->nr_files;
701d1277
JA
145}
146
a7086591 147static void init_io(struct submitter *s, unsigned index)
c9fb4c5b 148{
f0403f94 149 struct io_uring_sqe *sqe = &s->sqes[index];
c9fb4c5b 150 unsigned long offset;
a7086591 151 struct file *f;
c9fb4c5b
JA
152 long r;
153
8025517d
JA
154 if (do_nop) {
155 sqe->opcode = IORING_OP_NOP;
156 return;
157 }
158
701d1277
JA
159 if (s->nr_files == 1) {
160 f = &s->files[0];
161 } else {
162 f = &s->files[s->cur_file];
163 if (f->pending_ios >= file_depth(s)) {
164 s->cur_file++;
165 if (s->cur_file == s->nr_files)
166 s->cur_file = 0;
93d1811c 167 f = &s->files[s->cur_file];
701d1277
JA
168 }
169 }
170 f->pending_ios++;
a7086591 171
5e8865c0 172 r = lrand48();
5bd526f2 173 offset = (r % (f->max_blocks - 1)) * bs;
c9fb4c5b 174
8c5fa755
JA
175 if (register_files) {
176 sqe->flags = IOSQE_FIXED_FILE;
177 sqe->fd = f->fixed_fd;
178 } else {
179 sqe->flags = 0;
180 sqe->fd = f->real_fd;
181 }
f0403f94 182 if (fixedbufs) {
48e698fa 183 sqe->opcode = IORING_OP_READ_FIXED;
919850d2 184 sqe->addr = (unsigned long) s->iovecs[index].iov_base;
5bd526f2 185 sqe->len = bs;
2ea53ca3 186 sqe->buf_index = index;
f0403f94 187 } else {
48e698fa 188 sqe->opcode = IORING_OP_READV;
919850d2 189 sqe->addr = (unsigned long) &s->iovecs[index];
f0403f94 190 sqe->len = 1;
2ea53ca3 191 sqe->buf_index = 0;
f0403f94 192 }
f0403f94 193 sqe->ioprio = 0;
f0403f94 194 sqe->off = offset;
48e698fa 195 sqe->user_data = (unsigned long) f;
c9fb4c5b
JA
196}
197
a7086591 198static int prep_more_ios(struct submitter *s, int max_ios)
c9fb4c5b 199{
e31b8288 200 struct io_sq_ring *ring = &s->sq_ring;
e2239016 201 unsigned index, tail, next_tail, prepped = 0;
c9fb4c5b 202
c3e2fc25 203 next_tail = tail = *ring->tail;
c9fb4c5b
JA
204 do {
205 next_tail++;
679d8352 206 read_barrier();
c3e2fc25 207 if (next_tail == *ring->head)
c9fb4c5b
JA
208 break;
209
e39c34dc 210 index = tail & sq_ring_mask;
a7086591 211 init_io(s, index);
c3e2fc25 212 ring->array[index] = index;
c9fb4c5b
JA
213 prepped++;
214 tail = next_tail;
215 } while (prepped < max_ios);
216
c3e2fc25 217 if (*ring->tail != tail) {
c3e2fc25 218 *ring->tail = tail;
679d8352 219 write_barrier();
c9fb4c5b
JA
220 }
221 return prepped;
222}
223
a7086591 224static int get_file_size(struct file *f)
c9fb4c5b
JA
225{
226 struct stat st;
227
48e698fa 228 if (fstat(f->real_fd, &st) < 0)
c9fb4c5b
JA
229 return -1;
230 if (S_ISBLK(st.st_mode)) {
231 unsigned long long bytes;
232
48e698fa 233 if (ioctl(f->real_fd, BLKGETSIZE64, &bytes) != 0)
c9fb4c5b
JA
234 return -1;
235
5bd526f2 236 f->max_blocks = bytes / bs;
c9fb4c5b
JA
237 return 0;
238 } else if (S_ISREG(st.st_mode)) {
5bd526f2 239 f->max_blocks = st.st_size / bs;
c9fb4c5b
JA
240 return 0;
241 }
242
243 return -1;
244}
245
246static int reap_events(struct submitter *s)
247{
e31b8288 248 struct io_cq_ring *ring = &s->cq_ring;
f0403f94 249 struct io_uring_cqe *cqe;
e2239016 250 unsigned head, reaped = 0;
c9fb4c5b 251
c3e2fc25 252 head = *ring->head;
c9fb4c5b 253 do {
701d1277
JA
254 struct file *f;
255
679d8352 256 read_barrier();
c3e2fc25 257 if (head == *ring->tail)
c9fb4c5b 258 break;
f0403f94 259 cqe = &ring->cqes[head & cq_ring_mask];
8025517d 260 if (!do_nop) {
e3466352 261 f = (struct file *) (uintptr_t) cqe->user_data;
8025517d 262 f->pending_ios--;
5bd526f2 263 if (cqe->res != bs) {
8025517d 264 printf("io: unexpected ret=%d\n", cqe->res);
154a9582 265 if (polled && cqe->res == -EOPNOTSUPP)
8066f6b6 266 printf("Your filesystem/driver/kernel doesn't support polled IO\n");
8025517d
JA
267 return -1;
268 }
c9fb4c5b
JA
269 }
270 reaped++;
271 head++;
c9fb4c5b
JA
272 } while (1);
273
274 s->inflight -= reaped;
c3e2fc25 275 *ring->head = head;
679d8352 276 write_barrier();
c9fb4c5b
JA
277 return reaped;
278}
279
280static void *submitter_fn(void *data)
281{
282 struct submitter *s = data;
ce1705de 283 struct io_sq_ring *ring = &s->sq_ring;
a7086591 284 int ret, prepped;
c9fb4c5b
JA
285
286 printf("submitter=%d\n", gettid());
287
5e8865c0 288 srand48(pthread_self());
c9fb4c5b
JA
289
290 prepped = 0;
291 do {
f310970e 292 int to_wait, to_submit, this_reap, to_prep;
c9fb4c5b 293
e39863e3
KB
294 if (!prepped && s->inflight < depth) {
295 to_prep = min(depth - s->inflight, batch_submit);
a7086591 296 prepped = prep_more_ios(s, to_prep);
f310970e 297 }
c9fb4c5b
JA
298 s->inflight += prepped;
299submit_more:
300 to_submit = prepped;
301submit:
e39863e3 302 if (to_submit && (s->inflight + to_submit <= depth))
c9fb4c5b
JA
303 to_wait = 0;
304 else
e39863e3 305 to_wait = min(s->inflight + to_submit, batch_complete);
c9fb4c5b 306
ce1705de
JA
307 /*
308 * Only need to call io_uring_enter if we're not using SQ thread
309 * poll, or if IORING_SQ_NEED_WAKEUP is set.
310 */
311 if (!sq_thread_poll || (*ring->flags & IORING_SQ_NEED_WAKEUP)) {
e0abe388
JA
312 unsigned flags = 0;
313
314 if (to_wait)
315 flags = IORING_ENTER_GETEVENTS;
e2f309e6 316 if ((*ring->flags & IORING_SQ_NEED_WAKEUP))
b532dd6d 317 flags |= IORING_ENTER_SQ_WAKEUP;
e0abe388 318 ret = io_uring_enter(s, to_submit, to_wait, flags);
ce1705de
JA
319 s->calls++;
320 }
c9fb4c5b 321
ce1705de
JA
322 /*
323 * For non SQ thread poll, we already got the events we needed
324 * through the io_uring_enter() above. For SQ thread poll, we
325 * need to loop here until we find enough events.
326 */
327 this_reap = 0;
328 do {
329 int r;
330 r = reap_events(s);
7d1435e6
JA
331 if (r == -1) {
332 s->finish = 1;
ce1705de 333 break;
7d1435e6 334 } else if (r > 0)
ce1705de
JA
335 this_reap += r;
336 } while (sq_thread_poll && this_reap < to_wait);
c9fb4c5b
JA
337 s->reaps += this_reap;
338
339 if (ret >= 0) {
340 if (!ret) {
341 to_submit = 0;
342 if (s->inflight)
343 goto submit;
344 continue;
345 } else if (ret < to_submit) {
346 int diff = to_submit - ret;
347
348 s->done += ret;
349 prepped -= diff;
350 goto submit_more;
351 }
352 s->done += ret;
353 prepped = 0;
354 continue;
355 } else if (ret < 0) {
ac122fea 356 if (errno == EAGAIN) {
c9fb4c5b
JA
357 if (s->finish)
358 break;
359 if (this_reap)
360 goto submit;
c9fb4c5b
JA
361 to_submit = 0;
362 goto submit;
363 }
ac122fea 364 printf("io_submit: %s\n", strerror(errno));
c9fb4c5b
JA
365 break;
366 }
367 } while (!s->finish);
a7086591 368
c9fb4c5b
JA
369 finish = 1;
370 return NULL;
371}
372
373static void sig_int(int sig)
374{
375 printf("Exiting on signal %d\n", sig);
e39863e3 376 submitter->finish = 1;
c9fb4c5b
JA
377 finish = 1;
378}
379
380static void arm_sig_int(void)
381{
382 struct sigaction act;
383
384 memset(&act, 0, sizeof(act));
385 act.sa_handler = sig_int;
386 act.sa_flags = SA_RESTART;
387 sigaction(SIGINT, &act, NULL);
388}
389
c3e2fc25
JA
390static int setup_ring(struct submitter *s)
391{
e31b8288
JA
392 struct io_sq_ring *sring = &s->sq_ring;
393 struct io_cq_ring *cring = &s->cq_ring;
394 struct io_uring_params p;
2ea53ca3 395 int ret, fd;
c3e2fc25 396 void *ptr;
c3e2fc25
JA
397
398 memset(&p, 0, sizeof(p));
399
7d1435e6 400 if (polled && !do_nop)
0e47f11b 401 p.flags |= IORING_SETUP_IOPOLL;
3d7d00a3 402 if (sq_thread_poll) {
2ea53ca3 403 p.flags |= IORING_SETUP_SQPOLL;
3ade18a3 404 if (sq_thread_cpu != -1) {
3d7d00a3 405 p.flags |= IORING_SETUP_SQ_AFF;
3ade18a3
JA
406 p.sq_thread_cpu = sq_thread_cpu;
407 }
c3e2fc25
JA
408 }
409
e39863e3 410 fd = io_uring_setup(depth, &p);
c3e2fc25
JA
411 if (fd < 0) {
412 perror("io_uring_setup");
413 return 1;
414 }
f310970e 415 s->ring_fd = fd;
2ea53ca3
JA
416
417 if (fixedbufs) {
418 ret = io_uring_register_buffers(s);
419 if (ret < 0) {
a7abc9fb 420 perror("io_uring_register_buffers");
2ea53ca3
JA
421 return 1;
422 }
423 }
424
8c5fa755
JA
425 if (register_files) {
426 ret = io_uring_register_files(s);
427 if (ret < 0) {
428 perror("io_uring_register_files");
429 return 1;
430 }
a7abc9fb
JA
431 }
432
e2239016 433 ptr = mmap(0, p.sq_off.array + p.sq_entries * sizeof(__u32),
f310970e
JA
434 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd,
435 IORING_OFF_SQ_RING);
c3e2fc25
JA
436 printf("sq_ring ptr = 0x%p\n", ptr);
437 sring->head = ptr + p.sq_off.head;
438 sring->tail = ptr + p.sq_off.tail;
439 sring->ring_mask = ptr + p.sq_off.ring_mask;
440 sring->ring_entries = ptr + p.sq_off.ring_entries;
ce1705de 441 sring->flags = ptr + p.sq_off.flags;
ac122fea 442 sring->array = ptr + p.sq_off.array;
c3e2fc25
JA
443 sq_ring_mask = *sring->ring_mask;
444
f0403f94 445 s->sqes = mmap(0, p.sq_entries * sizeof(struct io_uring_sqe),
f310970e 446 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd,
f0403f94
JA
447 IORING_OFF_SQES);
448 printf("sqes ptr = 0x%p\n", s->sqes);
c3e2fc25 449
f0403f94 450 ptr = mmap(0, p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe),
f310970e
JA
451 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd,
452 IORING_OFF_CQ_RING);
c3e2fc25
JA
453 printf("cq_ring ptr = 0x%p\n", ptr);
454 cring->head = ptr + p.cq_off.head;
455 cring->tail = ptr + p.cq_off.tail;
456 cring->ring_mask = ptr + p.cq_off.ring_mask;
457 cring->ring_entries = ptr + p.cq_off.ring_entries;
f0403f94 458 cring->cqes = ptr + p.cq_off.cqes;
c3e2fc25
JA
459 cq_ring_mask = *cring->ring_mask;
460 return 0;
461}
462
2e7888ef
JA
463static void file_depths(char *buf)
464{
e39863e3 465 struct submitter *s = submitter;
2e7888ef
JA
466 char *p;
467 int i;
468
ac21bfab 469 buf[0] = '\0';
2e7888ef
JA
470 p = buf;
471 for (i = 0; i < s->nr_files; i++) {
472 struct file *f = &s->files[i];
473
474 if (i + 1 == s->nr_files)
475 p += sprintf(p, "%d", f->pending_ios);
476 else
477 p += sprintf(p, "%d, ", f->pending_ios);
478 }
479}
480
e39863e3
KB
481static void usage(char *argv)
482{
483 printf("%s [options] -- [filenames]\n"
484 " -d <int> : IO Depth, default %d\n"
485 " -s <int> : Batch submit, default %d\n"
5bd526f2
JA
486 " -c <int> : Batch complete, default %d\n"
487 " -b <int> : Block size, default %d\n"
488 " -p <bool> : Polled IO, default %d\n",
489 argv, DEPTH, BATCH_SUBMIT, BATCH_COMPLETE, BS, polled);
e39863e3
KB
490 exit(0);
491}
492
c9fb4c5b
JA
493int main(int argc, char *argv[])
494{
e39863e3 495 struct submitter *s;
05138221 496 unsigned long done, calls, reap;
e39863e3 497 int err, i, flags, fd, opt;
2e7888ef 498 char *fdepths;
c3e2fc25 499 void *ret;
c9fb4c5b 500
8025517d 501 if (!do_nop && argc < 2) {
e39863e3 502 printf("%s: filename [options]\n", argv[0]);
c9fb4c5b
JA
503 return 1;
504 }
505
5bd526f2 506 while ((opt = getopt(argc, argv, "d:s:c:b:p:h?")) != -1) {
e39863e3
KB
507 switch (opt) {
508 case 'd':
509 depth = atoi(optarg);
510 break;
511 case 's':
512 batch_submit = atoi(optarg);
513 break;
514 case 'c':
515 batch_complete = atoi(optarg);
516 break;
5bd526f2
JA
517 case 'b':
518 bs = atoi(optarg);
519 break;
520 case 'p':
521 polled = !!atoi(optarg);
522 break;
e39863e3
KB
523 case 'h':
524 case '?':
525 default:
526 usage(argv[0]);
527 break;
528 }
529 }
530
d9c50de7
KB
531 submitter = malloc(sizeof(*submitter) + depth * sizeof(struct iovec));
532 memset(submitter, 0, sizeof(*submitter) + depth * sizeof(struct iovec));
e39863e3
KB
533 s = submitter;
534
701d1277 535 flags = O_RDONLY | O_NOATIME;
a7086591
JA
536 if (!buffered)
537 flags |= O_DIRECT;
538
e39863e3 539 i = optind;
8025517d 540 while (!do_nop && i < argc) {
be26a982 541 struct file *f;
a7086591 542
be26a982
JA
543 if (s->nr_files == MAX_FDS) {
544 printf("Max number of files (%d) reached\n", MAX_FDS);
545 break;
546 }
a7086591
JA
547 fd = open(argv[i], flags);
548 if (fd < 0) {
549 perror("open");
550 return 1;
551 }
be26a982
JA
552
553 f = &s->files[s->nr_files];
48e698fa 554 f->real_fd = fd;
a7086591
JA
555 if (get_file_size(f)) {
556 printf("failed getting size of device/file\n");
557 return 1;
558 }
559 if (f->max_blocks <= 1) {
560 printf("Zero file/device size?\n");
561 return 1;
562 }
563 f->max_blocks--;
564
565 printf("Added file %s\n", argv[i]);
566 s->nr_files++;
567 i++;
568 }
569
b3ce355d
JA
570 if (fixedbufs) {
571 struct rlimit rlim;
572
573 rlim.rlim_cur = RLIM_INFINITY;
574 rlim.rlim_max = RLIM_INFINITY;
575 if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
576 perror("setrlimit");
577 return 1;
578 }
c9fb4c5b
JA
579 }
580
581 arm_sig_int();
582
e39863e3 583 for (i = 0; i < depth; i++) {
c3e2fc25 584 void *buf;
c9fb4c5b 585
5bd526f2 586 if (posix_memalign(&buf, bs, bs)) {
c9fb4c5b
JA
587 printf("failed alloc\n");
588 return 1;
589 }
c3e2fc25 590 s->iovecs[i].iov_base = buf;
5bd526f2 591 s->iovecs[i].iov_len = bs;
c9fb4c5b
JA
592 }
593
c3e2fc25 594 err = setup_ring(s);
c9fb4c5b 595 if (err) {
c3e2fc25 596 printf("ring setup failed: %s, %d\n", strerror(errno), err);
c9fb4c5b
JA
597 return 1;
598 }
c3e2fc25 599 printf("polled=%d, fixedbufs=%d, buffered=%d", polled, fixedbufs, buffered);
e39863e3 600 printf(" QD=%d, sq_ring=%d, cq_ring=%d\n", depth, *s->sq_ring.ring_entries, *s->cq_ring.ring_entries);
c9fb4c5b
JA
601
602 pthread_create(&s->thread, NULL, submitter_fn, s);
603
2e7888ef 604 fdepths = malloc(8 * s->nr_files);
05138221 605 reap = calls = done = 0;
c9fb4c5b
JA
606 do {
607 unsigned long this_done = 0;
608 unsigned long this_reap = 0;
609 unsigned long this_call = 0;
610 unsigned long rpc = 0, ipc = 0;
611
612 sleep(1);
613 this_done += s->done;
614 this_call += s->calls;
615 this_reap += s->reaps;
616 if (this_call - calls) {
617 rpc = (this_done - done) / (this_call - calls);
618 ipc = (this_reap - reap) / (this_call - calls);
191561c1
JA
619 } else
620 rpc = ipc = -1;
2e7888ef 621 file_depths(fdepths);
05138221 622 printf("IOPS=%lu, IOS/call=%ld/%ld, inflight=%u (%s)\n",
c9fb4c5b 623 this_done - done, rpc, ipc, s->inflight,
05138221 624 fdepths);
c9fb4c5b
JA
625 done = this_done;
626 calls = this_call;
627 reap = this_reap;
628 } while (!finish);
629
630 pthread_join(s->thread, &ret);
e31b8288 631 close(s->ring_fd);
2e7888ef 632 free(fdepths);
c9fb4c5b
JA
633 return 0;
634}