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

std: linux uring kernel interfaces #2525

Merged
merged 4 commits into from
Jun 10, 2019
Merged

Conversation

daurnimator
Copy link
Contributor

@daurnimator daurnimator commented May 20, 2019

This branch contains the start of a uring based command buffer structure.
Currently only implemented for linux (and needs kernel 5.1+); I have plans to modify/extend the interface to other operating systems and older linux versions.

Early commits on the branch are fixes for other areas, please consider cherry-picking them now even if the final commit is too much to review right away!

std/os.zig Outdated
// kernel has the matching store barrier for the update. The
// kernel also ensures that previous stores to CQEs are ordered
// with the tail update.
@fence(.SeqCst);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what sort of fence these should be. The upstream examples use these definitions: http://git.kernel.dk/cgit/liburing/tree/src/barrier.h

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has acquire semantics for loads and release semantics for stores, see here.

On x86 that means you don't need synchronization due to its memory model but on e.g. arm64 you'd insert ldar and stlr instructions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After seeing some commits

2019-04-30 | io_uring: remove unnecessary barrier after unsetting IORING_SQ_NEED_WAKEUP | Stefan Bühler
2019-04-30 | io_uring: remove unnecessary barrier after incrementing dropped counter | Stefan Bühler
2019-04-30 | io_uring: remove unnecessary barrier before reading SQ tail | Stefan Bühler
2019-04-30 | io_uring: remove unnecessary barrier after updating SQ head | Stefan Bühler
2019-04-30 | io_uring: remove unnecessary barrier before reading cq head | Stefan Bühler
2019-04-30 | io_uring: remove unnecessary barrier before wq_has_sleeper | Stefan Bühler

I'm not sure if that comment is still true? @stbuehler ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. The standard way would be using acquire on cq.khead here, which would order the load on cq.khead before all other loads following, especially those reading the CQE.

A SeqCst fence is basically a full memory barrier afaik, and should work of course; an Acquire fence should work too, or a simple read memory barrier.

I didn't bother fixing liburing, because I'm not that crazy about C, and liburing doesn't have atomic/fences - it only knows the barriers you linked (it probably should use C11 atomics instead, and then it should be easy).

You can see my proof-of-concept code for rust here (for now): https://github.com/stbuehler/rust-io-uring/blob/wip/io-uring/src/lib.rs

@daurnimator daurnimator force-pushed the uring branch 2 times, most recently from 0574a6c to 162af88 Compare May 20, 2019 16:02
@daurnimator daurnimator changed the title std: uring basics std: linux uring kernel interfaces Jun 2, 2019
@daurnimator
Copy link
Contributor Author

I've taken the wrapper out of this PR, I'll send it as another PR soon.
This PR is now just the linux kernel structures for uring.

std/os/linux.zig Outdated Show resolved Hide resolved
std/os/linux.zig Outdated Show resolved Hide resolved
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to change, everything else looks good.

std/os/bits/linux.zig Outdated Show resolved Hide resolved
@andrewrk andrewrk merged commit 9c2ed8d into ziglang:master Jun 10, 2019
@daurnimator daurnimator deleted the uring branch June 10, 2019 04:43
@daurnimator daurnimator mentioned this pull request Aug 17, 2019
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

Successfully merging this pull request may close these issues.

5 participants