-
Notifications
You must be signed in to change notification settings - Fork 411
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
stronger memory load acquire when reading the wakeup flag #219
Comments
If you agree, may I submit a PR to fix the man page and |
I think the comment talks about something else. The barrier happens at |
Thanks @romange, this is about |
@jorangreef Not trying to argue or anything - I am really not in expert in memory ordering.. Also I do not know io_uring code so I could be easily wrong. I think there is a bigger issue here and it's not related to barrier...
2.What confused me here is that this code:
should not require any ordering since it does not depend on any data besides
which signals user thread to waken him. However, this could happen: I am assuming that the kernel can not guarantee atomicity (i.e. transactional semantics) of multiple statements with respect to userland threads but maybe I am wrong. But If I am not wrong then the problem with the interface and not with memory barriers. There is a wonderful lock-free algorithm that is called event-count that can solve this issue but it requires more that just a bit in an integer. |
Specifically, the question is whether a userland thread can run when if it can - we have a bug that requires a different algorithm than just atomic.set/get |
The wakeup flag is ordered with the SQ ring kernel tail read, so as far as I can tell the logic should be sound. The kernel checks if it should go to sleep after setting |
You are right, I missed the piece where kernel checks the tail. So the ordering is around the tail which synchronizes both threads. |
Thanks for double checking. |
This has been an interesting thought exercise. Is this comment in the man page still correct then?
I think this should then be changed to |
@axboe, The man page for
io_uring_setup.2
recently added the rationale for usingmemory load acquire
semantics when checkingsq_ring->flags
:However, looking closer, just after the comment, the actual semantics being used in the example above are
atomic_load_relaxed
instead ofatomic_load_acquire
?The same might also be the case in
queue.c
for the implementation ofsq_ring_needs_enter()
, which usesIO_URING_READ_ONCE(*ring->sq.kflags)
.To avoid I/O starvation, maybe a stronger barrier such as
acquire
is needed here instead ofrelaxed
?The text was updated successfully, but these errors were encountered: