sqpoll-sleep.c 901 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Test that the sqthread goes to sleep around the specified time, and that
  5. * the NEED_WAKEUP flag is then set.
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <sys/time.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 timeval tv;
  18. struct io_uring ring;
  19. int ret;
  20. if (argc > 1)
  21. return 0;
  22. p.flags = IORING_SETUP_SQPOLL;
  23. p.sq_thread_idle = 100;
  24. ret = io_uring_queue_init_params(1, &ring, &p);
  25. if (ret) {
  26. if (geteuid()) {
  27. printf("%s: skipped, not root\n", argv[0]);
  28. return 0;
  29. }
  30. fprintf(stderr, "queue_init=%d\n", ret);
  31. return 1;
  32. }
  33. gettimeofday(&tv, NULL);
  34. do {
  35. usleep(1000);
  36. if ((*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP)
  37. return 0;
  38. } while (mtime_since_now(&tv) < 1000);
  39. return 1;
  40. }