* Run a shared buffer ring test with the given parameters. */
| 180 | * Run a shared buffer ring test with the given parameters. |
| 181 | */ |
| 182 | static int run_shared_test(int nr_bufs, int *sends_per_stream) |
| 183 | { |
| 184 | struct test_ctx ctx = { }; |
| 185 | struct sender_ctx senders[NR_STREAMS]; |
| 186 | pthread_t threads[NR_STREAMS]; |
| 187 | pthread_barrier_t barrier; |
| 188 | struct __kernel_timespec ts = { .tv_sec = 5 }; |
| 189 | int ret, i, done = 0; |
| 190 | |
| 191 | ret = io_uring_queue_init(128, &ctx.ring, 0); |
| 192 | if (ret) { |
| 193 | fprintf(stderr, "ring setup: %d\n", ret); |
| 194 | return T_EXIT_FAIL; |
| 195 | } |
| 196 | |
| 197 | ret = setup_streams(&ctx); |
| 198 | if (ret) { |
| 199 | io_uring_queue_exit(&ctx.ring); |
| 200 | return T_EXIT_FAIL; |
| 201 | } |
| 202 | |
| 203 | ret = setup_buf_ring(&ctx, nr_bufs); |
| 204 | if (ret == -EINVAL || ret == -ENOENT) { |
| 205 | no_buf_ring = 1; |
| 206 | close_streams(&ctx); |
| 207 | io_uring_queue_exit(&ctx.ring); |
| 208 | return T_EXIT_SKIP; |
| 209 | } |
| 210 | if (ret) { |
| 211 | close_streams(&ctx); |
| 212 | io_uring_queue_exit(&ctx.ring); |
| 213 | return T_EXIT_FAIL; |
| 214 | } |
| 215 | |
| 216 | for (i = 0; i < NR_STREAMS; i++) |
| 217 | ctx.streams[i].nr_sends = sends_per_stream[i]; |
| 218 | |
| 219 | pthread_barrier_init(&barrier, NULL, NR_STREAMS + 1); |
| 220 | |
| 221 | for (i = 0; i < NR_STREAMS; i++) { |
| 222 | senders[i].barrier = &barrier; |
| 223 | senders[i].stream = &ctx.streams[i]; |
| 224 | senders[i].stream_id = i; |
| 225 | pthread_create(&threads[i], NULL, sender_fn, &senders[i]); |
| 226 | } |
| 227 | |
| 228 | /* Arm multishot recv on all streams */ |
| 229 | for (i = 0; i < NR_STREAMS; i++) |
| 230 | arm_recv(&ctx.ring, ctx.streams[i].recv_fd, i); |
| 231 | |
| 232 | ret = io_uring_submit(&ctx.ring); |
| 233 | if (ret != NR_STREAMS) { |
| 234 | fprintf(stderr, "submit: %d\n", ret); |
| 235 | goto err; |
| 236 | } |
| 237 | |
| 238 | /* Release all senders */ |
| 239 | pthread_barrier_wait(&barrier); |