Behavior of io_uring_submit with unprepared SQEs #1483
Answered
by
krisman
DigoqueDigo
asked this question in
Q&A
Replies: 1 comment
-
|
Diogo Marques ***@***.***> writes:
The man page for [`io_uring_queue_submit`](https://man7.org/linux/man-pages/man3/io_uring_submit.3.html) says:
> After the caller retrieves a submission queue entry (SQE) with
> [io_uring_get_sqe(3)](https://man7.org/linux/man-pages/man3/io_uring_get_sqe.3.html)
> and prepares the SQE using one of the provided helpers, it can be
> submitted with
> [io_uring_submit(3)](https://man7.org/linux/man-pages/man3/io_uring_submit.3.html).
In this code, the next available submission queue entry is retrieved
until it returns `null`, and finally a submit is performed. Considering
that no SQE was actually prepared, how is it possible that
`io_uring_submit` returns `2`? This seems to indicate that 2 SQEs were
prepared, when in fact that did not happen.
Perhaps this is expected behavior, but it seems illogical to me.
It is expected behavior. io_urig_get_sqe gives you an SQE to fill, and
advances the userspace tail, indicating this sqe is "pending
submission". You are supposed to fill this sqe *before* calling
io_uring_submit. If you don't, io_uring will gladly submit everything
that is pending and you'll get an error CQE when it is processed,
indicating you submitted an invalid request.
io_uring_submit is basically telling the kernel you are done preparing
the SQEs and the kernel can try to execute them. You are required to
prepare them before calling io_uring_submit. It returns the number of
SQEs that were submitted to the kernel, not what was already executed.
… ```c
struct io_uring ring;
if (io_uring_queue_init(2, &ring, 0) < 0) {
exit(1);
}
struct io_uring_sqe* sqe = io_uring_get_sqe(&ring);
std::cout << sqe << std::endl;
sqe = io_uring_get_sqe(&ring);
std::cout << sqe << std::endl;
sqe = io_uring_get_sqe(&ring);
std::cout << sqe << std::endl;
int submitted = io_uring_submit(&ring);
std::cout << submitted << std::endl;
exit(1);
```
```
$ ./foo
0x7f14e3b5f000
0x7f14e3b5f040
0
2
--
Gabriel Krisman Bertazi
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
DigoqueDigo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The man page for
io_uring_queue_submitsays:In this code, the next available submission queue entry is retrieved until it returns
null, and finally a submit is performed. Considering that no SQE was actually prepared, how is it possible thatio_uring_submitreturns2? This seems to indicate that 2 SQEs were prepared, when in fact that did not happen.Perhaps this is expected behavior, but it seems illogical to me.
Beta Was this translation helpful? Give feedback.
All reactions