cq-size.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: test CQ ring sizing
  5. */
  6. #include <errno.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <fcntl.h>
  12. #include "liburing.h"
  13. #include "helpers.h"
  14. int main(int argc, char *argv[])
  15. {
  16. struct io_uring_params p;
  17. struct io_uring ring;
  18. int ret;
  19. if (argc > 1)
  20. return T_EXIT_SKIP;
  21. memset(&p, 0, sizeof(p));
  22. p.flags = IORING_SETUP_CQSIZE;
  23. p.cq_entries = 64;
  24. ret = io_uring_queue_init_params(4, &ring, &p);
  25. if (ret) {
  26. if (ret == -EINVAL) {
  27. printf("Skipped, not supported on this kernel\n");
  28. goto done;
  29. }
  30. printf("ring setup failed\n");
  31. return T_EXIT_FAIL;
  32. }
  33. if (p.cq_entries < 64) {
  34. printf("cq entries invalid (%d)\n", p.cq_entries);
  35. goto err;
  36. }
  37. io_uring_queue_exit(&ring);
  38. memset(&p, 0, sizeof(p));
  39. p.flags = IORING_SETUP_CQSIZE;
  40. p.cq_entries = 0;
  41. ret = io_uring_queue_init_params(4, &ring, &p);
  42. if (ret >= 0) {
  43. printf("zero sized cq ring succeeded\n");
  44. io_uring_queue_exit(&ring);
  45. goto err;
  46. }
  47. if (ret != -EINVAL) {
  48. printf("io_uring_queue_init_params failed, but not with -EINVAL"
  49. ", returned error %d (%s)\n", ret, strerror(-ret));
  50. goto err;
  51. }
  52. done:
  53. return T_EXIT_PASS;
  54. err:
  55. return T_EXIT_FAIL;
  56. }