Skip to content

liburing, man: make io_uring_sqring_wait() more consistent with API #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions man/io_uring_sqring_wait.3
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ This feature can only be used when the ring has been setup with
and hence is using an offloaded approach to request submissions.

.SH RETURN VALUE
On success it returns the free space. If the kernel does not support the
feature, -EINVAL is returned.
On success it returns an amount of free entries in the SQ ring. If the kernel
does not support the feature, or the ring was not setup with
.B IORING_SETUP_SQPOLL,
-EINVAL is returned.
.SH SEE ALSO
.BR io_uring_submit (3),
.BR io_uring_wait_cqe (3),
Expand Down
27 changes: 19 additions & 8 deletions src/include/liburing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1093,20 +1093,31 @@ static inline unsigned io_uring_sq_space_left(const struct io_uring *ring)
}

/*
* Only applicable when using SQPOLL - allows the caller to wait for space
* to free up in the SQ ring, which happens when the kernel side thread has
* consumed one or more entries. If the SQ ring is currently non-full, no
* action is taken. Note: may return -EINVAL if the kernel doesn't support
* Only applicable when using SQPOLL - allows the caller to wait for an at
* least one free entry in the SQ ring, which happens when the kernel side
* thread has consumed one or more entries. If the SQ ring is currently
* non-full, no waiting occured and an amout of free entries is returned
* immediately. Note: may also return -EINVAL if the kernel doesn't support
* this feature.
*/
static inline int io_uring_sqring_wait(struct io_uring *ring)
{
int ret;

if (!(ring->flags & IORING_SETUP_SQPOLL))
return 0;
if (io_uring_sq_space_left(ring))
return 0;
return -EINVAL;

do {
ret = io_uring_sq_space_left(ring);
if (ret)
break;

ret = __io_uring_sqring_wait(ring);
if (ret < 0)
return ret;
} while (ret == 0);

return __io_uring_sqring_wait(ring);
return ret;
}

/*
Expand Down