I want to experiment io_uring on the github project: https://github.com/alexhultman/io_uring_epoll_benchmark
referrence: https://unixism.net/loti/ref-liburing/completion.html
however I stumbled upon 2 functions:
unsigned io_uring_peek_batch_cqe(struct io_uring *ring, struct io_uring_cqe **cqes, unsigned count)
int io_uring_wait_cqe_nr(struct io_uring *ring, struct io_uring_cqe **cqe_ptr, unsigned wait_nr)
I understand that the first functions will fills in an array of I/O completions up to count to the cqes and will return regardless of how many cqes completions
However the second functions only fills in one I/O completions to the cqes even I wait for wait_nr completions, why is this so, if it wait for specific number of cqes completions, why i didn't fill in the array of I/O like the first function did?
like example i create: #define MAX_BATCH 2000
struct io_uring_cqe **cqes = malloc(sizeof(struct io_uring_cqe *) * MAX_BATCH);
if I run on the first function, i could access cqes[i] i = (0 to completions)
if I run on the second function, I can only access cqes[i] i = 0
I need to understand why the second function never update the array of cqes like the first function did
I've solved it, As the second function:
int io_uring_wait_cqe_nr(struct io_uring *ring, struct io_uring_cqe **cqe_ptr, unsigned wait_nr)
will wait until for wait_nr completions cqe to complete before moving on, and it will return cqe I/O completions and update only the first array of cqes, which is cqes[0],
But for the first function:
unsigned io_uring_peek_batch_cqe(struct io_uring *ring, struct io_uring_cqe **cqes, unsigned count)
will return regardless whether or not theres a cqe, and will return the numbers of cqes and the array of cqes I/O
After checking the struct of cqes whether the asynchronous was done properly, mark it with the function:
void io_uring_cq_advance(struct io_uring *ring, struct io_uring_cqe *cqe, unsigned count) to free up the cqes entries so the next cqes will point to cqes[0]