• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Test that we exit properly with SQPOLL and having a request that
3  * adds a circular reference to the ring itself.
4  */
5 #include <errno.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/time.h>
10 #include <sys/poll.h>
11 #include "liburing.h"
12 
mtime_since(const struct timeval * s,const struct timeval * e)13 static unsigned long long mtime_since(const struct timeval *s,
14 				      const struct timeval *e)
15 {
16 	long long sec, usec;
17 
18 	sec = e->tv_sec - s->tv_sec;
19 	usec = (e->tv_usec - s->tv_usec);
20 	if (sec > 0 && usec < 0) {
21 		sec--;
22 		usec += 1000000;
23 	}
24 
25 	sec *= 1000;
26 	usec /= 1000;
27 	return sec + usec;
28 }
29 
mtime_since_now(struct timeval * tv)30 static unsigned long long mtime_since_now(struct timeval *tv)
31 {
32 	struct timeval end;
33 
34 	gettimeofday(&end, NULL);
35 	return mtime_since(tv, &end);
36 }
37 
main(int argc,char * argv[])38 int main(int argc, char *argv[])
39 {
40 	struct io_uring_params p = {};
41 	struct timeval tv;
42 	struct io_uring ring;
43 	struct io_uring_sqe *sqe;
44 	int ret;
45 
46 	if (argc > 1)
47 		return 0;
48 
49 	p.flags = IORING_SETUP_SQPOLL;
50 	p.sq_thread_idle = 100;
51 
52 	ret = io_uring_queue_init_params(1, &ring, &p);
53 	if (ret) {
54 		if (geteuid()) {
55 			printf("%s: skipped, not root\n", argv[0]);
56 			return 0;
57 		}
58 		fprintf(stderr, "queue_init=%d\n", ret);
59 		return 1;
60 	}
61 
62 	if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
63 		fprintf(stdout, "Skipping\n");
64 		return 0;
65 	}
66 
67 	sqe = io_uring_get_sqe(&ring);
68 	io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
69 	io_uring_submit(&ring);
70 
71 	gettimeofday(&tv, NULL);
72 	do {
73 		usleep(1000);
74 	} while (mtime_since_now(&tv) < 1000);
75 
76 	return 0;
77 }
78