nop-all-sizes.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: exercise full filling of SQ and CQ ring
  5. *
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <fcntl.h>
  13. #include "liburing.h"
  14. #define MAX_ENTRIES 32768
  15. static int fill_nops(struct io_uring *ring)
  16. {
  17. struct io_uring_sqe *sqe;
  18. int filled = 0;
  19. do {
  20. sqe = io_uring_get_sqe(ring);
  21. if (!sqe)
  22. break;
  23. io_uring_prep_nop(sqe);
  24. filled++;
  25. } while (1);
  26. return filled;
  27. }
  28. static int test_nops(struct io_uring *ring)
  29. {
  30. struct io_uring_cqe *cqe;
  31. int ret, nr, total = 0, i;
  32. nr = fill_nops(ring);
  33. ret = io_uring_submit(ring);
  34. if (ret != nr) {
  35. fprintf(stderr, "submit %d, wanted %d\n", ret, nr);
  36. goto err;
  37. }
  38. total += ret;
  39. nr = fill_nops(ring);
  40. ret = io_uring_submit(ring);
  41. if (ret != nr) {
  42. fprintf(stderr, "submit %d, wanted %d\n", ret, nr);
  43. goto err;
  44. }
  45. total += ret;
  46. for (i = 0; i < total; i++) {
  47. ret = io_uring_wait_cqe(ring, &cqe);
  48. if (ret < 0) {
  49. fprintf(stderr, "wait completion %d\n", ret);
  50. goto err;
  51. }
  52. io_uring_cqe_seen(ring, cqe);
  53. }
  54. return 0;
  55. err:
  56. return 1;
  57. }
  58. int main(int argc, char *argv[])
  59. {
  60. struct io_uring ring;
  61. int ret, depth;
  62. if (argc > 1)
  63. return 0;
  64. depth = 1;
  65. while (depth <= MAX_ENTRIES) {
  66. ret = io_uring_queue_init(depth, &ring, 0);
  67. if (ret) {
  68. if (ret == -ENOMEM)
  69. break;
  70. fprintf(stderr, "ring setup failed: %d\n", ret);
  71. return 1;
  72. }
  73. ret = test_nops(&ring);
  74. if (ret) {
  75. fprintf(stderr, "test_single_nop failed\n");
  76. return ret;
  77. }
  78. depth <<= 1;
  79. io_uring_queue_exit(&ring);
  80. }
  81. return 0;
  82. }