liburing
liburing copied to clipboard
why io_uring_wait_cqe_nr (&ring, cqe_ptr, 10) only fill cqe_ptr[0], how to get others?
io_uring_wait_cqe_nr (&ring, cqe_ptr, 10) , why only fill cqe_ptr[0], cqe_ptr[1~9] is nullptr, how to get others cqe?
what is the specific meaning of this function?
It returns the next CQE, but if there is no error then there will be 10 available.
If you want a batch you could use io_uring_peek_batch_cqe
(which actually needs a man page I notice).
As Dylan said, it only returns the first one directly. Then you can iterate with eg io_uring_for_each_cqe() and advance the ring with io_uring_cq_advance() once done. Here's an example where we wait for 10 CQEs and then iterate/process them, and finally mark all of them seen in the ring as a single operation:
ret = io_uring_wait_cqe_nr(&ring, &cqe, 10);
assert(!ret);
nr = 0;
/* iterate all the CQEs we got, should be at least 10 */
io_uring_for_each_cqe(&ring, head, cqe) {
printf("Got cqe %ld\n", (long) cqe->user_data);
nr++;
}
/* now advance CQ ring, we've seen 'nr' CQEs */
io_uring_cq_advance(&ring, nr);
As Dylan said, it only returns the first one directly. Then you can iterate with eg io_uring_for_each_cqe() and advance the ring with io_uring_cq_advance() once done. Here's an example where we wait for 10 CQEs and then iterate/process them, and finally mark all of them seen in the ring as a single operation:
ret = io_uring_wait_cqe_nr(&ring, &cqe, 10); assert(!ret); nr = 0; /* iterate all the CQEs we got, should be at least 10 */ io_uring_for_each_cqe(&ring, head, cqe) { printf("Got cqe %ld\n", (long) cqe->user_data); nr++; } /* now advance CQ ring, we've seen 'nr' CQEs */ io_uring_cq_advance(&ring, nr);
About the note "should be at least 10", does it mean that io_uring_for_each_cqe
will iterate for more than 10 cqes if there are already more than 10 IO requests finished before calling to io_uring_wait_cqes()?
About the note "should be at least 10", does it mean that
io_uring_for_each_cqe
will iterate for more than 10 cqes if there are already more than 10 IO requests finished before calling to io_uring_wait_cqes()?
io_uring_for_each_cqe
will iterate over all CQEs that were completed by that point, and we expect at least 10 because we waited for them.
thanks;