Skip to content
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

Small question #1130

Open
MikuChan03 opened this issue Apr 17, 2024 · 3 comments
Open

Small question #1130

MikuChan03 opened this issue Apr 17, 2024 · 3 comments

Comments

@MikuChan03
Copy link

I'm wondering, do we really need the io_uring_smp_load_acquire barrier? As I understand it, while the code in the following if statement might be executed speculatively, the side effects of that execution are only supposed to be visible to other threads when it is clear that the condition is met.

Removing the barrier, I have compiled liburing on a weakly ordered armv7 and run the tests repeatedly. No error occurred.

/*
 * Return an sqe to fill. Application must later call io_uring_submit()
 * when it's ready to tell the kernel about it. The caller may call this
 * function multiple times before calling io_uring_submit().
 *
 * Returns a vacant sqe, or NULL if we're full.
 */
IOURINGINLINE struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
{
        struct io_uring_sq *sq = &ring->sq;
        unsigned int head, next = sq->sqe_tail + 1;
        int shift = 0;

        if (ring->flags & IORING_SETUP_SQE128)
                shift = 1;
        if (!(ring->flags & IORING_SETUP_SQPOLL))
                head = *sq->khead;
        else
                head = io_uring_smp_load_acquire(sq->khead);

        if (next - head <= sq->ring_entries) {
                struct io_uring_sqe *sqe;

                sqe = &sq->sqes[(sq->sqe_tail & sq->ring_mask) << shift];
                sq->sqe_tail = next;
                io_uring_initialize_sqe(sqe);
                return sqe;
        }

        return NULL;
}
@axboe
Copy link
Owner

axboe commented Apr 17, 2024

Don't think it's needed in practice, io_uring_get_sqe() isn't thread safe to begin with. Care to send a patch?

@MikuChan03
Copy link
Author

Right away, you'll have it shortly!

@MikuChan03
Copy link
Author

@axboe It's here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants